From 5192e612264da0e1990e81920410da77a10fa43f Mon Sep 17 00:00:00 2001 From: Alexey Bataev Date: Mon, 29 Apr 2019 15:51:36 +0000 Subject: [PATCH] [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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359459 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaOpenMP.cpp | 2 +- test/OpenMP/critical_ast_print.cpp | 38 ++++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/lib/Sema/SemaOpenMP.cpp b/lib/Sema/SemaOpenMP.cpp index 2011c0b927..0aebd8e03a 100644 --- a/lib/Sema/SemaOpenMP.cpp +++ b/lib/Sema/SemaOpenMP.cpp @@ -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; } diff --git a/test/OpenMP/critical_ast_print.cpp b/test/OpenMP/critical_ast_print.cpp index f51145e584..20cb9bf99a 100644 --- a/test/OpenMP/critical_ast_print.cpp +++ b/test/OpenMP/critical_ast_print.cpp @@ -15,28 +15,46 @@ void foo() {} // CHECK: template 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 argc, char **argv) template -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; } -- 2.40.0