mirror of
https://github.com/carp-lang/Carp.git
synced 2024-10-05 17:47:30 +03:00
Detect __builtin_x_overflow() based on __GNUC__ macro.
This commit is contained in:
parent
47c93f5fb6
commit
b681cf2644
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user