Skip to content

Commit 1317171

Browse files
committed
Fix Clang and GCC compilation
1 parent 139a049 commit 1317171

File tree

9 files changed

+30
-122
lines changed

9 files changed

+30
-122
lines changed

interface/core/builtin.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#define HD_HAS_BUILTIN_ATOMIC_FETCH_SUB __has_builtin(__atomic_fetch_sub)
2525
#define HD_HAS_BUILTIN_DEBUGTRAP __has_builtin(__builtin_debugtrap)
2626
#define HD_HAS_BUILTIN_ASSUME __has_builtin(__builtin_assume)
27+
#define HD_HAS_BUILTIN_UNREACHABLE __has_builtin(__builtin_unreachable)
2728
#define HD_HAS_BUILTIN_CLZS __has_builtin(__builtin_clzs)
2829
#define HD_HAS_BUILTIN_CLZ __has_builtin(__builtin_clz)
2930
#define HD_HAS_BUILTIN_CLZLL __has_builtin(__builtin_clzll)
@@ -49,6 +50,7 @@
4950
#define HD_HAS_BUILTIN_ATOMIC_FETCH_SUB __has_builtin(__atomic_fetch_sub)
5051
#define HD_HAS_BUILTIN_DEBUGTRAP __has_builtin(__builtin_debugtrap)
5152
#define HD_HAS_BUILTIN_ASSUME __has_builtin(__builtin_assume)
53+
#define HD_HAS_BUILTIN_UNREACHABLE __has_builtin(__builtin_unreachable)
5254
#define HD_HAS_BUILTIN_CLZS __has_builtin(__builtin_clzs)
5355
#define HD_HAS_BUILTIN_CLZ __has_builtin(__builtin_clz)
5456
#define HD_HAS_BUILTIN_CLZLL __has_builtin(__builtin_clzll)
@@ -74,6 +76,7 @@
7476
#define HD_HAS_BUILTIN_ATOMIC_FETCH_SUB 0
7577
#define HD_HAS_BUILTIN_DEBUGTRAP 0
7678
#define HD_HAS_BUILTIN_ASSUME 1
79+
#define HD_HAS_BUILTIN_UNREACHABLE 0
7780
#define HD_HAS_BUILTIN_CLZS 0
7881
#define HD_HAS_BUILTIN_CLZ 0
7982
#define HD_HAS_BUILTIN_CLZLL 0

interface/core/containers/hashset.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ namespace hud
423423
: control_ptr_(control_ptr)
424424
{
425425
hud::check(control_ptr != nullptr);
426-
HD_ASSUME(control_ptr != nullptr);
426+
HD_ASSUME((control_ptr != nullptr));
427427
}
428428

429429
constexpr iterator(control_type *control_ptr, slot_type *slot_ptr)

interface/core/defines.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,28 @@
4747
#define HD_RESTRICT __restrict__ // Indicates that a symbol is not aliased in the current scope.
4848
#define __STDC_WANT_LIB_EXT1__ 1 // Enable bounds-checked functions ( ISO C Safe Array Functions : memcpy_s, strcpy_s, snwprintf_s, etc... )
4949

50-
#if defined(HD_HAS_BUILTIN_ASSUME)
50+
#if !defined(HD_RELEASE)
51+
52+
#endif
53+
#if defined(HD_COMPILER_CLANG) && defined(HD_HAS_BUILTIN_ASSUME)
5154
#define HD_ASSUME(cond) __builtin_assume(cond)
55+
#else
56+
#if defined(HD_HAS_BUILTIN_UNREACHABLE)
57+
#define HD_ASSUME(cond) \
58+
do \
59+
{ \
60+
if (!(cond)) \
61+
__builtin_unreachable(); \
62+
} while (false)
63+
#else
64+
#define HD_ASSUME \
65+
do \
66+
{ \
67+
static_cast<void>(false && (cond)); \
68+
} while (false)
69+
#endif
5270
#endif
71+
5372
#if defined(HD_COMPILER_CLANG)
5473
#if __has_feature(address_sanitizer)
5574
#define HD_USE_ADDRESS_SANITIZER 1

interface/core/i128/i128_portable.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,10 +1002,12 @@ namespace hud
10021002
{
10031003
if (u64 hi = n.high_)
10041004
{
1005+
hud::check(hi != 0);
10051006
HD_ASSUME(hi != 0);
10061007
return 127 - hud::bits::leading_zero(hi);
10071008
}
10081009
const u64 low = n.low_;
1010+
hud::check(low != 0);
10091011
HD_ASSUME(low != 0);
10101012
return 63 - hud::bits::leading_zero(low);
10111013
};

interface/core/os_linux/bits.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ namespace hud::os::linux
168168
return value == 0 ? 64 : os::common::bits::trailing_zero(value);
169169
#endif
170170
}
171-
}; // namespace hud::os::linux
171+
};
172+
} // namespace hud::os::linux
172173

173174
#endif // HD_INC_CORE_OS_LINUX_BITS_H

src/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ cmake_minimum_required(VERSION 3.24)
55
# source_files variable is a list all files in Implementation and Interface directory
66
set( src
77
hash/crc32.cpp
8-
containers/hashset.cpp
98
)
109
#Linux implementations
1110
if(UNIX AND NOT APPLE)

src/containers/hashmap.cpp

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/containers/hashset.cpp

Lines changed: 0 additions & 78 deletions
This file was deleted.

src/precompiled.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#ifndef HD_PRECOMPILED
22
#define HD_PRECOMPILED
3+
#include <stdarg.h>
4+
#include <memory>
35
#include <core/minimal.h>
46

57
#endif // HD_PRECOMPILED

0 commit comments

Comments
 (0)