|
| 1 | +// illegal-func-decl.slang |
| 2 | + |
| 3 | +// This test checks that the in/out/inout modifiers in function declarations must |
| 4 | +// be consistent with the function's definition, and slang can diagnose the inconsistency. |
| 5 | + |
| 6 | +//TEST:COMPILE: tests/diagnostics/illegal-func-decl-module.slang -o tests/diagnostics/illegal-func-decl-module.slang-module |
| 7 | + |
| 8 | +//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK1): -r tests/diagnostics/illegal-func-decl-module.slang-module -DTEST1 -target spirv -o illegal-func-decl.spv |
| 9 | +//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK2): -r tests/diagnostics/illegal-func-decl-module.slang-module -DTEST2 -target spirv -o illegal-func-decl.spv |
| 10 | +//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK3): -r tests/diagnostics/illegal-func-decl-module.slang-module -DTEST3 -target spirv -o illegal-func-decl.spv |
| 11 | +//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK4): -r tests/diagnostics/illegal-func-decl-module.slang-module -DTEST4 -target spirv -o illegal-func-decl.spv |
| 12 | + |
| 13 | +#ifdef TEST1 |
| 14 | +// CHECK1: ([[# @LINE+1]]): error 45001: unresolved external symbol 'libraryFunction'. |
| 15 | +extern float libraryFunction(inout float a); // invalid: 'a' is 'in' |
| 16 | +#endif |
| 17 | + |
| 18 | +#ifdef TEST2 |
| 19 | +// CHECK2-NOT: ([[# @LINE+1]]): error 45001: unresolved external symbol 'libraryFunction1'. |
| 20 | +extern float libraryFunction1(inout float b); // valid |
| 21 | +#endif |
| 22 | + |
| 23 | +#ifdef TEST3 |
| 24 | +// CHECK3: ([[# @LINE+1]]): error 45001: unresolved external symbol 'libraryFunction2'. |
| 25 | +extern float libraryFunction2(inout float a, in float b, float c); // valid: 'c' is 'inout' |
| 26 | +#endif |
| 27 | + |
| 28 | +#ifdef TEST4 |
| 29 | +// CHECK4-NOT: ([[# @LINE+1]]): error 45001: unresolved external symbol 'libraryFunction3'. |
| 30 | +export float libraryFunction3(float a); // valid: 'in' is the default is not specified |
| 31 | +#endif |
| 32 | + |
| 33 | +[shader("compute")] |
| 34 | +[numthreads(1, 1, 1)] |
| 35 | +void main(out float4 col : SV_Target0, bool isFrontHit) |
| 36 | +{ |
| 37 | + float a = 5; |
| 38 | + float b = 7; |
| 39 | + float c = 7; |
| 40 | + |
| 41 | +#ifdef TEST1 |
| 42 | + col.x = libraryFunction(a); |
| 43 | +#endif |
| 44 | + |
| 45 | +#ifdef TEST2 |
| 46 | + col.y = libraryFunction1(b); |
| 47 | +#endif |
| 48 | + |
| 49 | +#ifdef TEST3 |
| 50 | + col.z = libraryFunction2(a, b, c); |
| 51 | +#endif |
| 52 | + |
| 53 | +#ifdef TEST4 |
| 54 | + col.w = libraryFunction3(a); |
| 55 | +#endif |
| 56 | +} |
| 57 | + |
| 58 | + |
0 commit comments