Skip to content

Commit

Permalink
Fix Clang build.
Browse files Browse the repository at this point in the history
(cherry-picked from commit 384d6d5)

The `__GNUC__` macro signals that GNU extensions are supported
by a compiler. Some versions of the clang compiler
(clang 10.0.0 targeting the MSVC ABI, for example) may not
define that macro. However, they still support the GNU
extensions. This patch fixes the build for those compilers
by checking the `__clang__` macro value alongside `__GNUC__`.

Part of the patch relevant to 'lj_err.c' is omitted since all
of the required changes were already backported in the scope
of the patch b6d2852 ('Cleanup
and enable external unwinding for more platforms.').

No tests were added since the issue is relevant for a very
specific type of very old clang 10.0.0, which is not really
relevant for us.

Maxim Kokryashkin:
* added the description for the problem

Part of tarantool/tarantool#9145
  • Loading branch information
Mike Pall authored and mkokryashkin committed Oct 3, 2023
1 parent 7d5901d commit 968e510
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/lj_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ static int has_segment_link(mstate m, msegmentptr ss)
noncontiguous segments are added.
*/
#define TOP_FOOT_SIZE\
(align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)
(align_offset(TWO_SIZE_T_SIZES)+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE)

/* ---------------------------- Indexing Bins ---------------------------- */

Expand Down
4 changes: 2 additions & 2 deletions src/lj_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ typedef uintptr_t BloomFilter;
#define bloomset(b, x) ((b) |= bloombit((x)))
#define bloomtest(b, x) ((b) & bloombit((x)))

#if defined(__GNUC__) || defined(__psp2__)
#if defined(__GNUC__) || defined(__clang__) || defined(__psp2__)

#define LJ_NORET __attribute__((noreturn))
#define LJ_ALIGN(n) __attribute__((aligned(n)))
Expand Down Expand Up @@ -182,7 +182,7 @@ static LJ_AINLINE uint64_t lj_bswap64(uint64_t x)
{
return ((uint64_t)lj_bswap((uint32_t)x)<<32) | lj_bswap((uint32_t)(x>>32));
}
#elif (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
#elif (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || __clang__
static LJ_AINLINE uint32_t lj_bswap(uint32_t x)
{
return (uint32_t)__builtin_bswap32((int32_t)x);
Expand Down
2 changes: 1 addition & 1 deletion src/lj_emit_x86.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static LJ_AINLINE MCode *emit_op(x86Op xo, Reg rr, Reg rb, Reg rx,
*(uint32_t *)(p+delta-5) = (uint32_t)xo;
return p+delta-5;
}
#if defined(__GNUC__)
#if defined(__GNUC__) || defined(__clang__)
if (__builtin_constant_p(xo) && n == -2)
p[delta-2] = (MCode)(xo >> 24);
else if (__builtin_constant_p(xo) && n == -3)
Expand Down
2 changes: 1 addition & 1 deletion src/lj_ircall.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ extern double lj_vm_sfmax(double a, double b);
#endif

#if LJ_HASFFI && LJ_NEED_FP64 && !(LJ_TARGET_ARM && LJ_SOFTFP)
#ifdef __GNUC__
#if defined(__GNUC__) || defined(__clang__)
#define fp64_l2d __floatdidf
#define fp64_ul2d __floatundidf
#define fp64_l2f __floatdisf
Expand Down
2 changes: 1 addition & 1 deletion src/lj_mcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void lj_mcode_sync(void *start, void *end)
sys_icache_invalidate(start, (char *)end-(char *)start);
#elif LJ_TARGET_PPC
lj_vm_cachesync(start, end);
#elif defined(__GNUC__)
#elif defined(__GNUC__) || defined(__clang__)
__clear_cache(start, end);
#else
#error "Missing builtin to flush instruction cache"
Expand Down
2 changes: 1 addition & 1 deletion src/lj_strfmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ LJ_FUNC GCstr * LJ_FASTCALL lj_strfmt_obj(lua_State *L, cTValue *o);
LJ_FUNC const char *lj_strfmt_pushvf(lua_State *L, const char *fmt,
va_list argp);
LJ_FUNC const char *lj_strfmt_pushf(lua_State *L, const char *fmt, ...)
#ifdef __GNUC__
#if defined(__GNUC__) || defined(__clang__)
__attribute__ ((format (printf, 2, 3)))
#endif
;
Expand Down
2 changes: 1 addition & 1 deletion src/lj_strscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static void strscan_double(uint64_t x, TValue *o, int32_t ex2, int32_t neg)
/* Avoid double rounding for denormals. */
if (LJ_UNLIKELY(ex2 <= -1075 && x != 0)) {
/* NYI: all of this generates way too much code on 32 bit CPUs. */
#if defined(__GNUC__) && LJ_64
#if (defined(__GNUC__) || defined(__clang__)) && LJ_64
int32_t b = (int32_t)(__builtin_clzll(x)^63);
#else
int32_t b = (x>>32) ? 32+(int32_t)lj_fls((uint32_t)(x>>32)) :
Expand Down

0 comments on commit 968e510

Please sign in to comment.