Skip to content

Commit b299069

Browse files
committed
sema_manager: report diagnostics in macro expansions
Fix #608
1 parent 1cec907 commit b299069

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

src/clang_tu.cc

+7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ std::string pathFromFileEntry(const FileEntry &file) {
2727
return normalizeFolder(ret) ? ret : realPath(ret);
2828
}
2929

30+
bool isInsideMainFile(const SourceManager &sm, SourceLocation sl) {
31+
if (!sl.isValid())
32+
return false;
33+
FileID fid = sm.getFileID(sm.getExpansionLoc(sl));
34+
return fid == sm.getMainFileID() || fid == sm.getPreambleFileID();
35+
}
36+
3037
static Pos decomposed2LineAndCol(const SourceManager &sm,
3138
std::pair<FileID, unsigned> i) {
3239
int l = (int)sm.getLineNumber(i.first, i.second) - 1,

src/clang_tu.hh

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ namespace vfs = clang::vfs;
2020
namespace ccls {
2121
std::string pathFromFileEntry(const clang::FileEntry &file);
2222

23+
bool isInsideMainFile(const clang::SourceManager &sm, clang::SourceLocation sl);
24+
2325
Range fromCharSourceRange(const clang::SourceManager &sm,
2426
const clang::LangOptions &lang,
2527
clang::CharSourceRange csr,

src/sema_manager.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ class StoreDiags : public DiagnosticConsumer {
243243
return;
244244
const SourceManager &sm = info.getSourceManager();
245245
StringRef filename = sm.getFilename(info.getLocation());
246-
bool concerned = sm.isWrittenInMainFile(l);
246+
bool concerned = isInsideMainFile(sm, l);
247247
auto fillDiagBase = [&](DiagBase &d) {
248248
llvm::SmallString<64> message;
249249
info.FormatDiagnostic(message);

0 commit comments

Comments
 (0)