-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[libc] Some MSVC compatibility fixes in src/__support. #159428
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
#include "src/__support/CPP/type_traits.h" // is_unsigned_v, is_constant_evaluated | ||
#include "src/__support/macros/attributes.h" // LIBC_INLINE | ||
#include "src/__support/macros/config.h" | ||
#include "src/__support/macros/properties/compiler.h" | ||
|
||
namespace LIBC_NAMESPACE_DECL { | ||
|
||
|
@@ -25,7 +26,17 @@ LIBC_INLINE constexpr cpp::enable_if_t<cpp::is_unsigned_v<T>, T> | |
mask_trailing_ones() { | ||
constexpr unsigned T_BITS = CHAR_BIT * sizeof(T); | ||
static_assert(count <= T_BITS && "Invalid bit index"); | ||
#ifndef LIBC_COMPILER_IS_MSVC | ||
return count == 0 ? 0 : (T(-1) >> (T_BITS - count)); | ||
#else | ||
// MSVC complains about out of range shifts. | ||
if constexpr (count == 0) | ||
return 0; | ||
else if constexpr (count >= T_BITS) | ||
return T(-1); | ||
else | ||
return T(-1) >> (T_BITS - count); | ||
#endif // !LIBC_COMPILER_IS_MSVC | ||
|
||
} | ||
|
||
// Create a bitmask with the count left-most bits set to 1, and all other bits | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we not just
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already define
__has_builtin(x) 0
for MSVC https://github.com/llvm/llvm-project/blob/main/libc/src/__support/macros/config.h#L26The problem here is that MSVC does have
__builtin_bit_cast
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What a pain