From: Joel Rosdahl Date: Sun, 28 Sep 2025 11:35:03 +0000 (+0200) Subject: fix: Handle -Xarch_host/-Xarch_device except with other -Xarch_* X-Git-Tag: v4.12.1~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1ac621c111afe0175b6465b59454f934400f71e4;p=thirdparty%2Fccache.git fix: Handle -Xarch_host/-Xarch_device except with other -Xarch_* -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. (cherry picked from commit 36282483f3ac0b2a018eb9ea1f543004620bf622) --- diff --git a/src/ccache/argprocessing.cpp b/src/ccache/argprocessing.cpp index d3ab568a..980b2b54 100644 --- a/src/ccache/argprocessing.cpp +++ b/src/ccache/argprocessing.cpp @@ -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()).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); diff --git a/unittest/test_argprocessing.cpp b/unittest/test_argprocessing.cpp index 8454058a..ec2778ff 100644 --- a/unittest/test_argprocessing.cpp +++ b/unittest/test_argprocessing.cpp @@ -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();