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: unassignedb...@nondot.org
Reporter: hjl.to...@gmail.com
CC: llvm-bugs@lists.llvm.org
[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]$
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs