[Bug c/67433] ?: expression returns unexpected value when condition is a bool variable which memory is not true/false

xuejuncao at gmail dot com gcc-bugzilla@gcc.gnu.org
Wed Sep 2 09:04:00 GMT 2015


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67433

--- Comment #8 from xuejuncao <xuejuncao at gmail dot com> ---
thanks, i get the below result with -fsanitize=undefined 

boolmagic.c:12:16: runtime error: load of value 255, which is not a valid value
for type '_Bool'
boolmagic.c:13:15: runtime error: load of value 255, which is not a valid value
for type '_Bool'
boolmagic.c:14:15: runtime error: load of value 255, which is not a valid value
for type '_Bool'
b = 1, i = 1, j = 1

but, can i say the "-fsanitize=undefined" will _corrects_ the undefined
behaviour?

or replace the code by if/else, which works fine (lucky?)

    int i; // = (u.b ? 1 : 0);
    if (u.b) i = 1; else i = 0;



More information about the Gcc-bugs mailing list