From 5a8ea4ca9470358800836a932c2fccb8f3b5710c Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Tue, 19 Mar 2019 01:51:17 +0000 Subject: 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. llvm-svn: 356432 --- clang/lib/Lex/PPDirectives.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'clang/lib/Lex') diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 39501745292..62796293b4d 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/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 -- cgit v1.2.3