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; }
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; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits