]> granicus.if.org Git - clang/commitdiff
[OPENMP] Fix PR35873: Fix data-sharing attributes for const variables.
authorAlexey Bataev <a.bataev@hotmail.com>
Fri, 16 Feb 2018 19:16:54 +0000 (19:16 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Fri, 16 Feb 2018 19:16:54 +0000 (19:16 +0000)
Compiler erroneously returned wrong data-sharing attributes for the
constant variables if they have explictly specified attributes.

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

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

index 7015b0119e1139ce44ead4e4e247f18fee76da35..a712a81ee71bf97d92f685252bdfb8b32d37a74f 100644 (file)
@@ -1025,7 +1025,7 @@ DSAStackTy::DSAVarData DSAStackTy::getTopDSA(ValueDecl *D, bool FromParent) {
         D, [](OpenMPClauseKind C) -> bool { return C == OMPC_firstprivate; },
         MatchesAlways, FromParent);
     if (DVarTemp.CKind == OMPC_firstprivate && DVarTemp.RefExpr)
-      return DVar;
+      return DVarTemp;
 
     DVar.CKind = OMPC_shared;
     return DVar;
index d2f3647221c8940c8d76e5a6970f5269ea1b350c..e6199f00eabd4bb8f4f9c7189e9555b77c1d7f42 100644 (file)
@@ -354,9 +354,9 @@ int foo() {return 0;};
 
 // TERM_DEBUG-LABEL: parallel_for
 // CLEANUP: parallel_for
-void parallel_for(float *a, int n) {
+void parallel_for(float *a, const int n) {
   float arr[n];
-#pragma omp parallel for schedule(static, 5) private(arr)
+#pragma omp parallel for schedule(static, 5) private(arr) default(none) firstprivate(n) shared(a)
   // 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{{.*}}()
@@ -370,7 +370,7 @@ void parallel_for(float *a, int n) {
   // CLEANUP:     call void @__kmpc_for_static_init_4u({{.+}})
   // CLEANUP:     call void @__kmpc_for_static_fini({{.+}})
   for (unsigned i = 131071; i <= 2147483647; i += 127)
-    a[i] += foo() + arr[i];
+    a[i] += foo() + arr[i] + n;
 }
 // Check source line corresponds to "#pragma omp parallel for schedule(static, 5)" above:
 // TERM_DEBUG-DAG: [[DBG_LOC_START]] = !DILocation(line: [[@LINE-4]],