[LLVMbugs] [Bug 1920] New: Structures are not Correctly Passed to Variadic Functions

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Thu Jan 17 11:47:42 PST 2008


http://llvm.org/bugs/show_bug.cgi?id=1920

           Summary: Structures are not Correctly Passed to Variadic
                    Functions
           Product: new-bugs
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Keywords: miscompilation
          Severity: major
          Priority: P2
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: tjablin at cs.princeton.edu
                CC: llvmbugs at cs.uiuc.edu


Created an attachment (id=1337)
 --> (http://llvm.org/bugs/attachment.cgi?id=1337)
Test Case

When LLVM tries to pass a structure, it breaks the structure up into several
parts, for example when passing the structure:
struct tiny {
char a;
char b;
char c;
}

LLVM generates the following code:
%tmp4 = bitcast %struct.tiny* %t to { i16, i8 }*                ; <{ i16, i8
}*> [#uses=1]
%tmp5 = getelementptr { i16, i8 }* %tmp4, i32 0, i32 0          ; <i16*>
[#uses=1]
%tmp6 = load i16* %tmp5         ; <i16> [#uses=1]
%tmp7 = bitcast %struct.tiny* %t to { i16, i8 }*                ; <{ i16, i8
}*> [#uses=1]
%tmp8 = getelementptr { i16, i8 }* %tmp7, i32 0, i32 1          ; <i8*>
[#uses=1]
%tmp9 = load i8* %tmp8          ; <i8> [#uses=1]
call void (i32, ...)* @foo( i32 0, i16 %tmp6, i8 %tmp9 )

This approach is okay in general, but disastrous for variadic functions. For
variadic functions, the callee will attempt to store each of the register
passed parameters into a contiguous region of memory. The code generator will
copy the %tmp6 and %tmp9 into adjacent machine-words of memory. Thus, on a
64-bit platform the date will appear as follows in memory: a b X X X X X X c. 
The solution is to layout parameters to variadic functions exactly as they
would be laid out in memory, replicating exactly any packing bits.

I have included a test case. The correct output is "a b c". GCC handles the
issue correctly. I have tested with llvm2.1-gcc4.2 on x86-64 and IA64.  On both
platforms the output is "a b".

Thanks.


-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list