aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/clang/Basic/DiagnosticSemaKinds.td2
-rw-r--r--lib/Sema/SemaDeclAttr.cpp7
-rw-r--r--lib/Sema/SemaExpr.cpp4
-rw-r--r--test/Sema/block-sentinel-attribute.c1
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<FunctionProtoType>(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<ObjCMethodDecl>(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<BlockDecl>(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<FunctionProtoType>(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<SentinelAttr>()) {
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<SentinelAttr>()) {
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}}