-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[attributes][analyzer] Generalize [[clang::suppress]] to declarations. #80371
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
haoNoQ
merged 2 commits into
llvm:main
from
haoNoQ:users/artemdergachev/analyzer-extend-suppress-to-decls
Feb 13, 2024
Merged
Changes from all commits
Commits
Show all changes
2 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
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
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,68 @@ | ||
// RUN: %clang_analyze_cc1 -analyzer-checker=core -verify %s | ||
|
||
namespace [[clang::suppress]] | ||
suppressed_namespace { | ||
int foo() { | ||
int *x = 0; | ||
return *x; | ||
} | ||
|
||
int foo_forward(); | ||
} | ||
|
||
int suppressed_namespace::foo_forward() { | ||
int *x = 0; | ||
return *x; // expected-warning{{Dereference of null pointer (loaded from variable 'x')}} | ||
} | ||
|
||
// Another instance of the same namespace. | ||
namespace suppressed_namespace { | ||
int bar() { | ||
int *x = 0; | ||
return *x; // expected-warning{{Dereference of null pointer (loaded from variable 'x')}} | ||
} | ||
} | ||
|
||
void lambda() { | ||
[[clang::suppress]] { | ||
auto lam = []() { | ||
int *x = 0; | ||
return *x; | ||
}; | ||
} | ||
} | ||
|
||
class [[clang::suppress]] SuppressedClass { | ||
int foo() { | ||
int *x = 0; | ||
return *x; | ||
} | ||
|
||
int bar(); | ||
}; | ||
|
||
int SuppressedClass::bar() { | ||
int *x = 0; | ||
return *x; // expected-warning{{Dereference of null pointer (loaded from variable 'x')}} | ||
} | ||
|
||
class SuppressedMethodClass { | ||
[[clang::suppress]] int foo() { | ||
int *x = 0; | ||
return *x; | ||
} | ||
|
||
[[clang::suppress]] int bar1(); | ||
int bar2(); | ||
}; | ||
|
||
int SuppressedMethodClass::bar1() { | ||
int *x = 0; | ||
return *x; // expected-warning{{Dereference of null pointer (loaded from variable 'x')}} | ||
} | ||
|
||
[[clang::suppress]] | ||
int SuppressedMethodClass::bar2() { | ||
int *x = 0; | ||
return *x; // no-warning | ||
} |
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.
What is going on here? How does this differ from just
getTranslationUnitDecl
?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 is, uh, a somewhat premature performance optimization. I think I want to get rid of it, as discussed in #79398 (it's incorrect as well), but it probably requires a separate discussion.
The static analyzer normally always takes the fast path as every single "supported" checker fills in the data correctly.
This isn't just about scanning the TU here for discovering suppressed ranges, it's more about the fact that the static analyzer is so careful about not analyzing non-user code that normally it doesn't even deserialize PCHs if they aren't directly required for analysis. This is demonstrated by the lovely test case in
clang/test/Analysis/check-deserialization.cpp
. A full TU scan here will cause these PCHs to be deserialized even though the rest of the analysis never needed to look at them.I have some data that this can have significant performance impact. However, other tools such as clang-tidy never had such optimization (they always scan the entire TU indiscriminately) and this never stopped them from satisfying the usual performance expectations of static analysis tools. We've also abandoned this optimization in a downstream fork for a while and it seems perfectly livable.
So I want to either abandon this non-deserialization guarantee (simply always scan the entire TU), or find a different way to satisfy it (eg., collect those ranges eagerly during AST construction so that to avoid the after-the-fact scan; then if PCHs/modules are used, suppression ranges will make it into PCHs and get deserialized together with them as-needed). I'll probably try to do some of that in the coming weeks but I wanted this patch to be independent from that so that to get the attribute's behavior to reasonable shape without breaking anything else.