]> granicus.if.org Git - clang/commitdiff
[OPENMP] Fixed DSA detecting for function parameters: by default they must be private.
authorAlexey Bataev <a.bataev@hotmail.com>
Thu, 24 Jul 2014 02:33:58 +0000 (02:33 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Thu, 24 Jul 2014 02:33:58 +0000 (02:33 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@213835 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 0dbdf16412c299ffb14606010146bf02be4a0821..9c05e9204e629fd459dddc0cd53827310c0e40ca 100644 (file)
@@ -226,7 +226,7 @@ DSAStackTy::DSAVarData DSAStackTy::getDSA(StackTy::reverse_iterator Iter,
     //  File-scope or namespace-scope variables referenced in called routines
     //  in the region are shared unless they appear in a threadprivate
     //  directive.
-    if (!D->isFunctionOrMethodVarDecl())
+    if (!D->isFunctionOrMethodVarDecl() && !isa<ParmVarDecl>(D))
       DVar.CKind = OMPC_shared;
 
     // OpenMP [2.9.1.2, Data-sharing Attribute Rules for Variables Referenced
@@ -393,8 +393,10 @@ DSAStackTy::DSAVarData DSAStackTy::getTopDSA(VarDecl *D, bool FromParent) {
     StartI = std::next(StartI);
   }
   if (!isParallelOrTaskRegion(Kind)) {
-    if (isOpenMPLocal(D, StartI) && D->isLocalVarDecl() &&
-        (D->getStorageClass() == SC_Auto || D->getStorageClass() == SC_None)) {
+    if (isOpenMPLocal(D, StartI) &&
+        ((D->isLocalVarDecl() && (D->getStorageClass() == SC_Auto ||
+                                  D->getStorageClass() == SC_None)) ||
+         isa<ParmVarDecl>(D))) {
       DVar.CKind = OMPC_private;
       return DVar;
     }
index f07ab12bfb46d8ab0ad2fa25f51ec51a63c091e8..7bb145c6d3253f2883c246eaaa418716782d8eae 100644 (file)
@@ -155,3 +155,23 @@ int main(int argc, char **argv) {
 
   return tmain(argc, argv); // expected-note {{in instantiation of function template specialization 'tmain<int, char>' requested here}}
 }
+
+extern void abort(void);
+
+void
+single(int a, int b) {
+#pragma omp single copyprivate(a) copyprivate(b)
+  {
+    a = b = 5;
+  }
+
+  if (a != b)
+    abort();
+}
+
+int parallel() {
+#pragma omp parallel
+  single(1, 2);
+
+  return 0;
+}