[cfe-commits] r102035 - in /cfe/trunk: lib/Sema/SemaExprObjC.cpp lib/Sema/SemaInit.cpp lib/Sema/SemaInit.h test/SemaObjCXX/message.mm test/SemaObjCXX/objc-pointer-conv.mm

Douglas Gregor dgregor at apple.com
Wed Apr 21 16:24:10 PDT 2010


Author: dgregor
Date: Wed Apr 21 18:24:10 2010
New Revision: 102035

URL: http://llvm.org/viewvc/llvm-project?rev=102035&view=rev
Log:
Switch the initialization of Objective-C message parameters (as occurs
during message sends) over to the new initialization code and away
from the C-only CheckSingleAssignmentConstraints. The enables the use
of C++ types in method parameters and message arguments, as well as
unifying more initialiation code overall.


Modified:
    cfe/trunk/lib/Sema/SemaExprObjC.cpp
    cfe/trunk/lib/Sema/SemaInit.cpp
    cfe/trunk/lib/Sema/SemaInit.h
    cfe/trunk/test/SemaObjCXX/message.mm
    cfe/trunk/test/SemaObjCXX/objc-pointer-conv.mm

Modified: cfe/trunk/lib/Sema/SemaExprObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprObjC.cpp?rev=102035&r1=102034&r2=102035&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprObjC.cpp Wed Apr 21 18:24:10 2010
@@ -13,6 +13,7 @@
 
 #include "Sema.h"
 #include "Lookup.h"
+#include "SemaInit.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/ExprObjC.h"
@@ -204,30 +205,23 @@
   bool IsError = false;
   for (unsigned i = 0; i < NumNamedArgs; i++) {
     Expr *argExpr = Args[i];
+    ParmVarDecl *Param = Method->param_begin()[i];
     assert(argExpr && "CheckMessageArgumentTypes(): missing expression");
 
-    QualType lhsType = Method->param_begin()[i]->getType();
-    QualType rhsType = argExpr->getType();
-
-    // If necessary, apply function/array conversion. C99 6.7.5.3p[7,8].
-    if (lhsType->isArrayType())
-      lhsType = Context.getArrayDecayedType(lhsType);
-    else if (lhsType->isFunctionType())
-      lhsType = Context.getPointerType(lhsType);
-
-    AssignConvertType Result =
-      CheckSingleAssignmentConstraints(lhsType, argExpr);
-    if (Result == Incompatible && !getLangOptions().CPlusPlus &&
-        CheckTransparentUnionArgumentConstraints(lhsType, argExpr)
-        == Sema::Compatible)
-      Result = Compatible;
-        
-    if (Args[i] != argExpr) // The expression was converted.
-      Args[i] = argExpr; // Make sure we store the converted expression.
+    if (RequireCompleteType(argExpr->getSourceRange().getBegin(),
+                            Param->getType(),
+                            PDiag(diag::err_call_incomplete_argument)
+                              << argExpr->getSourceRange()))
+      return true;
 
-    IsError |=
-      DiagnoseAssignmentResult(Result, argExpr->getLocStart(), lhsType, rhsType,
-                               argExpr, AA_Sending);
+    InitializedEntity Entity = InitializedEntity::InitializeParameter(Param);
+    OwningExprResult ArgE = PerformCopyInitialization(Entity,
+                                                      SourceLocation(),
+                                                      Owned(argExpr->Retain()));
+    if (ArgE.isInvalid())
+      IsError = true;
+    else
+      Args[i] = ArgE.takeAs<Expr>();
   }
 
   // Promote additional arguments to variadic methods.

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=102035&r1=102034&r2=102035&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Wed Apr 21 18:24:10 2010
@@ -3088,7 +3088,10 @@
     return Sema::AA_Initializing;
 
   case InitializedEntity::EK_Parameter:
-    // FIXME: Can we tell when we're sending vs. passing?
+    if (Entity.getDecl() && 
+        isa<ObjCMethodDecl>(Entity.getDecl()->getDeclContext()))
+      return Sema::AA_Sending;
+
     return Sema::AA_Passing;
 
   case InitializedEntity::EK_Result:

Modified: cfe/trunk/lib/Sema/SemaInit.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.h?rev=102035&r1=102034&r2=102035&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.h (original)
+++ cfe/trunk/lib/Sema/SemaInit.h Wed Apr 21 18:24:10 2010
@@ -142,7 +142,12 @@
   /// \brief Create the initialization entity for a parameter that is
   /// only known by its type.
   static InitializedEntity InitializeParameter(QualType Type) {
-    return InitializedEntity(EK_Parameter, SourceLocation(), Type);
+    InitializedEntity Entity;
+    Entity.Kind = EK_Parameter;
+    Entity.Type = Type;
+    Entity.Parent = 0;
+    Entity.VariableOrMember = 0;
+    return Entity;
   }
 
   /// \brief Create the initialization entity for the result of a function.

Modified: cfe/trunk/test/SemaObjCXX/message.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/message.mm?rev=102035&r1=102034&r2=102035&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjCXX/message.mm (original)
+++ cfe/trunk/test/SemaObjCXX/message.mm Wed Apr 21 18:24:10 2010
@@ -75,3 +75,18 @@
   return [super method];
 }
 @end
+
+struct String {
+  String(const char *);
+};
+
+struct MutableString : public String { };
+
+// C++-specific parameter types
+ at interface I5
+- method:(const String&)str1 other:(String&)str2;
+ at end
+
+void test_I5(I5 *i5, String s) {
+  [i5 method:"hello" other:s];
+}

Modified: cfe/trunk/test/SemaObjCXX/objc-pointer-conv.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/objc-pointer-conv.mm?rev=102035&r1=102034&r2=102035&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjCXX/objc-pointer-conv.mm (original)
+++ cfe/trunk/test/SemaObjCXX/objc-pointer-conv.mm Wed Apr 21 18:24:10 2010
@@ -32,7 +32,7 @@
 void Func (I* arg);  // expected-note {{candidate function not viable: no known conversion from 'I const *' to 'I *' for 1st argument}}
 
 void foo(const I *p, I* sel) {
-  [sel Meth : p];	// expected-error {{sending 'I const *' to parameter of incompatible type 'I *'}}
+  [sel Meth : p];	// expected-error {{cannot initialize a parameter of type 'I *' with an lvalue of type 'I const *'}}
   Func(p);		// expected-error {{no matching function for call to 'Func'}}
 }
 





More information about the cfe-commits mailing list