Skip to content

Commit f2ddce4

Browse files
committed
Add fix and test case for in modifier
1 parent 607518b commit f2ddce4

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ static void instantiateDependentHLSLParamModifierAttr(
770770
NewParm->addAttr(Attr->clone(S.getASTContext()));
771771

772772
const Type *OldParmTy = cast<ParmVarDecl>(Old)->getType().getTypePtr();
773-
if (OldParmTy->isDependentType())
773+
if (OldParmTy->isDependentType() && Attr->isAnyOut())
774774
NewParm->setType(S.HLSL().getInoutParameterType(NewParm->getType()));
775775

776776
assert(!Attr->isAnyOut() || (NewParm->getType().isRestrictQualified() &&

clang/test/SemaHLSL/Language/TemplateOutArg.hlsl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,43 @@ void fizz_two(inout T V, out int I) {
233233
I = V;
234234
}
235235

236+
// Case 5: Verify that `in` parameter modifier attributes are instantiated
237+
// for both templated and non-templated arguments and argument types are not
238+
// modified
239+
240+
// CHECK-LABEL: FunctionTemplateDecl {{.*}} buzz_two
241+
242+
// Check the pattern decl.
243+
// CHECK: FunctionDecl {{.*}} buzz_two 'int (T, int)'
244+
// CHECK-NEXT: ParmVarDecl {{.*}} referenced A 'T'
245+
// CHECK-NEXT: HLSLParamModifierAttr {{.*}} in
246+
// CHECK-NEXT: ParmVarDecl {{.*}} referenced B 'int'
247+
// CHECK-NEXT: HLSLParamModifierAttr {{.*}} in
248+
249+
// Check the 3 instantiations (int, float, & double).
250+
251+
// CHECK-LABEL: FunctionDecl {{.*}} used buzz_two 'int (int, int)' implicit_instantiation
252+
// CHECK: ParmVarDecl {{.*}} used A 'int'
253+
// CHECK-NEXT: HLSLParamModifierAttr {{.*}} in
254+
// CHECK: ParmVarDecl {{.*}} used B 'int'
255+
// CHECK-NEXT: HLSLParamModifierAttr {{.*}} in
256+
257+
// CHECK-LABEL: FunctionDecl {{.*}} used buzz_two 'int (float, int)' implicit_instantiation
258+
// CHECK: ParmVarDecl {{.*}} used A 'float'
259+
// CHECK-NEXT: HLSLParamModifierAttr {{.*}} in
260+
// CHECK: ParmVarDecl {{.*}} used B 'int'
261+
// CHECK-NEXT: HLSLParamModifierAttr {{.*}} in
262+
263+
// CHECK-LABEL: FunctionDecl {{.*}} used buzz_two 'int (double, int)' implicit_instantiation
264+
// CHECK: ParmVarDecl {{.*}} used A 'double'
265+
// CHECK-NEXT: HLSLParamModifierAttr {{.*}} in
266+
// CHECK: ParmVarDecl {{.*}} used B 'int'
267+
// CHECK-NEXT: HLSLParamModifierAttr {{.*}} in
268+
template <typename T>
269+
int buzz_two(in T A, in int B) {
270+
return A + B;
271+
}
272+
236273
export void caller() {
237274
int X = 2;
238275
float Y = 3.3;
@@ -253,4 +290,8 @@ export void caller() {
253290
fizz_two(X, X);
254291
fizz_two(Y, X);
255292
fizz_two(Z, X);
293+
294+
X = buzz_two(X, X);
295+
X = buzz_two(Y, X);
296+
X = buzz_two(Z, X);
256297
}

0 commit comments

Comments
 (0)