From 985f5ec4d391dd8f04a2d2eb23308d247878ba8f Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 10 Nov 2018 15:05:21 -0800 Subject: [PATCH] Use SM.isWrittenInMainFile; suppress -Werror in preamble SM.isWrittenInMainFile is to work around preamble bug: spurious err_pp_unterminated_conditional with circular #include --- src/clang_complete.cc | 7 ++++++- src/indexer.cc | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/clang_complete.cc b/src/clang_complete.cc index eb73e55d..b3466ad4 100644 --- a/src/clang_complete.cc +++ b/src/clang_complete.cc @@ -209,7 +209,7 @@ public: 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); @@ -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; diff --git a/src/indexer.cc b/src/indexer.cc index d78efc70..f240ebf1 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -707,7 +707,7 @@ public: 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);