[llvm-bugs] [Bug 35941] New: Missing -Waddress-of-packed-member check
via llvm-bugs
llvm-bugs at lists.llvm.org
Sat Jan 13 06:35:41 PST 2018
https://bugs.llvm.org/show_bug.cgi?id=35941
Bug ID: 35941
Summary: Missing -Waddress-of-packed-member check
Product: new-bugs
Version: 4.0
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: new bugs
Assignee: unassignedbugs at nondot.org
Reporter: hjl.tools at gmail.com
CC: llvm-bugs at lists.llvm.org
[hjl at 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 at gnu-tools-1 pr51628]$ clang -S p.c
[hjl at 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 at gnu-tools-1 pr51628]$
--
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/20180113/6ccb6d69/attachment-0001.html>
More information about the llvm-bugs
mailing list