[llvm-bugs] [Bug 26547] New: alignof(double) should yield 4 on x86

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Feb 9 08:28:05 PST 2016


https://llvm.org/bugs/show_bug.cgi?id=26547

            Bug ID: 26547
           Summary: alignof(double) should yield 4 on x86
           Product: clang
           Version: 3.7
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: eggert at cs.ucla.edu
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Created attachment 15864
  --> https://llvm.org/bugs/attachment.cgi?id=15864&action=edit
C program illustrating the bug

A user ran into a problem when porting bleeding-edge GNU Emacs to a clang-based
system; see
<http://lists.gnu.org/archive/html/emacs-devel/2016-02/msg00476.html>. I
tracked the issue down to a compiler bug with clang. Although Emacs 'configure'
detects and works around the compiler bug, the compiler bug ought to be fixed.

On x86 (32-bit), clang aligns some doubles to just a multiple of 4, but says
alignof(double) is 8; this violates the C standard.

Compile and run the attached program with "clang -m32" on an x86-64 platform; I
used Fedora 23, which has clang version 3.7.0 (tags/RELEASE_370/final)
Target: x86_64-redhat-linux-gnu. The program exits with status 1, but should
exit with status 0. GCC operates correctly.

If I compile with -DPRINT_DETAILS on clang, it outputs:

sizeof (struct { char a; double b; }) = 12
offsetof (struct { char a; double b; }, b) = 4
alignof (double) = 8
&s[0].b = 0x804a024, alignment_error = 4

If I compile the same with GCC it outputs:

sizeof (struct { char a; double b; }) = 12
offsetof (struct { char a; double b; }, b) = 4
alignof (double) = 4
&s[0].b = 0x804a024, alignment_error = 0
&s[1].b = 0x804a030, alignment_error = 0


Apparently clang is confusing alignof (most-conservative alignment) with
__alignof__ (best alignment). This bug was in GCC a while ago too, but it's
been fixed there.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160209/747908c8/attachment.html>


More information about the llvm-bugs mailing list