[libc-commits] [libc] [libc] Move EOF macro to stdio-macros.h (PR #85159)

Petr Hosek via libc-commits libc-commits at lists.llvm.org
Wed Mar 13 23:31:16 PDT 2024


https://github.com/petrhosek updated https://github.com/llvm/llvm-project/pull/85159

>From 5ab1ef66ecb97453b2767d09a65ebf6bacf0ad55 Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Wed, 13 Mar 2024 00:28:47 -0700
Subject: [PATCH 1/5] [libc] Include EOF macro in stdio.h on baremetal

libc++ char_traits.h assumes EOF is always available

See #85158 for more details.
---
 libc/config/baremetal/api.td | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/libc/config/baremetal/api.td b/libc/config/baremetal/api.td
index 80d0e0ba22ca51..e33c1ff5521902 100644
--- a/libc/config/baremetal/api.td
+++ b/libc/config/baremetal/api.td
@@ -52,6 +52,15 @@ def IntTypesAPI : PublicAPI<"inttypes.h"> {
   let Types = ["imaxdiv_t"];
 }
 
+def StdIOAPI : PublicAPI<"stdio.h"> {
+  let Macros = [
+    SimpleMacroDef<"EOF", "-1">,
+  ];
+  let Types = [
+    "size_t"
+  ];
+}
+
 def StdlibAPI : PublicAPI<"stdlib.h"> {
   let Types = [
     "div_t",

>From 6e546690a04a9fdec198a56dba2216003319f1d6 Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Wed, 13 Mar 2024 23:19:53 -0700
Subject: [PATCH 2/5] Move the definition to
 libc/include/llvm-libc-macros/stdio-macros.h

---
 libc/config/baremetal/api.td                 | 7 +------
 libc/include/llvm-libc-macros/stdio-macros.h | 4 ++++
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/libc/config/baremetal/api.td b/libc/config/baremetal/api.td
index e33c1ff5521902..9548cc47203d7d 100644
--- a/libc/config/baremetal/api.td
+++ b/libc/config/baremetal/api.td
@@ -53,12 +53,7 @@ def IntTypesAPI : PublicAPI<"inttypes.h"> {
 }
 
 def StdIOAPI : PublicAPI<"stdio.h"> {
-  let Macros = [
-    SimpleMacroDef<"EOF", "-1">,
-  ];
-  let Types = [
-    "size_t"
-  ];
+  let Types = ["size_t"];
 }
 
 def StdlibAPI : PublicAPI<"stdlib.h"> {
diff --git a/libc/include/llvm-libc-macros/stdio-macros.h b/libc/include/llvm-libc-macros/stdio-macros.h
index db747c5d5d6755..8c1b0b6b7a0b38 100644
--- a/libc/include/llvm-libc-macros/stdio-macros.h
+++ b/libc/include/llvm-libc-macros/stdio-macros.h
@@ -9,6 +9,10 @@
 #ifndef LLVM_LIBC_MACROS_STDIO_MACROS_H
 #define LLVM_LIBC_MACROS_STDIO_MACROS_H
 
+#ifndef EOF
+#define EOF -1
+#endif
+
 #define BUFSIZ 1024
 
 #endif // LLVM_LIBC_MACROS_STDIO_MACROS_H

>From 8ebc1416f1da487f536fd8366bac68dfc2e35218 Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Wed, 13 Mar 2024 23:23:06 -0700
Subject: [PATCH 3/5] Wrap the value in parens

---
 libc/include/llvm-libc-macros/stdio-macros.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/include/llvm-libc-macros/stdio-macros.h b/libc/include/llvm-libc-macros/stdio-macros.h
index 8c1b0b6b7a0b38..4664801c5731f0 100644
--- a/libc/include/llvm-libc-macros/stdio-macros.h
+++ b/libc/include/llvm-libc-macros/stdio-macros.h
@@ -10,7 +10,7 @@
 #define LLVM_LIBC_MACROS_STDIO_MACROS_H
 
 #ifndef EOF
-#define EOF -1
+#define EOF (-1)
 #endif
 
 #define BUFSIZ 1024

>From 5f3e0ab2521d11015a44b35c4bde3395d889ba3a Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Wed, 13 Mar 2024 23:29:51 -0700
Subject: [PATCH 4/5] Remove definition from linux/api.td

---
 libc/config/linux/api.td | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libc/config/linux/api.td b/libc/config/linux/api.td
index 75432a2a298652..04d720daf9509c 100644
--- a/libc/config/linux/api.td
+++ b/libc/config/linux/api.td
@@ -76,7 +76,6 @@ def StdIOAPI : PublicAPI<"stdio.h"> {
     SimpleMacroDef<"_IOFBF", "0">,
     SimpleMacroDef<"_IOLBF", "1">,
     SimpleMacroDef<"_IONBF", "2">,
-    SimpleMacroDef<"EOF", "-1">,
   ];
   let Types = ["size_t", "FILE", "cookie_io_functions_t"];
 }

>From 0b3de46f4b9b4f3b977a652f645cc5834f87f3a6 Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Wed, 13 Mar 2024 23:30:52 -0700
Subject: [PATCH 5/5] Remove definition from gpu/api.td

---
 libc/config/gpu/api.td | 1 -
 1 file changed, 1 deletion(-)

diff --git a/libc/config/gpu/api.td b/libc/config/gpu/api.td
index 607b8b6d5900c8..adaf5bfd747ac7 100644
--- a/libc/config/gpu/api.td
+++ b/libc/config/gpu/api.td
@@ -63,7 +63,6 @@ def StdIOAPI : PublicAPI<"stdio.h"> {
     SimpleMacroDef<"_IOFBF", "0">,
     SimpleMacroDef<"_IOLBF", "1">,
     SimpleMacroDef<"_IONBF", "2">,
-    SimpleMacroDef<"EOF", "-1">,
   ];
   let Types = ["size_t", "FILE"];
 }



More information about the libc-commits mailing list