101 lines · plain
1// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.6-library %s -verify -Wconversion2void fn(in out float f); // #fn3 4// expected-error@#fn2{{duplicate parameter modifier 'in'}}5// expected-note@#fn2{{conflicting attribute is here}}6void fn2(in in float f); // #fn27 8// expected-error@#fn3{{duplicate parameter modifier 'out'}}9// expected-note@#fn3{{conflicting attribute is here}}10void fn3(out out float f); // #fn311 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}}16void fn4(inout in out float f); // #fn417 18// expected-error@#fn5{{duplicate parameter modifier 'in'}}19// expected-note@#fn5{{conflicting attribute is here}}20void fn5(inout in float f); // #fn521 22// expected-error@#fn6{{duplicate parameter modifier 'out'}}23// expected-note@#fn6{{conflicting attribute is here}}24void fn6(inout out float f); // #fn625 26// expected-error@#fn-def{{conflicting parameter qualifier 'out' on parameter 'f'}}27// expected-note@#fn{{previously declared as 'inout' here}}28void fn(out float f) { // #fn-def29 f = 2;30}31 32// Overload resolution failure.33void fn(in float f); // #fn-in34 35void failOverloadResolution() {36 float f = 1.0;37 fn(f); // expected-error{{call to 'fn' is ambiguous}}38 // expected-note@#fn{{candidate function}}39 // expected-note@#fn-in{{candidate function}}40}41 42void implicitFn(float f);43void inFn(in float f);44void inoutFn(inout float f); // #inoutFn45void outFn(out float f); // #outFn46 47void callFns() {48 // Call with literal arguments.49 implicitFn(1); // Ok.50 inFn(1); // Ok.51 inoutFn(1); // expected-error{{cannot bind non-lvalue argument '1' to inout paramemter}}52 outFn(1); // expected-error{{cannot bind non-lvalue argument '1' to out paramemter}}53 54 // Call with variables.55 float f;56 implicitFn(f); // Ok.57 inFn(f); // Ok.58 inoutFn(f); // Ok.59 outFn(f); // Ok.60}61 62// No errors on these scenarios.63 64// Alternating `inout` and `in out` spellings between declaration and65// definitions is fine since they have the same semantic meaning.66void fn7(inout float f);67void fn7(in out float f) {}68 69void fn8(in out float f);70void fn8(inout float f) {}71 72// These two declare two different functions (although calling them will be73// ambiguous). This is equivalent to declaring a function that takes a74// reference and a function that takes a value of the same type.75void fn9(in float f);76void fn9(out float f);77 78// The `in` attribute is effectively optional. If no attribute is present it is79// the same as `in`, so these declarations match the functions.80void fn10(in float f);81void fn10(float f) {}82 83void fn11(float f);84void fn11(in float f) {}85 86template <typename T>87void fn12(inout T f);88 89void fn13() {90 float f;91 fn12<float>(f);92}93 94void fn14(out float f);95 96void fn15() {97 float f;98 int x = 5;99 fn14(f += x); // expected-warning{{implicit conversion from 'int' to 'float' may lose precision}}100}101