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

Domagoj Saric domagoj.saric at littleendian.com
Fri Apr 27 07:43:21 PDT 2012


On 20.3.2012. 22:56, Douglas Gregor wrote:
>
> 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.

A bit late but...
...isn't that still ugly?
One of the major reasons Xcode 4 was completely unusable on 32 bit machines with 
C++ projects was because libclang that was running indexing in the background 
would quickly hog all RAM and simply crash...
I'm in no way fan of blind use of exceptions (and the bloat they add to the 
binaries) but if there is no other ('easy') way to make clang properly handle 
out-of-memory errors then..I guess there is no other way..or?


-- 
"What Huxley teaches is that in the age of advanced technology, spiritual
devastation is more likely to come from an enemy with a smiling face than
from one whose countenance exudes suspicion and hate."
Neil Postman



More information about the cfe-dev mailing list