public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] ipa: Check cst type when propagating controled uses info (PR 105639)
@ 2022-05-26 14:47 Martin Jambor
  2022-05-27  6:40 ` Richard Biener
  0 siblings, 1 reply; 3+ messages in thread
From: Martin Jambor @ 2022-05-26 14:47 UTC (permalink / raw)
  To: GCC Patches; +Cc: Jan Hubicka, Martin Liska

Hi,

PR 105639 shows that code with type-mismatches can trigger an assert
after runnning into a branch that was inteded only for references to
variables - as opposed to references to functions.  Fixed by moving
the condition from the assert to the guarding if statement.

Bootstrapped and tested on x86_64.  OK for trunk and then gcc 12?

Thanks,

Martin



gcc/ChangeLog:

2022-05-25  Martin Jambor  <mjambor@suse.cz>

	PR ipa/105639
	* ipa-prop.cc (propagate_controlled_uses): Check type of the
	constant before adding a LOAD reference.

gcc/testsuite/ChangeLog:

2022-05-25  Martin Jambor  <mjambor@suse.cz>

	PR ipa/105639
	* gcc.dg/ipa/pr105639.c: New test.
---
 gcc/ipa-prop.cc                     | 10 ++++------
 gcc/testsuite/gcc.dg/ipa/pr105639.c | 16 ++++++++++++++++
 2 files changed, 20 insertions(+), 6 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/ipa/pr105639.c

diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
index c6c745f84a0..afd9222b5a2 100644
--- a/gcc/ipa-prop.cc
+++ b/gcc/ipa-prop.cc
@@ -4187,14 +4187,13 @@ propagate_controlled_uses (struct cgraph_edge *cs)
 	{
 	  int d = ipa_get_controlled_uses (old_root_info, i);
 	  int c = rdesc->refcount;
+	  tree cst = ipa_get_jf_constant (jf);
 	  rdesc->refcount = combine_controlled_uses_counters (c, d);
 	  if (rdesc->refcount != IPA_UNDESCRIBED_USE
-	      && ipa_get_param_load_dereferenced (old_root_info, i))
+	      && ipa_get_param_load_dereferenced (old_root_info, i)
+	      && TREE_CODE (cst) == ADDR_EXPR
+	      && TREE_CODE (TREE_OPERAND (cst, 0)) == VAR_DECL)
 	    {
-	      tree cst = ipa_get_jf_constant (jf);
-	      gcc_checking_assert (TREE_CODE (cst) == ADDR_EXPR
-				   && (TREE_CODE (TREE_OPERAND (cst, 0))
-				       == VAR_DECL));
 	      symtab_node *n = symtab_node::get (TREE_OPERAND (cst, 0));
 	      new_root->create_reference (n, IPA_REF_LOAD, NULL);
 	      if (dump_file)
@@ -4204,7 +4203,6 @@ propagate_controlled_uses (struct cgraph_edge *cs)
 	    }
 	  if (rdesc->refcount == 0)
 	    {
-	      tree cst = ipa_get_jf_constant (jf);
 	      gcc_checking_assert (TREE_CODE (cst) == ADDR_EXPR
 				   && ((TREE_CODE (TREE_OPERAND (cst, 0))
 					== FUNCTION_DECL)
diff --git a/gcc/testsuite/gcc.dg/ipa/pr105639.c b/gcc/testsuite/gcc.dg/ipa/pr105639.c
new file mode 100644
index 00000000000..5534fe93fbf
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/ipa/pr105639.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O -w" } */
+
+void typedef (*cb) (void);
+
+static void
+bar (cb *fp)
+{
+  (*fp) ();
+}
+
+void
+foo (void)
+{
+  bar (foo);
+}
-- 
2.36.0


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

* Re: [PATCH] ipa: Check cst type when propagating controled uses info (PR 105639)
  2022-05-26 14:47 [PATCH] ipa: Check cst type when propagating controled uses info (PR 105639) Martin Jambor
@ 2022-05-27  6:40 ` Richard Biener
  2022-05-27 10:19   ` Martin Jambor
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Biener @ 2022-05-27  6:40 UTC (permalink / raw)
  To: Martin Jambor; +Cc: GCC Patches, Jan Hubicka

On Thu, May 26, 2022 at 4:47 PM Martin Jambor <mjambor@suse.cz> wrote:
>
> Hi,
>
> PR 105639 shows that code with type-mismatches can trigger an assert
> after runnning into a branch that was inteded only for references to
> variables - as opposed to references to functions.  Fixed by moving
> the condition from the assert to the guarding if statement.
>
> Bootstrapped and tested on x86_64.  OK for trunk and then gcc 12?

OK.  There's the same assert below - I guess that doesn't need the same
treatment?

Thanks,
Richard.

> Thanks,
>
> Martin
>
>
>
> gcc/ChangeLog:
>
> 2022-05-25  Martin Jambor  <mjambor@suse.cz>
>
>         PR ipa/105639
>         * ipa-prop.cc (propagate_controlled_uses): Check type of the
>         constant before adding a LOAD reference.
>
> gcc/testsuite/ChangeLog:
>
> 2022-05-25  Martin Jambor  <mjambor@suse.cz>
>
>         PR ipa/105639
>         * gcc.dg/ipa/pr105639.c: New test.
> ---
>  gcc/ipa-prop.cc                     | 10 ++++------
>  gcc/testsuite/gcc.dg/ipa/pr105639.c | 16 ++++++++++++++++
>  2 files changed, 20 insertions(+), 6 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.dg/ipa/pr105639.c
>
> diff --git a/gcc/ipa-prop.cc b/gcc/ipa-prop.cc
> index c6c745f84a0..afd9222b5a2 100644
> --- a/gcc/ipa-prop.cc
> +++ b/gcc/ipa-prop.cc
> @@ -4187,14 +4187,13 @@ propagate_controlled_uses (struct cgraph_edge *cs)
>         {
>           int d = ipa_get_controlled_uses (old_root_info, i);
>           int c = rdesc->refcount;
> +         tree cst = ipa_get_jf_constant (jf);
>           rdesc->refcount = combine_controlled_uses_counters (c, d);
>           if (rdesc->refcount != IPA_UNDESCRIBED_USE
> -             && ipa_get_param_load_dereferenced (old_root_info, i))
> +             && ipa_get_param_load_dereferenced (old_root_info, i)
> +             && TREE_CODE (cst) == ADDR_EXPR
> +             && TREE_CODE (TREE_OPERAND (cst, 0)) == VAR_DECL)
>             {
> -             tree cst = ipa_get_jf_constant (jf);
> -             gcc_checking_assert (TREE_CODE (cst) == ADDR_EXPR
> -                                  && (TREE_CODE (TREE_OPERAND (cst, 0))
> -                                      == VAR_DECL));
>               symtab_node *n = symtab_node::get (TREE_OPERAND (cst, 0));
>               new_root->create_reference (n, IPA_REF_LOAD, NULL);
>               if (dump_file)
> @@ -4204,7 +4203,6 @@ propagate_controlled_uses (struct cgraph_edge *cs)
>             }
>           if (rdesc->refcount == 0)
>             {
> -             tree cst = ipa_get_jf_constant (jf);
>               gcc_checking_assert (TREE_CODE (cst) == ADDR_EXPR
>                                    && ((TREE_CODE (TREE_OPERAND (cst, 0))
>                                         == FUNCTION_DECL)
> diff --git a/gcc/testsuite/gcc.dg/ipa/pr105639.c b/gcc/testsuite/gcc.dg/ipa/pr105639.c
> new file mode 100644
> index 00000000000..5534fe93fbf
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/ipa/pr105639.c
> @@ -0,0 +1,16 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O -w" } */
> +
> +void typedef (*cb) (void);
> +
> +static void
> +bar (cb *fp)
> +{
> +  (*fp) ();
> +}
> +
> +void
> +foo (void)
> +{
> +  bar (foo);
> +}
> --
> 2.36.0
>

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

* Re: [PATCH] ipa: Check cst type when propagating controled uses info (PR 105639)
  2022-05-27  6:40 ` Richard Biener
