[cfe-commits] r59639 - in /cfe/trunk: include/clang/Parse/Action.h include/clang/Parse/Parser.h lib/Parse/ParseExpr.cpp lib/Parse/ParseInit.cpp lib/Parse/ParseObjc.cpp lib/Sema/Sema.h lib/Sema/SemaExprObjC.cpp test/SemaObjC/super.m
Steve Naroff
snaroff at apple.com
Wed Nov 19 07:54:33 PST 2008
Author: snaroff
Date: Wed Nov 19 09:54:23 2008
New Revision: 59639
URL: http://llvm.org/viewvc/llvm-project?rev=59639&view=rev
Log:
Fix <rdar://problem/6150376> [sema] crash on invalid message send.
The core fix in Sema::ActOnClassMessage(). All the other changes have to do with passing down the SourceLocation for the receiver (to properly position the cursor when producing an error diagnostic).
Modified:
cfe/trunk/include/clang/Parse/Action.h
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Parse/ParseInit.cpp
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/test/SemaObjC/super.m
Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=59639&r1=59638&r2=59639&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Wed Nov 19 09:54:23 2008
@@ -939,7 +939,8 @@
Scope *S,
IdentifierInfo *receivingClassName,
Selector Sel,
- SourceLocation lbrac,
+ SourceLocation lbrac,
+ SourceLocation receiverLoc,
SourceLocation rbrac,
ExprTy **ArgExprs, unsigned NumArgs) {
return 0;
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=59639&r1=59638&r2=59639&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Wed Nov 19 09:54:23 2008
@@ -556,9 +556,11 @@
ExprResult ParseObjCProtocolExpression(SourceLocation AtLoc);
ExprResult ParseObjCMessageExpression();
ExprResult ParseObjCMessageExpressionBody(SourceLocation LBracloc,
+ SourceLocation NameLoc,
IdentifierInfo *ReceiverName,
ExprTy *ReceiverExpr);
ExprResult ParseAssignmentExprWithObjCMessageExprStart(SourceLocation LBracloc,
+ SourceLocation NameLoc,
IdentifierInfo *ReceiverName,
ExprTy *ReceiverExpr);
Modified: cfe/trunk/lib/Parse/ParseExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseExpr.cpp?rev=59639&r1=59638&r2=59639&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseExpr.cpp (original)
+++ cfe/trunk/lib/Parse/ParseExpr.cpp Wed Nov 19 09:54:23 2008
@@ -212,9 +212,10 @@
/// expressions and other binary operators for these expressions as well.
Parser::ExprResult
Parser::ParseAssignmentExprWithObjCMessageExprStart(SourceLocation LBracLoc,
+ SourceLocation NameLoc,
IdentifierInfo *ReceiverName,
ExprTy *ReceiverExpr) {
- ExprResult R = ParseObjCMessageExpressionBody(LBracLoc, ReceiverName,
+ ExprResult R = ParseObjCMessageExpressionBody(LBracLoc, NameLoc, ReceiverName,
ReceiverExpr);
if (R.isInvalid) return R;
R = ParsePostfixExpressionSuffix(R);
Modified: cfe/trunk/lib/Parse/ParseInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseInit.cpp?rev=59639&r1=59638&r2=59639&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseInit.cpp (original)
+++ cfe/trunk/lib/Parse/ParseInit.cpp Wed Nov 19 09:54:23 2008
@@ -134,8 +134,9 @@
}
IdentifierInfo *Name = Tok.getIdentifierInfo();
- ConsumeToken();
- return ParseAssignmentExprWithObjCMessageExprStart(StartLoc, Name, 0);
+ SourceLocation NameLoc = ConsumeToken();
+ return ParseAssignmentExprWithObjCMessageExprStart(StartLoc, NameLoc,
+ Name, 0);
}
// Note that we parse this as an assignment expression, not a constant
@@ -166,7 +167,9 @@
Diag(Tok, diag::err_expected_equal_designator);
}
- return ParseAssignmentExprWithObjCMessageExprStart(StartLoc, 0,Idx.Val);
+ return ParseAssignmentExprWithObjCMessageExprStart(StartLoc,
+ SourceLocation(),
+ 0, Idx.Val);
}
// Create designation if we haven't already.
Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=59639&r1=59638&r2=59639&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Wed Nov 19 09:54:23 2008
@@ -1424,8 +1424,8 @@
// Parse receiver
if (isTokObjCMessageIdentifierReceiver()) {
IdentifierInfo *ReceiverName = Tok.getIdentifierInfo();
- ConsumeToken();
- return ParseObjCMessageExpressionBody(LBracLoc, ReceiverName, 0);
+ SourceLocation NameLoc = ConsumeToken();
+ return ParseObjCMessageExpressionBody(LBracLoc, NameLoc, ReceiverName, 0);
}
ExprResult Res = ParseExpression();
@@ -1434,7 +1434,7 @@
return Res;
}
- return ParseObjCMessageExpressionBody(LBracLoc, 0, Res.Val);
+ return ParseObjCMessageExpressionBody(LBracLoc, SourceLocation(), 0, Res.Val);
}
/// ParseObjCMessageExpressionBody - Having parsed "'[' objc-receiver", parse
@@ -1460,6 +1460,7 @@
///
Parser::ExprResult
Parser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc,
+ SourceLocation NameLoc,
IdentifierInfo *ReceiverName,
ExprTy *ReceiverExpr) {
// Parse objc-selector
@@ -1548,7 +1549,8 @@
// We've just parsed a keyword message.
if (ReceiverName)
return Actions.ActOnClassMessage(CurScope,
- ReceiverName, Sel, LBracLoc, RBracLoc,
+ ReceiverName, Sel,
+ LBracLoc, NameLoc, RBracLoc,
&KeyExprs[0], KeyExprs.size());
return Actions.ActOnInstanceMessage(ReceiverExpr, Sel, LBracLoc, RBracLoc,
&KeyExprs[0], KeyExprs.size());
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=59639&r1=59638&r2=59639&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Wed Nov 19 09:54:23 2008
@@ -1050,7 +1050,7 @@
virtual ExprResult ActOnClassMessage(
Scope *S,
IdentifierInfo *receivingClassName, Selector Sel,
- SourceLocation lbrac, SourceLocation rbrac,
+ SourceLocation lbrac, SourceLocation receiverLoc, SourceLocation rbrac,
ExprTy **ArgExprs, unsigned NumArgs);
// ActOnInstanceMessage - used for both unary and keyword messages.
Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=59639&r1=59638&r2=59639&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Wed Nov 19 09:54:23 2008
@@ -176,7 +176,8 @@
Sema::ExprResult Sema::ActOnClassMessage(
Scope *S,
IdentifierInfo *receiverName, Selector Sel,
- SourceLocation lbrac, SourceLocation rbrac, ExprTy **Args, unsigned NumArgs)
+ SourceLocation lbrac, SourceLocation receiverLoc, SourceLocation rbrac,
+ ExprTy **Args, unsigned NumArgs)
{
assert(receiverName && "missing receiver class name");
@@ -184,22 +185,38 @@
ObjCInterfaceDecl* ClassDecl = 0;
bool isSuper = false;
- if (receiverName == SuperID && getCurMethodDecl()) {
- isSuper = true;
- ClassDecl = getCurMethodDecl()->getClassInterface()->getSuperClass();
- if (!ClassDecl)
- return Diag(lbrac, diag::error_no_super_class)
- << getCurMethodDecl()->getClassInterface()->getName();
- if (getCurMethodDecl()->isInstance()) {
- QualType superTy = Context.getObjCInterfaceType(ClassDecl);
- superTy = Context.getPointerType(superTy);
- ExprResult ReceiverExpr = new ObjCSuperExpr(SourceLocation(), superTy);
- // We are really in an instance method, redirect.
- return ActOnInstanceMessage(ReceiverExpr.Val, Sel, lbrac, rbrac,
- Args, NumArgs);
- }
- // We are sending a message to 'super' within a class method. Do nothing,
- // the receiver will pass through as 'super' (how convenient:-).
+ if (receiverName == SuperID) {
+ if (getCurMethodDecl()) {
+ isSuper = true;
+ ClassDecl = getCurMethodDecl()->getClassInterface()->getSuperClass();
+ if (!ClassDecl)
+ return Diag(lbrac, diag::error_no_super_class,
+ getCurMethodDecl()->getClassInterface()->getName());
+ if (getCurMethodDecl()->isInstance()) {
+ QualType superTy = Context.getObjCInterfaceType(ClassDecl);
+ superTy = Context.getPointerType(superTy);
+ ExprResult ReceiverExpr = new ObjCSuperExpr(SourceLocation(), superTy);
+ // We are really in an instance method, redirect.
+ return ActOnInstanceMessage(ReceiverExpr.Val, Sel, lbrac, rbrac,
+ Args, NumArgs);
+ }
+ // We are sending a message to 'super' within a class method. Do nothing,
+ // the receiver will pass through as 'super' (how convenient:-).
+ } else {
+ // 'super' has been used outside a method context. If a variable named
+ // 'super' has been declared, redirect. If not, produce a diagnostic.
+ Decl *SuperDecl = LookupDecl(receiverName, Decl::IDNS_Ordinary, S, false);
+ ValueDecl *VD = dyn_cast_or_null<ValueDecl>(SuperDecl);
+ if (VD) {
+ ExprResult ReceiverExpr = new DeclRefExpr(VD, VD->getType(),
+ receiverLoc);
+ // We are really in an instance method, redirect.
+ return ActOnInstanceMessage(ReceiverExpr.Val, Sel, lbrac, rbrac,
+ Args, NumArgs);
+ }
+ return Diag(receiverLoc, diag::err_undeclared_var_use,
+ receiverName->getName());
+ }
} else
ClassDecl = getObjCInterfaceDecl(receiverName);
Modified: cfe/trunk/test/SemaObjC/super.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/super.m?rev=59639&r1=59638&r2=59639&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/super.m (original)
+++ cfe/trunk/test/SemaObjC/super.m Wed Nov 19 09:54:23 2008
@@ -23,3 +23,17 @@
[super cMethod]; // expected-warning{{method '+cMethod' not found (return type defaults to 'id')}}
}
@end
+
+ at interface XX
+- m;
+ at end
+
+void f(id super) {
+ [super m];
+}
+void f0(int super) {
+ [super m]; // expected-error{{bad receiver type 'int'}}
+}
+void f1(int puper) {
+ [super m]; // expected-error{{use of undeclared identifier 'super'}}
+}
More information about the cfe-commits
mailing list