<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 - Missing -Waddress-of-packed-member check"
href="https://bugs.llvm.org/show_bug.cgi?id=35941">35941</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Missing -Waddress-of-packed-member check
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>4.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>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>hjl.tools@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>[hjl@gnu-tools-1 pr51628]$ cat p.c
#include <stdio.h>
#include <stddef.h>
int main(void)
{
struct foo {
char c;
int x;
} __attribute__((packed));
struct foo arr[2] = { { 'a', 10 }, {'b', 20 } };
int *p0 = &arr[0].x;
int *p1 = &arr[1].x;
printf("sizeof(struct foo) = %d\n",
(int)sizeof(struct foo));
printf("offsetof(struct foo, c) = %d\n",
(int)offsetof(struct foo, c));
printf("offsetof(struct foo, x) = %d\n",
(int)offsetof(struct foo, x));
printf("arr[0].x = %d\n", arr[0].x);
printf("arr[1].x = %d\n", arr[1].x);
printf("p0 = %p\n", (void*)p0);
printf("p1 = %p\n", (void*)p1);
printf("*p0 = %d\n", *p0);
printf("*p1 = %d\n", *p1);
return 0;
}
[hjl@gnu-tools-1 pr51628]$ clang -S p.c
[hjl@gnu-tools-1 pr51628]$
/export/build/gnu/gcc-test/build-x86_64-linux/gcc/xg++
-B/export/build/gnu/gcc-test/build-x86_64-linux/gcc/ -O2 -S p.c
p.c: In function ‘int main()’:
p.c:10:23: warning: initialization of ‘int*’ from address of member of packed
‘main()::foo’ may result in an unaligned pointer value
[-Waddress-of-packed-member]
int *p0 = &arr[0].x;
^
p.c:11:23: warning: initialization of ‘int*’ from address of member of packed
‘main()::foo’ may result in an unaligned pointer value
[-Waddress-of-packed-member]
int *p1 = &arr[1].x;
^
[hjl@gnu-tools-1 pr51628]$</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>