public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH 1/2] Fix PRs 106764, 106765, and 107307, all ICE after invalid re-declaration
@ 2022-11-18  3:25 apinski
  2022-11-18  3:25 ` [PATCH 2/2] Fix PR middle-end/107705: ICE after reclaration error apinski
  2022-11-18  8:46 ` [PATCH 1/2] Fix PRs 106764, 106765, and 107307, all ICE after invalid re-declaration Richard Biener
  0 siblings, 2 replies; 4+ messages in thread
From: apinski @ 2022-11-18  3:25 UTC (permalink / raw)
  To: gcc-patches; +Cc: Andrew Pinski

From: Andrew Pinski <apinski@marvell.com>

The problem here is the gimplifier returns GS_ERROR but
in some cases we don't check that soon enough and try
to do other work which could crash.
So the fix in these two cases is to return GS_ERROR
early if the gimplify_* functions had return GS_ERROR.

OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

Thanks,
Andrew Pinski

gcc/ChangeLog:

	PR c/106764
	PR c/106765
	PR c/107307
	* gimplify.cc (gimplify_compound_lval): Return GS_ERROR
	if gimplify_expr had return GS_ERROR.
	(gimplify_call_expr): Likewise.

gcc/testsuite/ChangeLog:

	PR c/106764
	PR c/106765
	PR c/107307
	* gcc.dg/redecl-19.c: New test.
	* gcc.dg/redecl-20.c: New test.
	* gcc.dg/redecl-21.c: New test.
---
 gcc/gimplify.cc                  | 5 +++++
 gcc/testsuite/gcc.dg/redecl-19.c | 5 +++++
 gcc/testsuite/gcc.dg/redecl-20.c | 9 +++++++++
 gcc/testsuite/gcc.dg/redecl-21.c | 9 +++++++++
 4 files changed, 28 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/redecl-19.c
 create mode 100644 gcc/testsuite/gcc.dg/redecl-20.c
 create mode 100644 gcc/testsuite/gcc.dg/redecl-21.c

diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index f06ce3cc77a..c62a966e918 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -3272,6 +3272,8 @@ gimplify_compound_lval (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
   tret = gimplify_expr (p, pre_p, post_p, is_gimple_min_lval,
 			fallback | fb_lvalue);
   ret = MIN (ret, tret);
+  if (ret == GS_ERROR)
+    return GS_ERROR;
 
   /* Step 2a: if we have component references we do not support on
      registers then make sure the base isn't a register.  Of course
@@ -3709,6 +3711,9 @@ gimplify_call_expr (tree *expr_p, gimple_seq *pre_p, bool want_value)
   ret = gimplify_expr (&CALL_EXPR_FN (*expr_p), pre_p, NULL,
 		       is_gimple_call_addr, fb_rvalue);
 
+  if (ret == GS_ERROR)
+    return GS_ERROR;
+
   nargs = call_expr_nargs (*expr_p);
 
   /* Get argument types for verification.  */
diff --git a/gcc/testsuite/gcc.dg/redecl-19.c b/gcc/testsuite/gcc.dg/redecl-19.c
new file mode 100644
index 00000000000..cc10685448b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/redecl-19.c
@@ -0,0 +1,5 @@
+/* We used to ICE in the gimplifier, PR 106764 */
+/* { dg-do compile } */
+/* { dg-options "-w" } */
+(*a)(); // { dg-note "" }
+b(){a()} a; // { dg-error "" }
diff --git a/gcc/testsuite/gcc.dg/redecl-20.c b/gcc/testsuite/gcc.dg/redecl-20.c
new file mode 100644
index 00000000000..07f52115ec8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/redecl-20.c
@@ -0,0 +1,9 @@
+/* We used to ICE in the gimplifier, PR 107307 */
+// { dg-do compile }
+// { dg-options "-w" }
+void f ()
+{
+  const struct { int a[1]; } b; // { dg-note "" }
+  int *c = b.a;
+  int *b; // { dg-error "" }
+}
diff --git a/gcc/testsuite/gcc.dg/redecl-21.c b/gcc/testsuite/gcc.dg/redecl-21.c
new file mode 100644
index 00000000000..2f2a6548a57
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/redecl-21.c
@@ -0,0 +1,9 @@
+/* We used to ICE in the gimplifier, PR 106765 */
+/* { dg-do compile } */
+/* { dg-options "-w" } */
+struct a {
+  int b
+} c() {
+  struct a a; // { dg-note "" }
+  a.b;
+  d a; // { dg-error "" }
-- 
2.17.1


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

* [PATCH 2/2] Fix PR middle-end/107705: ICE after reclaration error
  2022-11-18  3:25 [PATCH 1/2] Fix PRs 106764, 106765, and 107307, all ICE after invalid re-declaration apinski
@ 2022-11-18  3:25 ` apinski
  2022-11-18  8:45   ` Richard Biener
  2022-11-18  8:46 ` [PATCH 1/2] Fix PRs 106764, 106765, and 107307, all ICE after invalid re-declaration Richard Biener
  1 sibling, 1 reply; 4+ messages in thread
From: apinski @ 2022-11-18  3:25 UTC (permalink / raw)
  To: gcc-patches; +Cc: Andrew Pinski

From: Andrew Pinski <apinski@marvell.com>

The problem here is after we created a call expression
in the C front-end, we replace the decl type with
an error mark node. We then end up calling
aggregate_value_p with the call expression
with the decl with the error mark as the type
and we ICE.

The fix is to check the function type
after we process the call expression inside
aggregate_value_p to get it.

OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

Thanks,
Andrew Pinski

gcc/ChangeLog:

	PR middle-end/107705
	* function.cc (aggregate_value_p): Return 0 if
	the function type was an error operand.

gcc/testsuite/ChangeLog:

	* gcc.dg/redecl-22.c: New test.
---
 gcc/function.cc                  | 3 +++
 gcc/testsuite/gcc.dg/redecl-22.c | 9 +++++++++
 2 files changed, 12 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/redecl-22.c

diff --git a/gcc/function.cc b/gcc/function.cc
index 361aa5f7ed1..9c8773bbc59 100644
--- a/gcc/function.cc
+++ b/gcc/function.cc
@@ -2090,6 +2090,9 @@ aggregate_value_p (const_tree exp, const_tree fntype)
   if (VOID_TYPE_P (type))
     return 0;
 
+  if (error_operand_p (fntype))
+    return 0;
+
   /* If a record should be passed the same as its first (and only) member
      don't pass it as an aggregate.  */
   if (TREE_CODE (type) == RECORD_TYPE && TYPE_TRANSPARENT_AGGR (type))
diff --git a/gcc/testsuite/gcc.dg/redecl-22.c b/gcc/testsuite/gcc.dg/redecl-22.c
new file mode 100644
index 00000000000..7758570fabe
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/redecl-22.c
@@ -0,0 +1,9 @@
+/* We used to ICE in the gimplifier, PR 107705 */
+/* { dg-do compile } */
+/* { dg-options "-w" } */
+int f (void)
+{
+  int (*p) (void) = 0; // { dg-note "" }
+  return p ();
+  int p = 1; // { dg-error "" }
+}
-- 
2.17.1


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

* Re: [PATCH 2/2] Fix PR middle-end/107705: ICE after reclaration error
  2022-11-18  3:25 ` [PATCH 2/2] Fix PR middle-end/107705: ICE after reclaration error apinski
@ 2022-11-18  8:45   ` Richard Biener
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Biener @ 2022-11-18  8:45 UTC (permalink / raw)
  To: apinski; +Cc: gcc-patches

On Fri, Nov 18, 2022 at 4:26 AM apinski--- via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> From: Andrew Pinski <apinski@marvell.com>
>
> The problem here is after we created a call expression
> in the C front-end, we replace the decl type with
> an error mark node. We then end up calling
> aggregate_value_p with the call expression
> with the decl with the error mark as the type
> and we ICE.
>
> The fix is to check the function type
> after we process the call expression inside
> aggregate_value_p to get it.
>
> OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

OK.

> Thanks,
> Andrew Pinski
>
> gcc/ChangeLog:
>
>         PR middle-end/107705
>         * function.cc (aggregate_value_p): Return 0 if
>         the function type was an error operand.
>
> gcc/testsuite/ChangeLog:
>
>         * gcc.dg/redecl-22.c: New test.
> ---
>  gcc/function.cc                  | 3 +++
>  gcc/testsuite/gcc.dg/redecl-22.c | 9 +++++++++
>  2 files changed, 12 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.dg/redecl-22.c
>
> diff --git a/gcc/function.cc b/gcc/function.cc
> index 361aa5f7ed1..9c8773bbc59 100644
> --- a/gcc/function.cc
> +++ b/gcc/function.cc
> @@ -2090,6 +2090,9 @@ aggregate_value_p (const_tree exp, const_tree fntype)
>    if (VOID_TYPE_P (type))
>      return 0;
>
> +  if (error_operand_p (fntype))
> +    return 0;
> +
>    /* If a record should be passed the same as its first (and only) member
>       don't pass it as an aggregate.  */
>    if (TREE_CODE (type) == RECORD_TYPE && TYPE_TRANSPARENT_AGGR (type))
> diff --git a/gcc/testsuite/gcc.dg/redecl-22.c b/gcc/testsuite/gcc.dg/redecl-22.c
> new file mode 100644
> index 00000000000..7758570fabe
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/redecl-22.c
> @@ -0,0 +1,9 @@
> +/* We used to ICE in the gimplifier, PR 107705 */
> +/* { dg-do compile } */
> +/* { dg-options "-w" } */
> +int f (void)
> +{
> +  int (*p) (void) = 0; // { dg-note "" }
> +  return p ();
> +  int p = 1; // { dg-error "" }
> +}
> --
> 2.17.1
>

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

* Re: [PATCH 1/2] Fix PRs 106764, 106765, and 107307, all ICE after invalid re-declaration
  2022-11-18  3:25 [PATCH 1/2] Fix PRs 106764, 106765, and 107307, all ICE after invalid re-declaration apinski
  2022-11-18  3:25 ` [PATCH 2/2] Fix PR middle-end/107705: ICE after reclaration error apinski
@ 2022-11-18  8:46 ` Richard Biener
  1 sibling, 0 replies; 4+ messages in thread
From: Richard Biener @ 2022-11-18  8:46 UTC (permalink / raw)
  To: apinski; +Cc: gcc-patches

On Fri, Nov 18, 2022 at 4:26 AM apinski--- via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> From: Andrew Pinski <apinski@marvell.com>
>
> The problem here is the gimplifier returns GS_ERROR but
> in some cases we don't check that soon enough and try
> to do other work which could crash.
> So the fix in these two cases is to return GS_ERROR
> early if the gimplify_* functions had return GS_ERROR.
>
> OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

OK.

> Thanks,
> Andrew Pinski
>
> gcc/ChangeLog:
>
>         PR c/106764
>         PR c/106765
>         PR c/107307
>         * gimplify.cc (gimplify_compound_lval): Return GS_ERROR
>         if gimplify_expr had return GS_ERROR.
>         (gimplify_call_expr): Likewise.
>
> gcc/testsuite/ChangeLog:
>
>         PR c/106764
>         PR c/106765
>         PR c/107307
>         * gcc.dg/redecl-19.c: New test.
>         * gcc.dg/redecl-20.c: New test.
>         * gcc.dg/redecl-21.c: New test.
> ---
>  gcc/gimplify.cc                  | 5 +++++
>  gcc/testsuite/gcc.dg/redecl-19.c | 5 +++++
>  gcc/testsuite/gcc.dg/redecl-20.c | 9 +++++++++
>  gcc/testsuite/gcc.dg/redecl-21.c | 9 +++++++++
>  4 files changed, 28 insertions(+)
>  create mode 100644 gcc/testsuite/gcc.dg/redecl-19.c
>  create mode 100644 gcc/testsuite/gcc.dg/redecl-20.c
>  create mode 100644 gcc/testsuite/gcc.dg/redecl-21.c
>
> diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
> index f06ce3cc77a..c62a966e918 100644
> --- a/gcc/gimplify.cc
> +++ b/gcc/gimplify.cc
> @@ -3272,6 +3272,8 @@ gimplify_compound_lval (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p,
>    tret = gimplify_expr (p, pre_p, post_p, is_gimple_min_lval,
>                         fallback | fb_lvalue);
>    ret = MIN (ret, tret);
> +  if (ret == GS_ERROR)
> +    return GS_ERROR;
>
>    /* Step 2a: if we have component references we do not support on
>       registers then make sure the base isn't a register.  Of course
> @@ -3709,6 +3711,9 @@ gimplify_call_expr (tree *expr_p, gimple_seq *pre_p, bool want_value)
>    ret = gimplify_expr (&CALL_EXPR_FN (*expr_p), pre_p, NULL,
>                        is_gimple_call_addr, fb_rvalue);
>
> +  if (ret == GS_ERROR)
> +    return GS_ERROR;
> +
>    nargs = call_expr_nargs (*expr_p);
>
>    /* Get argument types for verification.  */
> diff --git a/gcc/testsuite/gcc.dg/redecl-19.c b/gcc/testsuite/gcc.dg/redecl-19.c
> new file mode 100644
> index 00000000000..cc10685448b
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/redecl-19.c
> @@ -0,0 +1,5 @@
> +/* We used to ICE in the gimplifier, PR 106764 */
> +/* { dg-do compile } */
> +/* { dg-options "-w" } */
> +(*a)(); // { dg-note "" }
> +b(){a()} a; // { dg-error "" }
> diff --git a/gcc/testsuite/gcc.dg/redecl-20.c b/gcc/testsuite/gcc.dg/redecl-20.c
> new file mode 100644
> index 00000000000..07f52115ec8
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/redecl-20.c
> @@ -0,0 +1,9 @@
> +/* We used to ICE in the gimplifier, PR 107307 */
> +// { dg-do compile }
> +// { dg-options "-w" }
> +void f ()
> +{
> +  const struct { int a[1]; } b; // { dg-note "" }
> +  int *c = b.a;
> +  int *b; // { dg-error "" }
> +}
> diff --git a/gcc/testsuite/gcc.dg/redecl-21.c b/gcc/testsuite/gcc.dg/redecl-21.c
> new file mode 100644
> index 00000000000..2f2a6548a57
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/redecl-21.c
> @@ -0,0 +1,9 @@
> +/* We used to ICE in the gimplifier, PR 106765 */
> +/* { dg-do compile } */
> +/* { dg-options "-w" } */
> +struct a {
> +  int b
> +} c() {
> +  struct a a; // { dg-note "" }
> +  a.b;
> +  d a; // { dg-error "" }
> --
> 2.17.1
>

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

end of thread, other threads:[~2022-11-18  8:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-18  3:25 [PATCH 1/2] Fix PRs 106764, 106765, and 107307, all ICE after invalid re-declaration apinski
2022-11-18  3:25 ` [PATCH 2/2] Fix PR middle-end/107705: ICE after reclaration error apinski
2022-11-18  8:45   ` Richard Biener
2022-11-18  8:46 ` [PATCH 1/2] Fix PRs 106764, 106765, and 107307, all ICE after invalid re-declaration Richard Biener

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).