Skip to content

Commit

Permalink
Use SM.isWrittenInMainFile; suppress -Werror in preamble
Browse files Browse the repository at this point in the history
SM.isWrittenInMainFile is to work around preamble bug: spurious err_pp_unterminated_conditional with circular #include
  • Loading branch information
MaskRay committed Nov 10, 2019
1 parent d9a31a7 commit 985f5ec
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/clang_complete.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class StoreDiags : public DiagnosticConsumer {
if (!L.isValid()) return;
const SourceManager &SM = Info.getSourceManager();
StringRef Filename = SM.getFilename(Info.getLocation());
bool concerned = IsConcerned(SM, Info.getLocation());
bool concerned = SM.isWrittenInMainFile(L);
auto fillDiagBase = [&](DiagBase &d) {
llvm::SmallString<64> Message;
Info.FormatDiagnostic(Message);
Expand Down Expand Up @@ -303,6 +303,11 @@ void BuildPreamble(CompletionSession &session, CompilerInvocation &CI,
auto Bounds = ComputePreambleBounds(*CI.getLangOpts(), Buf.get(), 0);
if (OldP && OldP->Preamble.CanReuse(CI, Buf.get(), Bounds, FS.get()))
return;
// -Werror makes warnings issued as errors, which stops parsing
// prematurely because of -ferror-limit=. This also works around the issue
// of -Werror + -Wunused-parameter in interaction with SkipFunctionBodies.
auto &Ws = CI.getDiagnosticOpts().Warnings;
Ws.erase(std::remove(Ws.begin(), Ws.end(), "error"), Ws.end());
CI.getDiagnosticOpts().IgnoreWarnings = false;
CI.getFrontendOpts().SkipFunctionBodies = true;
CI.getLangOpts()->CommentOpts.ParseAllComments = g_config->index.comments > 1;
Expand Down
2 changes: 1 addition & 1 deletion src/indexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ class IndexDataConsumer : public index::IndexDataConsumer {
if (!db)
return true;
param.SeenFile(*FE);
if (!SM.isInMainFile(R.getBegin()))
if (!SM.isWrittenInMainFile(R.getBegin()))
lid = GetFileLID(db, SM, *FE);
} else {
db = param.ConsumeFile(*FE);
Expand Down

0 comments on commit 985f5ec

Please sign in to comment.