[clang] [clang][CUDA] Assume unknown emission status for skipped function definitions (PR #100124)

kadir çetinkaya via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 23 06:50:10 PDT 2024


https://github.com/kadircet created https://github.com/llvm/llvm-project/pull/100124

Emission status seems to be only used by cuda/openmp/hip compiles, to figure out
when to emit diagnostics. Current logic emits "uknown" when definition is
missing, so i extended that to skipped-function-bodies as well.


>From 60c60c8a3b7aea4f6307fa5e08ffad7b90005c44 Mon Sep 17 00:00:00 2001
From: Kadir Cetinkaya <kadircet at google.com>
Date: Tue, 23 Jul 2024 15:43:30 +0200
Subject: [PATCH] [clang][CUDA] Assume unknown emission status for skipped
 function definitions

---
 clang/lib/Sema/SemaDecl.cpp             | 3 ++-
 clang/unittests/Tooling/ToolingTest.cpp | 5 +++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index bb25a0b3a45ae..c04c66d8c445a 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -20148,7 +20148,8 @@ Sema::FunctionEmissionStatus Sema::getEmissionStatus(const FunctionDecl *FD,
     // be emitted, because (say) the definition could include "inline".
     const FunctionDecl *Def = FD->getDefinition();
 
-    return Def && !isDiscardableGVALinkage(
+    // We can't compute linkage when we skip function bodies.
+    return Def && !Def->hasSkippedBody() && !isDiscardableGVALinkage(
                       getASTContext().GetGVALinkageForFunction(Def));
   };
 
diff --git a/clang/unittests/Tooling/ToolingTest.cpp b/clang/unittests/Tooling/ToolingTest.cpp
index 2e3da2cd2a701..f41a44fa0922a 100644
--- a/clang/unittests/Tooling/ToolingTest.cpp
+++ b/clang/unittests/Tooling/ToolingTest.cpp
@@ -586,6 +586,11 @@ TEST(runToolOnCode, TestSkipFunctionBody) {
   EXPECT_FALSE(runToolOnCodeWithArgs(
       std::make_unique<SkipBodyAction>(),
       "template<typename T> int skipMeNot() { an_error_here }", Args2));
+
+  EXPECT_TRUE(runToolOnCodeWithArgs(
+      std::make_unique<SkipBodyAction>(),
+      "__inline __attribute__((__gnu_inline__)) void skipMe() {}",
+      {"--cuda-host-only", "-nocudainc", "-xcuda"}));
 }
 
 TEST(runToolOnCodeWithArgs, TestNoDepFile) {



More information about the cfe-commits mailing list