Author: abataev Date: Wed Aug 29 13:41:37 2018 New Revision: 340968 URL: http://llvm.org/viewvc/llvm-project?rev=340968&view=rev Log: [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. Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp cfe/trunk/test/OpenMP/declare_target_codegen.cpp Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=340968&r1=340967&r2=340968&view=diff ============================================================================== --- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original) +++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Wed Aug 29 13:41:37 2018 @@ -3989,6 +3989,9 @@ void CGOpenMPRuntime::createOffloadEntri 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::registerTargetGlob 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()) { Modified: cfe/trunk/test/OpenMP/declare_target_codegen.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/declare_target_codegen.cpp?rev=340968&r1=340967&r2=340968&view=diff ============================================================================== --- cfe/trunk/test/OpenMP/declare_target_codegen.cpp (original) +++ cfe/trunk/test/OpenMP/declare_target_codegen.cpp Wed Aug 29 13:41:37 2018 @@ -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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits