https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67433
Markus Trippelsdorf <trippels at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |trippels at gcc dot gnu.org --- Comment #9 from Markus Trippelsdorf <trippels at gcc dot gnu.org> --- (In reply to xuejuncao from comment #8) > 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; No, you're still invoking undefined behavior. -fsanitize=undefined will not fix this at all; it just points out the issues. You need to get rid of the underlying problem, but this is not the place to discuss this further.