From: Joel Rosdahl Date: Sat, 16 Jan 2021 19:09:03 +0000 (+0100) Subject: Support source code language “cuda”, used by Clang X-Git-Tag: v4.2~26 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=50737d3f494ea3f916dbc1d548b7f0dfa9572e8d;p=thirdparty%2Fccache.git Support source code language “cuda”, used by Clang See also 2728c68bba9f8b4bb5c8812cd1b50402b81ebfd9. Closes #772. --- diff --git a/src/argprocessing.cpp b/src/argprocessing.cpp index 42ca43d72..612eadd7e 100644 --- a/src/argprocessing.cpp +++ b/src/argprocessing.cpp @@ -999,7 +999,8 @@ process_args(Context& ctx) } args_info.actual_language = state.explicit_language; } else { - args_info.actual_language = language_for_file(args_info.input_file); + args_info.actual_language = + language_for_file(args_info.input_file, config.compiler_type()); } args_info.output_is_precompiled_header = @@ -1032,8 +1033,11 @@ process_args(Context& ctx) return Statistic::unsupported_source_language; } - if (!config.run_second_cpp() && args_info.actual_language == "cu") { - LOG_RAW("Using CUDA compiler; not compiling preprocessed code"); + if (!config.run_second_cpp() + && (args_info.actual_language == "cu" + || args_info.actual_language == "cuda")) { + LOG("Source language is \"{}\"; not compiling preprocessed code", + args_info.actual_language); config.set_run_second_cpp(true); } diff --git a/src/language.cpp b/src/language.cpp index 3dced4e2c..aa1a2cac7 100644 --- a/src/language.cpp +++ b/src/language.cpp @@ -67,7 +67,7 @@ const struct {".HXX", "c++-header"}, {".tcc", "c++-header"}, {".TCC", "c++-header"}, - {".cu", "cu"}, + {".cu", "cu"}, // Special case in language_for_file: "cuda" for Clang {".hip", "hip"}, {nullptr, nullptr}, }; @@ -84,7 +84,8 @@ const struct {"c++", "c++-cpp-output"}, {"c++-cpp-output", "c++-cpp-output"}, {"c++-header", "c++-cpp-output"}, - {"cu", "cpp-output"}, + {"cu", "cpp-output"}, // NVCC + {"cuda", "cpp-output"}, // Clang {"hip", "cpp-output"}, {"objective-c", "objective-c-cpp-output"}, {"objective-c-header", "objective-c-cpp-output"}, @@ -114,9 +115,13 @@ supported_source_extension(const std::string& fname) } std::string -language_for_file(const std::string& fname) +language_for_file(const std::string& fname, CompilerType compiler_type) { auto ext = Util::get_extension(fname); + if (ext == ".cu" && compiler_type == CompilerType::clang) { + // Special case: Clang maps .cu to cuda. + return "cuda"; + } for (size_t i = 0; k_ext_lang_table[i].extension; ++i) { if (k_ext_lang_table[i].extension == ext) { return k_ext_lang_table[i].language; diff --git a/src/language.hpp b/src/language.hpp index b90afdf54..99bf386e0 100644 --- a/src/language.hpp +++ b/src/language.hpp @@ -20,14 +20,17 @@ #include "system.hpp" +#include "Config.hpp" + #include // Return whether a filename has a supported source code extension. bool supported_source_extension(const std::string& fname); -// Guess the language of `fname` based on its extension. Returns the empty -// string if the extension is unknown. -std::string language_for_file(const std::string& fname); +// Guess the language of `fname` based on its extension and a compiler type. +// Returns the empty string if the extension is unknown. +std::string language_for_file(const std::string& fname, + CompilerType compiler_type); // Return the preprocessed language for `language`, or the empty string if // unknown.