]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Generalize "already preprocessed" compiler language slightly (#1684)
authorJoel Rosdahl <joel@rosdahl.net>
Thu, 12 Feb 2026 20:05:30 +0000 (21:05 +0100)
committerGitHub <noreply@github.com>
Thu, 12 Feb 2026 20:05:30 +0000 (21:05 +0100)
- Rename ArgsInfo::direct_i_file to preprocess_input_file, since that's
  what it now means.
- Add "ir" as a language and let "-fthinlto-index=" use that language
  implicitly instead of piggybacking on "assembler".

src/ccache/argprocessing.cpp
src/ccache/argsinfo.hpp
src/ccache/ccache.cpp
src/ccache/language.cpp

index c07dd1f876a35bb74f335a7c5c965d55759431cd..3809a00938e022de1dcbc6855ef4f8b1cc7f4f09 100644 (file)
@@ -739,8 +739,8 @@ process_option_arg(const Context& ctx,
     std::string thinlto_index = arg.substr(arg.find('=') + 1);
     args_info.thinlto_index_path = thinlto_index;
     // Thinlto backend phase, the extension of input file is .o but the file is
-    // IR. So treat it as assembler file.
-    args_info.actual_language = "assembler";
+    // IR.
+    args_info.actual_language = "ir";
     state.add_common_arg(args[i]);
     return Statistic::none;
   }
@@ -1612,14 +1612,19 @@ process_args(Context& ctx)
     return tl::unexpected(Statistic::unsupported_source_language);
   }
 
-  if (args_info.actual_language == "assembler") {
-    // -MD/-MMD for assembler file does not produce a dependency file.
+  if (args_info.actual_language == "assembler"
+      || args_info.actual_language == "ir") {
+    // -MD/-MMD do not produce a dependency file.
     args_info.generating_dependencies = false;
   }
 
-  args_info.direct_i_file = language_is_preprocessed(args_info.actual_language);
+  args_info.preprocess_input_file =
+    !language_is_preprocessed(args_info.actual_language);
 
-  if (config.cpp_extension().empty()) {
+  if (!args_info.preprocess_input_file) {
+    config.set_cpp_extension(
+      util::pstr(args_info.input_file.extension()).str().substr(1));
+  } else if (config.cpp_extension().empty()) {
     std::string p_language = p_language_for_language(args_info.actual_language);
     config.set_cpp_extension(extension_for_language(p_language).substr(1));
   }
index 7bae8b62937cf21151227df16a4873236b38eeb4..bf216f61239f2d4f2b8d48b5fe84dfbb23d80a4a 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2025 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2026 Joel Rosdahl and other contributors
 //
 // See doc/authors.adoc for a complete list of contributors.
 //
@@ -121,8 +121,9 @@ struct ArgsInfo
   // Have we seen -gsplit-dwarf?
   bool seen_split_dwarf = false;
 
-  // Are we compiling a .i or .ii file directly?
-  bool direct_i_file = false;
+  // Should we run the preprocessor on the input file? False for .i/.ii files,
+  // assembler or ThinLTO backend phase.
+  bool preprocess_input_file = true;
 
   // Whether the output is a precompiled header.
   bool output_is_precompiled_header = false;
index 13f42274cabccb3a4a64a607df0f0a881243a400..5dc99c96ee6b08aa81b24af658417834c7839b3b 100644 (file)
@@ -1394,9 +1394,8 @@ get_result_key_from_cpp(Context& ctx, util::Args& args, Hash& hash)
 
   const bool capture_stdout = is_clang_cu;
 
-  if (ctx.args_info.direct_i_file) {
-    // We are compiling a .i or .ii file - that means we can skip the cpp stage
-    // and directly form the correct i_tmpfile.
+  if (!ctx.args_info.preprocess_input_file) {
+    // We are compiling a file that should be used as is (not be preprocessed).
     preprocessed_path = ctx.args_info.input_file;
   } else {
     // Run cpp on the input file to obtain the .i.
index fff7b0f54333519ccf2aab375b58d52f9dd4cc14..3b2799f94860eb90a727e56f16d5c1d9531236fc 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2010-2024 Joel Rosdahl and other contributors
+// Copyright (C) 2010-2026 Joel Rosdahl and other contributors
 //
 // See doc/authors.adoc for a complete list of contributors.
 //
@@ -99,6 +99,7 @@ const struct
   {"objective-c++-cpp-output", "objective-c++-cpp-output"},
   {"assembler-with-cpp",       "assembler"               },
   {"assembler",                "assembler"               },
+  {"ir",                       "ir"                      }, // Clang ThinLTO
   {nullptr,                    nullptr                   },
 };