From f9a34131128dffaeac7561afe34956ec2ee17fef Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 17 Oct 2023 18:10:44 -0700 Subject: [PATCH] compiler: better default for valgrind * Default to off when strip=true * Report an error when explicitly enabled but not supported for the target --- src/Compilation.zig | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Compilation.zig b/src/Compilation.zig index 5bfabfdcfc..cb5281c696 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -1111,12 +1111,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { return error.StackProtectorUnavailableWithoutLibC; } - const valgrind: bool = b: { - if (!target_util.hasValgrindSupport(options.target)) - break :b false; - break :b options.want_valgrind orelse (options.optimize_mode == .Debug); - }; - const include_compiler_rt = options.want_compiler_rt orelse needs_c_symbols; const must_single_thread = target_util.isSingleThreaded(options.target); @@ -1159,6 +1153,15 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { } const strip = options.strip orelse !target_util.hasDebugInfo(options.target); + const valgrind: bool = b: { + if (!target_util.hasValgrindSupport(options.target)) break :b false; + if (options.want_valgrind) |explicit| break :b explicit; + if (strip) break :b false; + break :b options.optimize_mode == .Debug; + }; + if (!valgrind and options.want_valgrind == true) + return error.ValgrindUnsupportedOnTarget; + const red_zone = options.want_red_zone orelse target_util.hasRedZone(options.target); const omit_frame_pointer = options.omit_frame_pointer orelse (options.optimize_mode != .Debug); const linker_optimization: u8 = options.linker_optimization orelse switch (options.optimize_mode) {