From d5ead14365402730ba89af3e7a312487e96f8eee Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Mon, 30 Apr 2012 16:20:27 +0000 Subject: [PATCH] Restore paren, bracket and brace counts in parser when TentativeParsingAction is reverted, from Pasi Parviainen! Fixes PR12480 / . llvm-svn: 155823 --- clang/include/clang/Parse/Parser.h | 7 + clang/test/Parser/recursion-limits.cpp | 259 +++++++++++++++++++++++++ 2 files changed, 266 insertions(+) create mode 100644 clang/test/Parser/recursion-limits.cpp diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index 6404c9fbd4ff..332a8d0cfe85 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -584,11 +584,15 @@ private: class TentativeParsingAction { Parser &P; Token PrevTok; + unsigned short PrevParenCount, PrevBracketCount, PrevBraceCount; bool isActive; public: explicit TentativeParsingAction(Parser& p) : P(p) { PrevTok = P.Tok; + PrevParenCount = P.ParenCount; + PrevBracketCount = P.BracketCount; + PrevBraceCount = P.BraceCount; P.PP.EnableBacktrackAtThisPos(); isActive = true; } @@ -601,6 +605,9 @@ private: assert(isActive && "Parsing action was finished!"); P.PP.Backtrack(); P.Tok = PrevTok; + P.ParenCount = PrevParenCount; + P.BracketCount = PrevBracketCount; + P.BraceCount = PrevBraceCount; isActive = false; } ~TentativeParsingAction() { diff --git a/clang/test/Parser/recursion-limits.cpp b/clang/test/Parser/recursion-limits.cpp new file mode 100644 index 000000000000..ea25dea0dacc --- /dev/null +++ b/clang/test/Parser/recursion-limits.cpp @@ -0,0 +1,259 @@ +// RUN: %clang_cc1 -fsyntax-only %s -verify +class outer { + class inner1 { inner1(); }; + class inner2 { inner2(); }; + class inner3 { inner3(); }; + class inner4 { inner4(); }; + class inner5 { inner5(); }; + class inner6 { inner6(); }; + class inner7 { inner7(); }; + class inner8 { inner8(); }; + class inner9 { inner9(); }; + class inner10 { inner10(); }; + class inner11 { inner11(); }; + class inner12 { inner12(); }; + class inner13 { inner13(); }; + class inner14 { inner14(); }; + class inner15 { inner15(); }; + class inner16 { inner16(); }; + class inner17 { inner17(); }; + class inner18 { inner18(); }; + class inner19 { inner19(); }; + class inner20 { inner20(); }; + class inner21 { inner21(); }; + class inner22 { inner22(); }; + class inner23 { inner23(); }; + class inner24 { inner24(); }; + class inner25 { inner25(); }; + class inner26 { inner26(); }; + class inner27 { inner27(); }; + class inner28 { inner28(); }; + class inner29 { inner29(); }; + class inner30 { inner30(); }; + class inner31 { inner31(); }; + class inner32 { inner32(); }; + class inner33 { inner33(); }; + class inner34 { inner34(); }; + class inner35 { inner35(); }; + class inner36 { inner36(); }; + class inner37 { inner37(); }; + class inner38 { inner38(); }; + class inner39 { inner39(); }; + class inner40 { inner40(); }; + class inner41 { inner41(); }; + class inner42 { inner42(); }; + class inner43 { inner43(); }; + class inner44 { inner44(); }; + class inner45 { inner45(); }; + class inner46 { inner46(); }; + class inner47 { inner47(); }; + class inner48 { inner48(); }; + class inner49 { inner49(); }; + class inner50 { inner50(); }; + class inner51 { inner51(); }; + class inner52 { inner52(); }; + class inner53 { inner53(); }; + class inner54 { inner54(); }; + class inner55 { inner55(); }; + class inner56 { inner56(); }; + class inner57 { inner57(); }; + class inner58 { inner58(); }; + class inner59 { inner59(); }; + class inner60 { inner60(); }; + class inner61 { inner61(); }; + class inner62 { inner62(); }; + class inner63 { inner63(); }; + class inner64 { inner64(); }; + class inner65 { inner65(); }; + class inner66 { inner66(); }; + class inner67 { inner67(); }; + class inner68 { inner68(); }; + class inner69 { inner69(); }; + class inner70 { inner70(); }; + class inner71 { inner71(); }; + class inner72 { inner72(); }; + class inner73 { inner73(); }; + class inner74 { inner74(); }; + class inner75 { inner75(); }; + class inner76 { inner76(); }; + class inner77 { inner77(); }; + class inner78 { inner78(); }; + class inner79 { inner79(); }; + class inner80 { inner80(); }; + class inner81 { inner81(); }; + class inner82 { inner82(); }; + class inner83 { inner83(); }; + class inner84 { inner84(); }; + class inner85 { inner85(); }; + class inner86 { inner86(); }; + class inner87 { inner87(); }; + class inner88 { inner88(); }; + class inner89 { inner89(); }; + class inner90 { inner90(); }; + class inner91 { inner91(); }; + class inner92 { inner92(); }; + class inner93 { inner93(); }; + class inner94 { inner94(); }; + class inner95 { inner95(); }; + class inner96 { inner96(); }; + class inner97 { inner97(); }; + class inner98 { inner98(); }; + class inner99 { inner99(); }; + class inner100 { inner100(); }; + class inner101 { inner101(); }; + class inner102 { inner102(); }; + class inner103 { inner103(); }; + class inner104 { inner104(); }; + class inner105 { inner105(); }; + class inner106 { inner106(); }; + class inner107 { inner107(); }; + class inner108 { inner108(); }; + class inner109 { inner109(); }; + class inner110 { inner110(); }; + class inner111 { inner111(); }; + class inner112 { inner112(); }; + class inner113 { inner113(); }; + class inner114 { inner114(); }; + class inner115 { inner115(); }; + class inner116 { inner116(); }; + class inner117 { inner117(); }; + class inner118 { inner118(); }; + class inner119 { inner119(); }; + class inner120 { inner120(); }; + class inner121 { inner121(); }; + class inner122 { inner122(); }; + class inner123 { inner123(); }; + class inner124 { inner124(); }; + class inner125 { inner125(); }; + class inner126 { inner126(); }; + class inner127 { inner127(); }; + class inner128 { inner128(); }; + class inner129 { inner129(); }; + class inner130 { inner130(); }; + class inner131 { inner131(); }; + class inner132 { inner132(); }; + class inner133 { inner133(); }; + class inner134 { inner134(); }; + class inner135 { inner135(); }; + class inner136 { inner136(); }; + class inner137 { inner137(); }; + class inner138 { inner138(); }; + class inner139 { inner139(); }; + class inner140 { inner140(); }; + class inner141 { inner141(); }; + class inner142 { inner142(); }; + class inner143 { inner143(); }; + class inner144 { inner144(); }; + class inner145 { inner145(); }; + class inner146 { inner146(); }; + class inner147 { inner147(); }; + class inner148 { inner148(); }; + class inner149 { inner149(); }; + class inner150 { inner150(); }; + class inner151 { inner151(); }; + class inner152 { inner152(); }; + class inner153 { inner153(); }; + class inner154 { inner154(); }; + class inner155 { inner155(); }; + class inner156 { inner156(); }; + class inner157 { inner157(); }; + class inner158 { inner158(); }; + class inner159 { inner159(); }; + class inner160 { inner160(); }; + class inner161 { inner161(); }; + class inner162 { inner162(); }; + class inner163 { inner163(); }; + class inner164 { inner164(); }; + class inner165 { inner165(); }; + class inner166 { inner166(); }; + class inner167 { inner167(); }; + class inner168 { inner168(); }; + class inner169 { inner169(); }; + class inner170 { inner170(); }; + class inner171 { inner171(); }; + class inner172 { inner172(); }; + class inner173 { inner173(); }; + class inner174 { inner174(); }; + class inner175 { inner175(); }; + class inner176 { inner176(); }; + class inner177 { inner177(); }; + class inner178 { inner178(); }; + class inner179 { inner179(); }; + class inner180 { inner180(); }; + class inner181 { inner181(); }; + class inner182 { inner182(); }; + class inner183 { inner183(); }; + class inner184 { inner184(); }; + class inner185 { inner185(); }; + class inner186 { inner186(); }; + class inner187 { inner187(); }; + class inner188 { inner188(); }; + class inner189 { inner189(); }; + class inner190 { inner190(); }; + class inner191 { inner191(); }; + class inner192 { inner192(); }; + class inner193 { inner193(); }; + class inner194 { inner194(); }; + class inner195 { inner195(); }; + class inner196 { inner196(); }; + class inner197 { inner197(); }; + class inner198 { inner198(); }; + class inner199 { inner199(); }; + class inner200 { inner200(); }; + class inner201 { inner201(); }; + class inner202 { inner202(); }; + class inner203 { inner203(); }; + class inner204 { inner204(); }; + class inner205 { inner205(); }; + class inner206 { inner206(); }; + class inner207 { inner207(); }; + class inner208 { inner208(); }; + class inner209 { inner209(); }; + class inner210 { inner210(); }; + class inner211 { inner211(); }; + class inner212 { inner212(); }; + class inner213 { inner213(); }; + class inner214 { inner214(); }; + class inner215 { inner215(); }; + class inner216 { inner216(); }; + class inner217 { inner217(); }; + class inner218 { inner218(); }; + class inner219 { inner219(); }; + class inner220 { inner220(); }; + class inner221 { inner221(); }; + class inner222 { inner222(); }; + class inner223 { inner223(); }; + class inner224 { inner224(); }; + class inner225 { inner225(); }; + class inner226 { inner226(); }; + class inner227 { inner227(); }; + class inner228 { inner228(); }; + class inner229 { inner229(); }; + class inner230 { inner230(); }; + class inner231 { inner231(); }; + class inner232 { inner232(); }; + class inner233 { inner233(); }; + class inner234 { inner234(); }; + class inner235 { inner235(); }; + class inner236 { inner236(); }; + class inner237 { inner237(); }; + class inner238 { inner238(); }; + class inner239 { inner239(); }; + class inner240 { inner240(); }; + class inner241 { inner241(); }; + class inner242 { inner242(); }; + class inner243 { inner243(); }; + class inner244 { inner244(); }; + class inner245 { inner245(); }; + class inner246 { inner246(); }; + class inner247 { inner247(); }; + class inner248 { inner248(); }; + class inner249 { inner249(); }; + class inner250 { inner250(); }; + class inner251 { inner251(); }; + class inner252 { inner252(); }; + class inner253 { inner253(); }; + class inner254 { inner254(); }; + class inner255 { inner255(); }; + class inner256 { inner256(); }; +};