Hi Reid, Just a heads up that the test you added fails if the compiler defaults to a different C++ standard. Our internal version defaults to c++11, and the test fails because the error "expected ';' after top level declarator" is not emitted.
Douglas Yung > -----Original Message----- > From: cfe-commits [mailto:cfe-commits-boun...@lists.llvm.org] On Behalf > Of Reid Kleckner via cfe-commits > Sent: Thursday, October 20, 2016 13:53 > To: cfe-commits@lists.llvm.org > Subject: r284777 - Fix off-by-one error in PPCaching.cpp token > annotation assertion > > Author: rnk > Date: Thu Oct 20 15:53:20 2016 > New Revision: 284777 > > URL: http://llvm.org/viewvc/llvm-project?rev=284777&view=rev > Log: > Fix off-by-one error in PPCaching.cpp token annotation assertion > > This assert is intended to defend against backtracking into the middle > of a sequence of tokens that is being replaced with an annotation, but > it's OK if we backtrack to the exact position of the start of the > annotation sequence. Use a <= comparison instead of <. > > Fixes PR25946 > > Added: > cfe/trunk/test/Parser/backtrack-off-by-one.cpp > Modified: > cfe/trunk/lib/Lex/PPCaching.cpp > > Modified: cfe/trunk/lib/Lex/PPCaching.cpp > URL: http://llvm.org/viewvc/llvm- > project/cfe/trunk/lib/Lex/PPCaching.cpp?rev=284777&r1=284776&r2=284777& > view=diff > ======================================================================= > ======= > --- cfe/trunk/lib/Lex/PPCaching.cpp (original) > +++ cfe/trunk/lib/Lex/PPCaching.cpp Thu Oct 20 15:53:20 2016 > @@ -105,7 +105,7 @@ void Preprocessor::AnnotatePreviousCache > for (CachedTokensTy::size_type i = CachedLexPos; i != 0; --i) { > CachedTokensTy::iterator AnnotBegin = CachedTokens.begin() + i-1; > if (AnnotBegin->getLocation() == Tok.getLocation()) { > - assert((BacktrackPositions.empty() || BacktrackPositions.back() > < i) && > + assert((BacktrackPositions.empty() || BacktrackPositions.back() > + <= i) && > "The backtrack pos points inside the annotated tokens!"); > // Replace the cached tokens with the single annotation token. > if (i < CachedLexPos) > > Added: cfe/trunk/test/Parser/backtrack-off-by-one.cpp > URL: http://llvm.org/viewvc/llvm- > project/cfe/trunk/test/Parser/backtrack-off-by- > one.cpp?rev=284777&view=auto > ======================================================================= > ======= > --- cfe/trunk/test/Parser/backtrack-off-by-one.cpp (added) > +++ cfe/trunk/test/Parser/backtrack-off-by-one.cpp Thu Oct 20 15:53:20 > +++ 2016 > @@ -0,0 +1,17 @@ > +// RUN: %clang_cc1 -verify %s > + > +// PR25946 > +// We had an off-by-one error in an assertion when annotating A<int> > +below. Our // error recovery checks if A<int> is a constructor > +declarator, and opens a // TentativeParsingAction. Then we attempt to > +annotate the token at the exact // position that we want to possibly > backtrack to, and this used to crash. > + > +template <typename T> class A {}; > + > +// expected-error@+1 {{expected '{' after base class list}} template > +<typename T> class B : T // not ',' or '{' > +// expected-error@+3 {{C++ requires a type specifier for all > +declarations}} // expected-error@+2 {{expected ';' after top level > +declarator}} // expected-error@+1 {{expected ';' after class}} A<int> > { > +}; > > > _______________________________________________ > cfe-commits mailing list > cfe-commits@lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits