This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: C PATCH for c/70093 (ICE with nested-function returning VM type)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Marek Polacek <polacek at redhat dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, Joseph Myers <joseph at codesourcery dot com>
- Date: Wed, 9 Mar 2016 15:45:45 +0100
- Subject: Re: C PATCH for c/70093 (ICE with nested-function returning VM type)
- Authentication-results: sourceware.org; auth=none
- References: <20160309110550 dot GS10006 at redhat dot com> <20160309112442 dot GI3017 at tucnak dot redhat dot com> <20160309143440 dot GT10006 at redhat dot com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Wed, Mar 09, 2016 at 03:34:40PM +0100, Marek Polacek wrote:
> --- gcc/testsuite/gcc.dg/nested-func-10.c
> +++ gcc/testsuite/gcc.dg/nested-func-10.c
> @@ -0,0 +1,45 @@
> +/* PR c/70093 */
> +/* { dg-do compile } */
> +/* { dg-options "" } */
> +
> +void
> +foo (int n)
> +{
> + struct S { int a[n]; };
> +
> + struct S __attribute__((noreturn))
> + fn (void)
> + {
> + struct S s;
> + s.a[0] = 42;
> + return s; /* { dg-warning "function declared .noreturn.|.noreturn. function does return" } */
> + }
> +
> + auto struct S __attribute__((noreturn))
> + fn2 (void)
> + {
> + return fn (); /* { dg-warning "function declared .noreturn." } */
> + }
Instead of the expecting warnings, wouldn't it be better to simply call
__builtin_abort () in fn ()?
> + struct S x;
> + x = fn ();
> +
> + if (x.a[0] != 42)
> + __builtin_abort ();
> +
> + if (fn ().a[0] != 42)
> + __builtin_abort ();
> +
> + __typeof__ (fn ()) *p = &x;
> + if (p->a[0] != 42)
> + __builtin_abort ();
> +
> + if (fn2 ().a[0] != 42)
> + __builtin_abort ();
And do these all just conditionally, say in a big switch on foo's parameter?
And, I'm really surprised that you haven't included the case of a call
without lhs at the source level, so just
fn ();
and
fn2 ();
somewhere.
> --- gcc/testsuite/gcc.dg/nested-func-9.c
> +++ gcc/testsuite/gcc.dg/nested-func-9.c
> @@ -0,0 +1,45 @@
> +/* PR c/70093 */
> +/* { dg-do run } */
> +/* { dg-options "" } */
> +
> +void
> +foo (int n)
> +{
> + struct S { int a[n]; };
> +
> + struct S
> + fn (void)
> + {
> + struct S s;
> + s.a[0] = 42;
> + return s;
> + }
> +
> + auto struct S
> + fn2 (void)
> + {
> + return fn ();
> + }
> +
> + struct S x;
> + x = fn ();
> +
> + if (x.a[0] != 42)
> + __builtin_abort ();
> +
> + if (fn ().a[0] != 42)
> + __builtin_abort ();
> +
> + __typeof__ (fn ()) *p = &x;
> + if (p->a[0] != 42)
> + __builtin_abort ();
> +
> + if (fn2 ().a[0] != 42)
> + __builtin_abort ();
Similarly here, I miss calls that don't use the return value.
Jakub