[PATCH] D67837: [CUDA][HIP] Fix assertion in Sema::markKnownEmitted with -fopenmp

Yaxun Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 23 08:29:14 PDT 2019


yaxunl updated this revision to Diff 221341.
yaxunl added a comment.

revised by John's comments


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67837/new/

https://reviews.llvm.org/D67837

Files:
  lib/Sema/Sema.cpp
  test/SemaCUDA/openmp-static-func.cu


Index: test/SemaCUDA/openmp-static-func.cu
===================================================================
--- /dev/null
+++ test/SemaCUDA/openmp-static-func.cu
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only \
+// RUN:            -verify -fopenmp %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only \
+// RUN:            -verify -fopenmp -x hip %s
+// expected-no-diagnostics
+
+// Tests there is no assertion in Sema::markKnownEmitted when fopenmp is used
+// with CUDA/HIP host compilation.
+
+static void f() {}
+
+static void g() { f(); }
+
+static void h() { g(); }
Index: lib/Sema/Sema.cpp
===================================================================
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -1503,8 +1503,12 @@
     const llvm::function_ref<bool(Sema &, FunctionDecl *)> IsKnownEmitted) {
   // Nothing to do if we already know that FD is emitted.
   if (IsKnownEmitted(S, OrigCallee)) {
-    assert(!S.DeviceCallGraph.count(OrigCallee));
-    return;
+    // CUDA/HIP and OpenMP both put functions in DeviceCallGraph. A function
+    // not sure to be emitted by one language may be found sure to be emitted
+    // by another language. In that case, we will iterate the call graph and
+    // mark all the callees. Otherwise, do nothing.
+    if (!S.DeviceCallGraph.count(OrigCallee))
+      return;
   }
 
   // We've just discovered that OrigCallee is known-emitted.  Walk our call
@@ -1520,8 +1524,6 @@
   Seen.insert(OrigCallee);
   while (!Worklist.empty()) {
     CallInfo C = Worklist.pop_back_val();
-    assert(!IsKnownEmitted(S, C.Callee) &&
-           "Worklist should not contain known-emitted functions.");
     S.DeviceKnownEmittedFns[C.Callee] = {C.Caller, C.Loc};
     emitDeferredDiags(S, C.Callee, C.Caller);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67837.221341.patch
Type: text/x-patch
Size: 1811 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190923/40923b5e/attachment.bin>


More information about the cfe-commits mailing list