-
Notifications
You must be signed in to change notification settings - Fork 283
Fix#6784 - Add diagnostic for for-loop update expressions with no effect #6832
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name based checking is a big code smell, and always should be avoided.
The right way to check is to implement a general side effect detection logic in post lowering validation phase next to where we are detecting missing returns. If we see a loop whose condition is a constant and the loop does not have any exit jumps, then there should be a warning.
@csyonghe by post lowering validation does that mean |
Correct, we should add another pass after the check missing return pass to validate this. |
Okay. Would require to redo the logic. |
This commit introduces a new warning diagnostic (30506) for cases where the update expression in a for-loop does not modify any variables, potentially leading to infinite loops. The implementation includes checks in the `SemanticsStmtVisitor` to identify such expressions and provide appropriate warnings. Additionally, tests have been added to verify the new diagnostic behavior.
This reverts commit d709129.
3d9367c
to
f400187
Compare
8bffd28
to
3e2bee9
Compare
@@ -56,5 +58,9 @@ float doSomething(int x) | |||
{ | |||
i--; | |||
} | |||
for (int i = 1; i < 10; i+1) // warn. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@csyonghe - I observed that Diagnostics::potentialInfiniteLoop
is only emitted for first occurence in doSomething
. In the code we are doing a graph search - so ideally this should be caught, but i am not able to wrap my head on this.
void checkForPotentialInfiniteLoops(IRModule* module, DiagnosticSink* sink, bool diagnoseWarning) | ||
{ | ||
// Look for loops in the module | ||
checkForPotentialInfiniteLoopsInInst(module->getModuleInst(), sink, diagnoseWarning); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be done only for any IRLoop in the module, instead of just starting off on the first inst?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We start procesing all IR instructions - The IRloop check is done inside this function at L105
The original issue is NOT giving warning -> However able to do on sample repro loop_issue1.slang Image-2 |
This commit introduces a new warning diagnostic (30506) for cases where the update expression in a for-loop does not modify any variables, potentially leading to infinite loops. The implementation includes checks in the
SemanticsStmtVisitor
to identify such expressions and provide appropriate warnings. Additionally, tests have been added to verify the new diagnostic behavior.