Skip to content

Commit ffa75ca

Browse files
committed
Force inline fast_fail to improve MSVC codegen
1 parent 0b6810a commit ffa75ca

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

include/flux/core/assert.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ namespace detail {
3535
struct runtime_error_fn {
3636
private:
3737
[[noreturn]]
38-
static inline void fail_fast()
38+
FLUX_ALWAYS_INLINE
39+
static void fail_fast()
3940
{
4041
#if FLUX_HAS_BUILTIN_TRAP
4142
__builtin_trap();
@@ -67,8 +68,9 @@ struct runtime_error_fn {
6768

6869
public:
6970
[[noreturn]]
70-
inline void operator()(char const* msg,
71-
std::source_location loc = std::source_location::current()) const
71+
FLUX_ALWAYS_INLINE
72+
void operator()(char const* msg,
73+
std::source_location loc = std::source_location::current()) const
7274
{
7375
if constexpr (config::on_error == error_policy::fail_fast) {
7476
fail_fast();
@@ -125,8 +127,7 @@ struct indexed_bounds_check_fn {
125127
}
126128
}
127129
#endif
128-
assert_fn{}(idx >= T{0}, "index cannot be negative", loc);
129-
assert_fn{}(idx < limit, "out-of-bounds sequence access", loc);
130+
assert_fn{}(idx >= T{0} && idx < limit, "out-of-bounds sequence access", loc);
130131
}
131132
}
132133
};

include/flux/macros.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@
2323

2424
#define FLUX_DECLVAL(...) ((static_cast<__VA_ARGS__(*)()noexcept>(nullptr))())
2525

26-
#ifdef __GNUC__
27-
#define FLUX_ALWAYS_INLINE [[gnu::always_inline]]
26+
#if defined(__GNUC__)
27+
# define FLUX_ALWAYS_INLINE [[gnu::always_inline]] inline
28+
#elif defined(_MSC_VER)
29+
# define FLUX_ALWAYS_INLINE __forceinline
2830
#else
29-
#define FLUX_ALWAYS_INLINE
31+
# define FLUX_ALWAYS_INLINE inline
3032
#endif
3133

3234
#define FLUX_NO_UNIQUE_ADDRESS [[no_unique_address]]

0 commit comments

Comments
 (0)