From 6c7c575556cbcd49d3fe6321b3bf55c30111b4d9 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Wed, 1 Apr 2026 14:11:16 -0400 Subject: [PATCH] [clang] fix OutputSemantic list in HLSL (#185550) Normally sane front-ends with the common calling-conventions avoid having multiple sret with a return value, so this is NFCI. However, multiple can be valid. This rewrites an odd looking DenseMap of one element that was needed for iteration into a more sensible vector. Noted in https://github.com/llvm/llvm-project/pull/181740 review. --- clang/lib/CodeGen/CGHLSLRuntime.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp index 4e6f853890c8..6182663111f5 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -956,8 +956,7 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl *FD, OB.emplace_back("convergencectrl", bundleArgs); } - llvm::DenseMap> - OutputSemantic; + SmallVector> OutputSemantic; unsigned SRetOffset = 0; for (const auto &Param : Fn->args()) { @@ -965,7 +964,7 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl *FD, SRetOffset = 1; llvm::Type *VarType = Param.getParamStructRetType(); llvm::Value *Var = B.CreateAlloca(VarType); - OutputSemantic.try_emplace(FD, std::make_pair(Var, VarType)); + OutputSemantic.push_back(std::make_pair(Var, VarType)); Args.push_back(Var); continue; } @@ -1002,17 +1001,17 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl *FD, if (Fn->getReturnType() != CGM.VoidTy) // Element type is unused, so set to dummy value (NULL). - OutputSemantic.try_emplace(FD, std::make_pair(CI, nullptr)); + OutputSemantic.push_back(std::make_pair(CI, nullptr)); - for (auto &[Decl, SourcePair] : OutputSemantic) { + for (auto &SourcePair : OutputSemantic) { llvm::Value *Source = SourcePair.first; llvm::Type *ElementType = SourcePair.second; AllocaInst *AI = dyn_cast(Source); llvm::Value *SourceValue = AI ? B.CreateLoad(ElementType, Source) : Source; - auto AttrBegin = Decl->specific_attr_begin(); - auto AttrEnd = Decl->specific_attr_end(); - handleSemanticStore(B, FD, SourceValue, Decl, AttrBegin, AttrEnd); + auto AttrBegin = FD->specific_attr_begin(); + auto AttrEnd = FD->specific_attr_end(); + handleSemanticStore(B, FD, SourceValue, FD, AttrBegin, AttrEnd); } B.CreateRetVoid();