sema_manager: report diagnostics in macro expansions

Fix #608
This commit is contained in:
Fangrui Song 2020-04-19 11:27:57 -07:00
parent c10642d29b
commit de800ebb70
3 changed files with 10 additions and 1 deletions

View File

@ -27,6 +27,13 @@ std::string pathFromFileEntry(const FileEntry &file) {
return normalizeFolder(ret) ? ret : realPath(ret); return normalizeFolder(ret) ? ret : realPath(ret);
} }
bool isInsideMainFile(const SourceManager &sm, SourceLocation sl) {
if (!sl.isValid())
return false;
FileID fid = sm.getFileID(sm.getExpansionLoc(sl));
return fid == sm.getMainFileID() || fid == sm.getPreambleFileID();
}
static Pos decomposed2LineAndCol(const SourceManager &sm, static Pos decomposed2LineAndCol(const SourceManager &sm,
std::pair<FileID, unsigned> i) { std::pair<FileID, unsigned> i) {
int l = (int)sm.getLineNumber(i.first, i.second) - 1, int l = (int)sm.getLineNumber(i.first, i.second) - 1,

View File

@ -20,6 +20,8 @@ namespace vfs = clang::vfs;
namespace ccls { namespace ccls {
std::string pathFromFileEntry(const clang::FileEntry &file); std::string pathFromFileEntry(const clang::FileEntry &file);
bool isInsideMainFile(const clang::SourceManager &sm, clang::SourceLocation sl);
Range fromCharSourceRange(const clang::SourceManager &sm, Range fromCharSourceRange(const clang::SourceManager &sm,
const clang::LangOptions &lang, const clang::LangOptions &lang,
clang::CharSourceRange csr, clang::CharSourceRange csr,

View File

@ -243,7 +243,7 @@ public:
return; return;
const SourceManager &sm = info.getSourceManager(); const SourceManager &sm = info.getSourceManager();
StringRef filename = sm.getFilename(info.getLocation()); StringRef filename = sm.getFilename(info.getLocation());
bool concerned = sm.isWrittenInMainFile(l); bool concerned = isInsideMainFile(sm, l);
auto fillDiagBase = [&](DiagBase &d) { auto fillDiagBase = [&](DiagBase &d) {
llvm::SmallString<64> message; llvm::SmallString<64> message;
info.FormatDiagnostic(message); info.FormatDiagnostic(message);