Skip to content

Commit 2386c37

Browse files
nikictstellar
authored andcommitted
[BasicAA] Gracefully handle large LocationSize (llvm#138528)
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)
1 parent 961ce35 commit 2386c37

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

llvm/lib/Analysis/BasicAliasAnalysis.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -1245,8 +1245,11 @@ AliasResult BasicAAResult::aliasGEP(
12451245
if (V1Size.isScalable() || V2Size.isScalable())
12461246
return AliasResult::MayAlias;
12471247

1248-
// We need to know both acess sizes for all the following heuristics.
1249-
if (!V1Size.hasValue() || !V2Size.hasValue())
1248+
// We need to know both access sizes for all the following heuristics. Don't
1249+
// try to reason about sizes larger than the index space.
1250+
unsigned BW = DecompGEP1.Offset.getBitWidth();
1251+
if (!V1Size.hasValue() || !V2Size.hasValue() ||
1252+
!isUIntN(BW, V1Size.getValue()) || !isUIntN(BW, V2Size.getValue()))
12501253
return AliasResult::MayAlias;
12511254

12521255
APInt GCD;
@@ -1301,7 +1304,6 @@ AliasResult BasicAAResult::aliasGEP(
13011304

13021305
// Compute ranges of potentially accessed bytes for both accesses. If the
13031306
// interseciton is empty, there can be no overlap.
1304-
unsigned BW = OffsetRange.getBitWidth();
13051307
ConstantRange Range1 = OffsetRange.add(
13061308
ConstantRange(APInt(BW, 0), APInt(BW, V1Size.getValue())));
13071309
ConstantRange Range2 =
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; RUN: opt -passes=aa-eval -print-all-alias-modref-info -disable-output < %s 2>&1 | FileCheck %s
2+
3+
target datalayout = "p:32:32"
4+
5+
; Make sure that using a LocationSize larget than the index space does not
6+
; assert.
7+
8+
; CHECK: Just Mod: Ptr: i32* %gep <-> call void @llvm.memset.p0.i64(ptr %p, i8 0, i64 4294967296, i1 false)
9+
define void @test(ptr %p, i32 %idx) {
10+
%gep = getelementptr i8, ptr %p, i32 %idx
11+
load i32, ptr %gep
12+
call void @llvm.memset.i64(ptr %p, i8 0, i64 u0x100000000, i1 false)
13+
ret void
14+
}

0 commit comments

Comments
 (0)