OSDN Git Service

[BasicAA] Stop crashing when dealing with pointers > 64 bits.
authorDavide Italiano <davide@freebsd.org>
Mon, 15 Jan 2018 01:40:18 +0000 (01:40 +0000)
committerDavide Italiano <davide@freebsd.org>
Mon, 15 Jan 2018 01:40:18 +0000 (01:40 +0000)
An alternative (and probably better) fix would be that of
making `Scale` an APInt, and there's a patch floating around
to do this. As we're still discussing it, at least stop crashing
in the meanwhile (added bonus, we now have a regression test for
this situation).

Fixes PR35843.

Thanks to Eli for suggesting the fix and Simon for reporting and
reducing the bug.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@322467 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/BasicAliasAnalysis.cpp
test/Analysis/BasicAA/pr35843.ll [new file with mode: 0644]

index 5a2401f..dab5510 100644 (file)
@@ -503,6 +503,13 @@ bool BasicAAResult::DecomposeGEPExpression(const Value *V,
       Index = GetLinearExpression(Index, IndexScale, IndexOffset, ZExtBits,
                                   SExtBits, DL, 0, AC, DT, NSW, NUW);
 
+      // All GEP math happens in the width of the pointer type,
+      // so we can truncate the value to 64-bits as we don't handle
+      // currently pointers larger than 64 bits and we would crash
+      // later. TODO: Make `Scale` an APInt to avoid this problem.
+      if (IndexScale.getBitWidth() > 64)
+        IndexScale = IndexScale.sextOrTrunc(64);
+
       // The GEP index scale ("Scale") scales C1*V+C2, yielding (C1*V+C2)*Scale.
       // This gives us an aggregate computation of (C1*Scale)*V + C2*Scale.
       Decomposed.OtherOffset += IndexOffset.getSExtValue() * Scale;
diff --git a/test/Analysis/BasicAA/pr35843.ll b/test/Analysis/BasicAA/pr35843.ll
new file mode 100644 (file)
index 0000000..2830e97
--- /dev/null
@@ -0,0 +1,12 @@
+; RUN: opt %s -aa-eval -disable-output 2>&1 | FileCheck %s
+
+; CHECK: 6 Total Alias Queries Performed
+; CHECK-NEXT: 6 no alias responses
+
+define void @patatino() {
+BB:
+  %G22 = getelementptr i1*, i1** undef, i8 -1
+  %B1 = mul i66 undef, 9223372036854775808
+  %G45 = getelementptr i1**, i1*** undef, i66 %B1
+  ret void
+}