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);
}
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,
std::pair<FileID, unsigned> i) {
int l = (int)sm.getLineNumber(i.first, i.second) - 1,

View File

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

View File

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