]> granicus.if.org Git - clang/commitdiff
Don't apply the include depth limit until we actually decide to enter
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 19 Mar 2019 01:51:17 +0000 (01:51 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 19 Mar 2019 01:51:17 +0000 (01:51 +0000)
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

lib/Lex/PPDirectives.cpp

index 39501745292605d6111baf93896c0c8bc22d6fad..62796293b4dc50fc9e09846364536b1f7772730e 100644 (file)
@@ -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