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

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


This revision was automatically updated to reflect the committed changes.
Closed by commit rL337953: [Preprocessor] Stop entering included files after hitting a fatal error. (authored by vsapsai, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D48786?vs=156911&id=157336#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D48786

Files:
  cfe/trunk/lib/Lex/PPDirectives.cpp
  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


Index: cfe/trunk/test/Preprocessor/Inputs/cycle/c.h
===================================================================
--- cfe/trunk/test/Preprocessor/Inputs/cycle/c.h
+++ cfe/trunk/test/Preprocessor/Inputs/cycle/c.h
@@ -0,0 +1 @@
+#include "a.h"
Index: cfe/trunk/test/Preprocessor/Inputs/cycle/b.h
===================================================================
--- cfe/trunk/test/Preprocessor/Inputs/cycle/b.h
+++ cfe/trunk/test/Preprocessor/Inputs/cycle/b.h
@@ -0,0 +1 @@
+#include "a.h"
Index: cfe/trunk/test/Preprocessor/Inputs/cycle/a.h
===================================================================
--- cfe/trunk/test/Preprocessor/Inputs/cycle/a.h
+++ cfe/trunk/test/Preprocessor/Inputs/cycle/a.h
@@ -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"
Index: cfe/trunk/test/Preprocessor/include-cycle.c
===================================================================
--- cfe/trunk/test/Preprocessor/include-cycle.c
+++ cfe/trunk/test/Preprocessor/include-cycle.c
@@ -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"
Index: cfe/trunk/lib/Lex/PPDirectives.cpp
===================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp
+++ cfe/trunk/lib/Lex/PPDirectives.cpp
@@ -1896,6 +1896,12 @@
   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).


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48786.157336.patch
Type: text/x-patch
Size: 2155 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180725/f44f60c7/attachment-0001.bin>


More information about the cfe-commits mailing list