forked from OSchip/llvm-project
Parse: Don't parse after the eof has been consumed
ParseCXXNonStaticMemberInitializer stashes away all the tokens for the initializer and an additional EOF token to denote where the initializer ends. However, it is possible for ParseLexedMemberInitializer to get its hands on the "real" EOF token; since the two tokens are indistinguishable, we end up consuming the EOF and descend into madness. Instead, make it possible to tell which EOF token we are looking at. This fixes PR21872. llvm-svn: 224505
This commit is contained in:
parent
7cb1789011
commit
2d3663e559
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
namespace clang {
|
namespace clang {
|
||||||
|
|
||||||
|
class Decl;
|
||||||
class IdentifierInfo;
|
class IdentifierInfo;
|
||||||
|
|
||||||
/// Token - This structure provides full information about a lexed token.
|
/// Token - This structure provides full information about a lexed token.
|
||||||
|
@ -58,6 +59,8 @@ class Token {
|
||||||
/// may be dirty (have trigraphs / escaped newlines).
|
/// may be dirty (have trigraphs / escaped newlines).
|
||||||
/// Annotations (resolved type names, C++ scopes, etc): isAnnotation().
|
/// Annotations (resolved type names, C++ scopes, etc): isAnnotation().
|
||||||
/// This is a pointer to sema-specific data for the annotation token.
|
/// This is a pointer to sema-specific data for the annotation token.
|
||||||
|
/// Eof:
|
||||||
|
// This is a pointer to a Decl.
|
||||||
/// Other:
|
/// Other:
|
||||||
/// This is null.
|
/// This is null.
|
||||||
void *PtrData;
|
void *PtrData;
|
||||||
|
@ -164,12 +167,23 @@ public:
|
||||||
assert(!isAnnotation() &&
|
assert(!isAnnotation() &&
|
||||||
"getIdentifierInfo() on an annotation token!");
|
"getIdentifierInfo() on an annotation token!");
|
||||||
if (isLiteral()) return nullptr;
|
if (isLiteral()) return nullptr;
|
||||||
|
if (is(tok::eof)) return nullptr;
|
||||||
return (IdentifierInfo*) PtrData;
|
return (IdentifierInfo*) PtrData;
|
||||||
}
|
}
|
||||||
void setIdentifierInfo(IdentifierInfo *II) {
|
void setIdentifierInfo(IdentifierInfo *II) {
|
||||||
PtrData = (void*) II;
|
PtrData = (void*) II;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Decl *getDecl() const {
|
||||||
|
assert(is(tok::eof));
|
||||||
|
return reinterpret_cast<const Decl *>(PtrData);
|
||||||
|
}
|
||||||
|
void setDecl(const Decl *D) {
|
||||||
|
assert(is(tok::eof));
|
||||||
|
assert(!PtrData);
|
||||||
|
PtrData = const_cast<Decl *>(D);
|
||||||
|
}
|
||||||
|
|
||||||
/// getRawIdentifier - For a raw identifier token (i.e., an identifier
|
/// getRawIdentifier - For a raw identifier token (i.e., an identifier
|
||||||
/// lexed in raw mode), returns a reference to the text substring in the
|
/// lexed in raw mode), returns a reference to the text substring in the
|
||||||
/// buffer if known.
|
/// buffer if known.
|
||||||
|
|
|
@ -218,6 +218,7 @@ void Parser::ParseCXXNonStaticMemberInitializer(Decl *VarD) {
|
||||||
Eof.startToken();
|
Eof.startToken();
|
||||||
Eof.setKind(tok::eof);
|
Eof.setKind(tok::eof);
|
||||||
Eof.setLocation(Tok.getLocation());
|
Eof.setLocation(Tok.getLocation());
|
||||||
|
Eof.setDecl(VarD);
|
||||||
Toks.push_back(Eof);
|
Toks.push_back(Eof);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -622,7 +623,9 @@ void Parser::ParseLexedMemberInitializer(LateParsedMemberInitializer &MI) {
|
||||||
while (Tok.isNot(tok::eof))
|
while (Tok.isNot(tok::eof))
|
||||||
ConsumeAnyToken();
|
ConsumeAnyToken();
|
||||||
}
|
}
|
||||||
ConsumeAnyToken();
|
// Make sure this is *our* artificial EOF token.
|
||||||
|
if (Tok.getDecl() == MI.Field)
|
||||||
|
ConsumeAnyToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ConsumeAndStoreUntil - Consume and store the token at the passed token
|
/// ConsumeAndStoreUntil - Consume and store the token at the passed token
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
// RUN: not %clang_cc1 -fsyntax-only %s
|
||||||
|
template <typename T> struct S {
|
||||||
|
int k = ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((
|
||||||
|
int f;
|
Loading…
Reference in New Issue