@ 2022-05-27 10:19   ` Martin Jambor
  0 siblings, 0 replies; 3+ messages in thread
From: Martin Jambor @ 2022-05-27 10:19 UTC (permalink / raw)
  To: Richard Biener; +Cc: GCC Patches, Jan Hubicka

Hi,

On Fri, May 27 2022, Richard Biener wrote:
> On Thu, May 26, 2022 at 4:47 PM Martin Jambor <mjambor@suse.cz> wrote:
>>
>> Hi,
>>
>> PR 105639 shows that code with type-mismatches can trigger an assert
>> after runnning into a branch that was inteded only for references to
>> variables - as opposed to references to functions.  Fixed by moving
>> the condition from the assert to the guarding if statement.
>>
>> Bootstrapped and tested on x86_64.  OK for trunk and then gcc 12?
>
> OK.  There's the same assert below - I guess that doesn't need the same
> treatment?

Thanks.  The assert below also allows the case when cst is an ADDR_EXPR of
a function.  And the whole reference-counting is initiated only for
these two cases.  So in all other cases the condition

  rdesc->refcount != IPA_UNDESCRIBED_USE

will be false.

Martin

>>
>>
>> gcc/ChangeLog:
>>
>> 2022-05-25  Martin Jambor  <mjambor@suse.cz>
>>
>>         PR ipa/105639
>>         * ipa-prop.cc (propagate_controlled_uses): Check type of the
>>         constant before adding a LOAD reference.
>>
>> gcc/testsuite/ChangeLog:
>>
>> 2022-05-25  Martin Jambor  <mjambor@suse.cz>
>>
>>         PR ipa/105639
>>         * gcc.dg/ipa/pr105639.c: New test.

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

end of thread, other threads:[~2022-05-27 10:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-26 14:47 [PATCH] ipa: Check cst type when propagating controled uses info (PR 105639) Martin Jambor
2022-05-27  6:40 ` Richard Biener
2022-05-27 10:19   ` Martin Jambor

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