[LLVMdev] proposal for exploiting undefined behavior much more aggressively

Chris Lattner clattner at apple.com
Thu Jul 26 15:41:50 PDT 2012


On Jul 26, 2012, at 9:58 AM, John Regehr wrote:
> http://blog.regehr.org/archives/761

It's an interesting post, but I'd like to point out that it is a non-goal for the project to be actively hostile to users of the compiler.  :)  It is useful to have debugging tools for people who really care, but "exploiting" undefined behavior just for the sake of breaking code is a non-goal.

A specific example is code like this (which is quite common):

int ftoi(float F) {
  return *(int*)&F;
}

This is a violation of the C spec, due to type-based aliasing issues (the right approach is to use a union).  That said, we go out of our way to not break this sort of idiom, because it is obvious to the compiler and actively hostile to a widely used pattern in dusty deck code.

-Chris



More information about the llvm-dev mailing list