]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
feat: Don't treat /Zi as unsupported for clang-cl (#1266)
authorTobias Hieta <tobias@hieta.se>
Tue, 28 Mar 2023 19:45:37 +0000 (21:45 +0200)
committerGitHub <noreply@github.com>
Tue, 28 Mar 2023 19:45:37 +0000 (21:45 +0200)
For MSVC /Zi is unsupported since it writes a additional
.pdb file per each .obj file and it creates some messy
interaction with ccache. But for clang-cl /Zi is actually
treated as /Z7 and only embeds the debug info in the .obj
file so it makes sense to allow this flag when compiling
with clang-cl.

src/argprocessing.cpp
unittest/test_argprocessing.cpp

index bad2dadd991bfc3da98f9efc08b540f2d42b675a..f300e7bd766df32679a7fb64074a81a7d24bec79 100644 (file)
@@ -608,7 +608,8 @@ process_option_arg(const Context& ctx,
     return Statistic::none;
   }
 
-  if (config.is_compiler_group_msvc() && util::starts_with(arg, "-Z")) {
+  if (config.is_compiler_group_msvc() && !config.is_compiler_group_clang()
+      && util::starts_with(arg, "-Z")) {
     state.last_seen_msvc_z_option = args[i];
     state.common_args.push_back(args[i]);
     return Statistic::none;
index bf98b090e0ab28f17189f8328ee3a51e61268870..ccb6e1175047e206fd0ab7a6d2323b0580b15b01 100644 (file)
@@ -746,4 +746,30 @@ TEST_CASE("MSVC debug information format options")
   }
 }
 
+// Check that clang-cl debug information is parsed different,
+// since for clang-cl /Zi and /Z7 is the same!
+TEST_CASE("ClangCL Debug information options")
+{
+  TestContext test_context;
+  Context ctx;
+  ctx.config.set_compiler_type(CompilerType::clang_cl);
+  util::write_file("foo.c", "");
+
+  SUBCASE("/Z7")
+  {
+    ctx.orig_args = Args::from_string("clang-cl.exe /c foo.c /Z7");
+    const ProcessArgsResult result = process_args(ctx);
+    REQUIRE(!result.error);
+    CHECK(result.preprocessor_args.to_string() == "clang-cl.exe /Z7");
+  }
+
+  SUBCASE("/Zi")
+  {
+    ctx.orig_args = Args::from_string("clang-cl.exe /c foo.c /Zi");
+    const ProcessArgsResult result = process_args(ctx);
+    REQUIRE(!result.error);
+    CHECK(result.preprocessor_args.to_string() == "clang-cl.exe /Zi");
+  }
+}
+
 TEST_SUITE_END();