Don't crash on malformed attributes in an incorrect location.
authorNico Weber <nicolasweber@gmx.de>
Mon, 29 Dec 2014 06:56:50 +0000 (06:56 +0000)
committerNico Weber <nicolasweber@gmx.de>
Mon, 29 Dec 2014 06:56:50 +0000 (06:56 +0000)
commit4b4be84a2f747bc65ccfe53281ae0aa19259744c
treea9a3572b66ef241adff7aa31bc333022d40a4c6e
parent939111ac518530f79ffd430bbba4b846e8759518
Don't crash on malformed attributes in an incorrect location.

r168626 added nicer diagnostics for attributes in the wrong places, such as
after the `final` on a class.  To do this, it added code that did high-level
pattern matching for e.g. 'final' 'alignas' '(' and then skipped until the
closing ')'.  If it saw that, it then went down the regular class parsing
path and then called MaybeParseCXX11Attributes() to parse the attribute after
the 'final' using real attribute parsing code.  On invalid attributes, the
real attribute parsing code could eat more tokens than the pattern matching
code and for example skip past the '{' starting the class, which would then
lead to an assert.  To prevent this, check for a good state after calling
MaybeParseCXX11Attributes() (which morphed into CheckMisplacedCXX11Attribute()
in r175575) and bail out if things look bleak.

Found by SLi's afl bot.

llvm-svn: 224915
clang/lib/Parse/ParseDeclCXX.cpp
clang/test/Parser/cxx0x-attributes.cpp