public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* FYI: New Clang flag "-fnew-infallible" to mark C++ new as "throw()" and "returns_nonnull"
@ 2021-08-03 17:23 Modi Mo
  2021-08-03 20:50 ` Jonathan Wakely
  0 siblings, 1 reply; 2+ messages in thread
From: Modi Mo @ 2021-08-03 17:23 UTC (permalink / raw)
  To: gcc; +Cc: Richard Smith, Wenlei He

Hi all,

I recently committed support for the "-fnew-infallible" flag in Clang (https://reviews.llvm.org/D105225) to improve non-exceptional performance for code that contains exceptions. Having "new" terminate immediately on failure stops upward exception propagation and leads to significantly less landing pads generated. Posting here for visibility and to reduce the chance that a similar feature may manifest under a different flag for GCC.

Thanks,
Modi


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: FYI: New Clang flag "-fnew-infallible" to mark C++ new as "throw()" and "returns_nonnull"
  2021-08-03 17:23 FYI: New Clang flag "-fnew-infallible" to mark C++ new as "throw()" and "returns_nonnull" Modi Mo
@ 2021-08-03 20:50 ` Jonathan Wakely
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2021-08-03 20:50 UTC (permalink / raw)
  To: Modi Mo; +Cc: gcc, Wenlei He, Richard Smith

On Tue, 3 Aug 2021 at 18:26, Modi Mo via Gcc <gcc@gcc.gnu.org> wrote:
>
> Hi all,
>
> I recently committed support for the "-fnew-infallible" flag in Clang (https://reviews.llvm.org/D105225) to improve non-exceptional performance for code that contains exceptions. Having "new" terminate immediately on failure stops upward exception propagation and leads to significantly less landing pads generated. Posting here for visibility and to reduce the chance that a similar feature may manifest under a different flag for GCC.

Thanks for the heads up. This is interesting.

Could you explain this sentence in the commit message:
"Note that the definition of global new is user-replaceable so users
should ensure that the one used follows these semantics."

What happens if operator new does throw? Is that just treated like any
other noexcept function that throws, i.e. std::terminate()? Or is it
undefined behaviour?

And what if you use ::new(std::nothrow) and that fails, returning
null. Is that undefined?

It seems to me that the former case (a potentially-throwing allocation
function) could be turned into a std::terminate call fairly easily
without losing the benefits of this option (you still know that no
call to operator new will propagate exceptions). But for the latter
case the program *must* replace operator new to ensure that the
nothrow form never returns null, otherwise you violate the promise
that the returns_nonnull attribute makes, and have undefined
behaivour. Is that right?

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-03 20:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-03 17:23 FYI: New Clang flag "-fnew-infallible" to mark C++ new as "throw()" and "returns_nonnull" Modi Mo
2021-08-03 20:50 ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).