[PATCH] D152180: [Sema] Do not emit -Wunused-variable for variables declared with cleanup attribute

Nathan Chancellor via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 5 10:52:28 PDT 2023


nathanchance updated this revision to Diff 528510.
nathanchance added a comment.

Change `f4()`'s return type to `void` (Nick)


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152180/new/

https://reviews.llvm.org/D152180

Files:
  clang/lib/Sema/SemaDecl.cpp
  clang/test/Sema/warn-unused-variables.c


Index: clang/test/Sema/warn-unused-variables.c
===================================================================
--- clang/test/Sema/warn-unused-variables.c
+++ clang/test/Sema/warn-unused-variables.c
@@ -30,3 +30,8 @@
   (void)(^() { int X = 4; }); // expected-warning{{unused}}
   (void)(^() { int X = 4; return Y + X; }); // expected-error {{use of undeclared identifier 'Y'}}
 }
+
+void c1(int *);
+void f4(void) {
+  int __attribute__((cleanup(c1))) X1 = 4;
+}
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -1992,7 +1992,8 @@
     return false;
   }
 
-  if (D->hasAttr<UnusedAttr>() || D->hasAttr<ObjCPreciseLifetimeAttr>())
+  if (D->hasAttr<UnusedAttr>() || D->hasAttr<ObjCPreciseLifetimeAttr>() ||
+      D->hasAttr<CleanupAttr>())
     return false;
 
   if (isa<LabelDecl>(D))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152180.528510.patch
Type: text/x-patch
Size: 914 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230605/8a0b67a8/attachment.bin>


More information about the cfe-commits mailing list