From 20e2260b6c99e2bd176757f91f835d9990d10339 Mon Sep 17 00:00:00 2001 From: Alexey Bataev Date: Thu, 6 Sep 2018 17:56:28 +0000 Subject: [PATCH] [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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@341570 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDeclCXX.cpp | 5 +++++ test/OpenMP/declare_target_codegen.cpp | 21 +++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index d3f7af2529..dbca30aa43 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/lib/Sema/SemaDeclCXX.cpp @@ -14903,6 +14903,11 @@ void Sema::MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class, 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(); diff --git a/test/OpenMP/declare_target_codegen.cpp b/test/OpenMP/declare_target_codegen.cpp index 1694ec6072..2475c49d3d 100644 --- a/test/OpenMP/declare_target_codegen.cpp +++ b/test/OpenMP/declare_target_codegen.cpp @@ -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 +struct Base { + virtual ~Base() {} +}; + +template class Base; + +template +struct Bake { + virtual ~Bake() {} +}; + +#pragma omp declare target +template class Bake; +#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]+}}} -- 2.50.1