[OPENMP]Fix PR41617: crash on template instantiation.

Fixed the crash on the template instantiation when trying to check the
data locality in the current instantiation scope.

llvm-svn: 359459
This commit is contained in:
Alexey Bataev
2019-04-29 15:51:36 +00:00
parent 8a02f8d928
commit e66bf6357f
2 changed files with 29 additions and 11 deletions

View File

@@ -1145,7 +1145,7 @@ bool DSAStackTy::isOpenMPLocal(VarDecl *D, iterator Iter) const {
return false;
TopScope = I->CurScope ? I->CurScope->getParent() : nullptr;
Scope *CurScope = getCurScope();
while (CurScope != TopScope && !CurScope->isDeclScope(D))
while (CurScope && CurScope != TopScope && !CurScope->isDeclScope(D))
CurScope = CurScope->getParent();
return CurScope != TopScope;
}

View File

@@ -15,28 +15,46 @@ void foo() {}
// CHECK: template <typename T, int N> int tmain(T argc, char **argv)
// CHECK: static int a;
// CHECK-NEXT: #pragma omp critical{{$}}
// CHECK-NEXT: a = 2;
// CHECK-NEXT: a = argv[0][0];
// CHECK-NEXT: ++a;
// CHECK-NEXT: #pragma omp critical{{$}}
// CHECK-NEXT: {
// CHECK-NEXT: int b = 10;
// CHECK-NEXT: T c = 100;
// CHECK-NEXT: a = b + c;
// CHECK-NEXT: }
// CHECK-NEXT: #pragma omp critical (the_name) hint(N){{$}}
// CHECK-NEXT: foo();
// CHECK-NEXT: return N;
// CHECK: template<> int tmain<int, 4>(int argc, char **argv)
template <typename T, int N>
int tmain (T argc, char **argv) {
int tmain(T argc, char **argv) {
T b = argc, c, d, e, f, g;
static int a;
// CHECK: static int a;
#pragma omp critical
a=2;
// CHECK-NEXT: #pragma omp critical
// CHECK-NEXT: a = 2;
// CHECK-NEXT: ++a;
a = argv[0][0];
++a;
#pragma omp critical (the_name) hint(N)
// CHECK-NEXT: #pragma omp critical
// CHECK-NEXT: a = argv[0][0];
// CHECK-NEXT: ++a;
// CHECK-NEXT: #pragma omp critical{{$}}
// CHECK-NEXT: {
// CHECK-NEXT: int b = 10;
// CHECK-NEXT: int c = 100;
// CHECK-NEXT: a = b + c;
// CHECK-NEXT: }
#pragma omp critical
{
int b = 10;
T c = 100;
a = b + c;
}
#pragma omp critical(the_name) hint(N)
foo();
// CHECK-NEXT: #pragma omp critical (the_name) hint(4)
// CHECK-NEXT: foo();
// CHECK-NEXT: return 4;
// CHECK-NEXT: #pragma omp critical (the_name) hint(4)
// CHECK-NEXT: foo();
// CHECK-NEXT: return 4;
return N;
}