diff options
author | Chris Lattner <sabre@nondot.org> | 2009-03-09 21:19:16 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-03-09 21:19:16 +0000 |
commit | 0c73f37f0a48a1512bc0477a71f0d6cffcb78fc0 (patch) | |
tree | 5a14645dc411f5a67db698638f046d8601721aff /lib/Sema/SemaExprObjC.cpp | |
parent | 61f72cbd037e58f12cfe90cd442373f44092f030 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66468 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaExprObjC.cpp')
-rw-r--r-- | lib/Sema/SemaExprObjC.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index 512a72f9b4..98fbd96331 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/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; } |