[Bug sanitizer/105141] New: #pragma pack(1) causes incorrect UBSAN warning
shaohua.li at inf dot ethz.ch
gcc-bugzilla@gcc.gnu.org
Sun Apr 3 20:26:01 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105141
Bug ID: 105141
Summary: #pragma pack(1) causes incorrect UBSAN warning
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: sanitizer
Assignee: unassigned at gcc dot gnu.org
Reporter: shaohua.li at inf dot ethz.ch
CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxin at gcc dot gnu.org
Target Milestone: ---
For the following code, UBSAN would warn a "load of misaligned address".
Removing #pragma pack(1) will make the warning away.
$cat a.c
#pragma pack(1)
struct {
char a;
int b;
} c;
int *d = &c.b;
int main() {
__builtin_printf("%d\n", *d);
}
$
$gcc -fsanitize=undefined -O0 -w a.c;./a.out
~/a.c:8:5: runtime error: load of misaligned address 0x0000004040ca for type
'int', which requires 4 byte alignment
0x0000004040ca: note: pointer points here
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00
^
0
$
$
More information about the Gcc-bugs
mailing list