-
Notifications
You must be signed in to change notification settings - Fork 14.6k
[analyzer] Fix getElementRegion to retain address space information #151249
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,18 @@ | ||||||||||||||||||||||||||||
// RUN: %clang_analyze_cc1 -triple amdgcn-unknown-unknown \ | ||||||||||||||||||||||||||||
// RUN: -analyzer-checker=core,unix.Malloc,debug.ExprInspection -verify \ | ||||||||||||||||||||||||||||
// RUN: -Wno-incompatible-pointer-types -Wno-unused-comparison %s | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
// expected-no-diagnostics | ||||||||||||||||||||||||||||
// | ||||||||||||||||||||||||||||
// By default, pointers are 64-bits. | ||||||||||||||||||||||||||||
#define ADDRESS_SPACE_32BITS __attribute__((address_space(3))) | ||||||||||||||||||||||||||||
ADDRESS_SPACE_32BITS void *b(); | ||||||||||||||||||||||||||||
ADDRESS_SPACE_32BITS int *c(); | ||||||||||||||||||||||||||||
typedef struct { | ||||||||||||||||||||||||||||
ADDRESS_SPACE_32BITS int *e; | ||||||||||||||||||||||||||||
} f; | ||||||||||||||||||||||||||||
void g() { | ||||||||||||||||||||||||||||
ADDRESS_SPACE_32BITS void *h = b(); | ||||||||||||||||||||||||||||
ADDRESS_SPACE_32BITS f *j = c(); | ||||||||||||||||||||||||||||
j->e == h; | ||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||
Comment on lines
+9
to
+18
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. I experimented with this test and it turns out that the crux is that you compare an I verified that (without your fix) the assertion is also triggered by
Suggested change
so I think it would be better to use this instead of your (also correct, but more complex) example. |
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'm not sure how broadly this function is useful for anyone else.
If only the static analyzer uses this, then probably we should just have this as a static helper there instead.
BTW I'm not really familiar with the QualType methods, but I was not expecting mutations if we anyway return a value. What I'd expect when calling this function that this would not mutate (and have side effect) the object itself but just return the right value instead.
This semantic is usually achieved by taking a copy of self, apply the mutation on the copy and return the mutated copy.
Alternatively, you could decide to have a
void
return type to solve this inconsistency, and clearly admit that calling this has side effects.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 don't think that this method would be used outside of the static analyzer, so as @steakhal also suggested I think this should be a static function in
MemRegion.cpp
(and not a method ofQualType
which is used everywhere in clang).