------- Comment #2 from joseph at codesourcery dot com 2010-07-23 20:41 ------- Subject: Re: -fcatch-undefined-behavior: Turn on runtime code generation to check for undefined behavior
On Mon, 5 Jul 2010, pinskia at gcc dot gnu dot org wrote: > -ftrapv checks for one undefined behavior which is not mentioned in that > list. > Why isn't that listed? > > > # Shift operators where the amount shifted is greater or equal to the > promoted bit-width of the left-hand-side or less than zero. > > I think C90 and C99 say slightly different things here. You may be thinking of the cases of signed left shift that are undefined only in C99 (and implementation-defined in C90). I think having options to trap on various detectable cases of undefined behavior *is* a good idea, but there should be separate options for the separate cases. Thus we already have -ftrapv (which, if made to work properly, might have different variants for strict detection of overflow and for allowing overflows to be folded away) and could add -ftrapv-shift to detect cases of shift counts out of range (similarly, -fwrapv-shift to give defined results for such shifts). You might then consider a catch-all option to enable the various separate options. The C1x drafts have a woefully underdefined Analyzability annex describing an option that bounds most kinds of undefined behavior. If this ever gets better specified than it is at present, there would be various possibilities for an option to implement that annex, either trapping on particular undefined behavior or bounding what effects it has. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44786