Author: Nikita Popov Date: 2025-05-09T13:37:40-07:00 New Revision: 2386c377db4ff35129d1dc6a618ea13252493ca4
URL: https://github.com/llvm/llvm-project/commit/2386c377db4ff35129d1dc6a618ea13252493ca4 DIFF: https://github.com/llvm/llvm-project/commit/2386c377db4ff35129d1dc6a618ea13252493ca4.diff LOG: [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 https://github.com/llvm/llvm-project/pull/119365#issuecomment-2849874894. (cherry picked from commit 027b2038140f309467585298f9cb10d6b37411e7) Added: llvm/test/Analysis/BasicAA/size-overflow.ll Modified: llvm/lib/Analysis/BasicAliasAnalysis.cpp Removed: ################################################################################ diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp index b2a3f3390e000..06e8eb7072917 100644 --- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp +++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp @@ -1245,8 +1245,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; @@ -1301,7 +1304,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..2a390d29e472a --- /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 < %s 2>&1 | FileCheck %s + +target datalayout = "p:32:32" + +; Make sure that using a LocationSize larget than the index space does not +; assert. + +; CHECK: Just Mod: Ptr: i32* %gep <-> call void @llvm.memset.p0.i64(ptr %p, i8 0, i64 4294967296, 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 +} _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits