[LLVMbugs] [Bug 5598] New: Clang generate wrong alignement on packed structure

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Mon Nov 23 08:45:29 PST 2009


           Summary: Clang generate wrong alignement on packed structure
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: LLVM Codegen
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: quickslyver at free.fr
                CC: llvmbugs at cs.uiuc.edu

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

this code generate unaligned access with clang:

struct __attribute__((__packed__)) s { char c; unsigned long x; };
void foo (struct s *s) { s->x = 0; }

for example with arm:
clang outputs:

  mov r1, #0
  str r1, [r0, #+1]
  bx lr

this generate an unaligned access exception.

gcc outputs:

  mov r3, #0
  strb r3, [r0, #4]
  strb r3, [r0, #1]
  strb r3, [r0, #2]
  strb r3, [r0, #3]
  bx lr

the llvm IR with clang without optimizations:

$ clang-cc -emit-llvm -o - -disable-llvm-optzns test.c
; ModuleID = 'test.c'
target datalayout =
target triple = "arm-unknown-unknown"

%struct.s = type <{ i8, i32 }>

define arm_aapcscc void @foo(%struct.s* %s) nounwind {
  %s.addr = alloca %struct.s*                     ; <%struct.s**> [#uses=2]
  store %struct.s* %s, %struct.s** %s.addr
  %tmp = load %struct.s** %s.addr                 ; <%struct.s*> [#uses=1]
  %tmp1 = getelementptr inbounds %struct.s* %tmp, i32 0, i32 1 ; <i32*>
  store i32 0, i32* %tmp1
  ret void

According to baldrick the last store should be:
store i32 0, i32* %tmp1, align 1
instead of 
store i32 0, i32* %tmp1

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