cisco/ChezScheme

error: use of unknown builtin '__builtin_add_overflow'

ryandesign opened this issue · 1 comments

ChezScheme 10.0.0 fails to build with Apple Clang versions earlier than 800:

c/pb.c:122:10: error: use of unknown builtin '__builtin_add_overflow' [-Wimplicit-function-declaration]
    case COMMON_INSTR(pb_bin_op_pb_signal_pb_add_pb_register)
         ^
c/pb.c:51:28: note: expanded from macro 'COMMON_INSTR'
#define COMMON_INSTR(x) x: doi_ ## x(instr); break;
                           ^
<scratch space>:73:1: note: expanded from here
doi_pb_bin_op_pb_signal_pb_add_pb_register
^
c/pb.h:384:4: note: expanded from macro 'doi_pb_bin_op_pb_signal_pb_add_pb_register'
   do_pb_bin_op_pb_signal_pb_add_pb_register(INSTR_drr_dest(instr), INSTR_drr_reg1(instr), INSTR_drr_reg2(instr))
   ^
c/pb.h:390:12: note: expanded from macro 'do_pb_bin_op_pb_signal_pb_add_pb_register'
    flag = __builtin_add_overflow(a, b, &r);                         \
           ^

This was reported to MacPorts here: https://trac.macports.org/ticket/70278

You use __builtin_add_overflow if USE_OVERFLOW_INTRINSICS is defined:

ChezScheme/c/pb.h

Lines 382 to 404 in 3d1579e

#if USE_OVERFLOW_INTRINSICS
# define doi_pb_bin_op_pb_signal_pb_add_pb_register(instr) \
do_pb_bin_op_pb_signal_pb_add_pb_register(INSTR_drr_dest(instr), INSTR_drr_reg1(instr), INSTR_drr_reg2(instr))
# define do_pb_bin_op_pb_signal_pb_add_pb_register(dest, reg1, reg2) \
do { \
iptr a = (iptr)regs[reg1]; \
iptr b = (iptr)regs[reg2]; \
iptr r; \
flag = __builtin_add_overflow(a, b, &r); \
regs[dest] = (uptr)r; \
} while (0)
#else
# define doi_pb_bin_op_pb_signal_pb_add_pb_register(instr) \
do_pb_bin_op_pb_signal_pb_add_pb_register(INSTR_drr_dest(instr), INSTR_drr_reg1(instr), INSTR_drr_reg2(instr))
# define do_pb_bin_op_pb_signal_pb_add_pb_register(dest, reg1, reg2) \
do { \
uptr a = regs[reg1]; \
uptr b = regs[reg2]; \
uptr r = a + b; \
regs[dest] = r; \
flag = SIGN_FLIP(r, a, b); \
} while (0)
#endif

And you defined it for gcc 5 or greater or any version of clang:

ChezScheme/c/pb.h

Lines 74 to 78 in 3d1579e

#if (__GNUC__ >= 5) || defined(__clang__)
# define USE_OVERFLOW_INTRINSICS 1
#else
# define USE_OVERFLOW_INTRINSICS 0
#endif

But older versions of clang don't support it. Instead of relying on compiler version numbers (which is complicated to get right for clang, since there are two different clangs, one released by llvm.org, the other released by Apple, with different version numbering schemes), please use a method like __has_builtin to discover whether it is available.

Closed by #846