Skip to content

Commit 985f5ec

Browse files
committed
Use SM.isWrittenInMainFile; suppress -Werror in preamble
SM.isWrittenInMainFile is to work around preamble bug: spurious err_pp_unterminated_conditional with circular #include
1 parent d9a31a7 commit 985f5ec

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/clang_complete.cc

+6-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ class StoreDiags : public DiagnosticConsumer {
209209
if (!L.isValid()) return;
210210
const SourceManager &SM = Info.getSourceManager();
211211
StringRef Filename = SM.getFilename(Info.getLocation());
212-
bool concerned = IsConcerned(SM, Info.getLocation());
212+
bool concerned = SM.isWrittenInMainFile(L);
213213
auto fillDiagBase = [&](DiagBase &d) {
214214
llvm::SmallString<64> Message;
215215
Info.FormatDiagnostic(Message);
@@ -303,6 +303,11 @@ void BuildPreamble(CompletionSession &session, CompilerInvocation &CI,
303303
auto Bounds = ComputePreambleBounds(*CI.getLangOpts(), Buf.get(), 0);
304304
if (OldP && OldP->Preamble.CanReuse(CI, Buf.get(), Bounds, FS.get()))
305305
return;
306+
// -Werror makes warnings issued as errors, which stops parsing
307+
// prematurely because of -ferror-limit=. This also works around the issue
308+
// of -Werror + -Wunused-parameter in interaction with SkipFunctionBodies.
309+
auto &Ws = CI.getDiagnosticOpts().Warnings;
310+
Ws.erase(std::remove(Ws.begin(), Ws.end(), "error"), Ws.end());
306311
CI.getDiagnosticOpts().IgnoreWarnings = false;
307312
CI.getFrontendOpts().SkipFunctionBodies = true;
308313
CI.getLangOpts()->CommentOpts.ParseAllComments = g_config->index.comments > 1;

src/indexer.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ class IndexDataConsumer : public index::IndexDataConsumer {
707707
if (!db)
708708
return true;
709709
param.SeenFile(*FE);
710-
if (!SM.isInMainFile(R.getBegin()))
710+
if (!SM.isWrittenInMainFile(R.getBegin()))
711711
lid = GetFileLID(db, SM, *FE);
712712
} else {
713713
db = param.ConsumeFile(*FE);

0 commit comments

Comments
 (0)