diff --git a/src/clang_options_data.zig b/src/clang_options_data.zig index bd1237bc00..632857920b 100644 --- a/src/clang_options_data.zig +++ b/src/clang_options_data.zig @@ -75,8 +75,22 @@ flagpd1("M"), .psl = false, }, flagpd1("Mach"), -flagpd1("O0"), -flagpd1("O4"), +.{ + .name = "O0", + .syntax = .flag, + .zig_equivalent = .optimize, + .pd1 = true, + .pd2 = false, + .psl = false, +}, +.{ + .name = "O4", + .syntax = .flag, + .zig_equivalent = .optimize, + .pd1 = true, + .pd2 = false, + .psl = false, +}, .{ .name = "O", .syntax = .flag, @@ -2163,7 +2177,7 @@ flagpd1("fno-ident"), .{ .name = "Os", .syntax = .flag, - .zig_equivalent = .other, + .zig_equivalent = .optimize, .pd1 = true, .pd2 = false, .psl = true, @@ -3148,7 +3162,14 @@ flagpd1("fxray-link-deps"), flagpd1("fzero-initialized-in-bss"), flagpd1("fzvector"), flagpd1("g0"), -flagpd1("g1"), +.{ + .name = "g1", + .syntax = .flag, + .zig_equivalent = .debug, + .pd1 = true, + .pd2 = false, + .psl = false, +}, flagpd1("g2"), flagpd1("g3"), .{ @@ -3189,7 +3210,14 @@ flagpd1("ggdb3"), flagpd1("ggnu-pubnames"), flagpd1("ginline-line-tables"), flagpd1("gline-directives-only"), -flagpd1("gline-tables-only"), +.{ + .name = "gline-tables-only", + .syntax = .flag, + .zig_equivalent = .debug, + .pd1 = true, + .pd2 = false, + .psl = false, +}, flagpd1("glldb"), flagpd1("gmlt"), flagpd1("gmodules"), @@ -5363,7 +5391,7 @@ jspd1("iquote"), joinpd1("weak-l"), .{ .name = "Ofast", - .syntax = .joined, + .syntax = .flag, .zig_equivalent = .optimize, .pd1 = true, .pd2 = false, diff --git a/src/main.zig b/src/main.zig index b89ac3768e..8a3fb72102 100644 --- a/src/main.zig +++ b/src/main.zig @@ -992,15 +992,20 @@ fn buildOutputType( }, .optimize => { // Alright, what release mode do they want? - if (mem.eql(u8, it.only_arg, "Os")) { + const level = if (it.only_arg.len >= 1 and it.only_arg[0] == 'O') it.only_arg[1..] else it.only_arg; + if (mem.eql(u8, level, "s") or + mem.eql(u8, level, "z")) + { optimize_mode = .ReleaseSmall; - } else if (mem.eql(u8, it.only_arg, "O2") or - mem.eql(u8, it.only_arg, "O3") or - mem.eql(u8, it.only_arg, "O4")) + } else if (mem.eql(u8, level, "1") or + mem.eql(u8, level, "2") or + mem.eql(u8, level, "3") or + mem.eql(u8, level, "4") or + mem.eql(u8, level, "fast")) { optimize_mode = .ReleaseFast; - } else if (mem.eql(u8, it.only_arg, "Og") or - mem.eql(u8, it.only_arg, "O0")) + } else if (mem.eql(u8, level, "g") or + mem.eql(u8, level, "0")) { optimize_mode = .Debug; } else { @@ -1009,8 +1014,13 @@ fn buildOutputType( }, .debug => { strip = false; - if (mem.eql(u8, it.only_arg, "-g")) { + if (mem.eql(u8, it.only_arg, "g")) { // We handled with strip = false above. + } else if (mem.eql(u8, it.only_arg, "g1") or + mem.eql(u8, it.only_arg, "gline-tables-only")) + { + // We handled with strip = false above. but we also want reduced debug info. + try clang_argv.append("-gline-tables-only"); } else { try clang_argv.appendSlice(it.other_args); } diff --git a/tools/update_clang_options.zig b/tools/update_clang_options.zig index 8b7811aa26..9510b6a075 100644 --- a/tools/update_clang_options.zig +++ b/tools/update_clang_options.zig @@ -130,6 +130,10 @@ const known_options = [_]KnownOpt{ .name = "assemble", .ident = "asm_only", }, + .{ + .name = "O0", + .ident = "optimize", + }, .{ .name = "O1", .ident = "optimize", @@ -138,10 +142,20 @@ const known_options = [_]KnownOpt{ .name = "O2", .ident = "optimize", }, + // O3 is only detected from the joined "-O" option + .{ + .name = "O4", + .ident = "optimize", + }, .{ .name = "Og", .ident = "optimize", }, + .{ + .name = "Os", + .ident = "optimize", + }, + // Oz is only detected from the joined "-O" option .{ .name = "O", .ident = "optimize", @@ -154,6 +168,14 @@ const known_options = [_]KnownOpt{ .name = "optimize", .ident = "optimize", }, + .{ + .name = "g1", + .ident = "debug", + }, + .{ + .name = "gline-tables-only", + .ident = "debug", + }, .{ .name = "g", .ident = "debug", @@ -390,6 +412,10 @@ pub fn main() anyerror!void { // the only way. try stdout.print("flagpsl(\"{}\"),\n", .{name}); } else if (knownOption(name)) |ident| { + + // Workaround the fact that in 'Options.td' -Ofast is listed as 'joined' + const final_syntax = if (std.mem.eql(u8, name, "Ofast")) .flag else syntax; + try stdout.print( \\.{{ \\ .name = "{}", @@ -400,7 +426,7 @@ pub fn main() anyerror!void { \\ .psl = {}, \\}}, \\ - , .{ name, syntax, ident, pd1, pd2, pslash }); + , .{ name, final_syntax, ident, pd1, pd2, pslash }); } else if (pd1 and !pd2 and !pslash and syntax == .flag) { try stdout.print("flagpd1(\"{}\"),\n", .{name}); } else if (!pd1 and !pd2 and pslash and syntax == .flag) {