Skip to content

Commit

Permalink
sema_manager: report diagnostics in macro expansions
Browse files Browse the repository at this point in the history
Fix #608
  • Loading branch information
MaskRay committed Apr 19, 2020
1 parent c10642d commit de800eb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/clang_tu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/clang_tu.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/sema_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 243,7 @@ class StoreDiags : public DiagnosticConsumer {
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);
Expand Down

0 comments on commit de800eb

Please sign in to comment.