[PATCH] D15406: Add warning for attribute-cleanup on function parameter.

Nicholas Allegra via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 9 22:33:55 PST 2015


comex created this revision.
comex added a subscriber: cfe-commits.

When a function parameter is declared `__attribute__((cleanup))`, neither Clang nor GCC actually executes the cleanup function, but Clang didn't warn about it.  For the sake of compatibility, add a warning rather than making the attribute actually work.

http://reviews.llvm.org/D15406

Files:
  lib/Sema/SemaDeclAttr.cpp
  test/Sema/attr-cleanup.c

Index: test/Sema/attr-cleanup.c
===================================================================
--- test/Sema/attr-cleanup.c
+++ test/Sema/attr-cleanup.c
@@ -46,3 +46,5 @@
 void t6(void) {
   int i __attribute__((cleanup((void *)0)));  // expected-error {{'cleanup' argument is not a function}}
 }
+
+void t7(__attribute__((cleanup(c4))) int a) {} // expected-warning {{'cleanup' attribute ignored}}
Index: lib/Sema/SemaDeclAttr.cpp
===================================================================
--- lib/Sema/SemaDeclAttr.cpp
+++ lib/Sema/SemaDeclAttr.cpp
@@ -2595,7 +2595,7 @@
 
 static void handleCleanupAttr(Sema &S, Decl *D, const AttributeList &Attr) {
   VarDecl *VD = cast<VarDecl>(D);
-  if (!VD->hasLocalStorage()) {
+  if (!VD->hasLocalStorage() || isa<ParmVarDecl>(VD)) {
     S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
     return;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D15406.42389.patch
Type: text/x-patch
Size: 886 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20151210/74be9232/attachment.bin>


More information about the cfe-commits mailing list