diff options
author | John McCall <rjmccall@apple.com> | 2013-03-04 07:34:02 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2013-03-04 07:34:02 +0000 |
commit | 48f904271effd381ec3c1ae33b97d1ec7d95860a (patch) | |
tree | 2ffae6e7b7d7bfcf22f6570ca1b826c4822133e3 /lib/Sema/SemaExpr.cpp | |
parent | 0353a7b2df9dc36784f9ec354c266f9c603053e1 (diff) |
Centralize and refine the __unknown_anytype argument rules
and be sure to apply them whether or not the debugger gave
us a method declaration.
rdar://12565338
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176432 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaExpr.cpp')
-rw-r--r-- | lib/Sema/SemaExpr.cpp | 38 |
1 files changed, 21 insertions, 17 deletions
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 7dd17a028f..e1b9950eca 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -3835,11 +3835,8 @@ bool Sema::GatherArgumentsForCall(SourceLocation CallLoc, if (Proto->getResultType() == Context.UnknownAnyTy && FDecl && FDecl->isExternC()) { for (unsigned i = ArgIx; i != NumArgs; ++i) { - ExprResult arg; - if (isa<ExplicitCastExpr>(Args[i]->IgnoreParens())) - arg = DefaultFunctionArrayLvalueConversion(Args[i]); - else - arg = DefaultVariadicArgumentPromotion(Args[i], CallType, FDecl); + QualType paramType; // ignored + ExprResult arg = checkUnknownAnyArg(CallLoc, Args[i], paramType); Invalid |= arg.isInvalid(); AllArgs.push_back(arg.take()); } @@ -12013,20 +12010,27 @@ ExprResult Sema::forceUnknownAnyToType(Expr *E, QualType ToType) { return RebuildUnknownAnyExpr(*this, ToType).Visit(E); } -QualType Sema::checkUnknownAnyArg(Expr *&arg) { - // Filter out placeholders. - ExprResult argR = CheckPlaceholderExpr(arg); - if (argR.isInvalid()) return QualType(); - arg = argR.take(); - - // If the argument is an explicit cast, use that exact type as the - // effective parameter type. - if (ExplicitCastExpr *castArg = dyn_cast<ExplicitCastExpr>(arg)) { - return castArg->getTypeAsWritten(); +ExprResult Sema::checkUnknownAnyArg(SourceLocation callLoc, + Expr *arg, QualType ¶mType) { + // If the syntactic form of the argument is not an explicit cast of + // any sort, just do default argument promotion. + ExplicitCastExpr *castArg = dyn_cast<ExplicitCastExpr>(arg->IgnoreParens()); + if (!castArg) { + ExprResult result = DefaultArgumentPromotion(arg); + if (result.isInvalid()) return ExprError(); + paramType = result.get()->getType(); + return result; } - // Otherwise, try to pass by value. - return arg->getType().getUnqualifiedType(); + // Otherwise, use the type that was written in the explicit cast. + assert(!arg->hasPlaceholderType()); + paramType = castArg->getTypeAsWritten(); + + // Copy-initialize a parameter of that type. + InitializedEntity entity = + InitializedEntity::InitializeParameter(Context, paramType, + /*consumed*/ false); + return PerformCopyInitialization(entity, callLoc, Owned(arg)); } static ExprResult diagnoseUnknownAnyExpr(Sema &S, Expr *E) { |