[clang] [clang] Document the type_visibility attribute (PR #79157)

Louis Dionne via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 8 08:30:33 PST 2024


https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/79157

>From c525b81664d23e3bc75fb6b795459bcbb7e305a4 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Tue, 23 Jan 2024 10:51:53 -0500
Subject: [PATCH 1/2] [clang] Document the type_visibility attribute

I was looking for the documentation of that attribute, and the best
I could find was a Stackoverflow answer or the commit message that
originally introduced the attribute. I figured I might as well document
what I find to save everyone time in the future.
---
 clang/include/clang/Basic/Attr.td     |  4 ++--
 clang/include/clang/Basic/AttrDocs.td | 15 +++++++++++++++
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td
index 58838b01b4fd7..e47107d8edcb3 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3220,8 +3220,8 @@ def TypeVisibility : InheritableAttr {
   let Args = [EnumArgument<"Visibility", "VisibilityType",
                            ["default", "hidden", "internal", "protected"],
                            ["Default", "Hidden", "Hidden", "Protected"]>];
-//  let Subjects = [Tag, ObjCInterface, Namespace];
-  let Documentation = [Undocumented];
+  let Subjects = SubjectList<[Tag, ObjCInterface, Namespace], ErrorDiag>;
+  let Documentation = [TypeVisibilityDocs];
 }
 
 def VecReturn : InheritableAttr {
diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td
index 7e633f8e2635a..703f7cd314b72 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -5557,6 +5557,21 @@ See :doc:`LTOVisibility`.
   }];
 }
 
+def TypeVisibilityDocs : Documentation {
+  let Category = DocCatType;
+  let Content = [{
+The ``type_visibility`` attribute allows the ELF visibility of a type and its vague
+linkage objects (vtable, typeinfo, typeinfo name) to be controlled separately from
+the visibility of functions and data members of the type.
+
+For example, this can be used to give default visibility to the typeinfo and the vtable
+of a type while still keeping hidden visibility on its member functions and static data
+members.
+
+This attribute can only be applied to types and namespaces.
+  }]
+}
+
 def RenderScriptKernelAttributeDocs : Documentation {
   let Category = DocCatFunction;
   let Content = [{

>From 57dbc34b62ed01bf9034afcafebeb958778fb75f Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Thu, 8 Feb 2024 11:30:05 -0500
Subject: [PATCH 2/2] Address comments

---
 clang/include/clang/Basic/Attr.td     | 2 +-
 clang/include/clang/Basic/AttrDocs.td | 6 +++++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td
index e47107d8edcb3..3ff1155cf019d 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -3220,7 +3220,7 @@ def TypeVisibility : InheritableAttr {
   let Args = [EnumArgument<"Visibility", "VisibilityType",
                            ["default", "hidden", "internal", "protected"],
                            ["Default", "Hidden", "Hidden", "Protected"]>];
-  let Subjects = SubjectList<[Tag, ObjCInterface, Namespace], ErrorDiag>;
+  // let Subjects = SubjectList<[Tag, ObjCInterface, Namespace], ErrorDiag>;
   let Documentation = [TypeVisibilityDocs];
 }
 
diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td
index 703f7cd314b72..3657e1ea58543 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -5560,7 +5560,7 @@ See :doc:`LTOVisibility`.
 def TypeVisibilityDocs : Documentation {
   let Category = DocCatType;
   let Content = [{
-The ``type_visibility`` attribute allows the ELF visibility of a type and its vague
+The ``type_visibility`` attribute allows the visibility of a type and its vague
 linkage objects (vtable, typeinfo, typeinfo name) to be controlled separately from
 the visibility of functions and data members of the type.
 
@@ -5569,6 +5569,10 @@ of a type while still keeping hidden visibility on its member functions and stat
 members.
 
 This attribute can only be applied to types and namespaces.
+
+If both ``visibility`` and ``type_visibility`` are applied to a type or a namespace, the
+visibility specified with the ``type_visibility`` attribute overrides the visibility
+provided with the regular ``visibility`` attribute.
   }]
 }
 



More information about the cfe-commits mailing list