[cfe-commits] r64047 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.def lib/Sema/SemaDeclAttr.cpp test/Sema/attr-cleanup.c

Anders Carlsson andersca at mac.com
Sat Feb 7 15:16:50 PST 2009


Author: andersca
Date: Sat Feb  7 17:16:50 2009
New Revision: 64047

URL: http://llvm.org/viewvc/llvm-project?rev=64047&view=rev
Log:
Improve Sema of the cleanup attribute somewhat.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def
    cfe/trunk/lib/Sema/SemaDeclAttr.cpp
    cfe/trunk/test/Sema/attr-cleanup.c

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

==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.def Sat Feb  7 17:16:50 2009
@@ -385,8 +385,10 @@
      "'cleanup' argument %0 not found")
 DIAG(err_attribute_cleanup_arg_not_function, ERROR,
      "'cleanup' argument %0 is not a function")
-DIAG(err_attribute_cleanup_arg_must_take_one_arg, ERROR,
+DIAG(err_attribute_cleanup_func_must_take_one_arg, ERROR,
     "'cleanup' function %0 must take 1 parameter")
+DIAG(err_attribute_cleanup_func_arg_incompatible_type, ERROR,
+    "'cleanup' function %0 parameter has type %1, expected type %2")
     
 // Clang-Specific Attributes
 DIAG(err_attribute_iboutlet_non_ivar, ERROR,

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

==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Sat Feb  7 17:16:50 2009
@@ -847,6 +847,10 @@
 }
 
 static void HandleCleanupAttr(Decl *d, const AttributeList &Attr, Sema &S) {
+  // Match gcc which ignores cleanup attrs when compiling C++.
+  if (S.getLangOptions().CPlusPlus)
+    return;
+  
   if (!Attr.getParameterName()) {    
     S.Diag(Attr.getLoc(), diag::err_attribute_wrong_number_arguments) << 1;
     return;
@@ -868,26 +872,35 @@
   NamedDecl *CleanupDecl = S.LookupName(S.TUScope, Attr.getParameterName(),
                                         Sema::LookupOrdinaryName);
   if (!CleanupDecl) {
-    S.Diag(Attr.getLoc(), diag::err_attribute_cleanup_arg_not_found) << 
+    S.Diag(Attr.getLoc(), diag::err_attribute_cleanup_arg_not_found) <<
       Attr.getParameterName();
     return;
   }
   
   FunctionDecl *FD = dyn_cast<FunctionDecl>(CleanupDecl);
   if (!FD) {
-    S.Diag(Attr.getLoc(), diag::err_attribute_cleanup_arg_not_function) << 
+    S.Diag(Attr.getLoc(), diag::err_attribute_cleanup_arg_not_function) <<
       Attr.getParameterName();
     return;
   }
 
-  // FIXME: This needs to work with C++ overloading.
-  // FIXME: This should verify that the function type is compatible
   if (FD->getNumParams() != 1) {
-    S.Diag(Attr.getLoc(), diag::err_attribute_cleanup_arg_must_take_one_arg)<<
+    S.Diag(Attr.getLoc(), diag::err_attribute_cleanup_func_must_take_one_arg) <<
       Attr.getParameterName();
     return;
   }
   
+  // We're currently more strict than GCC about what function types we accept.
+  // If this ever proves to be a problem it should be easy to fix.
+  QualType Ty = S.Context.getPointerType(VD->getType());
+  QualType ParamTy = FD->getParamDecl(0)->getType();
+  if (Ty != ParamTy) {
+    S.Diag(Attr.getLoc(), 
+           diag::err_attribute_cleanup_func_arg_incompatible_type) <<
+      Attr.getParameterName() << ParamTy << Ty;
+    return;
+  }
+  
   d->addAttr(new CleanupAttr(FD));
 }
 

Modified: cfe/trunk/test/Sema/attr-cleanup.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-cleanup.c?rev=64047&r1=64046&r2=64047&view=diff

==============================================================================
--- cfe/trunk/test/Sema/attr-cleanup.c (original)
+++ cfe/trunk/test/Sema/attr-cleanup.c Sat Feb  7 17:16:50 2009
@@ -24,8 +24,10 @@
 };
 
 void c2();
+void c3(struct s a);
 
 void t2()
 {
     int v1 __attribute__((cleanup(c2))); // expected-error {{'cleanup' function 'c2' must take 1 parameter}}
-}
\ No newline at end of file
+    int v2 __attribute__((cleanup(c3))); // expected-error {{'cleanup' function 'c3' parameter has type 'struct s', expected type 'int *'}}
+}





More information about the cfe-commits mailing list