[llvm] r322467 - [BasicAA] Stop crashing when dealing with pointers > 64 bits.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 14 17:40:18 PST 2018


Author: davide
Date: Sun Jan 14 17:40:18 2018
New Revision: 322467

URL: http://llvm.org/viewvc/llvm-project?rev=322467&view=rev
Log:
[BasicAA] Stop crashing when dealing with pointers > 64 bits.

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.

Added:
    llvm/trunk/test/Analysis/BasicAA/pr35843.ll
Modified:
    llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp

Modified: llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp?rev=322467&r1=322466&r2=322467&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/BasicAliasAnalysis.cpp Sun Jan 14 17:40:18 2018
@@ -503,6 +503,13 @@ bool BasicAAResult::DecomposeGEPExpressi
       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;

Added: llvm/trunk/test/Analysis/BasicAA/pr35843.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/BasicAA/pr35843.ll?rev=322467&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/BasicAA/pr35843.ll (added)
+++ llvm/trunk/test/Analysis/BasicAA/pr35843.ll Sun Jan 14 17:40:18 2018
@@ -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
+}




More information about the llvm-commits mailing list