]> granicus.if.org Git - clang/commitdiff
[OPENMP] Do not create offloading entry for declare target variables
authorAlexey Bataev <a.bataev@hotmail.com>
Wed, 29 Aug 2018 20:41:37 +0000 (20:41 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Wed, 29 Aug 2018 20:41:37 +0000 (20:41 +0000)
declarations.

We should not create offloading entries for declare target var
declarations as it causes compiler crash.

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

lib/CodeGen/CGOpenMPRuntime.cpp
test/OpenMP/declare_target_codegen.cpp

index 050f4a616c33093c65676d0eeecd676cd5872aa6..6c37c6cf115b7a9dbd8c2cd977ec2127a75760fd 100644 (file)
@@ -3989,6 +3989,9 @@ void CGOpenMPRuntime::createOffloadEntriesAndInfoMetadata() {
           CGM.getDiags().Report(DiagID);
           continue;
         }
+        // The vaiable has no definition - no need to add the entry.
+        if (CE->getVarSize().isZero())
+          continue;
         break;
       }
       case OffloadEntriesInfoManagerTy::OMPTargetGlobalVarEntryLink:
@@ -8108,7 +8111,12 @@ void CGOpenMPRuntime::registerTargetGlobalVariable(const VarDecl *VD,
     case OMPDeclareTargetDeclAttr::MT_To:
       Flags = OffloadEntriesInfoManagerTy::OMPTargetGlobalVarEntryTo;
       VarName = CGM.getMangledName(VD);
-      VarSize = CGM.getContext().getTypeSizeInChars(VD->getType());
+      if (VD->hasDefinition(CGM.getContext()) != VarDecl::DeclarationOnly) {
+        VarSize = CGM.getContext().getTypeSizeInChars(VD->getType());
+        assert(!VarSize.isZero() && "Expected non-zero size of the variable");
+      } else {
+        VarSize = CharUnits::Zero();
+      }
       Linkage = CGM.getLLVMLinkageVarDefinition(VD, /*IsConstant=*/false);
       // Temp solution to prevent optimizations of the internal variables.
       if (CGM.getLangOpts().OpenMPIsDevice && !VD->isExternallyVisible()) {
index 0cd611b06f9f63478f0d8504537e64e82bf379b1..b8f03f7e205f475d8ed9f1fb14c0cf0b45ed7461 100644 (file)
@@ -143,4 +143,8 @@ int baz5() {
 // CHECK-DAG: declare extern_weak signext i32 @__create()
 
 // CHECK-NOT: define {{.*}}{{baz1|baz4|maini1}}
+
+// CHECK-DAG: !{i32 1, !"aaa", i32 0, i32 {{[0-9]+}}}
+// CHECK-DAG: !{i32 1, !"ccc", i32 0, i32 {{[0-9]+}}}
+
 #endif // HEADER