[libc-commits] [libc] 15ae08c - [libc] Add definitions of a few missing macros and types.

Siva Chandra Reddy via libc-commits libc-commits at lists.llvm.org
Wed Nov 2 00:20:07 PDT 2022


Author: Siva Chandra Reddy
Date: 2022-11-02T07:17:33Z
New Revision: 15ae08c1a17dbc4a8f8c06aa238a474ef7a7f4dc

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

LOG: [libc] Add definitions of a few missing macros and types.

Added: 
    libc/include/llvm-libc-macros/stdio-macros.h
    libc/include/llvm-libc-types/sig_atomic_t.h

Modified: 
    libc/config/linux/api.td
    libc/include/CMakeLists.txt
    libc/include/llvm-libc-macros/CMakeLists.txt
    libc/include/llvm-libc-macros/linux/sys-wait-macros.h
    libc/include/llvm-libc-macros/stdlib-macros.h
    libc/include/llvm-libc-types/CMakeLists.txt
    libc/include/stdio.h.def
    libc/spec/stdc.td

Removed: 
    


################################################################################
diff  --git a/libc/config/linux/api.td b/libc/config/linux/api.td
index a22b3772b303e..a84ab387bb8fe 100644
--- a/libc/config/linux/api.td
+++ b/libc/config/linux/api.td
@@ -106,6 +106,7 @@ def MathAPI : PublicAPI<"math.h"> {
     SimpleMacroDef<"MATH_ERREXCEPT", "2">,
     MathErrHandlingMacro,
 
+    SimpleMacroDef<"HUGE_VAL", "__builtin_huge_val()">,
     SimpleMacroDef<"INFINITY", "__builtin_inff()">,
     SimpleMacroDef<"NAN", "__builtin_nanf(\"\")">,
 
@@ -207,6 +208,7 @@ def SysMManAPI : PublicAPI<"sys/mman.h"> {
 
 def SignalAPI : PublicAPI<"signal.h"> {
   let Types = [
+    "sig_atomic_t",
     "sigset_t",
     "struct sigaction",
     "union sigval",

diff  --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 066c7783d82a8..ac4e57572a696 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -144,10 +144,11 @@ add_gen_header(
     ../config/${LIBC_TARGET_OS}/signal.h.in
   DEPENDS
     .llvm-libc-macros.signal_macros
-    .llvm-libc-types.struct_sigaction
     .llvm-libc-types.__sighandler_t
-    .llvm-libc-types.stack_t
     .llvm-libc-types.sigset_t
+    .llvm-libc-types.sig_atomic_t
+    .llvm-libc-types.stack_t
+    .llvm-libc-types.struct_sigaction
     .llvm-libc-types.pid_t
 )
 
@@ -158,6 +159,7 @@ add_gen_header(
   DEPENDS
     .llvm_libc_common_h
     .llvm-libc-macros.file_seek_macros
+    .llvm-libc-macros.stdio_macros
     .llvm-libc-types.cookie_io_functions_t
     .llvm-libc-types.FILE
     .llvm-libc-types.size_t

diff  --git a/libc/include/llvm-libc-macros/CMakeLists.txt b/libc/include/llvm-libc-macros/CMakeLists.txt
index 7469145098e51..fe2652a01d8dd 100644
--- a/libc/include/llvm-libc-macros/CMakeLists.txt
+++ b/libc/include/llvm-libc-macros/CMakeLists.txt
@@ -30,6 +30,12 @@ add_header(
     .linux.signal_macros
 )
 
+add_header(
+  stdio_macros
+  HDR
+    stdio-macros.h
+)
+
 add_header(
   stdlib_macros
   HDR

diff  --git a/libc/include/llvm-libc-macros/linux/sys-wait-macros.h b/libc/include/llvm-libc-macros/linux/sys-wait-macros.h
index aaafe42abc5fc..ad66d050334f1 100644
--- a/libc/include/llvm-libc-macros/linux/sys-wait-macros.h
+++ b/libc/include/llvm-libc-macros/linux/sys-wait-macros.h
@@ -18,5 +18,7 @@
 #define WTERMSIG(status) (((status)&0x7F))
 #define WIFEXITED(status) (WTERMSIG(status) == 0)
 #define WEXITSTATUS(status) (((status)&0xFF00) >> 8)
+#define WIFSIGNALED(status)                                                    \
+  ((WTERMSIG(status) < 0x7F) && (WTERMSIG(status) > 0))
 
 #endif // __LLVM_LIBC_MACROS_LINUX_SYS_WAIT_MACROS_H

diff  --git a/libc/include/llvm-libc-macros/stdio-macros.h b/libc/include/llvm-libc-macros/stdio-macros.h
new file mode 100644
index 0000000000000..b2c62ec7cff2a
--- /dev/null
+++ b/libc/include/llvm-libc-macros/stdio-macros.h
@@ -0,0 +1,14 @@
+//===-- Macros defined in stdio.h header file -----------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef __LLVM_LIBC_MACROS_STDIO_MACROS_H
+#define __LLVM_LIBC_MACROS_STDIO_MACROS_H
+
+#define BUFSIZ 1024
+
+#endif // __LLVM_LIBC_MACROS_STDIO_MACROS_H

diff  --git a/libc/include/llvm-libc-macros/stdlib-macros.h b/libc/include/llvm-libc-macros/stdlib-macros.h
index 930938dbe82f7..1c66a4359a687 100644
--- a/libc/include/llvm-libc-macros/stdlib-macros.h
+++ b/libc/include/llvm-libc-macros/stdlib-macros.h
@@ -9,6 +9,14 @@
 #ifndef __LLVM_LIBC_MACROS_STDLIB_MACROS_H
 #define __LLVM_LIBC_MACROS_STDLIB_MACROS_H
 
+#ifndef NULL
+#define __need_NULL
+#include <stddef.h>
+#endif // NULL
+
+#define EXIT_SUCCESS 0
+#define EXIT_FAILURE 1
+
 #define RAND_MAX 32767
 
 #endif // __LLVM_LIBC_MACROS_STDLIB_MACROS_H

diff  --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt
index 4bd69be95cfe3..7be24415b41b3 100644
--- a/libc/include/llvm-libc-types/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/CMakeLists.txt
@@ -62,6 +62,7 @@ add_header(ssize_t HDR ssize_t.h)
 add_header(struct_dirent HDR struct_dirent.h DEPENDS .ino_t .off_t)
 add_header(union_sigval HDR union_sigval.h)
 add_header(siginfo_t HDR siginfo_t.h DEPENDS .union_sigval .pid_t .uid_t)
+add_header(sig_atomic_t HDR sig_atomic_t.h)
 add_header(sigset_t HDR sigset_t.h DEPENDS libc.include.llvm-libc-macros.signal_macros)
 add_header(struct_sigaction HDR struct_sigaction.h DEPENDS .sigset_t .siginfo_t)
 add_header(struct_timespec HDR struct_timespec.h DEPENDS .time_t)

diff  --git a/libc/include/llvm-libc-types/sig_atomic_t.h b/libc/include/llvm-libc-types/sig_atomic_t.h
new file mode 100644
index 0000000000000..324629c1b55c3
--- /dev/null
+++ b/libc/include/llvm-libc-types/sig_atomic_t.h
@@ -0,0 +1,14 @@
+//===-- Definition of sig_atomic_t type -----------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef __LLVM_LIBC_TYPES_SIG_ATOMIC_T_H__
+#define __LLVM_LIBC_TYPES_SIG_ATOMIC_T_H__
+
+typedef int sig_atomic_t;
+
+#endif // __LLVM_LIBC_TYPES_SIG_ATOMIC_T_H__

diff  --git a/libc/include/stdio.h.def b/libc/include/stdio.h.def
index a643e22664913..5eb0e98809603 100644
--- a/libc/include/stdio.h.def
+++ b/libc/include/stdio.h.def
@@ -11,6 +11,7 @@
 
 #include <__llvm-libc-common.h>
 #include <llvm-libc-macros/file-seek-macros.h>
+#include <llvm-libc-macros/stdio-macros.h>
 
 %%public_api()
 

diff  --git a/libc/spec/stdc.td b/libc/spec/stdc.td
index 964b3e7c27338..a7a9df46747f4 100644
--- a/libc/spec/stdc.td
+++ b/libc/spec/stdc.td
@@ -338,6 +338,7 @@ def StdC : StandardSpec<"stdc"> {
           Macro<"MATH_ERREXCEPT">,
           Macro<"math_errhandling">,
 
+          Macro<"HUGE_VAL">,
           Macro<"INFINITY">,
           Macro<"NAN">,
 
@@ -740,6 +741,7 @@ def StdC : StandardSpec<"stdc"> {
       ]
   >;
 
+  NamedType SigAtomicT = NamedType<"sig_atomic_t">;
   HeaderSpec Signal = HeaderSpec<
       "signal.h",
       [
@@ -756,6 +758,7 @@ def StdC : StandardSpec<"stdc"> {
       ],
       [
         SizeTType,
+        SigAtomicT,
         SigHandlerT,
       ],
       [], // Enumerations


        


More information about the libc-commits mailing list