<html>
<head>
<base href="https://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - alignof(double) should yield 4 on x86"
href="https://llvm.org/bugs/show_bug.cgi?id=26547">26547</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>alignof(double) should yield 4 on x86
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.7
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>eggert@cs.ucla.edu
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=15864" name="attach_15864" title="C program illustrating the bug">attachment 15864</a> <a href="attachment.cgi?id=15864&action=edit" title="C program illustrating the bug">[details]</a></span>
C program illustrating the bug
A user ran into a problem when porting bleeding-edge GNU Emacs to a clang-based
system; see
<<a href="http://lists.gnu.org/archive/html/emacs-devel/2016-02/msg00476.html">http://lists.gnu.org/archive/html/emacs-devel/2016-02/msg00476.html</a>>. 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.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>