summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/tools/clang/lib/Parse/ParseObjc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm/tools/clang/lib/Parse/ParseObjc.cpp')
-rw-r--r--contrib/llvm/tools/clang/lib/Parse/ParseObjc.cpp47
1 files changed, 40 insertions, 7 deletions
diff --git a/contrib/llvm/tools/clang/lib/Parse/ParseObjc.cpp b/contrib/llvm/tools/clang/lib/Parse/ParseObjc.cpp
index 67abe58..81761bf 100644
--- a/contrib/llvm/tools/clang/lib/Parse/ParseObjc.cpp
+++ b/contrib/llvm/tools/clang/lib/Parse/ParseObjc.cpp
@@ -344,9 +344,11 @@ Decl *Parser::ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
protocols, protocolLocs, EndProtoLoc,
/*consumeLastToken=*/true,
/*warnOnIncompleteProtocols=*/true);
+ if (Tok.is(tok::eof))
+ return nullptr;
}
}
-
+
// Next, we need to check for any protocol references.
if (LAngleLoc.isValid()) {
if (!ProtocolIdents.empty()) {
@@ -367,7 +369,8 @@ Decl *Parser::ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
}
if (Tok.isNot(tok::less))
- Actions.ActOnTypedefedProtocols(protocols, superClassId, superClassLoc);
+ Actions.ActOnTypedefedProtocols(protocols, protocolLocs,
+ superClassId, superClassLoc);
Decl *ClsType =
Actions.ActOnStartClassInterface(getCurScope(), AtLoc, nameId, nameLoc,
@@ -1034,7 +1037,7 @@ IdentifierInfo *Parser::ParseObjCSelectorPiece(SourceLocation &SelectorLoc) {
case tok::caretequal: {
std::string ThisTok(PP.getSpelling(Tok));
if (isLetter(ThisTok[0])) {
- IdentifierInfo *II = &PP.getIdentifierTable().get(ThisTok.data());
+ IdentifierInfo *II = &PP.getIdentifierTable().get(ThisTok);
Tok.setKind(tok::identifier);
SelectorLoc = ConsumeToken();
return II;
@@ -1814,6 +1817,8 @@ void Parser::parseObjCTypeArgsAndProtocolQualifiers(
protocolRAngleLoc,
consumeLastToken,
/*warnOnIncompleteProtocols=*/false);
+ if (Tok.is(tok::eof)) // Nothing else to do here...
+ return;
// An Objective-C object pointer followed by type arguments
// can then be followed again by a set of protocol references, e.g.,
@@ -1862,6 +1867,9 @@ TypeResult Parser::parseObjCTypeArgsAndProtocolQualifiers(
protocols, protocolLocs,
protocolRAngleLoc, consumeLastToken);
+ if (Tok.is(tok::eof))
+ return true; // Invalid type result.
+
// Compute the location of the last token.
if (consumeLastToken)
endLoc = PrevTokLocation;
@@ -2238,7 +2246,6 @@ Parser::ParseObjCAtImplementationDeclaration(SourceLocation AtLoc) {
while (!ObjCImplParsing.isFinished() && !isEofOrEom()) {
ParsedAttributesWithRange attrs(AttrFactory);
MaybeParseCXX11Attributes(attrs);
- MaybeParseMicrosoftAttributes(attrs);
if (DeclGroupPtrTy DGP = ParseExternalDeclaration(attrs)) {
DeclGroupRef DG = DGP.get();
DeclsInGroup.append(DG.begin(), DG.end());
@@ -2766,6 +2773,7 @@ StmtResult Parser::ParseObjCAtStatement(SourceLocation AtLoc) {
return Actions.ActOnNullStmt(Tok.getLocation());
}
+ ExprStatementTokLoc = AtLoc;
ExprResult Res(ParseExpressionWithLeadingAt(AtLoc));
if (Res.isInvalid()) {
// If the expression is invalid, skip ahead to the next semicolon. Not
@@ -2862,7 +2870,11 @@ ExprResult Parser::ParseObjCAtExpression(SourceLocation AtLoc) {
return ParseAvailabilityCheckExpr(AtLoc);
default: {
const char *str = nullptr;
- if (GetLookAheadToken(1).is(tok::l_brace)) {
+ // Only provide the @try/@finally/@autoreleasepool fixit when we're sure
+ // that this is a proper statement where such directives could actually
+ // occur.
+ if (GetLookAheadToken(1).is(tok::l_brace) &&
+ ExprStatementTokLoc == AtLoc) {
char ch = Tok.getIdentifierInfo()->getNameStart()[0];
str =
ch == 't' ? "try"
@@ -3416,6 +3428,7 @@ ExprResult Parser::ParseObjCArrayLiteral(SourceLocation AtLoc) {
ExprVector ElementExprs; // array elements.
ConsumeBracket(); // consume the l_square.
+ bool HasInvalidEltExpr = false;
while (Tok.isNot(tok::r_square)) {
// Parse list of array element expressions (all must be id types).
ExprResult Res(ParseAssignmentExpression());
@@ -3427,11 +3440,15 @@ ExprResult Parser::ParseObjCArrayLiteral(SourceLocation AtLoc) {
return Res;
}
+ Res = Actions.CorrectDelayedTyposInExpr(Res.get());
+ if (Res.isInvalid())
+ HasInvalidEltExpr = true;
+
// Parse the ellipsis that indicates a pack expansion.
if (Tok.is(tok::ellipsis))
Res = Actions.ActOnPackExpansion(Res.get(), ConsumeToken());
if (Res.isInvalid())
- return true;
+ HasInvalidEltExpr = true;
ElementExprs.push_back(Res.get());
@@ -3442,6 +3459,10 @@ ExprResult Parser::ParseObjCArrayLiteral(SourceLocation AtLoc) {
<< tok::comma);
}
SourceLocation EndLoc = ConsumeBracket(); // location of ']'
+
+ if (HasInvalidEltExpr)
+ return ExprError();
+
MultiExprArg Args(ElementExprs);
return Actions.BuildObjCArrayLiteral(SourceRange(AtLoc, EndLoc), Args);
}
@@ -3449,6 +3470,7 @@ ExprResult Parser::ParseObjCArrayLiteral(SourceLocation AtLoc) {
ExprResult Parser::ParseObjCDictionaryLiteral(SourceLocation AtLoc) {
SmallVector<ObjCDictionaryElement, 4> Elements; // dictionary elements.
ConsumeBrace(); // consume the l_square.
+ bool HasInvalidEltExpr = false;
while (Tok.isNot(tok::r_brace)) {
// Parse the comma separated key : value expressions.
ExprResult KeyExpr;
@@ -3478,7 +3500,15 @@ ExprResult Parser::ParseObjCDictionaryLiteral(SourceLocation AtLoc) {
return ValueExpr;
}
- // Parse the ellipsis that designates this as a pack expansion.
+ // Check the key and value for possible typos
+ KeyExpr = Actions.CorrectDelayedTyposInExpr(KeyExpr.get());
+ ValueExpr = Actions.CorrectDelayedTyposInExpr(ValueExpr.get());
+ if (KeyExpr.isInvalid() || ValueExpr.isInvalid())
+ HasInvalidEltExpr = true;
+
+ // Parse the ellipsis that designates this as a pack expansion. Do not
+ // ActOnPackExpansion here, leave it to template instantiation time where
+ // we can get better diagnostics.
SourceLocation EllipsisLoc;
if (getLangOpts().CPlusPlus)
TryConsumeToken(tok::ellipsis, EllipsisLoc);
@@ -3495,6 +3525,9 @@ ExprResult Parser::ParseObjCDictionaryLiteral(SourceLocation AtLoc) {
<< tok::comma);
}
SourceLocation EndLoc = ConsumeBrace();
+
+ if (HasInvalidEltExpr)
+ return ExprError();
// Create the ObjCDictionaryLiteral.
return Actions.BuildObjCDictionaryLiteral(SourceRange(AtLoc, EndLoc),
OpenPOWER on IntegriCloud