-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Reapply "[analyzer] Handle [[assume(cond)]] as __builtin_assume(cond)" #129234
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
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
67d6420
Reapply "[analyzer] Handle [[assume(cond)]] as __builtin_assume(cond)…
steakhal 2e7c4e7
Fix reverse_children of AttributedStmt
steakhal bed6511
Fix review comments
steakhal f493f9b
Merge remote-tracking branch 'llvm/main' into reland-csa-assume-attr-…
steakhal 54f3aea
Fix dyncast
steakhal e1625b8
Fix buildin_assume callexprs with sideeffects, pin and clean tests
steakhal d3790ca
Further refine testing
steakhal 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
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
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
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// RUN: %clang_analyze_cc1 -std=c++23 -triple x86_64-pc-linux-gnu \ | ||
// RUN: -analyzer-checker=core,debug.ExprInspection -verify %s | ||
|
||
template <typename T> void clang_analyzer_dump(T); | ||
template <typename T> void clang_analyzer_value(T); | ||
|
||
int ternary_in_builtin_assume(int a, int b) { | ||
__builtin_assume(a > 10 ? b == 4 : b == 10); | ||
|
||
clang_analyzer_value(a); | ||
// expected-warning@-1 {{[-2147483648, 10]}} | ||
// expected-warning@-2 {{[11, 2147483647]}} | ||
|
||
clang_analyzer_dump(b); // expected-warning{{4}} expected-warning{{10}} | ||
|
||
if (a > 20) { | ||
clang_analyzer_dump(b + 100); // expected-warning {{104}} | ||
return 2; | ||
} | ||
if (a > 10) { | ||
clang_analyzer_dump(b + 200); // expected-warning {{204}} | ||
return 1; | ||
} | ||
clang_analyzer_dump(b + 300); // expected-warning {{310}} | ||
return 0; | ||
} | ||
|
||
// From: https://github.com/llvm/llvm-project/pull/116462#issuecomment-2517853226 | ||
int ternary_in_assume(int a, int b) { | ||
// FIXME notes | ||
// Currently, if this test is run without the core.builtin.Builtin checker, the above function with the __builtin_assume behaves identically to the following test | ||
// i.e. calls to `clang_analyzer_dump` result in "extraneous" prints of the SVal(s) `reg<int b> ...` | ||
// as opposed to 4 or 10 | ||
// which likely implies the Program State(s) did not get narrowed. | ||
// A new checker is likely needed to be implemented to properly handle the expressions within `[[assume]]` to eliminate the states where `b` is not narrowed. | ||
|
||
[[assume(a > 10 ? b == 4 : b == 10)]]; | ||
clang_analyzer_value(a); | ||
// expected-warning@-1 {{[-2147483648, 10]}} | ||
// expected-warning@-2 {{[11, 2147483647]}} | ||
|
||
clang_analyzer_dump(b); // expected-warning {{4}} expected-warning {{10}} | ||
// expected-warning-re@-1 {{reg_${{[0-9]+}}<int b>}} FIXME: We shouldn't have this dump. | ||
|
||
if (a > 20) { | ||
clang_analyzer_dump(b + 100); // expected-warning {{104}} | ||
// expected-warning-re@-1 {{(reg_${{[0-9]+}}<int b>) + 100}} FIXME: We shouldn't have this dump. | ||
return 2; | ||
} | ||
if (a > 10) { | ||
clang_analyzer_dump(b + 200); // expected-warning {{204}} | ||
// expected-warning-re@-1 {{(reg_${{[0-9]+}}<int b>) + 200}} FIXME: We shouldn't have this dump. | ||
return 1; | ||
} | ||
clang_analyzer_dump(b + 300); // expected-warning {{310}} | ||
// expected-warning-re@-1 {{(reg_${{[0-9]+}}<int b>) + 300}} FIXME: We shouldn't have this dump. | ||
return 0; | ||
} | ||
|
||
int assume_and_fallthrough_at_the_same_attrstmt(int a, int b) { | ||
[[assume(a == 2)]]; | ||
clang_analyzer_dump(a); // expected-warning {{2 S32b}} | ||
// expected-warning-re@-1 {{reg_${{[0-9]+}}<int a>}} FIXME: We shouldn't have this dump. | ||
switch (a) { | ||
case 2: | ||
[[fallthrough, assume(b == 30)]]; | ||
case 4: { | ||
clang_analyzer_dump(b); // expected-warning {{30 S32b}} | ||
// expected-warning-re@-1 {{reg_${{[0-9]+}}<int b>}} FIXME: We shouldn't have this dump. | ||
return b; | ||
} | ||
} | ||
// This code should be unreachable. | ||
[[assume(false)]]; // This should definitely make it so. | ||
clang_analyzer_dump(33); // expected-warning {{33 S32b}} | ||
return 0; | ||
} |
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
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.
Uh oh!
There was an error while loading. Please reload this page.