]> granicus.if.org Git - clang/commitdiff
don't crash when sentinel attribute is used on function without a prototype,
authorChris Lattner <sabre@nondot.org>
Tue, 17 Mar 2009 23:03:47 +0000 (23:03 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 17 Mar 2009 23:03:47 +0000 (23:03 +0000)
discovered as part of PR3817

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67127 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.def
include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDeclAttr.cpp
test/Sema/sentinel-attribute.c

index d415ee53926af373d8d50c96fcc7fa296aa00617..0cacb77cc9a32b24b372d39adb8fe6e684576a3c 100644 (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,
index a2ba0e97080dfe241b36c8837ae78848f0f4a32d..8b6ef49542d10ad6560771b1e9eab28639e161cb 100644 (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<
index 57cd3d2bcb235f1fe1061073d6ca628569a3861b..96812018a1931fccd55db82f5cb68ee53cd69064 100644 (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;
     }    
index a83cda771d2d1a257305977b106cfa48ca5ce339..37d0adc5966e7f6453fe9967c5c72f85c9123b6b 100644 (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}}