use of exceptions in GCC

2016-11-16 Thread Martin Sebor

GCC is built with -fno-exceptions.  I assume that's mainly to avoid
having to catch and handle exceptions in what was originally C code.
I also assume that also means that there's a policy or convention in
place against throwing exceptions in GCC or making use of constructs
that might throw (such as the non-placement new expressions).

By coincidence, bootstrapping my patch for bugs 77531 and 78284
exposed a few uses of the non-placement array new expression in
dominance.c (in dom_info::dom_init) that may throw an exception(*).

I'm wondering if those calls should be changed to avoid exceptions.

I'm also curious if there really is a policy/convention for dealing
with exceptions in GCC, what it actually is/says.

Thanks
Martin

[*] My patch exposed these because when -fno-exceptions is used
(and coincidentally also in C++ 98 mode) GCC emits conditional calls
to operator new[](SIZE_MAX) when the size computation that multiplies
the number of elements by the element size exceeds SIZE_MAX.  The
-Walloc-size-larger-than warning flags for attempting to allocate
more storage than the size of the biggest object, or SIZE_MAX / 2.


Re: use of exceptions in GCC

2016-11-16 Thread Segher Boessenkool
On Wed, Nov 16, 2016 at 01:48:41PM -0700, Martin Sebor wrote:
> I'm also curious if there really is a policy/convention for dealing
> with exceptions in GCC, what it actually is/says.

https://gcc.gnu.org/codingconventions.html#Exceptions


Segher


Re: use of exceptions in GCC

2016-11-16 Thread Martin Sebor

On 11/16/2016 07:36 PM, Segher Boessenkool wrote:

On Wed, Nov 16, 2016 at 01:48:41PM -0700, Martin Sebor wrote:

I'm also curious if there really is a policy/convention for dealing
with exceptions in GCC, what it actually is/says.


https://gcc.gnu.org/codingconventions.html#Exceptions


Thanks.  I guess I should have reviewed that document before asking.

The rationale makes it sound like the use of throwing new expressions
(i.e., those in dominance.c) or any other construct that may indirectly
throw is reasonable, as long as it doesn't prevent building GCC with
-fno-exceptions.

Martin


Re: use of exceptions in GCC

2016-11-16 Thread lhmouse
> GCC is built with -fno-exceptions.  I assume that's mainly to avoid
> having to catch and handle exceptions in what was originally C code.
> I also assume that also means that there's a policy or convention in
> place against throwing exceptions in GCC or making use of constructs
> that might throw (such as the non-placement new expressions).
It also drops the need of _runtime type info_ (a.k.a. RTTI) and stack unwind
table, reducing the size of binary files.

> 
> By coincidence, bootstrapping my patch for bugs 77531 and 78284
> exposed a few uses of the non-placement array new expression in
> dominance.c (in dom_info::dom_init) that may throw an exception(*).
> 
> I'm wondering if those calls should be changed to avoid exceptions.
If a program is compiled with `-fno-exceptions` and an exception
will have been thrown otherwise, `std::abort()` (or an equivalent such as
`__builtin_trap()`) is called. This preserves the semantical correctness
of not checking the value of a throwing new expression,
since it can't return a null pointer.

> 
> I'm also curious if there really is a policy/convention for dealing
> with exceptions in GCC, what it actually is/says.
Compilers aren't envisioned to be long-running programs, so aborting
on unexpected conditions is reasonable. This isn't only the case for GCC,
but also LLVM.

> 
> Thanks
> Martin
> 
> [*] My patch exposed these because when -fno-exceptions is used
> (and coincidentally also in C++ 98 mode) GCC emits conditional calls
> to operator new[](SIZE_MAX) when the size computation that multiplies
> the number of elements by the element size exceeds SIZE_MAX.  The
> -Walloc-size-larger-than warning flags for attempting to allocate
> more storage than the size of the biggest object, or SIZE_MAX / 2.



--   
Best regards,
lh_mouse
2016-11-17