[llvm-dev] How and where optimizing of undefined behavior happens

John Regehr via llvm-dev llvm-dev at lists.llvm.org
Sat Nov 18 12:55:12 PST 2017

By default, Clang has little or nothing to do with UB, its job is to do 
a straightforward translation to IR.  UB-related optimizations are 
spread throughout the passes.  You can get a bit of an idea of what's 
going on by running this command from an LLVM source tree:

   find ./lib -name '*.cpp' | xargs grep -i undef

But also, a lot of sanitizer code lives in Clang.


On 11/18/2017 11:35 AM, Denis Bakhvalov via llvm-dev wrote:
> Dear community,
> I was wondering how exactly clang/llvm handles undefined behavior (UB).
> Because of this experiment: https://godbolt.org/g/cEmGHa,
> I tend to think that clang is light-weight in this subject and does
> not detect UB.
> And all the optimizations related to UB are done in llvm via some
> optimization pass (passes).
> Is it so? If so than what is the name of that pass? And do different
> optimization levels detect different UB cases, i.e. will situation
> change with O1, O2, O3?

More information about the llvm-dev mailing list