]> granicus.if.org Git - clang/commitdiff
[OPENMP] Fix for http://llvm.org/PR24687: ICE on compilation of R package TPmsm.
authorAlexey Bataev <a.bataev@hotmail.com>
Thu, 3 Sep 2015 10:21:46 +0000 (10:21 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Thu, 3 Sep 2015 10:21:46 +0000 (10:21 +0000)
Fixed capturing of VLAs in 'private' clause of the OpenMP directives.

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

lib/Sema/SemaExpr.cpp
test/OpenMP/parallel_for_codegen.cpp

index 10b37557802de0bcafb2b1ee46d7dafbdf4abb78..bfb98413a8a6f52f04e5730a809fef9b31e678b6 100644 (file)
@@ -13000,21 +13000,6 @@ bool Sema::tryCaptureVariable(
     if (isVariableAlreadyCapturedInScopeInfo(CSI, Var, Nested, CaptureType, 
                                              DeclRefType)) 
       break;
-    if (getLangOpts().OpenMP) {
-      if (auto *RSI = dyn_cast<CapturedRegionScopeInfo>(CSI)) {
-        // OpenMP private variables should not be captured in outer scope, so
-        // just break here.
-        if (RSI->CapRegionKind == CR_OpenMP) {
-          if (isOpenMPPrivateVar(Var, OpenMPLevel)) {
-            Nested = true;
-            DeclRefType = DeclRefType.getUnqualifiedType();
-            CaptureType = Context.getLValueReferenceType(DeclRefType);
-            break;
-          }
-          ++OpenMPLevel;
-        }
-      }
-    }
     // If we are instantiating a generic lambda call operator body, 
     // we do not want to capture new variables.  What was captured
     // during either a lambdas transformation or initial parsing
@@ -13160,6 +13145,21 @@ bool Sema::tryCaptureVariable(
       } while (!QTy.isNull() && QTy->isVariablyModifiedType());
     }
 
+    if (getLangOpts().OpenMP) {
+      if (auto *RSI = dyn_cast<CapturedRegionScopeInfo>(CSI)) {
+        // OpenMP private variables should not be captured in outer scope, so
+        // just break here.
+        if (RSI->CapRegionKind == CR_OpenMP) {
+          if (isOpenMPPrivateVar(Var, OpenMPLevel)) {
+            Nested = true;
+            DeclRefType = DeclRefType.getUnqualifiedType();
+            CaptureType = Context.getLValueReferenceType(DeclRefType);
+            break;
+          }
+          ++OpenMPLevel;
+        }
+      }
+    }
     if (CSI->ImpCaptureStyle == CapturingScopeInfo::ImpCap_None && !Explicit) {
       // No capture-default, and this is not an explicit capture 
       // so cannot capture this variable.  
index 9fda8404c6e7931c4ddfafee15d765558abae722..314ba43ec6bcfb9f07ac7a63fc6b121b17192e15 100644 (file)
@@ -378,8 +378,9 @@ int foo() {return 0;};
 
 // TERM_DEBUG-LABEL: parallel_for
 // CLEANUP: parallel_for
-void parallel_for(float *a) {
-#pragma omp parallel for schedule(static, 5)
+void parallel_for(float *a, int n) {
+  float arr[n];
+#pragma omp parallel for schedule(static, 5) private(arr)
   // TERM_DEBUG-NOT: __kmpc_global_thread_num
   // TERM_DEBUG:     call void @__kmpc_for_static_init_4u({{.+}}), !dbg [[DBG_LOC_START:![0-9]+]]
   // TERM_DEBUG:     invoke i32 {{.*}}foo{{.*}}()
@@ -395,7 +396,7 @@ void parallel_for(float *a) {
   // CLEANUP:     call void @__kmpc_for_static_fini({{.+}})
   // CLEANUP:     call {{.+}} @__kmpc_barrier({{.+}})
   for (unsigned i = 131071; i <= 2147483647; i += 127)
-    a[i] += foo();
+    a[i] += foo() + arr[i];
 }
 // Check source line corresponds to "#pragma omp parallel for schedule(static, 5)" above:
 // TERM_DEBUG-DAG: [[DBG_LOC_START]] = !DILocation(line: [[@LINE-4]],