Skip to content

Commit 027b203

Browse files
authored
[BasicAA] Gracefully handle large LocationSize (#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 #119365 (comment).
1 parent 300d402 commit 027b203

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

llvm/lib/Analysis/BasicAliasAnalysis.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,8 +1237,11 @@ AliasResult BasicAAResult::aliasGEP(
12371237
if (V1Size.isScalable() || V2Size.isScalable())
12381238
return AliasResult::MayAlias;
12391239

1240-
// We need to know both acess sizes for all the following heuristics.
1241-
if (!V1Size.hasValue() || !V2Size.hasValue())
1240+
// We need to know both access sizes for all the following heuristics. Don't
1241+
// try to reason about sizes larger than the index space.
1242+
unsigned BW = DecompGEP1.Offset.getBitWidth();
1243+
if (!V1Size.hasValue() || !V2Size.hasValue() ||
1244+
!isUIntN(BW, V1Size.getValue()) || !isUIntN(BW, V2Size.getValue()))
12421245
return AliasResult::MayAlias;
12431246

12441247
APInt GCD;
@@ -1293,7 +1296,6 @@ AliasResult BasicAAResult::aliasGEP(
12931296

12941297
// Compute ranges of potentially accessed bytes for both accesses. If the
12951298
// interseciton is empty, there can be no overlap.
1296-
unsigned BW = OffsetRange.getBitWidth();
12971299
ConstantRange Range1 = OffsetRange.add(
12981300
ConstantRange(APInt(BW, 0), APInt(BW, V1Size.getValue())));
12991301
ConstantRange Range2 =
Lines changed: 14 additions & 0 deletions
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)