diff options
| author | Dan Gohman <sunfish@mozilla.com> | 2017-11-10 11:00:52 -0800 |
|---|---|---|
| committer | Dan Gohman <sunfish@mozilla.com> | 2017-11-10 11:46:06 -0800 |
| commit | d9f0e88f19b691cd3e69be997c4ec75ea14c1db3 (patch) | |
| tree | 6b49a09e0f4c7308335ce42e10cb160091bede2b /src/rustllvm/PassWrapper.cpp | |
| parent | 75d25acd977085e6ae01d6a5c56cbbfc97463f89 (diff) | |
| download | rust-d9f0e88f19b691cd3e69be997c4ec75ea14c1db3.tar.gz rust-d9f0e88f19b691cd3e69be997c4ec75ea14c1db3.zip | |
Enable TrapUnreachable in LLVM.
Enable LLVM's TrapUnreachable flag, which tells it to translate `unreachable` instructions into hardware trap instructions, rather than allowing control flow to "fall through" into whatever code happens to follow it in memory.
Diffstat (limited to 'src/rustllvm/PassWrapper.cpp')
| -rw-r--r-- | src/rustllvm/PassWrapper.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/rustllvm/PassWrapper.cpp b/src/rustllvm/PassWrapper.cpp index b397ad1e98f..1fc8c42f1dd 100644 --- a/src/rustllvm/PassWrapper.cpp +++ b/src/rustllvm/PassWrapper.cpp @@ -398,6 +398,12 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine( Options.DataSections = DataSections; Options.FunctionSections = FunctionSections; + // Tell LLVM to translate `unreachable` into an explicit trap instruction. + // This limits the extent of possible undefined behavior in some cases, as it + // prevents control flow from "falling through" into whatever code happens to + // be layed out next in memory. + Options.TrapUnreachable = true; + TargetMachine *TM = TheTarget->createTargetMachine( Trip.getTriple(), RealCPU, Feature, Options, RM, CM, OptLevel); return wrap(TM); |
