[LLVMbugs] [Bug 1531] NEW: type alignment non forwarded to malloc instruction in C and C++ frontends

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Mon Jul 2 09:57:27 PDT 2007


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

           Summary: type alignment non forwarded to malloc instruction in C
                    and C++ frontends
           Product: new-bugs
           Version: unspecified
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: loufoque at gmail.com


In the following C code (with GCC extensions):

struct test
{
    int a;
    int b __attribute__((aligned(16)));
};

void do_something(struct test*);

int main()
{
    struct test* t = malloc(sizeof *t);
    do_something(t);

    return 0;
}

The type "struct test" has an associated alignment of 16.

However, LLVM will do a normal malloc instruction, without saying it wants an
alignment of 16.
While it is true that GCC won't be able to do that anyway because to it malloc
is a regular function that only allocates with an alignment of 8, the malloc
instruction can be smart enough here to allocate with the appropriate alignment.

Actual output:

; ModuleID = '/tmp/webcompile/_30695_0.bc'
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"
target triple = "i686-pc-linux-gnu"
	%struct.test = type { i32, [12 x i8], i32, [12 x i8] }

define i32 @main() {
entry:
	%tmp16 = malloc %struct.test		; <%struct.test*> [#uses=1]
	tail call void @do_something( %struct.test* %tmp16 )
	ret i32 0
}

declare void @do_something(%struct.test*)


Expected output:

; ModuleID = '/tmp/webcompile/_30695_0.bc'
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"
target triple = "i686-pc-linux-gnu"
	%struct.test = type { i32, [12 x i8], i32, [12 x i8] }

define i32 @main() {
entry:
	%tmp16 = malloc %struct.test, align 16		; <%struct.test*> [#uses=1]
	tail call void @do_something( %struct.test* %tmp16 )
	ret i32 0
}

declare void @do_something(%struct.test*)



------- 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