]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
feat: Add support for clang --analyze (#1345)
authorMikhail B <55960560+mbel0@users.noreply.github.com>
Mon, 20 Nov 2023 20:57:49 +0000 (15:57 -0500)
committerGitHub <noreply@github.com>
Mon, 20 Nov 2023 20:57:49 +0000 (21:57 +0100)
src/argprocessing.cpp
src/compopt.cpp
unittest/test_compopt.cpp

index 22788cb9dca3e8bef166f71f4287b17db7ce9d22..f155e3500f447b9cbe34dba87e5df9af33e5975e 100644 (file)
@@ -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 {
index 93af673c621862ca8adba3a5db46b02fb1ec7b2a..1cceb8cb6e6b9803b3f73fec13560814162905ce 100644 (file)
@@ -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
index 508284e7bddf6d4e4df3d92a93b7f56077ec66ca..0f0bb986f6c88bca9ce509848c6445c2727c5575 100644 (file)
@@ -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"));