about summary refs log tree commit diff
path: root/src/rustllvm/PassWrapper.cpp
diff options
context:
space:
mode:
authorDan Gohman <sunfish@mozilla.com>2017-11-11 07:08:00 -0800
committerDan Gohman <sunfish@mozilla.com>2017-11-11 12:15:43 -0800
commit7b6b7649177db8edc9ef5c5075eb6cf9b00d8a9d (patch)
treedbb1a4bffeefc3121d8f3f96fab9fd117318b6c2 /src/rustllvm/PassWrapper.cpp
parent365c159b8074a89c72cfab54e53fe767f3a63900 (diff)
downloadrust-7b6b7649177db8edc9ef5c5075eb6cf9b00d8a9d.tar.gz
rust-7b6b7649177db8edc9ef5c5075eb6cf9b00d8a9d.zip
Control LLVM's TrapUnreachable feature through rustc's TargetOptions.
Diffstat (limited to 'src/rustllvm/PassWrapper.cpp')
-rw-r--r--src/rustllvm/PassWrapper.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/rustllvm/PassWrapper.cpp b/src/rustllvm/PassWrapper.cpp
index a04092cb5f9..b4116c96ba1 100644
--- a/src/rustllvm/PassWrapper.cpp
+++ b/src/rustllvm/PassWrapper.cpp
@@ -366,7 +366,7 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
     LLVMRustCodeModel RustCM, LLVMRustRelocMode RustReloc,
     LLVMRustCodeGenOptLevel RustOptLevel, bool UseSoftFloat,
     bool PositionIndependentExecutable, bool FunctionSections,
-    bool DataSections) {
+    bool DataSections, bool TrapUnreachable) {
 
   auto CM = fromRust(RustCM);
   auto OptLevel = fromRust(RustOptLevel);
@@ -398,11 +398,13 @@ 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 laid out next in memory.
-  Options.TrapUnreachable = true;
+  if (TrapUnreachable) {
+    // 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 laid out next in memory.
+    Options.TrapUnreachable = true;
+  }
 
   TargetMachine *TM = TheTarget->createTargetMachine(
       Trip.getTriple(), RealCPU, Feature, Options, RM, CM, OptLevel);