-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[clang][analyzer] CallAndMessage warnings at pointer to uninitialized struct #164600
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
Open
balazske
wants to merge
6
commits into
llvm:main
Choose a base branch
from
balazske:callandmessage_uninitref_struct
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+255
−76
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3d11777
[clang][analyzer] CallAndMessage warnings at pointer to uninitialized…
balazske 2ec7140
use the code already included in the checker to find uninitialized LCV
balazske fc0c6a0
using formatv
balazske 82bf7a1
fixed formatting
balazske efe0010
Merge branch 'main' into callandmessage_uninitref_struct
balazske 7260baf
adding option for complete struct initializedness
balazske 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,18 @@ void pointee_uninit(void) { | |
| doStuff_pointerToConstInt(p); // expected-warning{{1st function call argument is a pointer to uninitialized value [core.CallAndMessage]}} | ||
| } | ||
|
|
||
| typedef struct S { | ||
| int a; | ||
| short b; | ||
| } S; | ||
|
|
||
| void doStuff_pointerToConstStruct(const S *s){}; | ||
| void pointee_uninit_struct(void) { | ||
| S s; | ||
| S *p = &s; | ||
| doStuff_pointerToConstStruct(p); // expected-warning{{1st function call argument is a pointer to uninitialized value [core.CallAndMessage]}} | ||
|
||
| } | ||
|
|
||
| // TODO: If this hash ever changes, turn | ||
| // core.CallAndMessage:ArgPointeeInitializedness from a checker option into a | ||
| // checker, as described in the CallAndMessage comments! | ||
|
|
||
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.
I did not find information about if this is the correct way of detecting that the value is not initialized.
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.
Certainly more conditions are needed, the current version is
LCV->getStore() == nullptr && isa<NonParamVarRegion>(LCV->getRegion()). Still at some C++ cases (for example memory allocated withnew) the uninitialized struct is still not detected.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.
There is no way you can ask for the underlying value of an LCV, so by extension you also can't detect if it's uninitialized or not. Here you would need to know if any of the bindings in the cluster of the region of the LCV in the Store of the LCV refers to undef.
That can be undef for 2 reasons: 1) the default binding at least partially covering that region is undef., or 2) there is a direct binding of Undef that at least partially overlaps with that region.
iterBindings could give you the list of direct bindings, but I don't think there is a way to query a default binding. NVM, there is one api,
getDefaultBinding. But I start to really hate these LCVs and the regionstore.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.
Is it possible that there is no binding at all? Even with
iterBindingsover subregions and super-regions, no binding is found.LazyCoupoundValueis not necessary for this search (memregion and store is available from elsewhere). The LCV can contain a nullStorepointer (and exactly this case looks interesting).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.
If there is no cluster for the region, than it means that we saw no stores to that place.
Reading from such a place might be still valid for global storage duration objects such as: globals, local statics, thread local objects. This can be inferred from the memory space associated with the region.