Skip to content

[libc] Make two include/llvm-libc-types/ headers more self-contained. #128094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion libc/include/inttypes.h.def
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#include "__llvm-libc-common.h"
#include "llvm-libc-macros/inttypes-macros.h"
#include <stdint.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the C standard says "The header <inttypes.h> includes the header <stdint.h> and extends it with additional facilities provided by hosted implementations."

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good opportunity to add another little hdrgen feature and then eliminate inttypes.h.def.
That is, we can have an includes list in YAML, where this is the list of public <foo.h> headers that the actual API spec is for this other public header to include for re-export. I think there may be other cases than just <inttypes.h> -> <stdint.h> in standard C though I can't think of one off hand; there are certainly more in POSIX.
These should be in the source of truth about the API contract, and thus the actual #include can be generated. (Later we can exploit this in other ways like with generated tests.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this specific case though, helpful hdrgen already inserts #include <stdint.h> statement to the generated header: because intmax_t is among the types returned by the functions in inttypes.h.def. See:

COMPILER_HEADER_TYPES.update({f"int{size}_t": "<stdint.h>" for size in STDINT_SIZES})

Given that, is it OK to still remove this explicit include?


%%public_api()

Expand Down
9 changes: 8 additions & 1 deletion libc/include/llvm-libc-types/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,14 @@ add_header(tss_dtor_t HDR tss_dtor_t.h)
add_header(__atexithandler_t HDR __atexithandler_t.h)
add_header(speed_t HDR speed_t.h)
add_header(tcflag_t HDR tcflag_t.h)
add_header(struct_termios HDR struct_termios.h DEPENDS .cc_t .speed_t .tcflag_t)
add_header(
struct_termios
HDR
struct_termios.h
DEPENDS
.cc_t .speed_t .tcflag_t
libc.include.llvm-libc-macros.termios_macros
)
add_header(__getoptargv_t HDR __getoptargv_t.h)
add_header(wchar_t HDR wchar_t.h)
add_header(char8_t HDR char8_t.h)
Expand Down
2 changes: 2 additions & 0 deletions libc/include/llvm-libc-types/imaxdiv_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#ifndef __LLVM_LIBC_TYPES_IMAXDIV_T_H__
#define __LLVM_LIBC_TYPES_IMAXDIV_T_H__

#include <stdint.h>

typedef struct {
intmax_t quot;
intmax_t rem;
Expand Down
3 changes: 2 additions & 1 deletion libc/include/llvm-libc-types/struct_termios.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include "speed_t.h"
#include "tcflag_t.h"

#include "../llvm-libc-macros/termios-macros.h" // NCCS

struct termios {
tcflag_t c_iflag; // Input mode flags
tcflag_t c_oflag; // Output mode flags
Expand All @@ -21,7 +23,6 @@ struct termios {
#ifdef __linux__
cc_t c_line; // Line discipline
#endif // __linux__
// NCCS is defined in llvm-libc-macros/termios-macros.h.
cc_t c_cc[NCCS]; // Control characters
#ifdef __linux__
speed_t c_ispeed; // Input speed
Expand Down
Loading