[PATCH] D151732: [clang][docs] document __attribute__((cleanup())) GNU C extension

Nick Desaulniers via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 1 11:21:04 PDT 2023


nickdesaulniers updated this revision to Diff 527528.
nickdesaulniers added a comment.

- add note about function signature


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D151732

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td


Index: clang/include/clang/Basic/AttrDocs.td
===================================================================
--- clang/include/clang/Basic/AttrDocs.td
+++ clang/include/clang/Basic/AttrDocs.td
@@ -6988,3 +6988,28 @@
 its underlying representation to be a WebAssembly ``funcref``.
   }];
 }
+
+def CleanupDocs : Documentation {
+  let Category = DocCatType;
+  let Content = [{
+This attribute allows a function to be run when a local variable goes out of
+scope. The attribute takes the identifier of a function with a parameter type
+that is a pointer to the type with the attribute.
+
+.. code-block:: c
+
+  static void foo (int *) { ... }
+  static void bar (int *) { ... }
+  void baz (void) {
+    int x __attribute__((cleanup(foo)));
+    {
+      int y __attribute__((cleanup(bar)));
+    }
+  }
+
+The above example will result in a call to ``bar`` being passed the address of
+`y``, then a call to ``foo`` being passed the address of ``x`` (as ``y`` goes
+out of scope before ``x``). It is not possible to check the return value (if
+any) of these ``cleanup`` callback functions.
+}];
+}
Index: clang/include/clang/Basic/Attr.td
===================================================================
--- clang/include/clang/Basic/Attr.td
+++ clang/include/clang/Basic/Attr.td
@@ -1084,7 +1084,7 @@
   let Spellings = [GCC<"cleanup">];
   let Args = [DeclArgument<Function, "FunctionDecl">];
   let Subjects = SubjectList<[LocalVar]>;
-  let Documentation = [Undocumented];
+  let Documentation = [CleanupDocs];
 }
 
 def CmseNSEntry : InheritableAttr, TargetSpecificAttr<TargetARM> {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151732.527528.patch
Type: text/x-patch
Size: 1595 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230601/d8b57fa6/attachment.bin>


More information about the cfe-commits mailing list