[llvm-dev] PVS-Studio analysis of LLVM code

James Y Knight via llvm-dev llvm-dev at lists.llvm.org
Wed Nov 2 07:50:16 PDT 2016


On Wed, Nov 2, 2016 at 9:41 AM, Jonas Wagner via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Hello,
>
> I think this should be added by Clang itself.
>
>
> I don't think so. There are several sources online that indicate that
> developers need to *manually* specify std::nothrow. If they don't,
> operator new will throw an exception even if code is compiled with
> -fno-exception. This will abort the program.
>

That's correct. The default new should never return nullptr, even with
-fno-exceptions. It should either succeed, throw an exception, or abort.

At some point, this caused Firefox to replace a bunch of `new` with
> `new(std::nothrow)` [1] Would this be a good idea in LLVM as well? Or
> should we just let LLVM crash on OOM, and remove the null-checks as PVS
> suggests?
>

LLVM shouldn't replace new with new(std::nothrow), it should just abort.
There's effectively zero chance the codebase will ever be able to recover
from OOMing, and with modern OSes, you're almost never going to actually
see a malloc failure until it's way too late, anyways.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161102/7bdd1abf/attachment.html>


More information about the llvm-dev mailing list