From: Chris Lattner Date: Tue, 17 Mar 2009 23:03:47 +0000 (+0000) Subject: don't crash when sentinel attribute is used on function without a prototype, X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=897cd90fef4cd5139999585f3af31d85c2d07720;p=clang don't crash when sentinel attribute is used on function without a prototype, discovered as part of PR3817 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67127 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.def b/include/clang/Basic/DiagnosticSemaKinds.def index d415ee5392..0cacb77cc9 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.def +++ b/include/clang/Basic/DiagnosticSemaKinds.def @@ -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, diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index a2ba0e9708..8b6ef49542 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -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< diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 57cd3d2bcb..96812018a1 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -687,8 +687,15 @@ static void HandleSentinelAttr(Decl *d, const AttributeList &Attr, Sema &S) { } if (FunctionDecl *FD = dyn_cast(d)) { - QualType FT = FD->getType(); - if (!FT->getAsFunctionProtoType()->isVariadic()) { + const FunctionType *FT = FD->getType()->getAsFunctionType(); + assert(FT && "FunctionDecl has non-function type?"); + + if (isa(FT)) { + S.Diag(Attr.getLoc(), diag::warn_attribute_sentinel_named_arguments); + return; + } + + if (!cast(FT)->isVariadic()) { S.Diag(Attr.getLoc(), diag::warn_attribute_sentinel_not_variadic); return; } diff --git a/test/Sema/sentinel-attribute.c b/test/Sema/sentinel-attribute.c index a83cda771d..37d0adc596 100644 --- a/test/Sema/sentinel-attribute.c +++ b/test/Sema/sentinel-attribute.c @@ -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}}