[cfe-dev] -ftrapv

Mike Stump mrs at apple.com
Wed Apr 1 11:32:15 PDT 2009


On Apr 1, 2009, at 8:54 AM, David Chisnall wrote:
> I've attached a diff which adds -ftrapv to clang-cc

Delicious!  Added in r68221.

> (not to clang; the driver code scares me)

Check out the code I added to add the option to clang, turns out is is  
magically easy (for clang_f_options anyway).

> When an overflow is detected, it calls a function in a supporting  
> library to handle it.  I've provided a default implementation in  
> overflowlib.c.

Hum, I don't know quite what to do with runtime code yet.  Logically  
we need a runtime library.  I kinda like the idea of bundling in a  
reference to the required runtime into the output file, and then  
having the linker use that knowledge to ensure that the proper runtime  
is linked in.  Conceptually, it would be the same as actually putting  
the runtime into the output, with link-once style linkage, but  
cheaper, as one wouldn't need to generate or move all the bits,  
essentially just the name.  gcc would have done this 15 years ago if  
the linkers supported it, but they didn't.  Modern linkers probably  
could be encouraged to support this for us, if we try.

Absent that, either we need a libclang.{so,dylib,a} or some other  
suitably advanced technology.  Do we have such yet?

> This can be replaced in compiled code by some other function if  
> required.  For 100% GCC compatibility just add:
>
> __overflow_handler = abort;

I put this in without considering the finer point of exactly how we  
want this to be.  I think it is an excellent start.  I do encourage  
people to weigh in on how they think this should work, if they want to  
see something else.  My quick first impression is I like it exactly  
how you did it.



More information about the cfe-dev mailing list