Debian Codegraph @

clang/test/SemaHLSL/parameter_modifiers.hlsl

raw
1 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.6-library %s -verify
2 void fn(in out float f); // #fn
3
4 // expected-error@#fn2{{duplicate parameter modifier 'in'}}
5 // expected-note@#fn2{{conflicting attribute is here}}
6 void fn2(in in float f); // #fn2
7
8 // expected-error@#fn3{{duplicate parameter modifier 'out'}}
9 // expected-note@#fn3{{conflicting attribute is here}}
10 void fn3(out out float f); // #fn3
11
12 // expected-error@#fn4{{duplicate parameter modifier 'in'}}
13 // expected-error@#fn4{{duplicate parameter modifier 'out'}}
14 // expected-note@#fn4{{conflicting attribute is here}}
15 // expected-note@#fn4{{conflicting attribute is here}}
16 void fn4(inout in out float f); // #fn4
17
18 // expected-error@#fn5{{duplicate parameter modifier 'in'}}
19 // expected-note@#fn5{{conflicting attribute is here}}
20 void fn5(inout in float f); // #fn5
21
22 // expected-error@#fn6{{duplicate parameter modifier 'out'}}
23 // expected-note@#fn6{{conflicting attribute is here}}
24 void fn6(inout out float f); // #fn6
25
26 // expected-error@#fn-def{{conflicting parameter qualifier 'out' on parameter 'f'}}
27 // expected-note@#fn{{previously declared as 'inout' here}}
28 void fn(out float f) { // #fn-def
29 f = 2;
30 }
31
32 // Overload resolution failure.
33 void fn(in float f); // #fn-in
34
35 void failOverloadResolution() {
36 float f = 1.0;
37 fn(f); // expected-error{{call to 'fn' is ambiguous}}
38 // expected-note@#fn-def{{candidate function}}
39 // expected-note@#fn-in{{candidate function}}
40 }
41
42 void implicitFn(float f);
43 void inFn(in float f);
44 void inoutFn(inout float f); // #inoutFn
45 void outFn(out float f); // #outFn
46
47 void callFns() {
48 // Call with literal arguments.
49 implicitFn(1); // Ok.
50 inFn(1); // Ok.
51 inoutFn(1); // expected-error{{no matching function for call to 'inoutFn'}}
52 // expected-note@#inoutFn{{candidate function not viable: no known conversion from 'int' to 'float &' for 1st argument}}
53 outFn(1); // expected-error{{no matching function for call to 'outFn}}
54 // expected-note@#outFn{{candidate function not viable: no known conversion from 'int' to 'float &' for 1st argument}}
55
56 // Call with variables.
57 float f;
58 implicitFn(f); // Ok.
59 inFn(f); // Ok.
60 inoutFn(f); // Ok.
61 outFn(f); // Ok.
62 }
63
64 // No errors on these scenarios.
65
66 // Alternating `inout` and `in out` spellings between declaration and
67 // definitions is fine since they have the same semantic meaning.
68 void fn7(inout float f);
69 void fn7(in out float f) {}
70
71 void fn8(in out float f);
72 void fn8(inout float f) {}
73
74 // These two declare two different functions (although calling them will be
75 // ambiguous). This is equivalent to declaring a function that takes a
76 // reference and a function that takes a value of the same type.
77 void fn9(in float f);
78 void fn9(out float f);
79
80 // The `in` attribute is effectively optional. If no attribute is present it is
81 // the same as `in`, so these declarations match the functions.
82 void fn10(in float f);
83 void fn10(float f) {}
84
85 void fn11(float f);
86 void fn11(in float f) {}
87
88 template <typename T>
89 void fn12(inout T f);
90
91 void fn13() {
92 float f;
93 fn12<float>(f);
94 }