[cfe-dev] What clang should do when memory is exhausted?

Abramo Bagnara abramo.bagnara at gmail.com
Wed Mar 21 01:04:53 PDT 2012


Il 20/03/2012 22:56, Douglas Gregor ha scritto:
> 
> On Mar 20, 2012, at 4:41 AM, Abramo Bagnara wrote:
> 
>> Il 18/03/2012 12:51, Abramo Bagnara ha scritto:
>>> In http://llvm.org/docs/CodingStandards.html#ci_rtti_exceptions I read
>>> that exceptions are not used by design in clang code base.
>>>
>>> Despite this in source there are a lot of unguarded call to new
>>> operator, does this means that when memory is lacking the compiler
>>> executable is meant to fail in arbitrary way?
>>
>> I'd correct myself replacing "fail in arbitrary way" with "execute
>> arbitrary code".
>>
>> Can I suggest the use in clang executables of set_new_handler (C++
>> lib.set.new.handler) to have a graceful exit when memory is exhausted?
>>
>> Is it an acceptable solution?
> 
> Seems okay for the compiler proper. For libclang, we'd probably just want to trap to kill the current thread.

I'd leave the responsibility to use set_new_handler to application using
libclang (the clang compiler is not an exception).

The important thing for libclang is to document that using default
compilation flag the library does not propagate operator new exceptions:
the programmer likely is unaware that this might lead to disasters (read
arbitrary execution i.e. in unfortunate cases miscompilation of safety
critical application) when memory is less than needed.



More information about the cfe-dev mailing list