[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
Fri Jun 29 12:13:54 PDT 2018


vsapsai created this revision.
vsapsai added reviewers: bruno, rsmith.
Herald added a subscriber: dexonsmith.

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


https://reviews.llvm.org/D48786

Files:
  clang/lib/Lex/PPDirectives.cpp
  clang/test/Preprocessor/Inputs/cycle/a.h
  clang/test/Preprocessor/Inputs/cycle/b.h
  clang/test/Preprocessor/Inputs/cycle/c.h
  clang/test/Preprocessor/include-cycle.c


Index: clang/test/Preprocessor/include-cycle.c
===================================================================
--- /dev/null
+++ clang/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: clang/test/Preprocessor/Inputs/cycle/c.h
===================================================================
--- /dev/null
+++ clang/test/Preprocessor/Inputs/cycle/c.h
@@ -0,0 +1 @@
+#include "a.h"
Index: clang/test/Preprocessor/Inputs/cycle/b.h
===================================================================
--- /dev/null
+++ clang/test/Preprocessor/Inputs/cycle/b.h
@@ -0,0 +1 @@
+#include "a.h"
Index: clang/test/Preprocessor/Inputs/cycle/a.h
===================================================================
--- /dev/null
+++ clang/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: clang/lib/Lex/PPDirectives.cpp
===================================================================
--- clang/lib/Lex/PPDirectives.cpp
+++ clang/lib/Lex/PPDirectives.cpp
@@ -1871,6 +1871,11 @@
   if (PPOpts->SingleFileParseMode)
     ShouldEnter = false;
 
+  // Stop further preprocessing if a fatal error has occurred. Any diagnostics
+  // we might have raised will not be visible.
+  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.153553.patch
Type: text/x-patch
Size: 1896 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180629/99aa9953/attachment-0001.bin>


More information about the cfe-commits mailing list