don't crash when sentinel attribute is used on function without a prototype,

discovered as part of PR3817

llvm-svn: 67127
This commit is contained in:
Chris Lattner 2009-03-17 23:03:47 +00:00
parent 7440dcb53e
commit 9363e3106e
4 changed files with 16 additions and 2 deletions

View File

@ -429,6 +429,9 @@ DIAG(warn_attribute_nonnull_no_pointers, WARNING,
DIAG(warn_transparent_union_nonpointer, WARNING,
"'transparent_union' attribute support incomplete; only supported for "
"pointer unions")
DIAG(warn_attribute_sentinel_named_arguments, WARNING,
"'sentinel' attribute requires named arguments")
DIAG(warn_attribute_sentinel_not_variadic, WARNING,
"'sentinel' attribute only supported for variadic functions")
DIAG(err_attribute_sentinel_less_than_zero, ERROR,

View File

@ -393,6 +393,8 @@ def warn_transparent_union_nonpointer : Warning<
"'transparent_union' attribute support incomplete; only supported for "
"pointer unions">;
def warn_attribute_sentinel_named_arguments : Warning<
"'sentinel' attribute requires named arguments">;
def warn_attribute_sentinel_not_variadic : Warning<
"'sentinel' attribute only supported for variadic functions">;
def err_attribute_sentinel_less_than_zero : Error<

View File

@ -687,8 +687,15 @@ static void HandleSentinelAttr(Decl *d, const AttributeList &Attr, Sema &S) {
}
if (FunctionDecl *FD = dyn_cast<FunctionDecl>(d)) {
QualType FT = FD->getType();
if (!FT->getAsFunctionProtoType()->isVariadic()) {
const FunctionType *FT = FD->getType()->getAsFunctionType();
assert(FT && "FunctionDecl has non-function type?");
if (isa<FunctionNoProtoType>(FT)) {
S.Diag(Attr.getLoc(), diag::warn_attribute_sentinel_named_arguments);
return;
}
if (!cast<FunctionProtoType>(FT)->isVariadic()) {
S.Diag(Attr.getLoc(), diag::warn_attribute_sentinel_not_variadic);
return;
}

View File

@ -11,3 +11,5 @@ void f4(int a, ...) __attribute__ ((sentinel(0, 2))); // expected-error{{paramet
void f5(int a) __attribute__ ((sentinel)); //expected-warning{{'sentinel' attribute only supported for variadic functions}}
void f6() __attribute__((__sentinel__)); // expected-warning {{'sentinel' attribute requires named arguments}}