[clang] [clang] Fix static local variables in consteval functions (PR #156933)

Mariya Podchishchaeva via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 12 06:22:15 PDT 2025


================
@@ -4461,8 +4461,14 @@ void CodeGenModule::EmitGlobalDefinition(GlobalDecl GD, llvm::GlobalValue *GV) {
     return EmitGlobalFunctionDefinition(GD, GV);
   }
 
-  if (const auto *VD = dyn_cast<VarDecl>(D))
+  if (const auto *VD = dyn_cast<VarDecl>(D)) {
+    if (VD->isStaticLocal() && !getContext().shouldExternalize(D)) {
----------------
Fznamznon wrote:

After my changes, I noticed one of CUDA tests failing. The only difference between old and new IR was that one of the variables was getting internal linkage with my changes. I found that CUDA device static variables used by host (stored in `CUDADeviceVarODRUsedByHost` field of ASTContext) are also put into `DeferredDeclsToEmit` and they were emitted as globals. I'm not really an expert in CUDA support, so I tried to preserve the old behavior. `shouldExternalize` seems like an appropriate way to detect the case.

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


More information about the cfe-commits mailing list