]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Improve nvcc handling of -Xcompiler and --Werror (#1304)
authorAndrew Hardin <andrew.hardin5+git@gmail.com>
Thu, 29 Jun 2023 19:38:06 +0000 (13:38 -0600)
committerGitHub <noreply@github.com>
Thu, 29 Jun 2023 19:38:06 +0000 (21:38 +0200)
src/compopt.cpp
unittest/test_argprocessing.cpp

index f381c75e06175d6dc7b1be35b822cfc4f67384eb..668adccb2753e0d2d449d7b4a56feeaa73ed8022 100644 (file)
@@ -52,9 +52,10 @@ struct CompOpt
 };
 
 const CompOpt compopts[] = {
-  {"--Werror", TAKES_ARG},                             // nvcc
+  {"--Werror", TAKES_ARG | AFFECTS_COMP},              // nvcc
   {"--analyze", TOO_HARD},                             // Clang
   {"--compiler-bindir", AFFECTS_CPP | TAKES_ARG},      // nvcc
+  {"--compiler-options", AFFECTS_CPP | TAKES_ARG},     // nvcc
   {"--config", TAKES_ARG},                             // Clang
   {"--gcc-toolchain=", TAKES_CONCAT_ARG | TAKES_PATH}, // Clang
   {"--libdevice-directory", AFFECTS_CPP | TAKES_ARG},  // nvcc
@@ -92,6 +93,7 @@ const CompOpt compopts[] = {
   {"-Wno-error", AFFECTS_COMP},
   {"-Xassembler", TAKES_ARG | TAKES_CONCAT_ARG | AFFECTS_COMP},
   {"-Xclang", TAKES_ARG},
+  {"-Xcompiler", AFFECTS_CPP | TAKES_ARG}, // nvcc
   {"-Xlinker", TAKES_ARG | TAKES_CONCAT_ARG | AFFECTS_COMP},
   {"-Xpreprocessor", AFFECTS_CPP | TOO_HARD_DIRECT | TAKES_ARG},
   {"-Yc", TAKES_ARG | TOO_HARD},                                    // msvc
index ccb6e1175047e206fd0ab7a6d2323b0580b15b01..dc7e935ea427210691d03fec8bf8c1e9f39d7220 100644 (file)
@@ -569,6 +569,42 @@ TEST_CASE("cuda_option_file")
   CHECK(result.compiler_args.to_string() == "nvcc -g -Wall -DX -c");
 }
 
+TEST_CASE("nvcc_warning_flags_short")
+{
+  // With -Werror. This should conflict with host's -Werror flag.
+  TestContext test_context;
+  Context ctx;
+  ctx.config.set_compiler_type(CompilerType::nvcc);
+  ctx.orig_args =
+    Args::from_string("nvcc -Werror all-warnings -Xcompiler -Werror -c foo.cu");
+  util::write_file("foo.cu", "");
+  const ProcessArgsResult result = process_args(ctx);
+
+  CHECK(!result.error);
+  CHECK(result.preprocessor_args.to_string() == "nvcc -Xcompiler -Werror");
+  CHECK(result.extra_args_to_hash.to_string() == "-Werror all-warnings");
+  CHECK(result.compiler_args.to_string()
+        == "nvcc -Werror all-warnings -Xcompiler -Werror -c");
+}
+
+TEST_CASE("nvcc_warning_flags_long")
+{
+  // With --Werror. This shouldn't conflict with host's -Werror flag.
+  TestContext test_context;
+  Context ctx;
+  ctx.config.set_compiler_type(CompilerType::nvcc);
+  ctx.orig_args = Args::from_string(
+    "nvcc --Werror all-warnings -Xcompiler -Werror -c foo.cu");
+  util::write_file("foo.cu", "");
+  const ProcessArgsResult result = process_args(ctx);
+
+  CHECK(!result.error);
+  CHECK(result.preprocessor_args.to_string() == "nvcc -Xcompiler -Werror");
+  CHECK(result.extra_args_to_hash.to_string() == "--Werror all-warnings");
+  CHECK(result.compiler_args.to_string()
+        == "nvcc --Werror all-warnings -Xcompiler -Werror -c");
+}
+
 TEST_CASE("-Xclang")
 {
   TestContext test_context;