Commit fdc01373

fdc0137303d7Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified

Description

fix(build): define __has_builtin fallback for GCC < 10

GCC < 10 (e.g. Ubuntu 20.04's stock 9.4) doesn't predefine __has_builtin, so #if expressions of the form

#if defined(__GNUC__) || __has_builtin(__builtin_popcount)

trip "missing binary operator before token "("" because the preprocessor sees __has_builtin as an undefined identifier (replaced with 0) and then a stray ( after it. lib/sp_bigint.c uses this pattern in four places.

Define a no-op fallback __has_builtin(x) -> 0 in mruby_shim.h, the shim header sp_bigint.c already includes. On GCC 10+ / Clang the compiler's real __has_builtin is left in place by the #ifndef guard; on older toolchains the fallback makes the || short-circuit cleanly on defined(__GNUC__).

Closes #55

Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]

Details

Commit
fdc0137303d7
Parent
f2785f692d3d

lib/mruby_shim.hmodifiedView file

@@ -11,6 +11,14 @@
1111 #include <string.h>
1212 #include <assert.h>
1313
14+/* GCC < 10 doesn't predefine __has_builtin, so #if expressions like
15+ `defined(__GNUC__) || __has_builtin(...)` choke on the bare token.
16+ Provide a no-op fallback so the || short-circuits cleanly on the
17+ left when the compiler doesn't support __has_builtin (issue #55). */
18+#ifndef __has_builtin
19+#define __has_builtin(x) 0
20+#endif
21+
1422 /* Basic mruby types */
1523 typedef int64_t mrb_int;
1624 typedef uint64_t mrb_uint;