1
Fork 0

Control LLVM's TrapUnreachable feature through rustc's TargetOptions.

This commit is contained in:
Dan Gohman 2017-11-11 07:08:00 -08:00
parent 365c159b80
commit 7b6b764917
4 changed files with 19 additions and 7 deletions

View file

@ -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);