-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[analyzer] Handle [[assume(cond)]] as __builtin_assume(cond) #116462
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 17 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
daddb9e
[analyzer] Handle `[[assume(cond)]]` as `__builtin_assume(cond)`
vinay-deshmukh 7f1e341
NFC Simplify ExprEngine::VisitAttributedStmt
steakhal f4307e9
NFC Simplify AttributedStmt handling in clang CFG
steakhal c2b5e71
NFC Clarify test comment
steakhal 3d4953f
NFC De-indent some tests
steakhal 57751d1
NFC Mention the size of the array in its name
steakhal 75e964a
Add broken test about sideeffects
steakhal d55851b
[clang] Generalize getSpecificAttr for const attributes
steakhal c288bdc
Ignore assumptions with side-effects
vinay-deshmukh f79ad87
Merge remote-tracking branch 'upstream/main' into vinay-issue-100762
vinay-deshmukh b4e278a
Merge branch 'main' into vinay-issue-100762
vinay-deshmukh 8b877d1
Merge branch 'main' into vinay-issue-100762
vinay-deshmukh eabbef2
Add ternary test for assumption
vinay-deshmukh ae2038f
Merge remote-tracking branch 'upstream/main' into vinay-issue-100762
vinay-deshmukh c3d1c1a
clean
vinay-deshmukh e71023b
Merge branch 'main' into vinay-issue-100762
vinay-deshmukh 02c009d
Merge branch 'main' into vinay-issue-100762
vinay-deshmukh 3736854
Cleanup
steakhal d4c4e14
Merge remote-tracking branch 'llvm' into vinay-issue-100762
steakhal 342ef04
Update clang/test/Analysis/cxx23-assume-attribute.cpp
steakhal 670b358
Fix test
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// RUN: %clang_analyze_cc1 -std=c++11 -Wno-array-bounds -verify %s \ | ||
// RUN: -analyzer-checker=unix,core,alpha.security.ArrayBoundV2,debug.ExprInspection | ||
|
||
// TODO: fix the checker arguments | ||
|
||
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); // we should have 2 dumps here. expected-warning{{[-2147483648, 10]}} expected-warning{{[11, 2147483647]}} | ||
clang_analyzer_dump(b); // This should be either 4 or 10. expected-warning{{4}} expected-warning{{10}} | ||
if (a > 20) { | ||
clang_analyzer_dump(b + 100); // expecting 104 expected-warning{{104}} | ||
return 2; | ||
} | ||
if (a > 10) { | ||
clang_analyzer_dump(b + 200); // expecting 204 expected-warning{{204}} | ||
return 1; | ||
} | ||
clang_analyzer_dump(b + 300); // expecting 310 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_$2<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); // we should have 2 dumps here. expected-warning{{[-2147483648, 10]}} expected-warning{{[11, 2147483647]}} | ||
clang_analyzer_dump(b); // This should be either 4 or 10. expected-warning{{4}} expected-warning{{10}} FIXME: expected-warning{{reg_$2<int b>}} | ||
if (a > 20) { | ||
clang_analyzer_dump(b + 100); // expecting 104 expected-warning{{104}} FIXME: expected-warning{{(reg_$2<int b>) + 100}} | ||
return 2; | ||
} | ||
if (a > 10) { | ||
clang_analyzer_dump(b + 200); // expecting 204 expected-warning{{204}} FIXME: expected-warning{{(reg_$2<int b>) + 200}} | ||
return 1; | ||
} | ||
clang_analyzer_dump(b + 300); // expecting 310 expected-warning{{310}} FIXME: expected-warning{{(reg_$2<int b>) + 300}} | ||
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.