[llvm] r339556 - [CGP] Fix GEP issue with out of range APInt constant values not fitting in int64_t

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 13 05:10:09 PDT 2018


Author: rksimon
Date: Mon Aug 13 05:10:09 2018
New Revision: 339556

URL: http://llvm.org/viewvc/llvm-project?rev=339556&view=rev
Log:
[CGP] Fix GEP issue with out of range APInt constant values not fitting in int64_t

Test case reduced from https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=7173

Modified:
    llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
    llvm/trunk/test/CodeGen/X86/getelementptr.ll

Modified: llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp?rev=339556&r1=339555&r2=339556&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp (original)
+++ llvm/trunk/lib/CodeGen/CodeGenPrepare.cpp Mon Aug 13 05:10:09 2018
@@ -3801,8 +3801,13 @@ bool AddressingModeMatcher::matchOperati
       } else {
         uint64_t TypeSize = DL.getTypeAllocSize(GTI.getIndexedType());
         if (ConstantInt *CI = dyn_cast<ConstantInt>(AddrInst->getOperand(i))) {
-          ConstantOffset += CI->getSExtValue() * TypeSize;
-        } else if (TypeSize) {  // Scales of zero don't do anything.
+          const APInt &CVal = CI->getValue();
+          if (CVal.getMinSignedBits() <= 64) {
+            ConstantOffset += CVal.getSExtValue() * TypeSize;
+            continue;
+          }
+        }
+        if (TypeSize) {  // Scales of zero don't do anything.
           // We only allow one variable index at the moment.
           if (VariableOperand != -1)
             return false;

Modified: llvm/trunk/test/CodeGen/X86/getelementptr.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/getelementptr.ll?rev=339556&r1=339555&r2=339556&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/getelementptr.ll (original)
+++ llvm/trunk/test/CodeGen/X86/getelementptr.ll Mon Aug 13 05:10:09 2018
@@ -78,3 +78,14 @@ define i8* @test_sext16(i8* %ptr) nounwi
   %d = getelementptr i8, i8* %ptr, i8 -21
   ret i8* %d
 }
+
+
+; Test out of int64_t range indices
+
+; OSS-Fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=7173
+define void @test_outofrange(i96* %ptr) nounwind {
+; CHECK-LABEL: test_outofrange
+  %d = getelementptr i96, i96* %ptr, i96 39614081257132168796771975167
+  %ld = load i96, i96* %d, align 1
+  unreachable
+}




More information about the llvm-commits mailing list