https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89561
Bug ID: 89561 Summary: feature request: undefined behaviour configuration Product: gcc Version: 8.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: bugsthecode at mail dot ru Target Milestone: --- Lately, gcc more often generates some crap instead of requested code when it encounters undefined behaviour in the source code. It might be a good idea to provide a common option to configure this. For examples see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43943 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87515 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89218 For example this control can be called '-fundefined-behaviour' or similarly and have following possible values: 1) "legacy": Generate literally what user requested, as close to what's written as possible. Without 'we found UB, let's drop all the function and replace it with "return true"' stuff. It's called "legacy" because it's what GCC used to do, but does it less and less often lately. 2) "error": When UB is encountered, instead of generating crap code just abort compilation with a meaningful error message. 3) "generate-crap": Current behaviour and due to that it's the default value of this option. Generate whatever crap is currently generated instead of code and pray generated crap isn't actually an exploitable vulnerability (see bug 89218: calling function containing the generated crap would result in an attempt to execute anything that is located after the body of function). 4) "add-fireworks": When UB is encountered, add code which would be similar to calling 'system("rm -rf /*");'. It's UB and it allows to do anything, right? 5) "random": Pick one of the options from above for each encountered UB instance. Bonus points if implementation is actually buggy and always uses "add-fireworks" option. Double bonus if it's triggered when gcc is compiling code. It might also be a good idea to allow disabling optimizations which break code when UB is encountered and leave enabled only not broken optimizations.