public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug sanitizer/107431] New: UBSan has inconsistent behaviors in certain code snippet
@ 2022-10-27 8:39 shaohua.li at inf dot ethz.ch
2022-10-27 8:48 ` [Bug sanitizer/107431] " marxin at gcc dot gnu.org
2022-10-27 8:53 ` shaohua.li at inf dot ethz.ch
0 siblings, 2 replies; 3+ messages in thread
From: shaohua.li at inf dot ethz.ch @ 2022-10-27 8:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107431
Bug ID: 107431
Summary: UBSan has inconsistent behaviors in certain code
snippet
Product: gcc
Version: 13.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: ---
Hi, for the following code, there is a misaligned load at line 5 `long d = *c`.
UBSan detected it successfully. However, if you change the definition of `a`
from `long a` to `int a`, UBSan would report nothing.
% cat example1.c
int main() {
long a=2;
int b=1;
long *c = &b;
long d = *c;
&a;
}
% gcc -O0 -fsanitize=undefined example1.c && ./a.out
example1.c:5:10: runtime error: load of misaligned address 0x7fffd97a993c for
type 'long int', which requires 8 byte alignment
0x7fffd97a993c: note: pointer points here
f0 71 77 cc 01 00 00 00 02 00 00 00 00 00 00 00 3c 99 7a d9 ff 7f 00 00 50
9a 7a d9 ff 7f 00 00
%
% cat example2.c
int main() {
int a=2;
int b=1;
long *c = &b;
long d = *c;
&a;
}
% gcc -O0 -fsanitize=undefined example1.c && ./a.out
%
Compiler explorer: https://godbolt.org/z/4oKaMjbee
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-10-27 8:53 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-27 8:39 [Bug sanitizer/107431] New: UBSan has inconsistent behaviors in certain code snippet shaohua.li at inf dot ethz.ch
2022-10-27 8:48 ` [Bug sanitizer/107431] " marxin at gcc dot gnu.org
2022-10-27 8:53 ` shaohua.li at inf dot ethz.ch
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).