summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-03-09 21:19:16 +0000
committerChris Lattner <sabre@nondot.org>2009-03-09 21:19:16 +0000
commit1897de1c3804a85cbd43a0b0c00e46186e01876e (patch)
tree71b2be488ee8ea9f52dcc5875950b65bdda76b31 /clang/lib
parent34e52ddb7d05c832f6646102bddd778755c057e6 (diff)
downloadbcm5719-llvm-1897de1c3804a85cbd43a0b0c00e46186e01876e.tar.gz
bcm5719-llvm-1897de1c3804a85cbd43a0b0c00e46186e01876e.zip
Fix PR3766, a really nasty silent miscompilation case where we emitted
a warning and then threw away the AST. While I'm in there, tighten up the code to actually reject completely bogus cases (sending a message to a struct). We still allow sending a message to an int, which doesn't make sense but GCC allows it and is easy to support. llvm-svn: 66468
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Sema/SemaExprObjC.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index 512a72f9b47..98fbd963311 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -489,7 +489,7 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel,
// Handle messages to id.
if (ReceiverCType == Context.getCanonicalType(Context.getObjCIdType()) ||
- ReceiverCType->getAsBlockPointerType()) {
+ ReceiverCType->isBlockPointerType()) {
ObjCMethodDecl *Method = LookupInstanceMethodInGlobalPool(
Sel, SourceRange(lbrac,rbrac));
if (!Method)
@@ -582,9 +582,18 @@ Sema::ExprResult Sema::ActOnInstanceMessage(ExprTy *receiver, Selector Sel,
}
if (Method && DiagnoseUseOfDecl(Method, receiverLoc))
return true;
- } else {
+ } else if (!Context.getObjCIdType().isNull() &&
+ (ReceiverCType->isPointerType() ||
+ (ReceiverCType->isIntegerType() &&
+ ReceiverCType->isScalarType()))) {
+ // Implicitly convert integers and pointers to 'id' but emit a warning.
Diag(lbrac, diag::warn_bad_receiver_type)
<< RExpr->getType() << RExpr->getSourceRange();
+ ImpCastExprToType(RExpr, Context.getObjCIdType());
+ } else {
+ // Reject other random receiver types (e.g. structs).
+ Diag(lbrac, diag::err_bad_receiver_type)
+ << RExpr->getType() << RExpr->getSourceRange();
return true;
}
OpenPOWER on IntegriCloud