From 670551faa5bd9d580f44f931ada8d2d6da92f160 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20M=C3=BCller?= Date: Mon, 12 Mar 2018 11:31:11 +0100 Subject: [PATCH] Fix include issue on pre-clang 4.0.0 --- src/libclang/preprocessor.cpp | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/libclang/preprocessor.cpp b/src/libclang/preprocessor.cpp index 6b3ecb6..8b25018 100644 --- a/src/libclang/preprocessor.cpp +++ b/src/libclang/preprocessor.cpp @@ -1042,6 +1042,13 @@ detail::preprocessor_output detail::preprocess(const libclang_compile_config& co auto preprocessed = clang_preprocess(config, path, logger); + if (detail::libclang_compile_config_access::clang_version(config) < 40000) + { + // add headers from diagnostics w/o line information + for (auto name : preprocessed.included_files) + result.includes.push_back(pp_include{name, "", cpp_include_kind::local, 1u}); + } + position p(ts::ref(result.source), preprocessed.file.c_str()); ts::flag in_string(false), in_char(false), first_line(true); while (p) @@ -1120,12 +1127,16 @@ detail::preprocessor_output detail::preprocess(const libclang_compile_config& co if (p.write_enabled()) { // this is a direct include, update the full path of the last include - DEBUG_ASSERT(!result.includes.empty() - && result.includes.back().full_path.empty() - && lm.value().file.find(result.includes.back().file_name) - != std::string::npos, - detail::assert_handler{}); - result.includes.back().full_path = lm.value().file; + // note: path can be empty if pre clang 4 and not fast preprocessing + // in this case we can't get the full path at all + if (!result.includes.empty()) + { + DEBUG_ASSERT(result.includes.back().full_path.empty() + && lm.value().file.find(result.includes.back().file_name) + != std::string::npos, + detail::assert_handler{}); + result.includes.back().full_path = lm.value().file; + } } else { @@ -1183,14 +1194,6 @@ detail::preprocessor_output detail::preprocess(const libclang_compile_config& co p.bump(); } - if (result.includes.empty()) - { - // add headers from diagnostics w/o line information - // only needed for older clangs - for (auto name : preprocessed.included_files) - result.includes.push_back(pp_include{name, "", cpp_include_kind::local, 1u}); - } - // get full path for indirect includes // doesn't work if fast preprocessing if (!detail::libclang_compile_config_access::fast_preprocessing(config))