Use a single function for doing vararg argument promotion. Also, make sure to do the promotion before checking the type - fixes PR3340.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62323 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index bf2d7b1..820326f 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -87,6 +87,21 @@
UsualUnaryConversions(Expr);
}
+// DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
+// will warn if the resulting type is not a POD type.
+void Sema::DefaultVariadicArgumentPromotion(Expr *&Expr, VariadicCallType CT)
+
+{
+ DefaultArgumentPromotion(Expr);
+
+ if (!Expr->getType()->isPODType()) {
+ Diag(Expr->getLocStart(),
+ diag::warn_cannot_pass_non_pod_arg_to_vararg) <<
+ Expr->getType() << CT;
+ }
+}
+
+
/// UsualArithmeticConversions - Performs various conversions that are common to
/// binary operators (C99 6.3.1.8). If both operands aren't arithmetic, this
/// routine returns the first non-arithmetic type found. The client is
@@ -1703,21 +1718,16 @@
// If this is a variadic call, handle args passed through "...".
if (Proto->isVariadic()) {
+ VariadicCallType CallType = VariadicFunction;
+ if (Fn->getType()->isBlockPointerType())
+ CallType = VariadicBlock; // Block
+ else if (isa<MemberExpr>(Fn))
+ CallType = VariadicMethod;
+
// Promote the arguments (C99 6.5.2.2p7).
for (unsigned i = NumArgsInProto; i != NumArgs; i++) {
Expr *Arg = Args[i];
- if (!Arg->getType()->isPODType()) {
- int CallType = 0;
- if (Fn->getType()->isBlockPointerType())
- CallType = 1; // Block
- else if (isa<MemberExpr>(Fn))
- CallType = 2;
-
- Diag(Arg->getLocStart(),
- diag::warn_cannot_pass_non_pod_arg_to_vararg) <<
- Arg->getType() << CallType;
- }
- DefaultArgumentPromotion(Arg);
+ DefaultVariadicArgumentPromotion(Arg, CallType);
Call->setArg(i, Arg);
}
}