Skip to content

[libc++] Remove explicit mentions of __need_FOO macros #119025

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

Merged
merged 2 commits into from
Dec 17, 2024
Merged
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
8 changes: 4 additions & 4 deletions libcxx/include/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -2282,15 +2282,15 @@ module std_stdbool_h [system] {
textual header "stdbool.h"
}
module std_stddef_h [system] {
// <stddef.h>'s __need_* macros require textual inclusion.
// <stddef.h> supports being included multiple times with different pre-defined macros
textual header "stddef.h"
}
module std_stdio_h [system] {
// <stdio.h>'s __need_* macros require textual inclusion.
// <stdio.h> supports being included multiple times with different pre-defined macros
textual header "stdio.h"
}
module std_stdlib_h [system] {
// <stdlib.h>'s __need_* macros require textual inclusion.
// <stdlib.h> supports being included multiple times with different pre-defined macros
textual header "stdlib.h"
}
module std_string_h [system] {
Expand All @@ -2306,7 +2306,7 @@ module std_uchar_h [system] {
export *
}
module std_wchar_h [system] {
// <wchar.h>'s __need_* macros require textual inclusion.
// <wchar.h> supports being included multiple times with different pre-defined macros
textual header "wchar.h"
}
module std_wctype_h [system] {
Expand Down
33 changes: 16 additions & 17 deletions libcxx/include/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,6 @@
//
//===----------------------------------------------------------------------===//

#if defined(__need_FILE) || defined(__need___FILE)

# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
# endif

# include_next <stdio.h>

#elif !defined(_LIBCPP_STDIO_H)
# define _LIBCPP_STDIO_H

/*
stdio.h synopsis

Expand Down Expand Up @@ -98,13 +87,23 @@ int ferror(FILE* stream);
void perror(const char* s);
*/

# if 0
# else // 0
# include <__config>
#if 0
#else // 0
# include <__config>

# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
# endif
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
# endif

// The inclusion of the system's <stdio.h> is intentionally done once outside of any include
// guards because some code expects to be able to include the underlying system header multiple
// times to get different definitions based on the macros that are set before inclusion.
# if __has_include_next(<stdio.h>)
# include_next <stdio.h>
# endif

# ifndef _LIBCPP_STDIO_H
# define _LIBCPP_STDIO_H

# if __has_include_next(<stdio.h>)
# include_next <stdio.h>
Expand Down
37 changes: 18 additions & 19 deletions libcxx/include/stdlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,6 @@
//
//===----------------------------------------------------------------------===//

#if defined(__need_malloc_and_calloc)

# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
# endif

# include_next <stdlib.h>

#elif !defined(_LIBCPP_STDLIB_H)
# define _LIBCPP_STDLIB_H

/*
stdlib.h synopsis

Expand Down Expand Up @@ -84,13 +73,23 @@ void *aligned_alloc(size_t alignment, size_t size); // C11

*/

# if 0
# else // 0
# include <__config>
#if 0
#else // 0
# include <__config>

# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
# endif
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
# endif

// The inclusion of the system's <stdlib.h> is intentionally done once outside of any include
// guards because some code expects to be able to include the underlying system header multiple
// times to get different definitions based on the macros that are set before inclusion.
# if __has_include_next(<stdlib.h>)
# include_next <stdlib.h>
# endif

# if !defined(_LIBCPP_STDLIB_H)
# define _LIBCPP_STDLIB_H

# if __has_include_next(<stdlib.h>)
# include_next <stdlib.h>
Expand Down Expand Up @@ -148,7 +147,7 @@ inline _LIBCPP_HIDE_FROM_ABI lldiv_t div(long long __x, long long __y) _NOEXCEPT
# endif
# endif // _LIBCPP_MSVCRT
} // extern "C++"
# endif // __cplusplus
# endif // 0
# endif // __cplusplus
# endif // 0

#endif // _LIBCPP_STDLIB_H
45 changes: 22 additions & 23 deletions libcxx/include/wchar.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,6 @@
//
//===----------------------------------------------------------------------===//

#if defined(__need_wint_t) || defined(__need_mbstate_t)

# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
# endif

# include_next <wchar.h>

#elif !defined(_LIBCPP_WCHAR_H)
# define _LIBCPP_WCHAR_H

/*
wchar.h synopsis

Expand Down Expand Up @@ -105,25 +94,35 @@ size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len,

*/

# if 0
# else // 0
# include <__config>
# include <stddef.h>
#if 0
#else // 0
# include <__config>

# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
# endif
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
# endif

// We define this here to support older versions of glibc <wchar.h> that do
// not define this for clang.
# ifdef __cplusplus
# define __CORRECT_ISO_CPP_WCHAR_H_PROTO
# endif
# if defined(__cplusplus) && !defined(__CORRECT_ISO_CPP_WCHAR_H_PROTO)
# define __CORRECT_ISO_CPP_WCHAR_H_PROTO
# endif

// The inclusion of the system's <wchar.h> is intentionally done once outside of any include
// guards because some code expects to be able to include the underlying system header multiple
// times to get different definitions based on the macros that are set before inclusion.
# if __has_include_next(<wchar.h>)
# include_next <wchar.h>
# endif

# ifndef _LIBCPP_WCHAR_H
# define _LIBCPP_WCHAR_H

# include <__mbstate_t.h> // provide mbstate_t
# include <stddef.h> // provide size_t

# if __has_include_next(<wchar.h>)
# include_next <wchar.h>
# else
# include <__mbstate_t.h> // make sure we have mbstate_t regardless of the existence of <wchar.h>
# endif

// Determine whether we have const-correct overloads for wcschr and friends.
Expand Down
6 changes: 6 additions & 0 deletions libcxx/test/libcxx/clang_modules_include.gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
// TODO: Investigate why this doesn't work on Picolibc once the locale base API is refactored
// UNSUPPORTED: LIBCXX-PICOLIBC-FIXME

// TODO: Fix seemingly circular inclusion or <wchar.h> on AIX
// UNSUPPORTED: LIBCXX-AIX-FIXME
Comment on lines +52 to +53
Copy link
Member Author

Choose a reason for hiding this comment

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

@daltenty This appears to start failing on AIX after this patch, see e.g. https://buildkite.com/llvm-project/libcxx-ci/builds/39304#0193b131-ead6-42af-b231-48d8de48b2a6. I don't understand why it fails though, since we have proper include guards in wchar.h around the functions that are seemingly re-defined. Since I don't have access to an AIX box matching the CI to reproduce, it would be helpful if someone on the AIX side could take a look.


{lit_header_restrictions.get(header, '')}
{lit_header_undeprecations.get(header, '')}

Expand Down Expand Up @@ -83,6 +86,9 @@
// TODO: Investigate why this doesn't work on Picolibc once the locale base API is refactored
// UNSUPPORTED: LIBCXX-PICOLIBC-FIXME

// TODO: Fix seemingly circular inclusion or <wchar.h> on AIX
// UNSUPPORTED: LIBCXX-AIX-FIXME

@import std;

"""
Expand Down
Loading