Skip to content

[libc] fix type generic stdc_leading_zeros for GCC #79917

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 3 commits into from
Jan 30, 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
18 changes: 18 additions & 0 deletions libc/include/llvm-libc-macros/stdbit-macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,30 @@
#ifndef __LLVM_LIBC_MACROS_STDBIT_MACROS_H
#define __LLVM_LIBC_MACROS_STDBIT_MACROS_H

#ifdef __cplusplus
inline unsigned char stdc_leading_zeros(unsigned char x) {
return stdc_leading_zeros_uc(x);
}
inline unsigned short stdc_leading_zeros(unsigned short x) {
return stdc_leading_zeros_us(x);
}
inline unsigned stdc_leading_zeros(unsigned x) {
return stdc_leading_zeros_ui(x);
}
inline unsigned long stdc_leading_zeros(unsigned long x) {
return stdc_leading_zeros_ul(x);
}
inline unsigned long long stdc_leading_zeros(unsigned long long x) {
return stdc_leading_zeros_ull(x);
}
#else
#define stdc_leading_zeros(x) \
_Generic((x), \
unsigned char: stdc_leading_zeros_uc, \
unsigned short: stdc_leading_zeros_us, \
unsigned: stdc_leading_zeros_ui, \
unsigned long: stdc_leading_zeros_ul, \
unsigned long long: stdc_leading_zeros_ull)(x)
#endif // __cplusplus

#endif // __LLVM_LIBC_MACROS_STDBIT_MACROS_H
3 changes: 2 additions & 1 deletion libc/include/stdbit.h.def
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
#define LLVM_LIBC_STDBIT_H

#include <__llvm-libc-common.h>
#include <llvm-libc-macros/stdbit-macros.h>

%%public_api()

#include <llvm-libc-macros/stdbit-macros.h>

#endif // LLVM_LIBC_STDBIT_H
4 changes: 0 additions & 4 deletions libc/test/include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,5 @@ if (LLVM_LIBC_FULL_BUILD)
# simply testing the macros provided by stdbit.h, not the implementation
# of the underlying functions which the type generic macros may dispatch
# to.
COMPILE_OPTIONS
# stdbit.h is full of type generic macros implemented via C11 _Generic.
# Clang will produce -Wno-c11-extensions when using _Generic in C++ mode.
-Wno-c11-extensions
)
endif()