summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteve Naroff <snaroff@apple.com>2008-11-19 15:54:23 +0000
committerSteve Naroff <snaroff@apple.com>2008-11-19 15:54:23 +0000
commit9e4ac111f04b581b9d85d51c2f7f68af86d6d4ba (patch)
treea2d8836e4c66cab11715b9c397c2d346e6144ae6
parentd08452f60a2731c279f3b845d84a4a8940844d99 (diff)
downloadbcm5719-llvm-9e4ac111f04b581b9d85d51c2f7f68af86d6d4ba.tar.gz
bcm5719-llvm-9e4ac111f04b581b9d85d51c2f7f68af86d6d4ba.zip
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). llvm-svn: 59639
-rw-r--r--clang/include/clang/Parse/Action.h3
-rw-r--r--clang/include/clang/Parse/Parser.h2
-rw-r--r--clang/lib/Parse/ParseExpr.cpp3
-rw-r--r--clang/lib/Parse/ParseInit.cpp9
-rw-r--r--clang/lib/Parse/ParseObjc.cpp10
-rw-r--r--clang/lib/Sema/Sema.h2
-rw-r--r--clang/lib/Sema/SemaExprObjC.cpp51
-rw-r--r--clang/test/SemaObjC/super.m14
8 files changed, 67 insertions, 27 deletions
diff --git a/clang/include/clang/Parse/Action.h b/clang/include/clang/Parse/Action.h
index e9e59257dfd..71785430035 100644
--- a/clang/include/clang/Parse/Action.h
+++ b/clang/include/clang/Parse/Action.h
@@ -939,7 +939,8 @@ public:
Scope *S,
IdentifierInfo *receivingClassName,
Selector Sel,
- SourceLocation lbrac,
+ SourceLocation lbrac,
+ SourceLocation receiverLoc,
SourceLocation rbrac,
ExprTy **ArgExprs, unsigned NumArgs) {
return 0;
diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h
index ad6244fe4c3..0c061219f84 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -556,9 +556,11 @@ private:
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);
diff --git a/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp
index 440393dac6b..5f36f0bb272 100644
--- a/clang/lib/Parse/ParseExpr.cpp
+++ b/clang/lib/Parse/ParseExpr.cpp
@@ -212,9 +212,10 @@ Parser::ExprResult Parser::ParseAssignmentExpression() {
/// 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);
diff --git a/clang/lib/Parse/ParseInit.cpp b/clang/lib/Parse/ParseInit.cpp
index 9b488566a61..c3d2cd2c4cc 100644
--- a/clang/lib/Parse/ParseInit.cpp
+++ b/clang/lib/Parse/ParseInit.cpp
@@ -134,8 +134,9 @@ ParseInitializerWithPotentialDesignator(InitListDesignations &Designations,
}
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 @@ ParseInitializerWithPotentialDesignator(InitListDesignations &Designations,
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.
diff --git a/clang/lib/Parse/ParseObjc.cpp b/clang/lib/Parse/ParseObjc.cpp
index 793945bfd15..9c97ea2efa6 100644
--- a/clang/lib/Parse/ParseObjc.cpp
+++ b/clang/lib/Parse/ParseObjc.cpp
@@ -1424,8 +1424,8 @@ Parser::ExprResult Parser::ParseObjCMessageExpression() {
// 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 @@ Parser::ExprResult Parser::ParseObjCMessageExpression() {
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::ParseObjCMessageExpression() {
///
Parser::ExprResult
Parser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc,
+ SourceLocation NameLoc,
IdentifierInfo *ReceiverName,
ExprTy *ReceiverExpr) {
// Parse objc-selector
@@ -1548,7 +1549,8 @@ Parser::ParseObjCMessageExpressionBody(SourceLocation LBracLoc,
// 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());
diff --git a/clang/lib/Sema/Sema.h b/clang/lib/Sema/Sema.h
index c60fd352f9d..b10a98f0b3c 100644
--- a/clang/lib/Sema/Sema.h
+++ b/clang/lib/Sema/Sema.h
@@ -1050,7 +1050,7 @@ public:
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.
diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index 8bacea14bf8..786d74c9507 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -176,7 +176,8 @@ bool Sema::CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs,
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 @@ Sema::ExprResult Sema::ActOnClassMessage(
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);
diff --git a/clang/test/SemaObjC/super.m b/clang/test/SemaObjC/super.m
index 46b8b4a0974..243b84c353e 100644
--- a/clang/test/SemaObjC/super.m
+++ b/clang/test/SemaObjC/super.m
@@ -23,3 +23,17 @@
[super cMethod]; // expected-warning{{method '+cMethod' not found (return type defaults to 'id')}}
}
@end
+
+@interface XX
+- m;
+@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'}}
+}
OpenPOWER on IntegriCloud