[LLVMdev] Possible bug in TCO?

Jon Harrop jon at ffconsultancy.com
Wed Nov 25 15:15:19 PST 2009


On Wednesday 25 November 2009 19:19:28 Jon Harrop wrote:
> I'm using LLVM 2.6. Anyone recognise this as a bug in TCO fixed since then
> or should I try to boil it down and submit it?

I've come up with the following minimal repro that segfaults on my machine:

  define fastcc i32 @g({i32, {i32, i32}}) {
    %1 = extractvalue {i32, {i32, i32}} %0, 0
    %2 = extractvalue {i32, {i32, i32}} %0, 1
    %3 = extractvalue {i32, i32} %2, 0
    %4 = extractvalue {i32, i32} %2, 1
    %5 = add i32 %1, %3
    %6 = add i32 %5, %4
    ret i32 %6
  }
  
  define fastcc i32 @f({i32, {i32, i32}}) {
    %1 = tail call fastcc i32 @g({i32, {i32, i32}} %0)
    ret i32 %1
  }
  
  define i32 @main() {
    %1 = insertvalue {i32, {i32, i32}} undef, i32 1, 0
    %2 = insertvalue {i32, i32} undef, i32 2, 0
    %3 = insertvalue {i32, i32} %2, i32 3, 1
    %4 = insertvalue {i32, {i32, i32}} %1, {i32, i32} %3, 1
    %5 = call i32 @f({i32, {i32, i32}} %4)
    ret i32 %5
  }

I believe this is a bug in the handling of nested structs across tail calls. 
There is no pointer manipulation or allocation in this code yet valgrind says 
it dies trying to access memory location 0x1.

I'll try with the latest SVN repo to see if it works...

-- 
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e



More information about the llvm-dev mailing list