[clang] [Sema][CUDA][HIP] Report deferred diagnostics of force-emitted functions (PR #229008)

Steffen Larsen via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 5 08:48:00 PDT 2026


================
@@ -21537,6 +21537,14 @@ Sema::FunctionEmissionStatus Sema::getEmissionStatus(const FunctionDecl *FD,
 
     if (IsEmittedForExternalSymbol())
       return FunctionEmissionStatus::Emitted;
+
+    // CodeGen also emits a function regardless of its uses if it is forced to,
+    // so its deferred diagnostics must not wait for a use.
+    const FunctionDecl *Def = FD->getDefinition();
+    if (Def && !Def->hasSkippedBody() &&
+        (LangOpts.EmitAllDecls || Def->hasAttr<UsedAttr>() ||
+         Def->hasAttr<ConstructorAttr>() || Def->hasAttr<DestructorAttr>()))
----------------
steffenlarsen wrote:

Ah, good point. I did another pass over all these paths and found a handful other cases that will not emit:

1. Function that become immediate by calling `consteval` (C++20)
2. Lambdas
3. Implicit host/device template functions
4. Implicit functions and functions defaulted on their first declaration
5. `available_externally` definitions

I also found the helper function `DeclMustBeEmitted` to simplify the original check a little.

https://github.com/llvm/llvm-project/pull/229008


More information about the cfe-commits mailing list