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

Volodymyr Sapsai via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 25 12:16:26 PDT 2018


Author: vsapsai
Date: Wed Jul 25 12:16:26 2018
New Revision: 337953

URL: http://llvm.org/viewvc/llvm-project?rev=337953&view=rev
Log:
[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


Added:
    cfe/trunk/test/Preprocessor/Inputs/cycle/
    cfe/trunk/test/Preprocessor/Inputs/cycle/a.h
    cfe/trunk/test/Preprocessor/Inputs/cycle/b.h
    cfe/trunk/test/Preprocessor/Inputs/cycle/c.h
    cfe/trunk/test/Preprocessor/include-cycle.c
Modified:
    cfe/trunk/lib/Lex/PPDirectives.cpp

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=337953&r1=337952&r2=337953&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Wed Jul 25 12:16:26 2018
@@ -1896,6 +1896,12 @@ void Preprocessor::HandleIncludeDirectiv
   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).

Added: cfe/trunk/test/Preprocessor/Inputs/cycle/a.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/Inputs/cycle/a.h?rev=337953&view=auto
==============================================================================
--- cfe/trunk/test/Preprocessor/Inputs/cycle/a.h (added)
+++ cfe/trunk/test/Preprocessor/Inputs/cycle/a.h Wed Jul 25 12:16:26 2018
@@ -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"

Added: cfe/trunk/test/Preprocessor/Inputs/cycle/b.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/Inputs/cycle/b.h?rev=337953&view=auto
==============================================================================
--- cfe/trunk/test/Preprocessor/Inputs/cycle/b.h (added)
+++ cfe/trunk/test/Preprocessor/Inputs/cycle/b.h Wed Jul 25 12:16:26 2018
@@ -0,0 +1 @@
+#include "a.h"

Added: cfe/trunk/test/Preprocessor/Inputs/cycle/c.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/Inputs/cycle/c.h?rev=337953&view=auto
==============================================================================
--- cfe/trunk/test/Preprocessor/Inputs/cycle/c.h (added)
+++ cfe/trunk/test/Preprocessor/Inputs/cycle/c.h Wed Jul 25 12:16:26 2018
@@ -0,0 +1 @@
+#include "a.h"

Added: cfe/trunk/test/Preprocessor/include-cycle.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/include-cycle.c?rev=337953&view=auto
==============================================================================
--- cfe/trunk/test/Preprocessor/include-cycle.c (added)
+++ cfe/trunk/test/Preprocessor/include-cycle.c Wed Jul 25 12:16:26 2018
@@ -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"




More information about the cfe-commits mailing list