From 8515e24dd7862567a5deede68f26a769075d36ab Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 10 Nov 2018 15:05:21 -0800 Subject: [PATCH] setWarningsAsErrors(false); use SM.isInMainFile SM.isInMainFile is to work around preamble bug: spurious err_pp_unterminated_conditional with circular #include --- src/clang_complete.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/clang_complete.cc b/src/clang_complete.cc index bf3821c3..bdce7fbe 100644 --- a/src/clang_complete.cc +++ b/src/clang_complete.cc @@ -221,7 +221,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.isInMainFile(L); auto fillDiagBase = [&](DiagBase &d) { llvm::SmallString<64> Message; Info.FormatDiagnostic(Message); @@ -285,6 +285,10 @@ std::unique_ptr BuildCompilerInstance( Clang->getDiagnostics(), Clang->getInvocation().TargetOpts)); if (!Clang->hasTarget()) return nullptr; + // Otherwise -Werror makes warnings issued as errors, which stops parsing + // prematurely when reaching the limit. This also works around the issue of + // -Wunused-parameter in interaction with SkipFunctionBodies. + Clang->getDiagnostics().setWarningsAsErrors(false); // Construct SourceManager with UserFilesAreVolatile: true because otherwise // RequiresNullTerminator: true may cause out-of-bounds read when a file is // mmap'ed but is saved concurrently.