diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-03-21 22:30:46 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-03-21 22:30:46 -0400 |
| commit | 2b65dc10328cc437b21114e3c87fac2ef6ef9adc (patch) | |
| tree | e40cec4e13ea3f1605b47ff84e8bc956162dde6c /src/main.cpp | |
| parent | 4b0ddb817bb5d4effd8cd2dd0844ac278e35e1d5 (diff) | |
| download | zig-2b65dc10328cc437b21114e3c87fac2ef6ef9adc.tar.gz zig-2b65dc10328cc437b21114e3c87fac2ef6ef9adc.zip | |
zig cc: detect optimization and debug flags
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp index 071b365d2f..b47e532d9b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -580,6 +580,7 @@ static int main0(int argc, char **argv) { return stage2_fmt(argc, argv); } else if (argc >= 2 && strcmp(argv[1], "cc") == 0) { emit_h = false; + strip = true; bool c_arg = false; Stage2ClangArgIterator it; @@ -664,6 +665,42 @@ static int main0(int argc, char **argv) { case Stage2ClangArgPreprocess: only_preprocess = true; break; + case Stage2ClangArgOptimize: + // alright what release mode do they want? + if (strcmp(it.only_arg, "Os") == 0) { + build_mode = BuildModeSmallRelease; + } else if (strcmp(it.only_arg, "O2") == 0 || + strcmp(it.only_arg, "O3") == 0 || + strcmp(it.only_arg, "O4") == 0) + { + build_mode = BuildModeFastRelease; + } else if (strcmp(it.only_arg, "Og") == 0) { + build_mode = BuildModeDebug; + } else { + for (size_t i = 0; i < it.other_args_len; i += 1) { + clang_argv.append(it.other_args_ptr[i]); + } + } + break; + case Stage2ClangArgDebug: + strip = false; + if (strcmp(it.only_arg, "-g") == 0) { + // we handled with strip = false above + } else { + for (size_t i = 0; i < it.other_args_len; i += 1) { + clang_argv.append(it.other_args_ptr[i]); + } + } + break; + case Stage2ClangArgSanitize: + if (strcmp(it.only_arg, "undefined") == 0) { + want_sanitize_c = WantCSanitizeEnabled; + } else { + for (size_t i = 0; i < it.other_args_len; i += 1) { + clang_argv.append(it.other_args_ptr[i]); + } + } + break; } } // Parse linker args @@ -715,6 +752,10 @@ static int main0(int argc, char **argv) { } } + if (want_sanitize_c == WantCSanitizeEnabled && build_mode == BuildModeFastRelease) { + build_mode = BuildModeSafeRelease; + } + if (!nostdlib && !have_libc) { have_libc = true; link_libs.append("c"); |
