diff options
| author | Yong He <yonghe@outlook.com> | 2022-08-17 23:08:34 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-17 23:08:34 -0700 |
| commit | adaea0e993fd8db351b5dad92802e47ed6d0ec77 (patch) | |
| tree | dfad5201677b0202b0b890cbae066b5b2f3f033b /tests/diagnostics | |
| parent | d65c6183c0d8b365aa182c3d9026ba85522531f2 (diff) | |
Warning on lossy implicit casts. (#2367)
* Warning on bool to float conversion.
* Fix test cases.
* Improve.
* LanguageServer: don't show constant value for non constant variables.
* Fix tests.
* Fix warnings in tests.
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'tests/diagnostics')
| -rw-r--r-- | tests/diagnostics/attribute-error.slang.expected | 3 | ||||
| -rw-r--r-- | tests/diagnostics/bool-to-float.slang | 13 | ||||
| -rw-r--r-- | tests/diagnostics/bool-to-float.slang.expected | 8 | ||||
| -rw-r--r-- | tests/diagnostics/constexpr-error.slang | 6 | ||||
| -rw-r--r-- | tests/diagnostics/constexpr-error.slang.expected | 11 | ||||
| -rw-r--r-- | tests/diagnostics/enum-implicit-conversion.slang.expected | 9 | ||||
| -rw-r--r-- | tests/diagnostics/generic-invalid-type-specialization.slang.expected | 3 | ||||
| -rw-r--r-- | tests/diagnostics/local-line.slang | 10 |
8 files changed, 51 insertions, 12 deletions
diff --git a/tests/diagnostics/attribute-error.slang.expected b/tests/diagnostics/attribute-error.slang.expected index 386d08422..cde43142d 100644 --- a/tests/diagnostics/attribute-error.slang.expected +++ b/tests/diagnostics/attribute-error.slang.expected @@ -6,6 +6,9 @@ tests/diagnostics/attribute-error.slang(19): error 30019: expected an expression tests/diagnostics/attribute-error.slang(22): error 31002: attribute 'MyStruct' is not valid here [MyStruct(0, 10.0)] // attribute does not apply to this construct ^~~~~~~~ +tests/diagnostics/attribute-error.slang(24): warning 30081: implicit conversion from 'float' to 'int' is not recommended + [DefaultValue(2.0)] // attribute arg type mismatch + ^~~ tests/diagnostics/attribute-error.slang(24): error 39999: expression does not evaluate to a compile-time constant [DefaultValue(2.0)] // attribute arg type mismatch ^~~ diff --git a/tests/diagnostics/bool-to-float.slang b/tests/diagnostics/bool-to-float.slang new file mode 100644 index 000000000..087cf86b3 --- /dev/null +++ b/tests/diagnostics/bool-to-float.slang @@ -0,0 +1,13 @@ +// bool-to-float.slang + +// Diagnostic messages related to converting bool to float + +//DIAGNOSTIC_TEST:SIMPLE: + +struct Test +{ + void test() + { + float f = true; + } +} diff --git a/tests/diagnostics/bool-to-float.slang.expected b/tests/diagnostics/bool-to-float.slang.expected new file mode 100644 index 000000000..e1d851163 --- /dev/null +++ b/tests/diagnostics/bool-to-float.slang.expected @@ -0,0 +1,8 @@ +result code = 0 +standard error = { +tests/diagnostics/bool-to-float.slang(11): warning 30081: implicit conversion from 'bool' to 'float' is not recommended + float f = true; + ^~~~ +} +standard output = { +} diff --git a/tests/diagnostics/constexpr-error.slang b/tests/diagnostics/constexpr-error.slang index f0de9280d..a5b98264b 100644 --- a/tests/diagnostics/constexpr-error.slang +++ b/tests/diagnostics/constexpr-error.slang @@ -21,7 +21,7 @@ float4 main() : SV_Target float4 result = 0.0f; // Okay, immediate constant - result += t.Sample(s, uv, uint2(0,0)); + result += t.Sample(s, uv, int2(0,0)); // Error: data passed through cbuffer isn't compile-time constant result += t.Sample(s, uv, offset); @@ -32,13 +32,13 @@ float4 main() : SV_Target { ii = 1; } - result += t.Sample(s, uv, uint2(ii)); + result += t.Sample(s, uv, int2(ii)); // Error: data computed in loop isn't compile-time constant // (and loop isn't unroll-able) for(uint jj = 0; jj < uv.y; jj++) { - result += t.Sample(s, uv, uint2(jj)); + result += t.Sample(s, uv, int2(jj)); } return result; diff --git a/tests/diagnostics/constexpr-error.slang.expected b/tests/diagnostics/constexpr-error.slang.expected index 4dea62ca1..a744fcafd 100644 --- a/tests/diagnostics/constexpr-error.slang.expected +++ b/tests/diagnostics/constexpr-error.slang.expected @@ -1,14 +1,17 @@ result code = -1 standard error = { +tests/diagnostics/constexpr-error.slang(27): warning 30081: implicit conversion from 'vector<uint,2>' to 'vector<int,2>' is not recommended + result += t.Sample(s, uv, offset); + ^~~~~~ tests/diagnostics/constexpr-error.slang(27): error 40006: expected a compile-time constant result += t.Sample(s, uv, offset); ^~~~~~ tests/diagnostics/constexpr-error.slang(35): error 40006: expected a compile-time constant - result += t.Sample(s, uv, uint2(ii)); - ^ + result += t.Sample(s, uv, int2(ii)); + ^ tests/diagnostics/constexpr-error.slang(41): error 40006: expected a compile-time constant - result += t.Sample(s, uv, uint2(jj)); - ^ + result += t.Sample(s, uv, int2(jj)); + ^ } standard output = { } diff --git a/tests/diagnostics/enum-implicit-conversion.slang.expected b/tests/diagnostics/enum-implicit-conversion.slang.expected index 61164bbaa..4efdc9c75 100644 --- a/tests/diagnostics/enum-implicit-conversion.slang.expected +++ b/tests/diagnostics/enum-implicit-conversion.slang.expected @@ -1,5 +1,11 @@ result code = -1 standard error = { +tests/diagnostics/enum-implicit-conversion.slang(18): warning 30081: implicit conversion from 'uint' to 'int' is not recommended +int foo(uint x) { return x * 256 * 16; } + ^ +tests/diagnostics/enum-implicit-conversion.slang(22): warning 30081: implicit conversion from 'uint' to 'int' is not recommended +int bar(uint x) { return x * 256 * 256 * 16; } + ^ tests/diagnostics/enum-implicit-conversion.slang(27): error 30019: expected an expression of type 'Color', got 'int' Color c = val; ^~~ @@ -17,6 +23,9 @@ tests/diagnostics/enum-implicit-conversion.slang(42): error 39999: ambiguous cal ^ tests/diagnostics/enum-implicit-conversion.slang(18): note 39999: candidate: func foo(uint) -> int tests/diagnostics/enum-implicit-conversion.slang(17): note 39999: candidate: func foo(int) -> int +tests/diagnostics/enum-implicit-conversion.slang(47): warning 30081: implicit conversion from 'uint' to 'int' is not recommended + return x + y + z; + ^ } standard output = { } diff --git a/tests/diagnostics/generic-invalid-type-specialization.slang.expected b/tests/diagnostics/generic-invalid-type-specialization.slang.expected index 3c323ef46..0fc68f6b6 100644 --- a/tests/diagnostics/generic-invalid-type-specialization.slang.expected +++ b/tests/diagnostics/generic-invalid-type-specialization.slang.expected @@ -1,5 +1,8 @@ result code = -1 standard error = { +tests/diagnostics/generic-invalid-type-specialization.slang(14): warning 30081: implicit conversion from 'uint' to 'int' is not recommended + int index = dispatchThreadID.x; + ^ tests/diagnostics/generic-invalid-type-specialization.slang(17): error 30060: expected a type, got a 'int' Check<2 + 2> v; ^ diff --git a/tests/diagnostics/local-line.slang b/tests/diagnostics/local-line.slang index 1cdeba7e4..973c234c0 100644 --- a/tests/diagnostics/local-line.slang +++ b/tests/diagnostics/local-line.slang @@ -22,21 +22,21 @@ int doThing(int a, int b) [numthreads(4, 1, 1)] void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) { - int a = dispatchThreadID.x; - int b = dispatchThreadID.y; - int c = dispatchThreadID.z; + int a = int(dispatchThreadID.x); + int b = int(dispatchThreadID.y); + int c = int(dispatchThreadID.z); int d = a + b * c; int e = d + c / 2; for (int i = 0; i < b; ++i) { - if (e > 10 && i & 2) + if (e > 10 && (i & 2) != 0) { a += b; b -= c; c += c; d = d + e + a; e = a; } else { - a = e; b = c + c; d += d + __SyntaxError(); e = doThing(e, dispatchThreadID.x); + a = e; b = c + c; d += d + __SyntaxError(); e = doThing(e, int(dispatchThreadID.x)); } } |
