]> granicus.if.org Git - clang/commitdiff
[OPENMP]Fix lookup of the user-defined reductions in C.
authorAlexey Bataev <a.bataev@hotmail.com>
Thu, 4 Apr 2019 17:28:22 +0000 (17:28 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Thu, 4 Apr 2019 17:28:22 +0000 (17:28 +0000)
Fixed the regression of the lookup of user-defined reductions for C.

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

lib/Sema/SemaOpenMP.cpp
test/OpenMP/declare_reduction_ast_print.c

index 9a9bdfaaf5d23ba4b05aa40d19d0b441289a66dd..1ab0e0117f723592ee9ef4ec451be0e5d9a2eca8 100644 (file)
@@ -11269,17 +11269,18 @@ buildDeclareReductionRef(Sema &SemaRef, SourceLocation Loc, SourceRange Range,
     }
   }
   // Perform ADL.
-  if (SemaRef.getLangOpts().CPlusPlus) {
+  if (SemaRef.getLangOpts().CPlusPlus)
     argumentDependentLookup(SemaRef, ReductionId, Loc, Ty, Lookups);
-    if (auto *VD = filterLookupForUDReductionAndMapper<ValueDecl *>(
-            Lookups, [&SemaRef, Ty](ValueDecl *D) -> ValueDecl * {
-              if (!D->isInvalidDecl() &&
-                  SemaRef.Context.hasSameType(D->getType(), Ty))
-                return D;
-              return nullptr;
-            }))
-      return SemaRef.BuildDeclRefExpr(VD, VD->getType().getNonReferenceType(),
-                                      VK_LValue, Loc);
+  if (auto *VD = filterLookupForUDReductionAndMapper<ValueDecl *>(
+          Lookups, [&SemaRef, Ty](ValueDecl *D) -> ValueDecl * {
+            if (!D->isInvalidDecl() &&
+                SemaRef.Context.hasSameType(D->getType(), Ty))
+              return D;
+            return nullptr;
+          }))
+    return SemaRef.BuildDeclRefExpr(VD, VD->getType().getNonReferenceType(),
+                                    VK_LValue, Loc);
+  if (SemaRef.getLangOpts().CPlusPlus) {
     if (auto *VD = filterLookupForUDReductionAndMapper<ValueDecl *>(
             Lookups, [&SemaRef, Ty, Loc](ValueDecl *D) -> ValueDecl * {
               if (!D->isInvalidDecl() &&
@@ -11893,7 +11894,8 @@ static bool actOnOMPReductionKindClause(
       S.ActOnUninitializedDecl(RHSVD);
     if (RHSVD->isInvalidDecl())
       continue;
-    if (!RHSVD->hasInit() && DeclareReductionRef.isUnset()) {
+    if (!RHSVD->hasInit() &&
+        (DeclareReductionRef.isUnset() || !S.LangOpts.CPlusPlus)) {
       S.Diag(ELoc, diag::err_omp_reduction_id_not_compatible)
           << Type << ReductionIdRange;
       bool IsDecl = !VD || VD->isThisDeclarationADefinition(Context) ==
index 239b1cfd4432695130578c43597015bcca50a45b..37b722e5f8ca12269dddb77fee8fafc8814e4375 100644 (file)
@@ -43,4 +43,17 @@ int main() {
 }
 // CHECK: }
 
+#pragma omp declare reduction(mymin:int                                        \
+                              : omp_out = omp_out > omp_in ? omp_in : omp_out) \
+    initializer(omp_priv = 2147483647)
+
+int foo(int argc, char **argv) {
+  int x;
+#pragma omp parallel for reduction(mymin : x)
+  for (int i = 0; i < 1000; i++)
+    ;
+  return 0;
+}
+
+// CHECK: #pragma omp parallel for reduction(mymin: x)
 #endif