[libc-commits] [libc] [libc] Fix typo and amend restrict qualifier (PR #152410)

Caslyn Tonelli via libc-commits libc-commits at lists.llvm.org
Thu Aug 7 16:12:27 PDT 2025


https://github.com/Caslyn updated https://github.com/llvm/llvm-project/pull/152410

>From f3ca4fa844cc8791dc30c3edc298d3388aceba53 Mon Sep 17 00:00:00 2001
From: Caslyn Tonelli <caslyn at google.com>
Date: Wed, 6 Aug 2025 16:39:55 -0700
Subject: [PATCH 1/2] [lib] Fix typo and amend restrict qualifier

This removes an extraneous ',' in the generated dlfcn header.

This also adds `__restrict` to `dladdr`'s declaration per POSIX. The
`restrict` C standard keyword is removed from dlinfo.cpp/dlinfo.h
(but note that the dlinfo's declaration in dlfcn.h still annoates
__restrict in the decl).
---
 libc/include/dlfcn.yaml   | 6 +++---
 libc/src/dlfcn/dlinfo.cpp | 3 +--
 libc/src/dlfcn/dlinfo.h   | 2 +-
 3 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/libc/include/dlfcn.yaml b/libc/include/dlfcn.yaml
index db2893aaff5d9..bf17a11111050 100644
--- a/libc/include/dlfcn.yaml
+++ b/libc/include/dlfcn.yaml
@@ -46,7 +46,7 @@ enums:
     standards:
       - gnu
     value: 2
-  - name: RTLD_DI_CONFIGADDR,
+  - name: RTLD_DI_CONFIGADDR
     standards:
       - gnu
     value: 3
@@ -127,5 +127,5 @@ functions:
       - POSIX
     return_type: int
     arguments:
-      - type: const void *
-      - type: Dl_info *
+      - type: const void *__restrict
+      - type: Dl_info *__restrict
diff --git a/libc/src/dlfcn/dlinfo.cpp b/libc/src/dlfcn/dlinfo.cpp
index d78cade5ea593..ec2b0fe1464bc 100644
--- a/libc/src/dlfcn/dlinfo.cpp
+++ b/libc/src/dlfcn/dlinfo.cpp
@@ -15,8 +15,7 @@
 namespace LIBC_NAMESPACE_DECL {
 
 // TODO: https://github.com/llvm/llvm-project/issues/149911
-LLVM_LIBC_FUNCTION(int, dlinfo,
-                   (void *restrict handle, int request, void *restrict info)) {
+LLVM_LIBC_FUNCTION(int, dlinfo, (void *handle, int request, void *info)) {
   return -1;
 }
 
diff --git a/libc/src/dlfcn/dlinfo.h b/libc/src/dlfcn/dlinfo.h
index c2c34f02bd6f1..98f627636a34c 100644
--- a/libc/src/dlfcn/dlinfo.h
+++ b/libc/src/dlfcn/dlinfo.h
@@ -13,7 +13,7 @@
 
 namespace LIBC_NAMESPACE_DECL {
 
-int dlinfo(void *restrict, int, void *restrict);
+int dlinfo(void *, int, void *);
 
 } // namespace LIBC_NAMESPACE_DECL
 

>From d01192e2f3dfde082605633252ee3a3b0c749332 Mon Sep 17 00:00:00 2001
From: Caslyn Tonelli <caslyn at google.com>
Date: Thu, 7 Aug 2025 16:11:53 -0700
Subject: [PATCH 2/2] add __restrict qualifiers to source

---
 libc/src/dlfcn/dladdr.cpp | 3 ++-
 libc/src/dlfcn/dladdr.h   | 2 +-
 libc/src/dlfcn/dlinfo.cpp | 4 +++-
 libc/src/dlfcn/dlinfo.h   | 2 +-
 libc/src/dlfcn/dlsym.cpp  | 4 +++-
 libc/src/dlfcn/dlsym.h    | 2 +-
 6 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/libc/src/dlfcn/dladdr.cpp b/libc/src/dlfcn/dladdr.cpp
index 61490fd9a64b5..3db68b4a4c729 100644
--- a/libc/src/dlfcn/dladdr.cpp
+++ b/libc/src/dlfcn/dladdr.cpp
@@ -14,7 +14,8 @@
 namespace LIBC_NAMESPACE_DECL {
 
 // TODO: https:// github.com/llvm/llvm-project/issues/97929
-LLVM_LIBC_FUNCTION(int, dladdr, (const void *addr, Dl_info *info)) {
+LLVM_LIBC_FUNCTION(int, dladdr,
+                   (const void *__restrict addr, Dl_info *__restrict info)) {
   return -1;
 }
 
diff --git a/libc/src/dlfcn/dladdr.h b/libc/src/dlfcn/dladdr.h
index 346fc8dc27aed..abbc9a9008d92 100644
--- a/libc/src/dlfcn/dladdr.h
+++ b/libc/src/dlfcn/dladdr.h
@@ -13,7 +13,7 @@
 
 namespace LIBC_NAMESPACE_DECL {
 
-int dladdr(const void *, Dl_info *);
+int dladdr(const void *__restrict, Dl_info *__restrict);
 
 } // namespace LIBC_NAMESPACE_DECL
 
diff --git a/libc/src/dlfcn/dlinfo.cpp b/libc/src/dlfcn/dlinfo.cpp
index ec2b0fe1464bc..e1938d19c9657 100644
--- a/libc/src/dlfcn/dlinfo.cpp
+++ b/libc/src/dlfcn/dlinfo.cpp
@@ -15,7 +15,9 @@
 namespace LIBC_NAMESPACE_DECL {
 
 // TODO: https://github.com/llvm/llvm-project/issues/149911
-LLVM_LIBC_FUNCTION(int, dlinfo, (void *handle, int request, void *info)) {
+LLVM_LIBC_FUNCTION(int, dlinfo,
+                   (void *__restrict handle, int request,
+                    void *__restrict info)) {
   return -1;
 }
 
diff --git a/libc/src/dlfcn/dlinfo.h b/libc/src/dlfcn/dlinfo.h
index 98f627636a34c..bc13152e40f44 100644
--- a/libc/src/dlfcn/dlinfo.h
+++ b/libc/src/dlfcn/dlinfo.h
@@ -13,7 +13,7 @@
 
 namespace LIBC_NAMESPACE_DECL {
 
-int dlinfo(void *, int, void *);
+int dlinfo(void *__restrict, int, void *__restrict);
 
 } // namespace LIBC_NAMESPACE_DECL
 
diff --git a/libc/src/dlfcn/dlsym.cpp b/libc/src/dlfcn/dlsym.cpp
index c075c203bd583..dc0da7d6d120f 100644
--- a/libc/src/dlfcn/dlsym.cpp
+++ b/libc/src/dlfcn/dlsym.cpp
@@ -14,6 +14,8 @@
 namespace LIBC_NAMESPACE_DECL {
 
 // TODO(@izaakschroeder): https://github.com/llvm/llvm-project/issues/97920
-LLVM_LIBC_FUNCTION(void *, dlsym, (void *, const char *)) { return nullptr; }
+LLVM_LIBC_FUNCTION(void *, dlsym, (void *__restrict, const char *__restrict)) {
+  return nullptr;
+}
 
 } // namespace LIBC_NAMESPACE_DECL
diff --git a/libc/src/dlfcn/dlsym.h b/libc/src/dlfcn/dlsym.h
index 70c6ab3fbb143..f879792d3c5f6 100644
--- a/libc/src/dlfcn/dlsym.h
+++ b/libc/src/dlfcn/dlsym.h
@@ -13,7 +13,7 @@
 
 namespace LIBC_NAMESPACE_DECL {
 
-void *dlsym(void *, const char *);
+void *dlsym(void *__restrict, const char *__restrict);
 
 } // namespace LIBC_NAMESPACE_DECL
 



More information about the libc-commits mailing list