]> granicus.if.org Git - clang/commitdiff
[OPENMP]Fix emission of the target regions in virtual functions.
authorAlexey Bataev <a.bataev@hotmail.com>
Wed, 28 Nov 2018 19:00:07 +0000 (19:00 +0000)
committerAlexey Bataev <a.bataev@hotmail.com>
Wed, 28 Nov 2018 19:00:07 +0000 (19:00 +0000)
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
test/OpenMP/declare_target_codegen.cpp

index 8a716ed4ccaf73871c3e5fd3abd9c5ea775517e2..e408c0437918412d9596c921de48542d874f005f 100644 (file)
@@ -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();
index 70da60a422e52f1b3a78a52536c94feb1c3df430..cc7525a44b20ea72b019be5d01055678b0c5bbbe 100644 (file)
@@ -180,6 +180,30 @@ void B<T>::virtual_foo() {
   {}
 }
 
+struct A {
+  virtual void emitted() {}
+};
+
+template <typename T>
+struct C : public A {
+  virtual void emitted();
+};
+
+template <typename T>
+void C<T>::emitted() {
+#pragma omp target
+  {}
+}
+
+int main() {
+  A *X = new C<int>();
+  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_}}