}
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 =
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);
}
{".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},
};
{"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"},
}
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;
#include "system.hpp"
+#include "Config.hpp"
+
#include <string>
// 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.