Fix the use of __has_builtin for GCC < 10.
The breakage was introduced in af12322e9d.
__has_builtin was introduced to GCC in version 10, and the arithmetic overflow builtins were available since version 5.
Fixes deepmind/mujoco#386.
Tested with GCC 9.
PiperOrigin-RevId: 461463027
Change-Id: I76627539a5c0e7f5617b56a2c9ada9251bceb0f6
This commit is contained in:
committed by
Copybara-Service
parent
5ef1e59f06
commit
1392843aed
@@ -45,6 +45,10 @@
|
||||
#pragma warning (disable: 4305) // disable MSVC warning: truncation from 'double' to 'float'
|
||||
#endif
|
||||
|
||||
#ifndef __has_builtin
|
||||
#define __has_builtin(x) 0
|
||||
#endif
|
||||
|
||||
#define PTRDIFF(x, y) ((void*)(x) - (void*)(y))
|
||||
|
||||
|
||||
@@ -357,8 +361,8 @@ static void mj_setPtrModel(mjModel* m) {
|
||||
// *nbuffer += SKIP(*offset) + type_size*nr*nc;
|
||||
// *offset += SKIP(*offset) + type_size*nr*nc;
|
||||
static int safeAddToBufferSize(intptr_t* offset, int* nbuffer, size_t type_size, int nr, int nc) {
|
||||
#if defined(__has_builtin) \
|
||||
&& __has_builtin(__builtin_add_overflow) && __has_builtin(__builtin_mul_overflow)
|
||||
#if (__has_builtin(__builtin_add_overflow) && __has_builtin(__builtin_mul_overflow)) \
|
||||
|| (defined(__GNUC__) && __GNUC__ >= 5)
|
||||
// supported by GCC and Clang
|
||||
int to_add = 0;
|
||||
if (__builtin_mul_overflow(nc, nr, &to_add)) return 0;
|
||||
|
||||
Reference in New Issue
Block a user