From e568fa2d29c58aaedcaa832f805949d5e4371b4b Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 3 Dec 2009 01:05:45 +0000 Subject: [PATCH] fix PR5673 by being more careful about pointers to functions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@90369 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/ConstantFolding.cpp | 13 ++++++++++--- test/Transforms/InstCombine/crash.ll | 11 +++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp index 96f738edad4..4b0b9a54c77 100644 --- a/lib/Analysis/ConstantFolding.cpp +++ b/lib/Analysis/ConstantFolding.cpp @@ -569,9 +569,16 @@ static Constant *SymbolicallyEvaluateGEP(Constant *const *Ops, unsigned NumOps, SmallVector NewIdxs; do { if (const SequentialType *ATy = dyn_cast(Ty)) { - // The only pointer indexing we'll do is on the first index of the GEP. - if (isa(ATy) && !NewIdxs.empty()) - break; + if (isa(ATy)) { + // The only pointer indexing we'll do is on the first index of the GEP. + if (!NewIdxs.empty()) + break; + + // Only handle pointers to sized types, not pointers to functions. + if (!ATy->getElementType()->isSized()) + return 0; + } + // Determine which element of the array the offset points into. APInt ElemSize(BitWidth, TD->getTypeAllocSize(ATy->getElementType())); if (ElemSize == 0) diff --git a/test/Transforms/InstCombine/crash.ll b/test/Transforms/InstCombine/crash.ll index 1528f6ddf3c..82ac5757178 100644 --- a/test/Transforms/InstCombine/crash.ll +++ b/test/Transforms/InstCombine/crash.ll @@ -137,3 +137,14 @@ define arm_apcscc void @test5() { exit: ret void } + + +; PR5673 + +@test6g = external global i32* + +define arm_aapcs_vfpcc i32 @test6(i32 %argc, i8** %argv) nounwind { +entry: + store i32* getelementptr (i32* bitcast (i32 (i32, i8**)* @test6 to i32*), i32 -2048), i32** @test6g, align 4 + unreachable +}