yaxunl created this revision.
yaxunl added reviewers: tra, rjmccall.
Herald added a subscriber: guansong.
Herald added a reviewer: jdoerfert.
Herald added a project: clang.
CUDA/HIP program may be compiled with -fopenmp. In this case, -fopenmp is only
passed to host compilation
to take advantages of multi-threads computation.
CUDA/HIP and OpenMP both use Sema::DeviceCallGraph to store functions to be
analyzed and remove them
once they decide the function is sure to be emitted. CUDA/HIP and OpenMP have
different functions to determine
of a function is sure to be emitted.
This patch fixes an assertion which happens when CUDA/HIP is compiled with
-fopenmp.
Repository:
rC Clang
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,7 +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));
+ // 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 this case, just erase it from DeviceCallGraph.
+ auto Loc = S.DeviceCallGraph.find(OrigCallee);
+ if (Loc != S.DeviceCallGraph.end())
+ S.DeviceCallGraph.erase(Loc);
return;
}
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,7 +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));
+ // 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 this case, just erase it from DeviceCallGraph.
+ auto Loc = S.DeviceCallGraph.find(OrigCallee);
+ if (Loc != S.DeviceCallGraph.end())
+ S.DeviceCallGraph.erase(Loc);
return;
}
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits