forked from OSchip/llvm-project
Add a warning for questionable va_args usage.
llvm-svn: 68435
This commit is contained in:
parent
9e658eccab
commit
3f5cd77db2
|
@ -1464,6 +1464,8 @@ def err_va_start_used_in_non_variadic_function : Error<
|
|||
"'va_start' used in function with fixed args">;
|
||||
def warn_second_parameter_of_va_start_not_last_named_argument : Warning<
|
||||
"second parameter of 'va_start' not last named argument">;
|
||||
def warn_va_arg_with_qualified_va_list : Warning<
|
||||
"va_arg applied to va_list type %0 with unexpected qualifiers">;
|
||||
def err_first_argument_to_va_arg_not_of_type_va_list : Error<
|
||||
"first argument to 'va_arg' is of type %0 and not 'va_list'">;
|
||||
|
||||
|
|
|
@ -4726,11 +4726,18 @@ Sema::OwningExprResult Sema::ActOnVAArg(SourceLocation BuiltinLoc,
|
|||
|
||||
AssignConvertType ConvResult =
|
||||
CheckAssignmentConstraints(VaListType, E->getType());
|
||||
if (ConvResult != Compatible &&
|
||||
ConvResult != CompatiblePointerDiscardsQualifiers)
|
||||
switch (ConvResult) {
|
||||
case Compatible: break; // Everything good.
|
||||
case CompatiblePointerDiscardsQualifiers:
|
||||
Diag(E->getLocStart(), diag::warn_va_arg_with_qualified_va_list)
|
||||
<< E->getType() << E->getSourceRange();
|
||||
break;
|
||||
|
||||
default:
|
||||
return ExprError(Diag(E->getLocStart(),
|
||||
diag::err_first_argument_to_va_arg_not_of_type_va_list)
|
||||
<< E->getType() << E->getSourceRange());
|
||||
}
|
||||
|
||||
// FIXME: Check that type is complete/non-abstract
|
||||
// FIXME: Warn if a non-POD type is passed in.
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
// RUN: clang-cc -fsyntax-only -verify %s -triple x86_64-apple-darwin9
|
||||
|
||||
// rdar://6726818
|
||||
void f1() {
|
||||
const __builtin_va_list args2;
|
||||
(void)__builtin_va_arg(args2, int); // expected-warning {{va_arg applied to va_list type 'struct __va_list_tag const *' with unexpected qualifiers}}
|
||||
}
|
||||
|
|
@ -61,9 +61,3 @@ void f7(int a, ...) {
|
|||
__builtin_va_end(ap);
|
||||
}
|
||||
|
||||
// rdar://6726818
|
||||
void f8() {
|
||||
const __builtin_va_list args2;
|
||||
(void)__builtin_va_arg(args2, int);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue