Todd Lehman
Todd Lehman

Reputation: 2950

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

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.

Upvotes: 5

Views: 857

Answers (1)

Collin Dauphinee
Collin Dauphinee

Reputation: 13993

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

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

Upvotes: 6

Related Questions