[clang] [HLSL] Update type for `out` arguments only for dependent params types (PR #163832)

Justin Bogner via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 16 14:20:09 PDT 2025


================
@@ -765,10 +765,18 @@ static bool isRelevantAttr(Sema &S, const Decl *D, const Attr *A) {
 
 static void instantiateDependentHLSLParamModifierAttr(
     Sema &S, const MultiLevelTemplateArgumentList &TemplateArgs,
-    const HLSLParamModifierAttr *Attr, Decl *New) {
-  ParmVarDecl *P = cast<ParmVarDecl>(New);
-  P->addAttr(Attr->clone(S.getASTContext()));
-  P->setType(S.HLSL().getInoutParameterType(P->getType()));
+    const HLSLParamModifierAttr *Attr, const Decl *Old, Decl *New) {
+  ParmVarDecl *NewParm = cast<ParmVarDecl>(New);
+  NewParm->addAttr(Attr->clone(S.getASTContext()));
+
+  const Type *OldParmTy = cast<ParmVarDecl>(Old)->getType().getTypePtr();
+  if (OldParmTy->isDependentType() && Attr->isAnyOut())
+    NewParm->setType(S.HLSL().getInoutParameterType(NewParm->getType()));
+
+  assert(!Attr->isAnyOut() || (NewParm->getType().isRestrictQualified() &&
+                               NewParm->getType()->isReferenceType()) &&
+                                  "out or inout parameter type must be a "
+                                  "reference and restrict qualified");
----------------
bogner wrote:

It doesn't matter logically, but I think parenthesizing the entire assert condition before `&&` with the message is more readable
```suggestion
  assert(
      (!Attr->isAnyOut() || (NewParm->getType().isRestrictQualified() &&
                             NewParm->getType()->isReferenceType())) &&
      "out or inout parameter type must be a reference and restrict qualified");
```

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


More information about the cfe-commits mailing list