]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Handle -Xarch_host/-Xarch_device except with other -Xarch_*
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 28 Sep 2025 11:35:03 +0000 (13:35 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 28 Sep 2025 12:10:58 +0000 (14:10 +0200)
-Xarch_host and -Xarch_device appear to have different semantics than
other -Xarch_* options, so add special case code that allows only
-Xarch_host options or only -Xarch_device options while falling back to
the compiler for other combinations.

A future improvement would be to add multi-pass support for -Xarch_host
and -Xarch_device combinations as well.

Fixes #1632.

src/ccache/argprocessing.cpp
unittest/test_argprocessing.cpp

index d3ab568a5de4a9137fa8976e7c0702310276f77b..980b2b54c86ec9d91e170dccc2efcd6308221ccc 100644 (file)
@@ -509,6 +509,10 @@ process_option_arg(const Context& ctx,
     const auto arch = arg.substr(7);
     auto it = state.xarch_args.emplace(arch, std::vector<std::string>()).first;
     it->second.emplace_back(args[i + 1]);
+    if (arch == "host" || arch == "device") {
+      state.add_common_arg(args[i]);
+      state.add_common_arg(args[i + 1]);
+    }
     ++i;
     return Statistic::none;
   }
@@ -1650,6 +1654,17 @@ process_args(Context& ctx)
       ctx, util::add_extension(args_info.orig_input_file, ".000i.ipa-clones"));
   }
 
+  if (state.xarch_args.size() > 1) {
+    if (state.xarch_args.find("host") != state.xarch_args.end()) {
+      LOG_RAW("-Xarch_host in combination with other -Xarch_* is too hard");
+      return tl::unexpected(Statistic::unsupported_compiler_option);
+    }
+    if (state.xarch_args.find("device") != state.xarch_args.end()) {
+      LOG_RAW("-Xarch_device in combination with other -Xarch_* is too hard");
+      return tl::unexpected(Statistic::unsupported_compiler_option);
+    }
+  }
+
   if (!state.xarch_args.empty()) {
     for (const auto& arch : args_info.arch_args) {
       auto it = state.xarch_args.find(arch);
index 8454058a105b5fa76d5769fb85a9b61ad35ca4f7..ec2778ff40fe083923fdd04095b5fe1d3f9c86f5 100644 (file)
@@ -984,4 +984,82 @@ TEST_CASE("ClangCL Debug information options")
   }
 }
 
+TEST_CASE("Supports -Xarch_host without other -Xarch_*")
+{
+  TestContext test_context;
+  Context ctx;
+  ctx.orig_args =
+    Args::from_string("clang -Xarch_host -foo -c foo.c -Xarch_host -bar");
+  REQUIRE(util::write_file("foo.c", ""));
+
+  const auto result = process_args(ctx);
+
+  REQUIRE(result);
+  CHECK(result->preprocessor_args.to_string()
+        == "clang -Xarch_host -foo -Xarch_host -bar");
+  CHECK(result->extra_args_to_hash.to_string() == "");
+  CHECK(result->compiler_args.to_string()
+        == "clang -Xarch_host -foo -Xarch_host -bar -c");
+}
+
+TEST_CASE("Supports -Xarch_device without other -Xarch_*")
+{
+  TestContext test_context;
+  Context ctx;
+  ctx.orig_args =
+    Args::from_string("clang -Xarch_device -foo -c foo.c -Xarch_device -bar");
+  REQUIRE(util::write_file("foo.c", ""));
+
+  const auto result = process_args(ctx);
+
+  REQUIRE(result);
+  CHECK(result->preprocessor_args.to_string()
+        == "clang -Xarch_device -foo -Xarch_device -bar");
+  CHECK(result->extra_args_to_hash.to_string() == "");
+  CHECK(result->compiler_args.to_string()
+        == "clang -Xarch_device -foo -Xarch_device -bar -c");
+}
+
+TEST_CASE("-Xarch_host with -Xarch_device is too hard")
+{
+  TestContext test_context;
+  Context ctx;
+  ctx.orig_args =
+    Args::from_string("clang -Xarch_device -foo -c foo.c -Xarch_host -bar");
+  REQUIRE(util::write_file("foo.c", ""));
+
+  const auto result = process_args(ctx);
+
+  REQUIRE(!result);
+  CHECK(result.error() == Statistic::unsupported_compiler_option);
+}
+
+TEST_CASE("-Xarch_host with -Xarch_x86_64 is too hard")
+{
+  TestContext test_context;
+  Context ctx;
+  ctx.orig_args =
+    Args::from_string("clang -Xarch_host -foo -c foo.c -Xarch_x86_64 -bar");
+  REQUIRE(util::write_file("foo.c", ""));
+
+  const auto result = process_args(ctx);
+
+  REQUIRE(!result);
+  CHECK(result.error() == Statistic::unsupported_compiler_option);
+}
+
+TEST_CASE("-Xarch_device with -Xarch_x86_64 is too hard")
+{
+  TestContext test_context;
+  Context ctx;
+  ctx.orig_args =
+    Args::from_string("clang -Xarch_device -foo -c foo.c -Xarch_x86_64 -bar");
+  REQUIRE(util::write_file("foo.c", ""));
+
+  const auto result = process_args(ctx);
+
+  REQUIRE(!result);
+  CHECK(result.error() == Statistic::unsupported_compiler_option);
+}
+
 TEST_SUITE_END();