cisco / ChezScheme

Chez Scheme
Apache License 2.0
6.89k stars 983 forks source link

error: use of unknown builtin '__builtin_add_overflow' #845

Closed ryandesign closed 1 week ago

ryandesign commented 1 week ago

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:

https://github.com/cisco/ChezScheme/blob/3d1579e6c67e145895e6a0e7d0f9bf2b8853fbb3/c/pb.h#L382-L404

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

https://github.com/cisco/ChezScheme/blob/3d1579e6c67e145895e6a0e7d0f9bf2b8853fbb3/c/pb.h#L74-L78

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.

mflatt commented 1 week ago

Closed by #846