Skip to content

Recognize compile-time constants in LoopConditionChecker. - #6292

Merged
copybara-service[bot] merged 1 commit into
masterfrom
test_1012915780
Nov 4, 2026
Merged

copybara-service[bot] merged 1 commit into
masterfrom
test_1012915780

Conversation

@copybara-service

Copy link
Copy Markdown
Contributor

Recognize compile-time constants in LoopConditionChecker.

Treat identifiers and member selects with compile-time constant values as constant expressions when scanning loop conditions, so loops like for (int i = 0; i < MAX; ) are recognized when i is never modified.

Fixes #5826

@utafrali utafrali left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean, minimal fix for issue #5826. The change correctly extends LoopConditionVisitor to treat compile-time constant identifiers and member selects as constant expressions via ASTHelpers.constValue, and the new test covers both the unqualified (ONE) and qualified (Test.ONE) cases plus a negative control where i is modified.

Treat identifiers and member selects with compile-time constant values as constant expressions when scanning loop conditions, so loops like `for (int i = 0; i < MAX; )` are recognized when `i` is never modified.

Fixes #5826

PiperOrigin-RevId: 1013627639
@copybara-service
copybara-service Bot merged commit d59febd into master Nov 4, 2026
1 check passed
@copybara-service
copybara-service Bot deleted the test_1012915780 branch November 4, 2026 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LoopConditionChecker fails to resolve compile-time constant loop bounds, missing genuine infinite loops

2 participants