[clang] [Hlsl][Spirv] Don't emit global variables for structs containing resources (PR #234797)

via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 5 23:50:18 PST 2026


================
@@ -6537,10 +6538,16 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D,
 
   // TODO(Reflection): add support for consteval-only types.
 
-  // HLSL default buffer constants will be emitted during HLSLBufferDecl codegen
+  // HLSL default buffer constants will be emitted during HLSLBufferDecl codegen.
+  // Also skip emitting globals for structs or arrays of structs containing only
+  // resource constants, which should have already been flattened into separate
+  // variables.
   if (getLangOpts().HLSL &&
-      D->getType().getAddressSpace() == LangAS::hlsl_constant)
+      (ASTTy.getAddressSpace() == LangAS::hlsl_constant ||
+       (D->getStorageClass() != SC_Static &&
+        hlsl::isStructOrArrayOfWithResources(ASTTy)))) {
----------------
rj123-nv wrote:

done

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


More information about the cfe-commits mailing list