summaryrefslogtreecommitdiff
path: root/tests/diagnostics/for-loop-warning.slang
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-02-20 10:17:00 -0800
committerGitHub <noreply@github.com>2023-02-20 10:17:00 -0800
commit8b05df4187117d61491f2fdbeb7d744146ad73f7 (patch)
treecfb17b26e9db313d0b6ce1a07efe85b35d6d1638 /tests/diagnostics/for-loop-warning.slang
parenta8da735ca4e0ed49796dda164c39e21aea4a7bc6 (diff)
Add static for loop iteration inference. (#2659)
Diffstat (limited to 'tests/diagnostics/for-loop-warning.slang')
-rw-r--r--tests/diagnostics/for-loop-warning.slang60
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/diagnostics/for-loop-warning.slang b/tests/diagnostics/for-loop-warning.slang
new file mode 100644
index 000000000..226af46f5
--- /dev/null
+++ b/tests/diagnostics/for-loop-warning.slang
@@ -0,0 +1,60 @@
+//DIAGNOSTIC_TEST:SIMPLE:
+
+
+float doSomething(int x)
+{
+ for (int i = 0; i < x; i--) // warn.
+ {}
+ for (int i = 0; i < 5; i-=-2) // ok.
+ {}
+ for (int j = 0; j < 3; j += 0) // warn.
+ {}
+ for (int i = 0; i < 5; i++) // ok
+ {
+ for (int j = 0; j < 3; i++) // warn.
+ {}
+ }
+ for (int i = 0; i < 5; i++) // ok
+ {
+ for (int j = 0; i < 4; j++) // warn.
+ {}
+ }
+
+ [MaxIters(6)] // warn
+ for (int i = 0; i <= 6; i+=3)
+ {
+ }
+
+ [MaxIters(6)] // warn
+ for (int i = 5; i >= 0; i -= 3)
+ {
+ }
+ [MaxIters(6)] // warn
+ for (int i = 5; i > 0; i--)
+ {
+ }
+
+ [MaxIters(5)] // ok
+ for (int i = 0; i < 5; i++) // ok
+ {
+ }
+
+ for (int i = 1; i < 0; i++) // warn
+ {
+ }
+ for (int i = 1; i >= 2; i--) // warn
+ {
+ }
+ for (int i = 1; i >= 1; i--) // ok
+ {
+ }
+ for (int i = 1; i > 1; i--) // warn
+ {
+ }
+ [MaxIters(5)] // ok, because the loop body modifies i so we can't infer the iterations.
+ for (int i = 0; i < 5; i+=2)
+ {
+ i--;
+ }
+ return 0.0;
+}