Skip to content
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

Fixes for building with clang-cl on Windows #104

Merged
merged 3 commits into from
Jan 21, 2025
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
4 changes: 3 additions & 1 deletion ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ extern "C" {
# endif
/* Only supported is little endian for any arch on Windows,
so just fake the same for all. */
# define __ORDER_LITTLE_ENDIAN__ 1
# ifndef __ORDER_LITTLE_ENDIAN__
# define __ORDER_LITTLE_ENDIAN__ 1
# endif
# define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__
# ifndef __has_builtin
# define __has_builtin(arg) (0)
Expand Down
2 changes: 1 addition & 1 deletion ir_emit.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,10 @@ static bool ir_is_same_mem_var(const ir_ctx *ctx, ir_ref r1, int32_t offset)

void *ir_resolve_sym_name(const char *name)
{
void *handle = NULL;
void *addr;

#ifndef _WIN32
void *handle = NULL;
# ifdef RTLD_DEFAULT
handle = RTLD_DEFAULT;
# endif
Expand Down
9 changes: 6 additions & 3 deletions ir_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,10 @@ IR_ALWAYS_INLINE uint32_t ir_ntz(uint32_t num)
/* Number of trailing zero bits (0x01 -> 0; 0x40 -> 6; 0x00 -> LEN) */
IR_ALWAYS_INLINE uint32_t ir_ntzl(uint64_t num)
{
#if (defined(__GNUC__) || __has_builtin(__builtin_ctzl))
return __builtin_ctzl(num);
#elif defined(_WIN64)
// Note that the _WIN64 case should come before __has_builtin() below so that
// clang-cl on Windows will use the uint64_t version, not the "long" uint32_t
// version.
#if defined(_WIN64)
unsigned long index;

if (!_BitScanForward64(&index, num)) {
Expand All @@ -148,6 +149,8 @@ IR_ALWAYS_INLINE uint32_t ir_ntzl(uint64_t num)
}

return (uint32_t) index;
#elif (defined(__GNUC__) || __has_builtin(__builtin_ctzl))
return __builtin_ctzl(num);
#else
uint32_t n;

Expand Down