From: Richard Smith <richard-llvm@metafoo.co.uk>
Date: Tue, 19 Mar 2019 01:51:17 +0000 (+0000)
Subject: Don't apply the include depth limit until we actually decide to enter
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6e323b2030566b88627f140e5675bf7aed04bc07;p=clang

Don't apply the include depth limit until we actually decide to enter
the file.

NFC unless a skipped #include is found at the final permitted #include
level.

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

diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp
index 3950174529..62796293b4 100644
--- a/lib/Lex/PPDirectives.cpp
+++ b/lib/Lex/PPDirectives.cpp
@@ -1724,13 +1724,6 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc,
   // C99 6.10.2p4.
   CheckEndOfDirective(IncludeTok.getIdentifierInfo()->getNameStart(), true);
 
-  // Check that we don't have infinite #include recursion.
-  if (IncludeMacroStack.size() == MaxAllowedIncludeStackDepth-1) {
-    Diag(FilenameTok, diag::err_pp_include_too_deep);
-    HasReachedMaxIncludeDepth = true;
-    return;
-  }
-
   // Complain about attempts to #include files in an audit pragma.
   if (PragmaARCCFCodeAuditedLoc.isValid()) {
     Diag(HashLoc, diag::err_pp_include_in_arc_cf_code_audited);
@@ -2071,6 +2064,13 @@ void Preprocessor::HandleIncludeDirective(SourceLocation HashLoc,
     return;
   }
 
+  // Check that we don't have infinite #include recursion.
+  if (IncludeMacroStack.size() == MaxAllowedIncludeStackDepth-1) {
+    Diag(FilenameTok, diag::err_pp_include_too_deep);
+    HasReachedMaxIncludeDepth = true;
+    return;
+  }
+
   // Look up the file, create a File ID for it.
   SourceLocation IncludePos = End;
   // If the filename string was the result of macro expansions, set the include