-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[Analysis] Make LocationSize conversion from uint64_t explicit #133342
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 1 commit
88f4db6
4bbcf54
875f3ee
7d8a534
799bfa2
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 |
|---|---|---|
|
|
@@ -102,7 +102,7 @@ class LocationSize { | |
| // | ||
| // Since the overwhelming majority of users of this provide precise values, | ||
| // this assumes the provided value is precise. | ||
| constexpr LocationSize(uint64_t Raw) | ||
| explicit constexpr LocationSize(uint64_t Raw) | ||
| : Value(Raw > MaxValue ? AfterPointer : Raw) {} | ||
| // Create non-scalable LocationSize | ||
| static LocationSize precise(uint64_t Value) { | ||
|
|
@@ -189,14 +189,16 @@ class LocationSize { | |
| bool operator==(const LocationSize &Other) const { | ||
| return Value == Other.Value; | ||
| } | ||
|
|
||
| bool operator==(const TypeSize &Other) const { | ||
| return hasValue() && getValue() == Other; | ||
| return (*this == LocationSize::precise(Other)); | ||
|
Collaborator
Author
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. This change isn't related to the conversion case. I noticed when writing the other equality operand that this idiom seems unsound - unless I'm misreading the code it allows an imprecise upper bound to compare equal with a typesize. I can split this off if anyone asks, but I don't have a test case which shows it being actually problematic in practice. |
||
| } | ||
| bool operator==(const uint64_t &Other) const { | ||
preames marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return (*this == LocationSize::precise(Other)); | ||
| } | ||
|
|
||
| bool operator!=(const LocationSize &Other) const { return !(*this == Other); } | ||
|
|
||
| bool operator!=(const TypeSize &Other) const { return !(*this == Other); } | ||
| bool operator!=(const uint64_t &Other) const { return !(*this == Other); } | ||
|
|
||
| // Ordering operators are not provided, since it's unclear if there's only one | ||
| // reasonable way to compare: | ||
|
|
@@ -301,6 +303,12 @@ class MemoryLocation { | |
| explicit MemoryLocation(const Value *Ptr, LocationSize Size, | ||
| const AAMDNodes &AATags = AAMDNodes()) | ||
| : Ptr(Ptr), Size(Size), AATags(AATags) {} | ||
| explicit MemoryLocation(const Value *Ptr, TypeSize Size, | ||
| const AAMDNodes &AATags = AAMDNodes()) | ||
| : Ptr(Ptr), Size(LocationSize::precise(Size)), AATags(AATags) {} | ||
| explicit MemoryLocation(const Value *Ptr, uint64_t Size, | ||
| const AAMDNodes &AATags = AAMDNodes()) | ||
| : Ptr(Ptr), Size(LocationSize::precise(Size)), AATags(AATags) {} | ||
|
|
||
| MemoryLocation getWithNewPtr(const Value *NewPtr) const { | ||
| MemoryLocation Copy(*this); | ||
|
|
@@ -313,6 +321,12 @@ class MemoryLocation { | |
| Copy.Size = NewSize; | ||
| return Copy; | ||
| } | ||
| MemoryLocation getWithNewSize(uint64_t NewSize) const { | ||
| return getWithNewSize(LocationSize::precise(NewSize)); | ||
| } | ||
| MemoryLocation getWithNewSize(TypeSize NewSize) const { | ||
| return getWithNewSize(LocationSize::precise(NewSize)); | ||
| } | ||
|
|
||
| MemoryLocation getWithoutAATags() const { | ||
| MemoryLocation Copy(*this); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.