================ @@ -455,14 +456,22 @@ void createHostLayoutStructForBuffer(Sema &S, HLSLBufferDecl *BufDecl) { LS->setImplicit(true); LS->startDefinition(); - for (const Decl *D : BufDecl->decls()) { - const VarDecl *VD = dyn_cast<VarDecl>(D); + for (Decl *D : BufDecl->decls()) { + VarDecl *VD = dyn_cast<VarDecl>(D); if (!VD || VD->getStorageClass() == SC_Static) continue; const Type *Ty = VD->getType()->getUnqualifiedDesugaredType(); if (FieldDecl *FD = createFieldForHostLayoutStruct( - S, Ty, VD->getIdentifier(), LS, BufDecl)) + S, Ty, VD->getIdentifier(), LS, BufDecl)) { + // add the field decl to the layout struct LS->addDecl(FD); + // update address space of the original decl to hlsl_constant + // and disable initialization + QualType NewTy = + AST.getAddrSpaceQualType(VD->getType(), LangAS::hlsl_constant); + VD->setType(NewTy); + VD->setInit(nullptr); ---------------- hekota wrote:
If we need to preserve the initializers in the AST even though they are not used, we could mark the generated global variable as `externally_initialized`. The global gets removed in the final DXIL after all. https://github.com/llvm/llvm-project/pull/123411 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits