[LLVMbugs] [Bug 6178] New: Unaligned loads are created for packed structs

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Sat Jan 30 05:21:14 PST 2010


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

           Summary: Unaligned loads are created for packed structs
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: LLVM Codegen
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: asl at math.spbu.ru
                CC: llvmbugs at cs.uiuc.edu


Consider the following code:

struct foo
{  char a;
   char b;
   char c;
   int  d;
} __attribute__((packed));

extern struct foo bar;
extern int baz;

void y(void)
{
    baz = bar.d;
}

Access to "d" results in unaligned load. However, no extra alignment specifier
is attached to load:

x86-64:
  %tmp = load i32* getelementptr inbounds (%struct.foo* @bar, i64 0, i32 3) ;
<i32> [#uses=1]

msp430:
  %tmp = load i16* getelementptr inbounds (%struct.foo* @bar, i16 0, i32 3) ;
<i16> [#uses=1]

This results to unaligned access on targets where unaligned memops are
prohibited (e.g. arm, ppc, msp430, ...).

The correct one (for msp430) should be:
  %tmp = load i16* getelementptr inbounds (%struct.foo* @bar, i16 0, i32 3),
align 1

In fact, there is no single setAlignment() call inside CGExpr.cpp!


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