implement rdar://6780761, making sema reject some code that otherwise
crashes codegen.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68891 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index 8138379..5018833 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -2210,7 +2210,7 @@
// DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
// will warn if the resulting type is not a POD type.
- void DefaultVariadicArgumentPromotion(Expr *&Expr, VariadicCallType CT);
+ bool DefaultVariadicArgumentPromotion(Expr *&Expr, VariadicCallType CT);
// UsualArithmeticConversions - performs the UsualUnaryConversions on it's
// operands and then handles various conversions that are common to binary
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index f2820df..e380f78 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -154,16 +154,25 @@
UsualUnaryConversions(Expr);
}
-// DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
-// will warn if the resulting type is not a POD type.
-void Sema::DefaultVariadicArgumentPromotion(Expr *&Expr, VariadicCallType CT) {
+/// DefaultVariadicArgumentPromotion - Like DefaultArgumentPromotion, but
+/// will warn if the resulting type is not a POD type, and rejects ObjC
+/// interfaces passed by value. This returns true if the argument type is
+/// completely illegal.
+bool 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;
+ if (Expr->getType()->isObjCInterfaceType()) {
+ Diag(Expr->getLocStart(),
+ diag::err_cannot_pass_objc_interface_to_vararg)
+ << Expr->getType() << CT;
+ return true;
}
+
+ if (!Expr->getType()->isPODType())
+ Diag(Expr->getLocStart(), diag::warn_cannot_pass_non_pod_arg_to_vararg)
+ << Expr->getType() << CT;
+
+ return false;
}
@@ -2223,7 +2232,7 @@
// Promote the arguments (C99 6.5.2.2p7).
for (unsigned i = NumArgsInProto; i != NumArgs; i++) {
Expr *Arg = Args[i];
- DefaultVariadicArgumentPromotion(Arg, CallType);
+ Invalid |= DefaultVariadicArgumentPromotion(Arg, CallType);
Call->setArg(i, Arg);
}
}
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp
index 54a18ac..8d8fae0 100644
--- a/lib/Sema/SemaExprObjC.cpp
+++ b/lib/Sema/SemaExprObjC.cpp
@@ -164,7 +164,7 @@
unsigned NumNamedArgs = Sel.getNumArgs();
assert(NumArgs >= NumNamedArgs && "Too few arguments for selector!");
- bool anyIncompatibleArgs = false;
+ bool IsError = false;
for (unsigned i = 0; i < NumNamedArgs; i++) {
Expr *argExpr = Args[i];
assert(argExpr && "CheckMessageArgumentTypes(): missing expression");
@@ -183,7 +183,7 @@
if (Args[i] != argExpr) // The expression was converted.
Args[i] = argExpr; // Make sure we store the converted expression.
- anyIncompatibleArgs |=
+ IsError |=
DiagnoseAssignmentResult(Result, argExpr->getLocStart(), lhsType, rhsType,
argExpr, "sending");
}
@@ -191,7 +191,7 @@
// Promote additional arguments to variadic methods.
if (Method->isVariadic()) {
for (unsigned i = NumNamedArgs; i < NumArgs; ++i)
- DefaultVariadicArgumentPromotion(Args[i], VariadicMethod);
+ IsError |= DefaultVariadicArgumentPromotion(Args[i], VariadicMethod);
} else {
// Check for extra arguments to non-variadic methods.
if (NumArgs != NumNamedArgs) {
@@ -203,7 +203,7 @@
}
}
- return anyIncompatibleArgs;
+ return IsError;
}
bool Sema::isSelfExpr(Expr *RExpr) {
diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp
index 0a12a71..875a382 100644
--- a/lib/Sema/SemaOverload.cpp
+++ b/lib/Sema/SemaOverload.cpp
@@ -4178,11 +4178,13 @@
else if (NumArgs > NumArgsInProto)
NumArgsToCheck = NumArgsInProto;
+ bool IsError = false;
+
// Initialize the implicit object parameter.
- if (PerformObjectArgumentInitialization(Object, Method))
- return true;
+ IsError |= PerformObjectArgumentInitialization(Object, Method);
TheCall->setArg(0, Object);
+
// Check the argument types.
for (unsigned i = 0; i != NumArgsToCheck; i++) {
Expr *Arg;
@@ -4191,8 +4193,7 @@
// Pass the argument.
QualType ProtoArgType = Proto->getArgType(i);
- if (PerformCopyInitialization(Arg, ProtoArgType, "passing"))
- return true;
+ IsError |= PerformCopyInitialization(Arg, ProtoArgType, "passing");
} else {
Arg = new (Context) CXXDefaultArgExpr(Method->getParamDecl(i));
}
@@ -4205,12 +4206,13 @@
// Promote the arguments (C99 6.5.2.2p7).
for (unsigned i = NumArgsInProto; i != NumArgs; i++) {
Expr *Arg = Args[i];
-
- DefaultVariadicArgumentPromotion(Arg, VariadicMethod);
+ IsError |= DefaultVariadicArgumentPromotion(Arg, VariadicMethod);
TheCall->setArg(i + 1, Arg);
}
}
+ if (IsError) return true;
+
return CheckFunctionCall(Method, TheCall.take()).release();
}