]> granicus.if.org Git - clang/commitdiff
[OPENMP] Fix assert fail after target implicit map checks.
authorAlexey Bataev <a.bataev@hotmail.com>
Tue, 5 Dec 2017 15:22:49 +0000 (15:22 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Tue, 5 Dec 2017 15:22:49 +0000 (15:22 +0000)
If the error is generated during analysis of implicitly or explicitly
mapped variables, it may cause compiler crash because of incorrect
analysis.

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

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

index 28e40d32e090a389c22897cac74dc6523c0e12e7..e77f908337789adedf537f1c782d9628870af685 100644 (file)
@@ -1996,7 +1996,8 @@ public:
     }
     if (isOpenMPTargetExecutionDirective(DKind) && !FD->isBitField()) {
       OMPClauseMappableExprCommon::MappableExprComponentList CurComponents;
-      CheckMapClauseExpressionBase(SemaRef, E, CurComponents, OMPC_map);
+      if (!CheckMapClauseExpressionBase(SemaRef, E, CurComponents, OMPC_map))
+        return;
       auto *VD = cast<ValueDecl>(
           CurComponents.back().getAssociatedDeclaration()->getCanonicalDecl());
       if (!Stack->checkMappableExprComponentListsForDecl(
@@ -11467,7 +11468,7 @@ static Expr *CheckMapClauseExpressionBase(
 
     if (auto *CurE = dyn_cast<DeclRefExpr>(E)) {
       if (!isa<VarDecl>(CurE->getDecl()))
-        break;
+        return nullptr;
 
       RelevantExpr = CurE;
 
@@ -11477,12 +11478,8 @@ static Expr *CheckMapClauseExpressionBase(
       AllowWholeSizeArraySection = false;
 
       // Record the component.
-      CurComponents.push_back(OMPClauseMappableExprCommon::MappableComponent(
-          CurE, CurE->getDecl()));
-      continue;
-    }
-
-    if (auto *CurE = dyn_cast<MemberExpr>(E)) {
+      CurComponents.emplace_back(CurE, CurE->getDecl());
+    } else if (auto *CurE = dyn_cast<MemberExpr>(E)) {
       auto *BaseE = CurE->getBase()->IgnoreParenImpCasts();
 
       if (isa<CXXThisExpr>(BaseE))
@@ -11494,7 +11491,7 @@ static Expr *CheckMapClauseExpressionBase(
       if (!isa<FieldDecl>(CurE->getMemberDecl())) {
         SemaRef.Diag(ELoc, diag::err_omp_expected_access_to_data_field)
             << CurE->getSourceRange();
-        break;
+        return nullptr;
       }
 
       auto *FD = cast<FieldDecl>(CurE->getMemberDecl());
@@ -11505,7 +11502,7 @@ static Expr *CheckMapClauseExpressionBase(
       if (FD->isBitField()) {
         SemaRef.Diag(ELoc, diag::err_omp_bit_fields_forbidden_in_clause)
             << CurE->getSourceRange() << getOpenMPClauseName(CKind);
-        break;
+        return nullptr;
       }
 
       // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1]
@@ -11521,7 +11518,7 @@ static Expr *CheckMapClauseExpressionBase(
         if (RT->isUnionType()) {
           SemaRef.Diag(ELoc, diag::err_omp_union_type_not_allowed)
               << CurE->getSourceRange();
-          break;
+          return nullptr;
         }
 
       // If we got a member expression, we should not expect any array section
@@ -11535,18 +11532,14 @@ static Expr *CheckMapClauseExpressionBase(
       AllowWholeSizeArraySection = false;
 
       // Record the component.
-      CurComponents.push_back(
-          OMPClauseMappableExprCommon::MappableComponent(CurE, FD));
-      continue;
-    }
-
-    if (auto *CurE = dyn_cast<ArraySubscriptExpr>(E)) {
+      CurComponents.emplace_back(CurE, FD);
+    } else if (auto *CurE = dyn_cast<ArraySubscriptExpr>(E)) {
       E = CurE->getBase()->IgnoreParenImpCasts();
 
       if (!E->getType()->isAnyPointerType() && !E->getType()->isArrayType()) {
         SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name)
             << 0 << CurE->getSourceRange();
-        break;
+        return nullptr;
       }
 
       // If we got an array subscript that express the whole dimension we
@@ -11557,15 +11550,11 @@ static Expr *CheckMapClauseExpressionBase(
         AllowWholeSizeArraySection = false;
 
       // Record the component - we don't have any declaration associated.
-      CurComponents.push_back(
-          OMPClauseMappableExprCommon::MappableComponent(CurE, nullptr));
-      continue;
-    }
-
-    if (auto *CurE = dyn_cast<OMPArraySectionExpr>(E)) {
+      CurComponents.emplace_back(CurE, nullptr);
+    } else if (auto *CurE = dyn_cast<OMPArraySectionExpr>(E)) {
       E = CurE->getBase()->IgnoreParenImpCasts();
 
-      auto CurType =
+      QualType CurType =
           OMPArraySectionExpr::getBaseOriginalType(E).getCanonicalType();
 
       // OpenMP 4.5 [2.15.5.1, map Clause, Restrictions, C++, p.1]
@@ -11579,7 +11568,7 @@ static Expr *CheckMapClauseExpressionBase(
       if (!IsPointer && !CurType->isArrayType()) {
         SemaRef.Diag(ELoc, diag::err_omp_expected_base_var_name)
             << 0 << CurE->getSourceRange();
-        break;
+        return nullptr;
       }
 
       bool NotWhole =
@@ -11602,20 +11591,18 @@ static Expr *CheckMapClauseExpressionBase(
         SemaRef.Diag(
             ELoc, diag::err_array_section_does_not_specify_contiguous_storage)
             << CurE->getSourceRange();
-        break;
+        return nullptr;
       }
 
       // Record the component - we don't have any declaration associated.
-      CurComponents.push_back(
-          OMPClauseMappableExprCommon::MappableComponent(CurE, nullptr));
-      continue;
+      CurComponents.emplace_back(CurE, nullptr);
+    } else {
+      // If nothing else worked, this is not a valid map clause expression.
+      SemaRef.Diag(ELoc,
+                   diag::err_omp_expected_named_var_member_or_array_expression)
+          << ERange;
+      return nullptr;
     }
-
-    // If nothing else worked, this is not a valid map clause expression.
-    SemaRef.Diag(ELoc,
-                 diag::err_omp_expected_named_var_member_or_array_expression)
-        << ERange;
-    break;
   }
 
   return RelevantExpr;
index f607dcf369845ef5ef6dba8cf929c78baa94a857..52a492920fbbb4f47e48134f7105fb5ab6f4448a 100644 (file)
@@ -269,6 +269,10 @@ void SAclient(int arg) {
   {}
   #pragma omp target map(u.B)  // expected-error {{mapped storage cannot be derived from a union}}
   {}
+  #pragma omp target
+  {
+    u.B = 0; // expected-error {{mapped storage cannot be derived from a union}}
+  }
 
   #pragma omp target data map(to: r.C) //expected-note {{used here}}
   {