From: Mikhail B <55960560+mbel0@users.noreply.github.com> Date: Mon, 20 Nov 2023 20:57:49 +0000 (-0500) Subject: feat: Add support for clang --analyze (#1345) X-Git-Tag: v4.9~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=67da9633387c58c856d80d126ea4dfd0ad17ff28;p=thirdparty%2Fccache.git feat: Add support for clang --analyze (#1345) --- diff --git a/src/argprocessing.cpp b/src/argprocessing.cpp index 22788cb9d..f155e3500 100644 --- a/src/argprocessing.cpp +++ b/src/argprocessing.cpp @@ -60,6 +60,7 @@ struct ArgumentProcessingState bool found_c_opt = false; bool found_dc_opt = false; bool found_S_opt = false; + bool found_analyze_opt = false; bool found_pch = false; bool found_fpch_preprocess = false; bool found_Yu = false; @@ -530,6 +531,13 @@ process_option_arg(const Context& ctx, return Statistic::none; } + // --analyze changes the default extension too + if (arg == "--analyze") { + state.common_args.push_back(args[i]); + state.found_analyze_opt = true; + return Statistic::none; + } + if (util::starts_with(arg, "-x")) { if (arg.length() >= 3 && !islower(arg[2])) { // -xCODE (where CODE can be e.g. Host or CORE-AVX2, always starting with @@ -1131,7 +1139,8 @@ process_arg(const Context& ctx, if (supported_source_extension(args[i])) { LOG("Multiple input files: {} and {}", args_info.input_file, args[i]); return Statistic::multiple_source_files; - } else if (!state.found_c_opt && !state.found_dc_opt) { + } else if (!state.found_c_opt && !state.found_dc_opt + && !state.found_analyze_opt) { LOG("Called for link with {}", args[i]); if (args[i].find("conftest.") != std::string::npos) { return Statistic::autoconf_test; @@ -1221,8 +1230,14 @@ process_args(Context& ctx) } if (output_obj_by_source && !args_info.input_file.empty()) { - std::string_view extension = - state.found_S_opt ? ".s" : get_default_object_file_extension(ctx.config); + std::string_view extension; + if (state.found_analyze_opt) { + extension = ".plist"; + } else if (state.found_S_opt) { + extension = ".s"; + } else { + extension = get_default_object_file_extension(ctx.config); + } args_info.output_obj += Util::change_extension(Util::base_name(args_info.input_file), extension); } @@ -1309,7 +1324,7 @@ process_args(Context& ctx) // -fsyntax-only/-Zs does not need -c if (!state.found_c_opt && !state.found_dc_opt && !state.found_S_opt - && !state.found_syntax_only) { + && !state.found_syntax_only && !state.found_analyze_opt) { if (args_info.output_is_precompiled_header) { state.common_args.push_back("-c"); } else { diff --git a/src/compopt.cpp b/src/compopt.cpp index 93af673c6..1cceb8cb6 100644 --- a/src/compopt.cpp +++ b/src/compopt.cpp @@ -53,7 +53,7 @@ struct CompOpt const CompOpt compopts[] = { {"--Werror", TAKES_ARG | AFFECTS_COMP}, // nvcc - {"--analyze", TOO_HARD}, // Clang + {"--analyzer-output", TOO_HARD}, // Clang {"--compiler-bindir", AFFECTS_CPP | TAKES_ARG}, // nvcc {"--compiler-options", AFFECTS_CPP | TAKES_ARG}, // nvcc {"--config", TAKES_ARG}, // Clang diff --git a/unittest/test_compopt.cpp b/unittest/test_compopt.cpp index 508284e7b..0f0bb986f 100644 --- a/unittest/test_compopt.cpp +++ b/unittest/test_compopt.cpp @@ -51,7 +51,8 @@ TEST_CASE("too_hard") CHECK(compopt_too_hard("-save-temps=cwd")); CHECK(compopt_too_hard("-save-temps=obj")); CHECK(compopt_too_hard("-analyze")); - CHECK(compopt_too_hard("--analyze")); + CHECK(compopt_too_hard("--analyzer-output")); + CHECK(!compopt_too_hard("--analyze")); CHECK(!compopt_too_hard("-MD")); CHECK(!compopt_too_hard("-fprofile-arcs")); CHECK(!compopt_too_hard("-ftest-coverage"));