Detect __builtin_x_overflow() based on __GNUC__ macro.

This commit is contained in:
Jorge Acereda 2020-05-23 19:03:07 +02:00
parent 47c93f5fb6
commit b681cf2644
2 changed files with 22 additions and 23 deletions

View File

@ -10,7 +10,17 @@ Long Long__MUL_(Long x, Long y) {
Long Long__DIV_(Long x, Long y) {
return x / y;
}
#if defined _WIN32 || defined __TINYC__
#if defined __GNUC__
bool Long_safe_MINUS_add(Long x, Long y, Long* res) {
return __builtin_add_overflow(x, y, res);
}
bool Long_safe_MINUS_sub(Long x, Long y, Long* res) {
return __builtin_sub_overflow(x, y, res);
}
bool Long_safe_MINUS_mul(Long x, Long y, Long* res) {
return __builtin_mul_overflow(x, y, res);
}
#else
bool Long_safe_MINUS_add(Long x, Long y, Long* res) {
Long r = x + y;
*res = r;
@ -26,16 +36,6 @@ bool Long_safe_MINUS_mul(Long x, Long y, Long* res) {
*res = r;
return y == 0 || (r / y) != x;
}
#else
bool Long_safe_MINUS_add(Long x, Long y, Long* res) {
return __builtin_add_overflow(x, y, res);
}
bool Long_safe_MINUS_sub(Long x, Long y, Long* res) {
return __builtin_sub_overflow(x, y, res);
}
bool Long_safe_MINUS_mul(Long x, Long y, Long* res) {
return __builtin_mul_overflow(x, y, res);
}
#endif
bool Long__EQ_(Long x, Long y) {
return x == y;

View File

@ -1,5 +1,14 @@
#if defined _WIN32 || defined __TINYC__
#if defined __GNUC__
bool Int_safe_MINUS_add(int x, int y, int* res) {
return __builtin_add_overflow(x, y, res);
}
bool Int_safe_MINUS_sub(int x, int y, int* res) {
return __builtin_sub_overflow(x, y, res);
}
bool Int_safe_MINUS_mul(int x, int y, int* res) {
return __builtin_mul_overflow(x, y, res);
}
#else
bool Int_safe_MINUS_add(int x, int y, int* res) {
int r = x + y;
*res = r;
@ -16,14 +25,4 @@ bool Int_safe_MINUS_mul(int x, int y, int* res) {
*res = r;
return y == 0 || (r / y) != x;
}
#else
bool Int_safe_MINUS_add(int x, int y, int* res) {
return __builtin_add_overflow(x, y, res);
}
bool Int_safe_MINUS_sub(int x, int y, int* res) {
return __builtin_sub_overflow(x, y, res);
}
bool Int_safe_MINUS_mul(int x, int y, int* res) {
return __builtin_mul_overflow(x, y, res);
}
#endif