Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do `__builtin_{{s,u}{add,sub,mul}ll_overflow` give a `long int` result instead of a `long long int` result?

Tags:

c

gcc

clang

The int versions of the overflow-checking add/subtract/multiply builtins in GCC return an int result (good), and the long int versions return a long int result (also good), but the long long int versions return a long int result (not good). Why is this? It seems insane to me.

Example:

bool __builtin_uadd_overflow (unsigned int a, unsigned int b, unsigned int *res)
bool __builtin_uaddl_overflow (unsigned long int a, unsigned long int b, unsigned long int *res)
bool __builtin_uaddll_overflow (unsigned long long int a, unsigned long long int b, unsigned long int *res)

This is so broken, I can't even believe it. It means that on a target where long and long long are different sizes (for example, 32-bit ARM iOS targets), the ll versions of the functions are completely useless.

like image 829
Todd Lehman Avatar asked Jun 01 '15 18:06

Todd Lehman


1 Answers

This is a bug in GCC that hasn't been fixed yet.

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65007

like image 148
Collin Dauphinee Avatar answered Nov 04 '22 06:11

Collin Dauphinee