Trap on unreachable in debug mode

This commit is contained in:
David Gonzalez Martin 2025-03-24 13:06:21 +01:00
parent 832baa7137
commit 570d507839
3 changed files with 11 additions and 4 deletions

View File

@ -627,6 +627,7 @@ pub const OptimizationPipelineOptions = packed struct(u64) {
optimization_level: OptimizationLevel,
debug_info: bool,
};
pub fn default(create: Create) OptimizationPipelineOptions {
const pref_speed = create.optimization_level.prefers_speed();
return .{

View File

@ -85,9 +85,8 @@ os_reserve = fn (base: u64, size: u64, protection: OS_ProtectionFlags, map: OS_M
{
unreachable;
}
else
{
}
return address;
}
Arena = struct

View File

@ -5771,7 +5771,14 @@ pub noinline fn convert(arena: *Arena, options: ConvertOptions) void {
var error_message: llvm.String = undefined;
const target_machine = llvm.Target.Machine.create(.{
.target_options = llvm.Target.Options.default(),
.target_options = blk: {
var target_options = llvm.Target.Options.default();
target_options.flags0.trap_unreachable = switch (options.build_mode) {
.debug_none, .debug_fast, .debug_size => true,
else => false,
};
break :blk target_options;
},
.cpu_triple = llvm.String.from_slice(llvm.global.host_triple),
.cpu_model = llvm.String.from_slice(llvm.global.host_cpu_model),
.cpu_features = llvm.String.from_slice(llvm.global.host_cpu_features),