[BasicAA] Gracefully handle large LocationSize#138528
Merged
Conversation
If the LocationSize is larger than the index space of the pointer type, bail out instead of triggering an APInt assertion.
Member
|
@llvm/pr-subscribers-llvm-analysis Author: Nikita Popov (nikic) ChangesIf the LocationSize is larger than the index space of the pointer type, bail out instead of triggering an APInt assertion. Fixes the issue reported at #119365 (comment). 2 Files Affected:
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
index 2de9bb502baf4..30222b87ea467 100644
--- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp
@@ -1237,8 +1237,11 @@ AliasResult BasicAAResult::aliasGEP(
if (V1Size.isScalable() || V2Size.isScalable())
return AliasResult::MayAlias;
- // We need to know both acess sizes for all the following heuristics.
- if (!V1Size.hasValue() || !V2Size.hasValue())
+ // We need to know both access sizes for all the following heuristics. Don't
+ // try to reason about sizes larger than the index space.
+ unsigned BW = DecompGEP1.Offset.getBitWidth();
+ if (!V1Size.hasValue() || !V2Size.hasValue() ||
+ !isUIntN(BW, V1Size.getValue()) || !isUIntN(BW, V2Size.getValue()))
return AliasResult::MayAlias;
APInt GCD;
@@ -1293,7 +1296,6 @@ AliasResult BasicAAResult::aliasGEP(
// Compute ranges of potentially accessed bytes for both accesses. If the
// interseciton is empty, there can be no overlap.
- unsigned BW = OffsetRange.getBitWidth();
ConstantRange Range1 = OffsetRange.add(
ConstantRange(APInt(BW, 0), APInt(BW, V1Size.getValue())));
ConstantRange Range2 =
diff --git a/llvm/test/Analysis/BasicAA/size-overflow.ll b/llvm/test/Analysis/BasicAA/size-overflow.ll
new file mode 100644
index 0000000000000..18791ba20ef5f
--- /dev/null
+++ b/llvm/test/Analysis/BasicAA/size-overflow.ll
@@ -0,0 +1,14 @@
+; RUN: opt -passes=aa-eval -print-all-alias-modref-info -disable-output 2>&1 | FileCheck %s
+
+target datalayout = "p:32:32"
+
+; Make sure that using a LocationSize larget than the index space does not
+; assert.
+
+; Just Mod: Ptr: i32* %gep <-> call void @llvm.memset.p0.i64(ptr %p, i8 0, i64 68719476736, i1 false)
+define void @test(ptr %p, i32 %idx) {
+ %gep = getelementptr i8, ptr %p, i32 %idx
+ load i32, ptr %gep
+ call void @llvm.memset.i64(ptr %p, i8 0, i64 u0x100000000, i1 false)
+ ret void
+}
|
fhahn
reviewed
May 5, 2025
| ; Make sure that using a LocationSize larget than the index space does not | ||
| ; assert. | ||
|
|
||
| ; Just Mod: Ptr: i32* %gep <-> call void @llvm.memset.p0.i64(ptr %p, i8 0, i64 68719476736, i1 false) |
Contributor
There was a problem hiding this comment.
Missing CHECK below?
Suggested change
| ; Just Mod: Ptr: i32* %gep <-> call void @llvm.memset.p0.i64(ptr %p, i8 0, i64 68719476736, i1 false) | |
| ; CHECK: Just Mod: Ptr: i32* %gep <-> call void @llvm.memset.p0.i64(ptr %p, i8 0, i64 68719476736, i1 false) |
Contributor
Author
There was a problem hiding this comment.
Oops, looks like I never actually ran the new test...
Contributor
Author
|
/cherry-pick 027b203 |
Member
|
/pull-request #138681 |
GeorgeARM
pushed a commit
to GeorgeARM/llvm-project
that referenced
this pull request
May 7, 2025
If the LocationSize is larger than the index space of the pointer type, bail out instead of triggering an APInt assertion. Fixes the issue reported at llvm#119365 (comment).
swift-ci
pushed a commit
to swiftlang/llvm-project
that referenced
this pull request
May 9, 2025
If the LocationSize is larger than the index space of the pointer type, bail out instead of triggering an APInt assertion. Fixes the issue reported at llvm#119365 (comment). (cherry picked from commit 027b203)
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
If the LocationSize is larger than the index space of the pointer type, bail out instead of triggering an APInt assertion.
Fixes the issue reported at #119365 (comment).