Skip to content

Instantly share code, notes, and snippets.

@regehr
Last active April 13, 2016 22:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save regehr/65252e90fb6bad82d533 to your computer and use it in GitHub Desktop.
Save regehr/65252e90fb6bad82d533 to your computer and use it in GitHub Desktop.
implementation sketch for faster integer overflow checking in clang/llvm

I want to speed up integer overflow checking for hardening purposes by keeping a sticky overflow flag and only trapping when necessary. I want to keep it super simple while hopefully giving the optimizers room to do their thing.

In the codegen part of clang:

  • each function gets an i1 for storing overflow information, initialized to 0
  • each integer overflow check ORs its result into the overflow flag
  • before each function call, return instruction, or other side-effecting operation, execude ud2 if overflow is set

Reasonable?

@regehr
Copy link
Author

regehr commented Mar 25, 2016

Ok, I'm convinced, thanks guys, I'll start reading the passes relevant for check removal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment