-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[analyzer] Unroll loops of compile-time upper-bounded loops #169400
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
Merged
steakhal
merged 3 commits into
llvm:main
from
steakhal:bb/rdar-165363923-relax-loop-unrolling-pattern
Nov 25, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config unroll-loops=true,cfg-loopexit=true -verify=expected,default -std=c++14 -analyzer-config exploration_strategy=unexplored_first_queue %s | ||
| // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config unroll-loops=true,cfg-loopexit=true,exploration_strategy=dfs -verify=expected,dfs -std=c++14 %s | ||
| // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config unroll-loops=true,cfg-loopexit=true -verify=expected,default -std=c++17 -analyzer-config exploration_strategy=unexplored_first_queue %s | ||
| // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config unroll-loops=true,cfg-loopexit=true,exploration_strategy=dfs -verify=expected,dfs -std=c++17 %s | ||
|
|
||
| void clang_analyzer_numTimesReached(); | ||
| void clang_analyzer_warnIfReached(); | ||
|
|
@@ -580,3 +580,21 @@ void test_escaping_on_var_before_switch_case_no_crash(int c) { | |
| } | ||
| } | ||
| } | ||
|
|
||
| template <int Val> struct Integer { | ||
| static constexpr int value = Val; | ||
| }; | ||
|
|
||
| void complicated_compile_time_upper_bound() { | ||
| static_assert((sizeof(char) * Integer<4>::value + 3) == 7); | ||
| for (int i = 0; i < (sizeof(char) * Integer<4>::value + (((3)))); ++i) { | ||
| clang_analyzer_numTimesReached(); // expected-warning {{7}} | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These outcomes would be 4 without the patch, due to the block count limit which is relied upon in case loop unrolling is not applicable. |
||
| } | ||
| } | ||
|
|
||
| void complicated_compile_time_upper_bound_indirect() { | ||
| using Seven = Integer<(sizeof(char) * Integer<4>::value + 3)>; | ||
| for (int i = 0; i < ((Seven::value)); ++i) { | ||
| clang_analyzer_numTimesReached(); // expected-warning {{7}} | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This hunk was just hoisted, and
hasEitherOperandwas replaced by an explicit matching to LHS and RHS because the patterns are somewhat overlapping due to theexpr()matcher.