]> granicus.if.org Git - clang/commitdiff
Switch parameter-passing for calls via function pointers (where we
authorDouglas Gregor <dgregor@apple.com>
Tue, 22 Dec 2009 16:09:06 +0000 (16:09 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 22 Dec 2009 16:09:06 +0000 (16:09 +0000)
don't have a FunctionDecl) over to InitializationSequence.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91906 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
lib/Sema/SemaInit.cpp
lib/Sema/SemaInit.h

index d01516c77fe039b167fcccbecaab6c7daa83c3ed..09e1d6f455120d72e5a921bbfa919b7e50ff5122 100644 (file)
@@ -3181,21 +3181,22 @@ bool Sema::GatherArgumentsForCall(SourceLocation CallLoc,
                               << Arg->getSourceRange()))
         return true;
       
-      // Pass the argument.
-      if (FDecl && i < FDecl->getNumParams()) {
-        ParmVarDecl *Param = FDecl->getParamDecl(i);
-        InitializedEntity Entity =InitializedEntity::InitializeParameter(Param);
-        OwningExprResult ArgE = PerformCopyInitialization(Entity,
-                                                          SourceLocation(),
-                                                          Owned(Arg));
-        if (ArgE.isInvalid())
-          return true;
-
-        Arg = ArgE.takeAs<Expr>();
-      } else {
-        if (PerformCopyInitialization(Arg, ProtoArgType, AA_Passing))
-          return true;
-      }
+      // Pass the argument
+      ParmVarDecl *Param = 0;
+      if (FDecl && i < FDecl->getNumParams())
+        Param = FDecl->getParamDecl(i);
+
+      
+      InitializedEntity Entity =
+        Param? InitializedEntity::InitializeParameter(Param)
+             : InitializedEntity::InitializeParameter(ProtoArgType);
+      OwningExprResult ArgE = PerformCopyInitialization(Entity,
+                                                        SourceLocation(),
+                                                        Owned(Arg));
+      if (ArgE.isInvalid())
+        return true;
+
+      Arg = ArgE.takeAs<Expr>();
       
       if (!ProtoArgType->isReferenceType())
         Arg = MaybeBindToTemporary(Arg).takeAs<Expr>();
index b72fede8bb27965fa4b9f0336d36401f4c76ce0d..9c85ceca74e8f18cabd01840eb026914de486db9 100644 (file)
@@ -1807,8 +1807,12 @@ InitializedEntity InitializedEntity::InitializeBase(ASTContext &Context,
 
 DeclarationName InitializedEntity::getName() const {
   switch (getKind()) {
-  case EK_Variable:
   case EK_Parameter:
+    if (!VariableOrMember)
+      return DeclarationName();
+    // Fall through
+
+  case EK_Variable:
   case EK_Member:
     return VariableOrMember->getDeclName();
 
index c5ba57c72648d0e2fb8d275adeb24898b0ef51c1..959c55e3d32d3b9cc077114c85311f61d43a3774 100644 (file)
@@ -105,8 +105,9 @@ private:
     : Kind(EK_Parameter), Parent(0), Type(Parm->getType()),
       VariableOrMember(reinterpret_cast<DeclaratorDecl*>(Parm)) { }
   
-  /// \brief Create the initialization entity for the result of a function,
-  /// throwing an object, or performing an explicit cast.
+  /// \brief Create the initialization entity for the result of a
+  /// function, throwing an object, performing an explicit cast, or
+  /// initializing a parameter for which there is no declaration.
   InitializedEntity(EntityKind Kind, SourceLocation Loc, QualType Type)
     : Kind(Kind), Parent(0), Type(Type), Location(Loc.getRawEncoding()) { }
   
@@ -130,6 +131,12 @@ public:
     return InitializedEntity(Parm);
   }
 
+  /// \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);
+  }
+
   /// \brief Create the initialization entity for the result of a function.
   static InitializedEntity InitializeResult(SourceLocation ReturnLoc,
                                             QualType Type) {