From 3bba33d6f58844d4924ab1e221dc2ff44c521624 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Fri, 15 May 2009 21:18:04 +0000 Subject: [PATCH] improved on diagnosing misplacement of sentinel attributes. No change in functionality. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71894 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticSemaKinds.td | 2 +- lib/Sema/SemaDeclAttr.cpp | 7 ++++--- lib/Sema/SemaExpr.cpp | 4 ++-- test/Sema/block-sentinel-attribute.c | 1 + 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 7bb9a38422..bc92264e5a 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -483,7 +483,7 @@ def warn_transparent_union_nonpointer : Warning< 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">; + "'sentinel' attribute only supported for variadic %select{functions|blocks}0">; def err_attribute_sentinel_less_than_zero : Error< "'sentinel' parameter 1 less than zero">; def err_attribute_sentinel_not_zero_or_one : Error< diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index f5b6595b18..42a177a497 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -712,12 +712,12 @@ static void HandleSentinelAttr(Decl *d, const AttributeList &Attr, Sema &S) { } if (!cast(FT)->isVariadic()) { - S.Diag(Attr.getLoc(), diag::warn_attribute_sentinel_not_variadic); + S.Diag(Attr.getLoc(), diag::warn_attribute_sentinel_not_variadic) << 0; return; } } else if (ObjCMethodDecl *MD = dyn_cast(d)) { if (!MD->isVariadic()) { - S.Diag(Attr.getLoc(), diag::warn_attribute_sentinel_not_variadic); + S.Diag(Attr.getLoc(), diag::warn_attribute_sentinel_not_variadic) << 0; return; } } else if (isa(d)) { @@ -730,7 +730,8 @@ static void HandleSentinelAttr(Decl *d, const AttributeList &Attr, Sema &S) { const FunctionType *FT = Ty->isFunctionPointerType() ? getFunctionType(d) : Ty->getAsBlockPointerType()->getPointeeType()->getAsFunctionType(); if (!cast(FT)->isVariadic()) { - S.Diag(Attr.getLoc(), diag::warn_attribute_sentinel_not_variadic); + int m = Ty->isFunctionPointerType() ? 0 : 1; + S.Diag(Attr.getLoc(), diag::warn_attribute_sentinel_not_variadic) << m; return; } } diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 8aaa8b1399..0d72a7534e 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -5068,7 +5068,7 @@ void Sema::ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope) { // Check for a valid sentinel attribute on this block. if (CurBlock->TheDecl->getAttr()) { Diag(ParamInfo.getAttributes()->getLoc(), - diag::warn_attribute_sentinel_not_variadic); + diag::warn_attribute_sentinel_not_variadic) << 1; // FIXME: remove the attribute. } QualType RetTy = T.getTypePtr()->getAsFunctionType()->getResultType(); @@ -5115,7 +5115,7 @@ void Sema::ActOnBlockArguments(Declarator &ParamInfo, Scope *CurScope) { // Check for a valid sentinel attribute on this block. if (!CurBlock->isVariadic && CurBlock->TheDecl->getAttr()) { Diag(ParamInfo.getAttributes()->getLoc(), - diag::warn_attribute_sentinel_not_variadic); + diag::warn_attribute_sentinel_not_variadic) << 1; // FIXME: remove the attribute. } diff --git a/test/Sema/block-sentinel-attribute.c b/test/Sema/block-sentinel-attribute.c index c78f526cdf..a7d4df108e 100644 --- a/test/Sema/block-sentinel-attribute.c +++ b/test/Sema/block-sentinel-attribute.c @@ -4,6 +4,7 @@ void (^e) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (1,1) int main() { + void (^bbad) (int arg, const char * format) __attribute__ ((__sentinel__)) ; // expected-warning {{sentinel' attribute only supported for variadic blocks}} void (^b) (int arg, const char * format, ...) __attribute__ ((__sentinel__)) = // expected-note {{block has been explicitly marked sentinel here}} ^ __attribute__ ((__sentinel__)) (int arg, const char * format, ...) {}; void (^z) (int arg, const char * format, ...) __attribute__ ((__sentinel__ (2))) = ^ __attribute__ ((__sentinel__ (2))) (int arg, const char * format, ...) {}; // expected-note {{block has been explicitly marked sentinel here}} -- 2.40.0