[LLVMbugs] [Bug 11597] New: Incorrect alignment warning about aligned struct members

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Dec 16 06:36:56 PST 2011


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

             Bug #: 11597
           Summary: Incorrect alignment warning about aligned struct
                    members
           Product: new-bugs
           Version: trunk
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: dimitry at andric.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified


Using clang trunk r146734 (and also 3.0 release), I get unexpected
warnings when checking for alignment problems using -Wcast-align.  I
reduced the problem case to the following:

struct foo {
} __attribute__((__aligned__(16)));

struct bar {
  int m[128] __attribute__((__aligned__(16)));
};

void baz(struct bar *b)
{
  struct foo *f = (struct foo *)&b->m;
}

Here, the bar::m member is declared to be 16-byte aligned, but clang
still warns about it, as shown:

$ clang -Wcast-align -c align2.c
align2.c:10:19: warning: cast from 'int (*)[128]' to 'struct foo *' increases
required alignment from 4 to 16 [-Wcast-align]
  struct foo *f = (struct foo *)&b->m;
                  ^~~~~~~~~~~~~~~~~~~
1 warning generated.

If I interpret gcc's documentation on aligned attributes correctly, the
alignment is supposed to apply to the array base m here, not to each
individual member of the array.  So in that case, the warning is
incorrect.

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