https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108432
--- Comment #3 from Segher Boessenkool <segher at gcc dot gnu.org> --- (In reply to David Malcolm from comment #2) > Unfortunately, some analyzer warnings work better with optimization > *disabled*. -fanalyzer runs much later than most other static analyzers. Understood. But some work better with it enabled, right? > For example, -Wanalyzer-deref-before-check doesn't work well with > optimization, as the dereference means that that optimized can remove the > checks before the analyzer "sees" them. Yes. > I think there's a natural tension between optimization and detecting > undefined behavior, in that -fanalyzer wants to report on possible undefined > behavior, whereas optimization wants to take advantage of undefined behavior. "Take advantage of"... A program that contains UB is erroneous, has no defined semantics *at all*, so what the compiler is really doing is assuming the program is a correct program, and generating more optimal target code based on that not unreasonable assumption. This sounds a bit better, right? It still is true that the compiler cannot detect all UB during compilation (it needs to know the program's input as well for that, and even then it isn't realistic). Is it even possible to detect *all* UB at runtime?