From 3d01334e6fa5caba1361d088fabf728c64b23c58 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 19 Aug 2009 22:46:59 +0000 Subject: Fix a bug in the over-index constant folding. When over-indexing an array member of a struct, it's possible to land in an arbitrary position inside that struct, such that attempting to find further getelementptr indices will fail. In such cases, folding cannot be done. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79485 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../InstCombine/constant-fold-gep-overindex.ll | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 test/Transforms/InstCombine/constant-fold-gep-overindex.ll (limited to 'test') diff --git a/test/Transforms/InstCombine/constant-fold-gep-overindex.ll b/test/Transforms/InstCombine/constant-fold-gep-overindex.ll new file mode 100644 index 0000000000..15bdab49ee --- /dev/null +++ b/test/Transforms/InstCombine/constant-fold-gep-overindex.ll @@ -0,0 +1,17 @@ +; RUN: llvm-as < %s | opt -instcombine +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128" +target triple = "i386-apple-darwin10.0" + +%0 = type { i8*, [19 x i8] } +%1 = type { i8*, [0 x i8] } + +@s = external global %0 ; <%0*> [#uses=1] +@"\01LC8" = external constant [17 x i8] ; <[17 x i8]*> [#uses=1] + +define i32 @main() nounwind { +entry: + %0 = call i32 (i8*, ...)* @printf(i8* getelementptr ([17 x i8]* @"\01LC8", i32 0, i32 0), i8* undef, i8* getelementptr (%1* bitcast (%0* @s to %1*), i32 0, i32 1, i32 0)) nounwind ; [#uses=0] + ret i32 0 +} + +declare i32 @printf(i8*, ...) nounwind -- cgit v1.2.3