From: Andrew Hardin Date: Thu, 29 Jun 2023 19:38:06 +0000 (-0600) Subject: fix: Improve nvcc handling of -Xcompiler and --Werror (#1304) X-Git-Tag: v4.8.3~7 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=912cabd0ccd763a9e90bfc1dcba7c6de4df5bbbb;p=thirdparty%2Fccache.git fix: Improve nvcc handling of -Xcompiler and --Werror (#1304) (cherry picked from commit ce11e31a54c1708776d13c47ec10286410519499) --- diff --git a/src/compopt.cpp b/src/compopt.cpp index f381c75e0..668adccb2 100644 --- a/src/compopt.cpp +++ b/src/compopt.cpp @@ -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 diff --git a/unittest/test_argprocessing.cpp b/unittest/test_argprocessing.cpp index ccb6e1175..dc7e935ea 100644 --- a/unittest/test_argprocessing.cpp +++ b/unittest/test_argprocessing.cpp @@ -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;