make simplifycfg insert an llvm.trap before the 'unreachable' it introduces
authorChris Lattner <sabre@nondot.org>
Sat, 8 May 2010 22:15:59 +0000 (22:15 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 8 May 2010 22:15:59 +0000 (22:15 +0000)
commitc7d7e0cbe0a83881e4a01b0be745e169bd1baea0
tree9f8309dc29adc503fd04011c1332eb63767bd5a7
parent6745191070503f669b07bc14cd6f7e518bd4d5b0
make simplifycfg insert an llvm.trap before the 'unreachable' it introduces
when it detects undefined behavior.  llvm.trap generally codegens into some
thing really small (e.g. a 2 byte ud2 instruction on x86) and debugging this
sort of thing is "nontrivial".  For example, we now compile:

void foo() { *(int*)0 = 42; }

into:

_foo:
pushl %ebp
movl %esp, %ebp
ud2

Some may even claim that this is a security hole, though that seems dubious
to me.  This addresses rdar://7958343 - Optimizing away null dereference
potentially allows arbitrary code execution

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@103356 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Scalar/SimplifyCFGPass.cpp
test/Transforms/SimplifyCFG/trapping-load-unreachable.ll