diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 8a716ed4ccaf..e408c0437918 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -14968,8 +14968,11 @@ void Sema::MarkVTableUsed(SourceLocation Loc, CXXRecordDecl *Class, // region. if (LangOpts.OpenMP && LangOpts.OpenMPIsDevice && !isInOpenMPDeclareTargetContext() && - !isInOpenMPTargetExecutionDirective()) + !isInOpenMPTargetExecutionDirective()) { + if (!DefinitionRequired) + MarkVirtualMembersReferenced(Loc, Class); return; + } // Try to insert this class into the map. LoadExternalVTableUses(); diff --git a/clang/test/OpenMP/declare_target_codegen.cpp b/clang/test/OpenMP/declare_target_codegen.cpp index 70da60a422e5..cc7525a44b20 100644 --- a/clang/test/OpenMP/declare_target_codegen.cpp +++ b/clang/test/OpenMP/declare_target_codegen.cpp @@ -180,6 +180,30 @@ void B::virtual_foo() { {} } +struct A { + virtual void emitted() {} +}; + +template +struct C : public A { + virtual void emitted(); +}; + +template +void C::emitted() { +#pragma omp target + {} +} + +int main() { + A *X = new C(); + X->emitted(); + return 0; +} + +// CHECK-DAG: define {{.*}}void @__omp_offloading_{{.*}}virtual_foo{{.*}}_l[[@LINE-25]]() +// CHECK-DAG: define {{.*}}void @__omp_offloading_{{.*}}emitted{{.*}}_l[[@LINE-11]]() + // CHECK-DAG: declare extern_weak signext i32 @__create() // CHECK-NOT: define {{.*}}{{baz1|baz4|maini1|Base|virtual_}}