]> granicus.if.org Git - clang/commitdiff
[OPENMP] Handle re-declaration of captured variables in CodeGen.
authorAlexey Bataev <a.bataev@hotmail.com>
Fri, 22 Sep 2017 16:56:13 +0000 (16:56 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Fri, 22 Sep 2017 16:56:13 +0000 (16:56 +0000)
If the captured variable has re-declaration we may end up with the
situation where the captured variable is the re-declaration while the
referenced variable is the canonical declaration (or vice versa). In
this case we may generate wrong code. Patch fixes this situation.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@313995 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenFunction.h
test/OpenMP/target_codegen.cpp

index 33bf74b5d39876fedfa010384561fb13afe94ddb..7dca38059735b1f162d7af611c6f3837f9791aaf 100644 (file)
@@ -263,9 +263,9 @@ public:
         if (I->capturesThis())
           CXXThisFieldDecl = *Field;
         else if (I->capturesVariable())
-          CaptureFields[I->getCapturedVar()] = *Field;
+          CaptureFields[I->getCapturedVar()->getCanonicalDecl()] = *Field;
         else if (I->capturesVariableByCopy())
-          CaptureFields[I->getCapturedVar()] = *Field;
+          CaptureFields[I->getCapturedVar()->getCanonicalDecl()] = *Field;
       }
     }
 
@@ -279,7 +279,7 @@ public:
 
     /// \brief Lookup the captured field decl for a variable.
     virtual const FieldDecl *lookup(const VarDecl *VD) const {
-      return CaptureFields.lookup(VD);
+      return CaptureFields.lookup(VD->getCanonicalDecl());
     }
 
     bool isCXXThisExprCaptured() const { return getThisFieldDecl() != nullptr; }
index 9d68dd4a1e5bd092fee943ab80eb2c8176b3902b..21c82d1cadb7beb99bd99c5cb3bc30b8beb61c4f 100644 (file)
@@ -110,7 +110,7 @@ int foo(int n) {
   // CHECK:       [[RET2:%.+]] = load i32, i32* [[RHV]], align 4
   // CHECK-NEXT:  [[ERROR:%.+]] = icmp ne i32 [[RET2]], 0
   // CHECK:       call void [[HVT1:@.+]](i[[SZ]] {{[^,]+}})
-  #pragma omp target if(0)
+  #pragma omp target if(0) firstprivate(global)
   {
     global += 1;
   }