summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexey Bataev <a.bataev@hotmail.com>2018-08-29 20:41:37 +0000
committerAlexey Bataev <a.bataev@hotmail.com>2018-08-29 20:41:37 +0000
commitb4dd6d24d7567869e66e901b02d886095b87525d (patch)
tree1545608586f1a2bf0d525db7483de0b6bb0ca55e
parent0e9a76dbe3b4beeb5d326070834f16826e0c74a1 (diff)
downloadbcm5719-llvm-b4dd6d24d7567869e66e901b02d886095b87525d.tar.gz
bcm5719-llvm-b4dd6d24d7567869e66e901b02d886095b87525d.zip
[OPENMP] Do not create offloading entry for declare target variables
declarations. We should not create offloading entries for declare target var declarations as it causes compiler crash. llvm-svn: 340968
-rw-r--r--clang/lib/CodeGen/CGOpenMPRuntime.cpp10
-rw-r--r--clang/test/OpenMP/declare_target_codegen.cpp4
2 files changed, 13 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 050f4a616c3..6c37c6cf115 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -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()) {
diff --git a/clang/test/OpenMP/declare_target_codegen.cpp b/clang/test/OpenMP/declare_target_codegen.cpp
index 0cd611b06f9..b8f03f7e205 100644
--- a/clang/test/OpenMP/declare_target_codegen.cpp
+++ b/clang/test/OpenMP/declare_target_codegen.cpp
@@ -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
OpenPOWER on IntegriCloud