]> granicus.if.org Git - clang/commitdiff
[Preprocessor] Stop entering included files after hitting a fatal error.
authorVolodymyr Sapsai <vsapsai@apple.com>
Wed, 25 Jul 2018 19:16:26 +0000 (19:16 +0000)
committerVolodymyr Sapsai <vsapsai@apple.com>
Wed, 25 Jul 2018 19:16:26 +0000 (19:16 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@337953 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/PPDirectives.cpp
test/Preprocessor/Inputs/cycle/a.h [new file with mode: 0644]
test/Preprocessor/Inputs/cycle/b.h [new file with mode: 0644]
test/Preprocessor/Inputs/cycle/c.h [new file with mode: 0644]
test/Preprocessor/include-cycle.c [new file with mode: 0644]

index 4ea0f485d31d5782cbf19bf6392e731216f866d6..d8dae73037a89fe5bced7f0b3956900e7d8cbfe5 100644 (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).
diff --git a/test/Preprocessor/Inputs/cycle/a.h b/test/Preprocessor/Inputs/cycle/a.h
new file mode 100644 (file)
index 0000000..dd3ef35
--- /dev/null
@@ -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"
diff --git a/test/Preprocessor/Inputs/cycle/b.h b/test/Preprocessor/Inputs/cycle/b.h
new file mode 100644 (file)
index 0000000..2243de1
--- /dev/null
@@ -0,0 +1 @@
+#include "a.h"
diff --git a/test/Preprocessor/Inputs/cycle/c.h b/test/Preprocessor/Inputs/cycle/c.h
new file mode 100644 (file)
index 0000000..2243de1
--- /dev/null
@@ -0,0 +1 @@
+#include "a.h"
diff --git a/test/Preprocessor/include-cycle.c b/test/Preprocessor/include-cycle.c
new file mode 100644 (file)
index 0000000..52fcfbd
--- /dev/null
@@ -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"