Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use GCC/Clang builtins for overflows checking #4356

Open
XVilka opened this issue Mar 15, 2024 · 4 comments · May be fixed by #4447
Open

Use GCC/Clang builtins for overflows checking #4356

XVilka opened this issue Mar 15, 2024 · 4 comments · May be fixed by #4447
Assignees
Labels
good first issue Good for newcomers RzUtil

Comments

@XVilka
Copy link
Member

XVilka commented Mar 15, 2024

See librz/include/rz_types_overflow.h

See https://gcc.gnu.org/onlinedocs/gcc/Integer-Overflow-Builtins.html

An example how Meson checks for those could be added: bbc5457

@XVilka XVilka added good first issue Good for newcomers RzUtil labels Mar 15, 2024
@KBhushan07
Copy link

Hello @XVilka , want to work on it. can you assign it to me?

@XVilka
Copy link
Member Author

XVilka commented Mar 16, 2024

@KBhushan07 done, go ahead

@KBhushan07
Copy link

Could you please review my approach for implementing GCC built-ins overflow checking in my code? I used "__builtin_add_overflow_p" for addition instead of "__builtin_add_overflow" due to the third argument requirement. For multiplication, I utilized a similar library for signed numbers, as I couldn't find one for unsigned numbers. I left subtraction unchanged since it uses addition checking internally. Lastly, I couldn't find a built-in function for division. Do you think this approach is appropriate, or do you have any suggestions for improvement?

Screenshot -

Screenshot from 2024-03-16 09-44-30

@XVilka
Copy link
Member Author

XVilka commented Mar 16, 2024

  1. I recommend using the subtraction nevertheless when available
  2. You can not use builtins when they are not available, so it's ok to leave division checkers untouched
  3. Using __builtin_add_overflow_p is fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers RzUtil
Projects
None yet
2 participants