[libc-commits] [libc] e6e7da3 - [libc][hdrgen] Improve support for function-types as function args. (#227088)

via libc-commits libc-commits at lists.llvm.org
Tue Sep 29 11:48:47 PDT 2026


Author: Alexey Samsonov
Date: 2026-09-29T11:48:39-07:00
New Revision: e6e7da35405a3f6d91bc6a91d8bb2bd533a94276

URL: https://github.com/llvm/llvm-project/commit/e6e7da35405a3f6d91bc6a91d8bb2bd533a94276
DIFF: https://github.com/llvm/llvm-project/commit/e6e7da35405a3f6d91bc6a91d8bb2bd533a94276.diff

LOG: [libc][hdrgen] Improve support for function-types as function args. (#227088)

Previously entries like
```
type: int (*)(const struct type_b **, const struct type_c **)
```
ended up assuming the type should be `struct_type_b_struct_type_c`.

Fix this by splitting the type strings into components, where each
component can be a type name itself (which is the case for a complex
function types like in the example above. This was raised during the
discussion in https://github.com/llvm/llvm-project/pull/223198

Added: 
    

Modified: 
    libc/utils/hdrgen/hdrgen/function.py
    libc/utils/hdrgen/tests/expected_output/subdir/test.h
    libc/utils/hdrgen/tests/input/subdir/test.yaml

Removed: 
    


################################################################################
diff  --git a/libc/utils/hdrgen/hdrgen/function.py b/libc/utils/hdrgen/hdrgen/function.py
index 4de3406cc408e..8d92bd805abb2 100644
--- a/libc/utils/hdrgen/hdrgen/function.py
+++ b/libc/utils/hdrgen/hdrgen/function.py
@@ -35,6 +35,7 @@
     "volatile",
 ]
 NONIDENTIFIER = re.compile("[^a-zA-Z0-9_]+")
+TYPE_SEPARATOR = re.compile("[(),]+")
 
 
 class Function(Symbol):
@@ -63,7 +64,12 @@ def collapse(type_string):
                 if word and not word.isdecimal() and word not in KEYWORDS
             )
 
-        all_types = [self.return_type] + self.arguments
+        all_types = [
+            sub_type
+            for t in [self.return_type] + self.arguments
+            for sub_type in TYPE_SEPARATOR.split(t)
+            if sub_type
+        ]
         return {
             Type(string) for string in filter(None, (collapse(t) for t in all_types))
         }

diff  --git a/libc/utils/hdrgen/tests/expected_output/subdir/test.h b/libc/utils/hdrgen/tests/expected_output/subdir/test.h
index 40936bcfcba6d..e35e53a20bb8e 100644
--- a/libc/utils/hdrgen/tests/expected_output/subdir/test.h
+++ b/libc/utils/hdrgen/tests/expected_output/subdir/test.h
@@ -10,6 +10,8 @@
 #define _LLVM_LIBC_SUBDIR_TEST_H
 
 #include "../__llvm-libc-common.h"
+#include "../llvm-libc-types/struct_type_b.h"
+#include "../llvm-libc-types/struct_type_c.h"
 #include "../llvm-libc-types/type_a.h"
 #include "../llvm-libc-types/type_b.h"
 
@@ -19,7 +21,7 @@ type_a func(type_b) __NOEXCEPT;
 
 void gnufunc(type_a) __NOEXCEPT;
 
-int *ptrfunc(void) __NOEXCEPT;
+int *ptrfunc(int (*)(struct type_b **, struct type_c **)) __NOEXCEPT;
 
 __END_C_DECLS
 

diff  --git a/libc/utils/hdrgen/tests/input/subdir/test.yaml b/libc/utils/hdrgen/tests/input/subdir/test.yaml
index 5bc8b29e334f8..a310c811ab129 100644
--- a/libc/utils/hdrgen/tests/input/subdir/test.yaml
+++ b/libc/utils/hdrgen/tests/input/subdir/test.yaml
@@ -14,4 +14,5 @@ functions:
       - gnu
   - name: ptrfunc
     return_type: int *
-    arguments: []
+    arguments:
+      - type: int (*)(struct type_b **, struct type_c **)


        


More information about the libc-commits mailing list