[Preprocessor] Stop entering included files after hitting a fatal error.

Fixes a problem when we have multiple inclusion cycles and try to
enumerate all possible ways to reach the max inclusion depth.

rdar://problem/38871876

Reviewers: bruno, rsmith, jkorous, aaron.ballman

Reviewed By: bruno, jkorous, aaron.ballman

Subscribers: dexonsmith, cfe-commits

Differential Revision: https://reviews.llvm.org/D48786

llvm-svn: 337953
This commit is contained in:
Volodymyr Sapsai 2018-07-25 19:16:26 +00:00
parent d78b394543
commit 482070b40a
5 changed files with 21 additions and 0 deletions

View File

@ -1896,6 +1896,12 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc,
if (PPOpts->SingleFileParseMode)
ShouldEnter = false;
// Any diagnostics after the fatal error will not be visible. As the
// compilation failed already and errors in subsequently included files won't
// be visible, avoid preprocessing those files.
if (ShouldEnter && Diags->hasFatalErrorOccurred())
ShouldEnter = false;
// Determine whether we should try to import the module for this #include, if
// there is one. Don't do so if precompiled module support is disabled or we
// are processing this module textually (because we're building the module).

View File

@ -0,0 +1,8 @@
// Presence of 2 inclusion cycles
// b.h -> a.h -> b.h -> ...
// c.h -> a.h -> c.h -> ...
// makes it unfeasible to reach max inclusion depth in all possible ways. Need
// to stop earlier.
#include "b.h"
#include "c.h"

View File

@ -0,0 +1 @@
#include "a.h"

View File

@ -0,0 +1 @@
#include "a.h"

View File

@ -0,0 +1,5 @@
// RUN: not %clang_cc1 -E -I%S/Inputs -ferror-limit 20 %s
// Test that preprocessing terminates even if we have inclusion cycles.
#include "cycle/a.h"