[Bug c/87392] UBSAN behavior on left-shifting 1 into the sign bit is dependent on C standard
pinskia at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Sun Sep 23 11:08:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87392
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
In C90, it was implemented defined behavior (while in C99 and above it is
undefined behavior).
See the thread which added undefined santizer:
https://gcc.gnu.org/ml/gcc-patches/2013-06/msg00275.html
For the "a < 0" here, and signed left shift of a positive value shifting a
1 into or past the sign bit, I think it should be possible to control the
checks separately from other checks on shifts - both because those cases
were implementation-defined in C90, only undefined in C99/C11, and because
they are widely used in practice.
--- CUT ---
See also https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54027 where a C90 program
is defined but C99 would be defined and there is talk about why too.
>I provide evidence that UBSAN behaves differently between the C89/C90 and C11/C18 implementations.
Yes you did not read the full quote there. The part about ubsan is with
respect to C99 undefined behavior. AGain in C90, this is implementation
defined while C99 it is undefined. YES there is a huge difference between the
languages which cannot be changed now as that would be requiring to change C90.
>ANSI C
ANSI C is ISO C. ANSI is a member of ISO. I think you meant to write ANSI C89
there :).
More information about the Gcc-bugs
mailing list