From 6d4f8b1dbfd21811351bec205154992afddbc5ea Mon Sep 17 00:00:00 2001 From: Steven Perron Date: Wed, 5 Mar 2025 14:02:39 -0500 Subject: [HLSL] Fix resource wrapper declaration (#129100) The resource wrapper should have internal linkage because it contains a handle to the global resource, and it not the actual global. Makeing this changed exposed that we were zeroinitializing the resouce, which is a problem. The handle cannot be zeroinitialized. This is changed to use poison instead. Fixes https://github.com/llvm/llvm-project/issues/122767. --------- Co-authored-by: Helena Kotas --- clang/lib/CodeGen/CodeGenModule.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index cec8f12..bca0a93 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -5595,7 +5595,11 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D, if (D->getType()->isReferenceType()) T = D->getType(); - if (getLangOpts().CPlusPlus) { + if (getLangOpts().HLSL && + D->getType().getTypePtr()->isHLSLResourceRecord()) { + Init = llvm::PoisonValue::get(getTypes().ConvertType(ASTTy)); + NeedsGlobalCtor = true; + } else if (getLangOpts().CPlusPlus) { Init = EmitNullConstant(T); if (!IsDefinitionAvailableExternally) NeedsGlobalCtor = true; -- cgit v1.1