diff options
author | Simon Pilgrim <llvm-dev@redking.me.uk> | 2018-08-13 12:10:09 +0000 |
---|---|---|
committer | Simon Pilgrim <llvm-dev@redking.me.uk> | 2018-08-13 12:10:09 +0000 |
commit | ee82a79041a43dfa3e8249cc66c1dd0c9918c202 (patch) | |
tree | 4581dcf310924154b5972538a915e28b4c63bee4 | |
parent | b44789759b7093728849d0f4c9ae8857deea35b1 (diff) | |
download | bcm5719-llvm-ee82a79041a43dfa3e8249cc66c1dd0c9918c202.tar.gz bcm5719-llvm-ee82a79041a43dfa3e8249cc66c1dd0c9918c202.zip |
[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
llvm-svn: 339556
-rw-r--r-- | llvm/lib/CodeGen/CodeGenPrepare.cpp | 9 | ||||
-rw-r--r-- | llvm/test/CodeGen/X86/getelementptr.ll | 11 |
2 files changed, 18 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp index 725b69dbaf5..2dbf2637dc8 100644 --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -3801,8 +3801,13 @@ bool AddressingModeMatcher::matchOperationAddr(User *AddrInst, unsigned Opcode, } 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; diff --git a/llvm/test/CodeGen/X86/getelementptr.ll b/llvm/test/CodeGen/X86/getelementptr.ll index 68caf7a65f8..11d534e0560 100644 --- a/llvm/test/CodeGen/X86/getelementptr.ll +++ b/llvm/test/CodeGen/X86/getelementptr.ll @@ -78,3 +78,14 @@ define i8* @test_sext16(i8* %ptr) nounwind { %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 +} |