Submitted by:
Reviewed by:

Fixed a bug in the parser's handling of attributes on pointer declarators.

For example, the following code was producing a syntax error...

int *__attribute(()) foo;

attrib.c:10:25: error: expected identifier or '('
int *__attribute(()) foo;
                        ^
Changed Parser::ParseTypeQualifierListOpt to not consume the token following
an attribute declaration.

Also added LexerToken::getName() convenience method...useful when tracking
down errors like this.

llvm-svn: 39602
This commit is contained in:
Steve Naroff 2007-06-06 23:19:11 +00:00
parent 98cf3e95ce
commit 98d153c730
2 changed files with 8 additions and 3 deletions

View File

@ -181,8 +181,10 @@ Parser::DeclTy *Parser::ParseAttributes() {
CurrAttr = Actions.ParseAttribute(AttrName, AttrNameLoc, CurrAttr);
}
}
SkipUntil(tok::r_paren, false);
SkipUntil(tok::r_paren, false);
if (ExpectAndConsume(tok::r_paren, diag::err_expected_rparen))
SkipUntil(tok::r_paren, false);
if (ExpectAndConsume(tok::r_paren, diag::err_expected_rparen))
SkipUntil(tok::r_paren, false);
}
return CurrAttr;
}
@ -929,7 +931,7 @@ void Parser::ParseTypeQualifierListOpt(DeclSpec &DS) {
break;
case tok::kw___attribute:
ParseAttributes();
break;
continue; // do *not* consume the next token!
}
// If the specifier combination wasn't legal, issue a diagnostic.
@ -979,6 +981,7 @@ void Parser::ParseDeclaratorInternal(Declarator &D) {
if (Kind == tok::star) {
// Is a pointer
DeclSpec DS;
ParseTypeQualifierListOpt(DS);
// Recursively parse the declarator.

View File

@ -62,6 +62,8 @@ public:
void setLocation(SourceLocation L) { Loc = L; }
void setLength(unsigned Len) { Length = Len; }
const char *getName() const { return getTokenName(Kind); }
/// startToken - Reset all flags to cleared.
///
void startToken() {