[cfe-commits] r67127 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.def include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclAttr.cpp test/Sema/sentinel-attribute.c

Chris Lattner sabre at nondot.org
Tue Mar 17 16:03:48 PDT 2009


Author: lattner
Date: Tue Mar 17 18:03:47 2009
New Revision: 67127

URL: http://llvm.org/viewvc/llvm-project?rev=67127&view=rev
Log:
don't crash when sentinel attribute is used on function without a prototype,
discovered as part of PR3817

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

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def?rev=67127&r1=67126&r2=67127&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def Tue Mar 17 18:03:47 2009
@@ -429,6 +429,9 @@
 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,

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=67127&r1=67126&r2=67127&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Mar 17 18:03:47 2009
@@ -393,6 +393,8 @@
   "'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<

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=67127&r1=67126&r2=67127&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Tue Mar 17 18:03:47 2009
@@ -687,8 +687,15 @@
   }
 
   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;
     }    

Modified: cfe/trunk/test/Sema/sentinel-attribute.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/sentinel-attribute.c?rev=67127&r1=67126&r2=67127&view=diff

==============================================================================
--- cfe/trunk/test/Sema/sentinel-attribute.c (original)
+++ cfe/trunk/test/Sema/sentinel-attribute.c Tue Mar 17 18:03:47 2009
@@ -11,3 +11,5 @@
 
 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}}





More information about the cfe-commits mailing list