[LLVMdev] GEP instruction change

Duncan Sands baldrick at free.fr
Fri Aug 21 04:51:22 PDT 2009


Artur Pietrek wrote:
> 
> 
> On Fri, Aug 21, 2009 at 12:33 PM, Eli Friedman <eli.friedman at gmail.com 
> <mailto:eli.friedman at gmail.com>> wrote:
> 
>     On Fri, Aug 21, 2009 at 2:02 AM, Artur Pietrek<pietreka at gmail.com
>     <mailto:pietreka at gmail.com>> wrote:
>      > Hi All,
>      > Since few days I observe weird change.
>      > Consider the following C code
>      >
>      > char array[] = "0123456789";
>      > extern int test(char arr[], int size);
>      >
>      > int main(void) {
>      >   return test(array-1, sizeof(array)-1);
>      > }
>      >
>      > using clang frontend i get this:
>      >
>      > %call = call i32 @test(i8* getelementptr inbounds ([11 x i8]*
>     @array, i32 0,
>      > i32 -1), i32 10) ; <i32> [#uses=1]
>      >
>      > and using LLVM-GCC this:
>      > %1 = call i32 @test(i8* getelementptr ([11 x i8]* @array, i32
>     1561806289,
>      > i32 4), i32 10) nounwind ; <i32> [#uses=1]
>      >
>      > Should the second getelementptr look like this? Is it correct or
>     a bug?
> 
>     Indexing out of an array is undefined behavior per C99, but that
>     particular result does look strange...
> 
> 
> So it isn't a bug?
> It's weird that it simply started to happen few days ago and only with 
> llvm-gcc.

Maybe the GEP overflow folding stuff Dan committed recently doesn't
handle negative indices properly.

Ciao,

Duncan.



More information about the llvm-dev mailing list