From 703fc351e3eb3b737c565bc9fba6ac4a9ee6927e Mon Sep 17 00:00:00 2001 From: Alexey Bataev Date: Wed, 28 Nov 2018 19:00:07 +0000 Subject: [PATCH] [OPENMP]Fix emission of the target regions in virtual functions. Fixed emission of the target regions found in the virtual functions. Previously we may end up with the situation when those regions could be skipped. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@347793 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDeclCXX.cpp | 5 ++++- test/OpenMP/declare_target_codegen.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 8a716ed4cc..e408c04379 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/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/test/OpenMP/declare_target_codegen.cpp b/test/OpenMP/declare_target_codegen.cpp index 70da60a422..cc7525a44b 100644 --- a/test/OpenMP/declare_target_codegen.cpp +++ b/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_}} -- 2.50.1