Author: abataev Date: Thu Sep 6 10:56:28 2018 New Revision: 341570 URL: http://llvm.org/viewvc/llvm-project?rev=341570&view=rev Log: [OPENMP] Fix PR38823: Do not emit vtable if it is not used in target context.
If the explicit template instantiation definition defined outside of the target context, its vtable should not be marked as used. This is true for other situations where the compiler want to emit vtables unconditionally. Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp cfe/trunk/test/OpenMP/declare_target_codegen.cpp Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=341570&r1=341569&r2=341570&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original) +++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Sep 6 10:56:28 2018 @@ -14903,6 +14903,11 @@ void Sema::MarkVTableUsed(SourceLocation if (!Class->isDynamicClass() || Class->isDependentContext() || CurContext->isDependentContext() || isUnevaluatedContext()) return; + // Do not mark as used if compiling for the device outside of the target + // region. + if (LangOpts.OpenMP && LangOpts.OpenMPIsDevice && + !isInOpenMPDeclareTargetContext() && !getCurFunctionDecl()) + return; // Try to insert this class into the map. LoadExternalVTableUses(); 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=341570&r1=341569&r2=341570&view=diff ============================================================================== --- cfe/trunk/test/OpenMP/declare_target_codegen.cpp (original) +++ cfe/trunk/test/OpenMP/declare_target_codegen.cpp Thu Sep 6 10:56:28 2018 @@ -12,7 +12,8 @@ // SIMD-ONLY-NOT: {{__kmpc|__tgt}} -// CHECK-NOT: define {{.*}}{{baz1|baz4|maini1}} +// CHECK-NOT: define {{.*}}{{baz1|baz4|maini1|Base}} +// CHECK-DAG: Bake // CHECK-NOT: @{{hhh|ggg|fff|eee}} = // CHECK-DAG: @aaa = external global i32, // CHECK-DAG: @bbb = global i32 0, @@ -140,9 +141,25 @@ int baz5() { return a; } +template <typename T> +struct Base { + virtual ~Base() {} +}; + +template class Base<int>; + +template <typename T> +struct Bake { + virtual ~Bake() {} +}; + +#pragma omp declare target +template class Bake<int>; +#pragma omp end declare target + // CHECK-DAG: declare extern_weak signext i32 @__create() -// CHECK-NOT: define {{.*}}{{baz1|baz4|maini1}} +// CHECK-NOT: define {{.*}}{{baz1|baz4|maini1|Base}} // CHECK-DAG: !{i32 1, !"aaa", i32 0, i32 {{[0-9]+}}} // CHECK-DAG: !{i32 1, !"ccc", i32 0, i32 {{[0-9]+}}} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits