[LLVMbugs] [Bug 1541] NEW: incorrect code generation from LLVM to	x86 asm w/r to __alloca
    bugzilla-daemon at cs.uiuc.edu 
    bugzilla-daemon at cs.uiuc.edu
       
    Thu Jul  5 05:32:53 PDT 2007
    
    
  
http://llvm.org/bugs/show_bug.cgi?id=1541
           Summary: incorrect code generation from LLVM to x86 asm w/r to
                    __alloca
           Product: new-bugs
           Version: unspecified
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: normal
          Priority: P2
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: nadiasvertex at gmail.com
I'm using LLVM as the backend compiler for a language compiler I am running. 
While trying to interface to the C runtime libraries on the platform, I
consistently got garbage to the display when executing puts.
Running through a debugger, I see that the memory being set aside by __alloca is
being lost.  I have included both the LLVM and the generated x86 code, as well a
comment where I think the generated code is broken.
The LLVM code:
%r2 = select i1 true, %type.metal_string_t * %data, %type.metal_string_t * %data
;id_val
; Copy the metal string and make it into a c-string.
%r4 = getelementptr %type.metal_string_t *%r2, i32 0, i32 0
%r5 = load i32 *%r4
%r6 = add  i32 %r5, 1
%r3 = alloca i8, i32 %r6
call void @llvm.memset.i32(i8 *%r3, i8 0, i32 %r6, i32 0) 
%r7 = getelementptr %type.metal_string_t *%r2, i32 0, i32 1
%r8 = load i8 **%r7
call void @llvm.memcpy.i32(i8 *%r3, i8 *%r8, i32 %r5, i32 0)
; End copy into a c-string.
        
call i32 @puts(i8 * %r3)
The actual x86 assembler:
        movl (%esi), %edi
	movl %edi, %eax
	addl $16, %eax
	andl $4294967280, %eax
	call __alloca
	subl $16, %esp
; THIS IS THE PROBLEM: The return value from __alloca is being lost.
	movl %edi, %eax
	incl %eax
	movl %eax, 8(%esp)
	movl $0, 4(%esp)
	movl %esp, %ebx
	movl %ebx, (%esp)
	call _memset
	addl $16, %esp
	movl 4(%esi), %eax
	subl $16, %esp
	movl %edi, 8(%esp)
	movl %eax, 4(%esp)
	movl %ebx, (%esp)
	call _memcpy
	addl $16, %esp
	subl $16, %esp
	movl %ebx, (%esp)
	call _puts
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
    
    
More information about the llvm-bugs
mailing list