From: Joel Rosdahl Date: Thu, 12 Feb 2026 20:05:30 +0000 (+0100) Subject: refactor: Generalize "already preprocessed" compiler language slightly (#1684) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5da91eb2b4f4cd09a5669f0aebfc534b514826ce;p=thirdparty%2Fccache.git refactor: Generalize "already preprocessed" compiler language slightly (#1684) - 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". --- diff --git a/src/ccache/argprocessing.cpp b/src/ccache/argprocessing.cpp index c07dd1f8..3809a009 100644 --- a/src/ccache/argprocessing.cpp +++ b/src/ccache/argprocessing.cpp @@ -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)); } diff --git a/src/ccache/argsinfo.hpp b/src/ccache/argsinfo.hpp index 7bae8b62..bf216f61 100644 --- a/src/ccache/argsinfo.hpp +++ b/src/ccache/argsinfo.hpp @@ -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; diff --git a/src/ccache/ccache.cpp b/src/ccache/ccache.cpp index 13f42274..5dc99c96 100644 --- a/src/ccache/ccache.cpp +++ b/src/ccache/ccache.cpp @@ -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. diff --git a/src/ccache/language.cpp b/src/ccache/language.cpp index fff7b0f5..3b2799f9 100644 --- a/src/ccache/language.cpp +++ b/src/ccache/language.cpp @@ -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 }, };