<html>
<head>
<base href="https://bugs.llvm.org/">
</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 - -Waddress-of-packed-member false positive on sizeof(*&struct->field)"
href="https://bugs.llvm.org/show_bug.cgi?id=39113">39113</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>-Waddress-of-packed-member false positive on sizeof(*&struct->field)
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>7.0
</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>peter.maydell@linaro.org
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>clang's -Waddress-of-packed-member warning gives false positives on constructs
like "sizeof(*&px->i)". This doesn't actually ever dereference the member
field, so there is never an unaligned pointer in play, and it shouldn't cause
a warning. The same thing applies to typeof() and possibly other similar
constructs.
Reproducer:
$ cat zz9.c
struct x {
char c;
int i;
} __attribute__((packed));
int main(void) {
struct x *px;
typeof(*&px->i) v = 0;
return v + sizeof(*&px->i);
}
$ clang-7 -g -Wall -o zz9.o -c zz9.c
zz9.c:8:15: warning: taking address of packed member 'i' of class or
structure 'x' may result in an unaligned pointer value
[-Waddress-of-packed-member]
typeof(*&px->i) v = 0;
^~~~~
zz9.c:9:26: warning: taking address of packed member 'i' of class or
structure 'x' may result in an unaligned pointer value
[-Waddress-of-packed-member]
return v + sizeof(*&px->i);
^~~~~
2 warnings generated.
Tested using clang-7 from the Ubuntu Xenial packages at <a href="http://apt.llvm.org/">http://apt.llvm.org/</a>.
(The real world code that triggers this false-positive is in QEMU. It's in a
macro which takes an address, which is the cause of the odd-looking "*&"
construction; the * is in the macro and the & in its caller.
<a href="https://git.qemu.org/?p=qemu.git;a=blob;f=linux-user/qemu.h;h=b4959e41c6e384f4523573049db4b56a22ee3880;hb=38441756b70eec5807b5f60dad11a93a91199866#l471">https://git.qemu.org/?p=qemu.git;a=blob;f=linux-user/qemu.h;h=b4959e41c6e384f4523573049db4b56a22ee3880;hb=38441756b70eec5807b5f60dad11a93a91199866#l471</a>
The __get_user_e() and __put_user_e() macros trigger the warning for the sizeof
and typeof uses if the user of the macro does "__get_user_e(x,
&packed_struct->member)".)</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>