[libc-commits] [libc] [libc] add support for function level attributes (PR #79891)

Schrodinger ZHU Yifan via libc-commits libc-commits at lists.llvm.org
Mon Feb 12 09:47:30 PST 2024


================
@@ -170,10 +170,33 @@ class ArgSpec<Type type, list<Annotation> annotations = [], string name = ""> {
   string Name = name;
 }
 
-class FunctionSpec<string name, RetValSpec return, list<ArgSpec> args> {
+// The following classes are used to describe function attributes.
+// In the future, we may consider supporting parameter attributes as well.
+// https://clang.llvm.org/docs/AttributeReference.html
+class FunctionAttr<string style, string attr> {
+  string Attr = attr;
+  // The style of the attribute, e.g. "gnu", "cxx11", "declspec".
+  // - "gnu" is for GNU-style attributes: __attribute__((...))
+  // - "cxx11" is for C++11-style attributes: [[...]]
+  // - "declspec" is for Microsoft-style attributes: __declspec(...)
+  string Style = style;
+}
+class GnuFunctionAttr<string attr> : FunctionAttr<"gnu", attr> {}
+class Cxx11FunctionAttr<string attr, string namespace> : FunctionAttr<"cxx11", attr> {
+  // The namespace of the attribute, e.g. "gnu" or "clang".
+  string Namespace = namespace;
----------------
SchrodingerZhu wrote:

Actually, it is already optional (empty string is handled). I will add a note in comments.

https://github.com/llvm/llvm-project/pull/79891


More information about the libc-commits mailing list