[llvm-dev] Clang -O0 performs optimizations that undermine dynamic bug-finding tools

Daniel Berlin via llvm-dev llvm-dev at lists.llvm.org
Tue Mar 21 09:47:22 PDT 2017

>  can still detect them.
> Following, I have the following questions/suggestions:
> - Is it known that Clang performs optimizations that hide program bugs,
> even when compiling with -O0?
Some, yes, some no.

> - Are there command line options to specify that no optimizations should
> be performed?

It is not possible to compile all code correctly without optimization,
interestingly enough.  It would be nice though.
In fact, i expect things like C++ constexpr make this significantly worse.

> Until recently, I thought that -O0 had this effect.
> - In each case, I would propose to not perform optimizations at -O0 to
> allow dynamic bug finding tools to find such bugs, or at least offer a flag
> to turn off optimizations altogether.
> Again, this is impossible :)
For example, there are high profile things that depend on always_inline
functions not existing after inlining.
This inlining can definitely hide bugs (smashing call stacks, etc).
But we have to do it anyway.

So as a general statement, your proposal will not work.
If you revised it to "the minimum set of optimizations necessary for
correctness", it would be doable, but that set already conflicts in a
number of ways with "dynamic bug finding tools" :(
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170321/52d5d31b/attachment.html>

More information about the llvm-dev mailing list