Skip to content

Commit 1392843

Browse files
nimrod-gileadicopybara-github
authored andcommitted
Fix the use of __has_builtin for GCC < 10.
The breakage was introduced in af12322. __has_builtin was introduced to GCC in version 10, and the arithmetic overflow builtins were available since version 5. Fixes #386. Tested with GCC 9. PiperOrigin-RevId: 461463027 Change-Id: I76627539a5c0e7f5617b56a2c9ada9251bceb0f6
1 parent 5ef1e59 commit 1392843

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/engine/engine_io.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
#pragma warning (disable: 4305) // disable MSVC warning: truncation from 'double' to 'float'
4646
#endif
4747

48+
#ifndef __has_builtin
49+
#define __has_builtin(x) 0
50+
#endif
51+
4852
#define PTRDIFF(x, y) ((void*)(x) - (void*)(y))
4953

5054

@@ -357,8 +361,8 @@ static void mj_setPtrModel(mjModel* m) {
357361
// *nbuffer += SKIP(*offset) + type_size*nr*nc;
358362
// *offset += SKIP(*offset) + type_size*nr*nc;
359363
static int safeAddToBufferSize(intptr_t* offset, int* nbuffer, size_t type_size, int nr, int nc) {
360-
#if defined(__has_builtin) \
361-
&& __has_builtin(__builtin_add_overflow) && __has_builtin(__builtin_mul_overflow)
364+
#if (__has_builtin(__builtin_add_overflow) && __has_builtin(__builtin_mul_overflow)) \
365+
|| (defined(__GNUC__) && __GNUC__ >= 5)
362366
// supported by GCC and Clang
363367
int to_add = 0;
364368
if (__builtin_mul_overflow(nc, nr, &to_add)) return 0;

0 commit comments

Comments
 (0)