зеркало из https://github.com/microsoft/clang-1.git
Warn when someone tries to pass a variable with a non-POD type to a varargs function/method/block.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62148 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
518fda1d12
Коммит
906fed0fb5
|
@ -1410,6 +1410,9 @@ DIAG(err_typecheck_call_too_few_args, ERROR,
|
||||||
"too few arguments to %select{function|block|method}0 call")
|
"too few arguments to %select{function|block|method}0 call")
|
||||||
DIAG(err_typecheck_call_too_many_args, ERROR,
|
DIAG(err_typecheck_call_too_many_args, ERROR,
|
||||||
"too many arguments to %select{function|block|method}0 call")
|
"too many arguments to %select{function|block|method}0 call")
|
||||||
|
DIAG(warn_cannot_pass_non_pod_arg_to_vararg, WARNING,
|
||||||
|
"cannot pass object of non-POD type %0 through variadic "
|
||||||
|
"%select{function|block|method}1; call will abort at runtime")
|
||||||
DIAG(err_typecheck_closure_too_many_args, ERROR,
|
DIAG(err_typecheck_closure_too_many_args, ERROR,
|
||||||
"too many arguments to closure call")
|
"too many arguments to closure call")
|
||||||
DIAG(err_typecheck_call_invalid_ordered_compare, ERROR,
|
DIAG(err_typecheck_call_invalid_ordered_compare, ERROR,
|
||||||
|
|
|
@ -1688,6 +1688,17 @@ Sema::ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
|
||||||
// Promote the arguments (C99 6.5.2.2p7).
|
// Promote the arguments (C99 6.5.2.2p7).
|
||||||
for (unsigned i = NumArgsInProto; i != NumArgs; i++) {
|
for (unsigned i = NumArgsInProto; i != NumArgs; i++) {
|
||||||
Expr *Arg = Args[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);
|
DefaultArgumentPromotion(Arg);
|
||||||
Call->setArg(i, Arg);
|
Call->setArg(i, Arg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,8 +156,15 @@ bool Sema::CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs,
|
||||||
|
|
||||||
// Promote additional arguments to variadic methods.
|
// Promote additional arguments to variadic methods.
|
||||||
if (Method->isVariadic()) {
|
if (Method->isVariadic()) {
|
||||||
for (unsigned i = NumNamedArgs; i < NumArgs; ++i)
|
for (unsigned i = NumNamedArgs; i < NumArgs; ++i) {
|
||||||
|
if (!Args[i]->getType()->isPODType()) {
|
||||||
|
Diag(Args[i]->getLocStart(),
|
||||||
|
diag::warn_cannot_pass_non_pod_arg_to_vararg) <<
|
||||||
|
Args[i]->getType() << 2; // Method
|
||||||
|
}
|
||||||
|
|
||||||
DefaultArgumentPromotion(Args[i]);
|
DefaultArgumentPromotion(Args[i]);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Check for extra arguments to non-variadic methods.
|
// Check for extra arguments to non-variadic methods.
|
||||||
if (NumArgs != NumNamedArgs) {
|
if (NumArgs != NumNamedArgs) {
|
||||||
|
|
|
@ -3576,6 +3576,13 @@ Sema::BuildCallToObjectOfClassType(Scope *S, Expr *Object,
|
||||||
// Promote the arguments (C99 6.5.2.2p7).
|
// Promote the arguments (C99 6.5.2.2p7).
|
||||||
for (unsigned i = NumArgsInProto; i != NumArgs; i++) {
|
for (unsigned i = NumArgsInProto; i != NumArgs; i++) {
|
||||||
Expr *Arg = Args[i];
|
Expr *Arg = Args[i];
|
||||||
|
|
||||||
|
if (!Arg->getType()->isPODType()) {
|
||||||
|
Diag(Arg->getLocStart(),
|
||||||
|
diag::warn_cannot_pass_non_pod_arg_to_vararg) <<
|
||||||
|
Arg->getType() << 2; // Method
|
||||||
|
}
|
||||||
|
|
||||||
DefaultArgumentPromotion(Arg);
|
DefaultArgumentPromotion(Arg);
|
||||||
TheCall->setArg(i + 1, Arg);
|
TheCall->setArg(i + 1, Arg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
// RUN: clang -fsyntax-only -verify -fblocks %s
|
||||||
|
|
||||||
|
class C {
|
||||||
|
public:
|
||||||
|
C(int);
|
||||||
|
void g(int a, ...);
|
||||||
|
static void h(int a, ...);
|
||||||
|
};
|
||||||
|
|
||||||
|
void g(int a, ...);
|
||||||
|
|
||||||
|
void t1()
|
||||||
|
{
|
||||||
|
C c(10);
|
||||||
|
|
||||||
|
g(10, c); // expected-warning{{cannot pass object of non-POD type 'class C' through variadic function; call will abort at runtime}}
|
||||||
|
}
|
||||||
|
|
||||||
|
void t2()
|
||||||
|
{
|
||||||
|
C c(10);
|
||||||
|
|
||||||
|
c.g(10, c); // expected-warning{{cannot pass object of non-POD type 'class C' through variadic method; call will abort at runtime}}
|
||||||
|
|
||||||
|
C::h(10, c); // expected-warning{{cannot pass object of non-POD type 'class C' through variadic function; call will abort at runtime}}
|
||||||
|
}
|
||||||
|
|
||||||
|
int (^block)(int, ...);
|
||||||
|
|
||||||
|
void t3()
|
||||||
|
{
|
||||||
|
C c(10);
|
||||||
|
|
||||||
|
block(10, c); // expected-warning{{cannot pass object of non-POD type 'class C' through variadic block; call will abort at runtime}}
|
||||||
|
}
|
||||||
|
|
||||||
|
class D {
|
||||||
|
public:
|
||||||
|
void operator() (int a, ...);
|
||||||
|
};
|
||||||
|
|
||||||
|
void t4()
|
||||||
|
{
|
||||||
|
C c(10);
|
||||||
|
|
||||||
|
D d;
|
||||||
|
|
||||||
|
d(10, c); // expected-warning{{Line 48: cannot pass object of non-POD type 'class C' through variadic method; call will abort at runtime}}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
// RUN: clang -fsyntax-only -verify %s
|
||||||
|
|
||||||
|
class C {
|
||||||
|
public:
|
||||||
|
C(int);
|
||||||
|
};
|
||||||
|
|
||||||
|
@interface D
|
||||||
|
- (void)g:(int)a, ...;
|
||||||
|
@end
|
||||||
|
|
||||||
|
void t1(D *d)
|
||||||
|
{
|
||||||
|
C c(10);
|
||||||
|
|
||||||
|
[d g:10, c]; // expected-warning{{cannot pass object of non-POD type 'class C' through variadic method; call will abort at runtime}}
|
||||||
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче