public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jan Hubicka <hubicka@kam.mff.cuni.cz>
To: Martin Sebor <msebor@gmail.com>
Cc: "Martin Liška" <mliska@suse.cz>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] Fix IPA modref ubsan.
Date: Thu, 18 Nov 2021 17:22:03 +0100	[thread overview]
Message-ID: <20211118162203.GA76860@kam.mff.cuni.cz> (raw)
In-Reply-To: <3969b362-f4e1-a2fe-8feb-6fda99131122@gmail.com>

> On 11/18/21 5:41 AM, Jan Hubicka via Gcc-patches wrote:
> > > modref_tree<tree_node*>::merge(modref_tree<tree_node*>*, vec<modref_parm_map, va_heap, vl_ptr>*, modref_parm_map*, bool)
> > > 
> > > is called with modref_parm_map chain_map;
> > > 
> > > The variable has uninitialized m.parm_offset_known and it is accessed
> > > here:
> > > 
> > > gcc/ipa-modref-tree.h:572 a.parm_offset_known &= m.parm_offset_known;
> > > 
> > > Ready to be installed after testing?
> > > Thanks,
> > > Martin
> > > 
> > > 	PR ipa/103230
> > > 
> > > gcc/ChangeLog:
> > > 
> > > 	* ipa-modref-tree.h (struct modref_parm_map): Add default
> > > 	constructor.
> > > 	* ipa-modref.c (ipa_merge_modref_summary_after_inlining): Use it.
> > > ---
> > >   gcc/ipa-modref-tree.h | 5 +++++
> > >   gcc/ipa-modref.c      | 3 +--
> > >   2 files changed, 6 insertions(+), 2 deletions(-)
> > > 
> > > diff --git a/gcc/ipa-modref-tree.h b/gcc/ipa-modref-tree.h
> > > index 0a097349ebd..6796e6ecc34 100644
> > > --- a/gcc/ipa-modref-tree.h
> > > +++ b/gcc/ipa-modref-tree.h
> > > @@ -287,6 +287,11 @@ struct GTY((user)) modref_base_node
> > >   struct modref_parm_map
> > >   {
> > > +  /* Default constructor.  */
> > > +  modref_parm_map ()
> > > +  : parm_index (MODREF_UNKNOWN_PARM), parm_offset_known (false), parm_offset ()
> > > +  {}
> > > +
> > I think we are generally not supposed to put non-pods to vec<..>
> 
> I don't know what the guidance is on using vec in IPA passes
> but with respect to existing practice elsewhere, there are
> existing uses of vec and auto_vec with non-POD types and vec
> does work with them  (see the vec_default_construct and
> vec_copy_construct templates, for example, whose goal is
> to support nontrivial classes).

I see, since 2017 :).  The patch is OK then.
Nontrivial destructors also behave in a sane way these days?

Honza
> 
> Martin
> 
> > The diagnostics should be from
> > 			a.parm_offset_known &= m.parm_offset_known;
> > Becasue both in the parm_map (which is variable m) and access_node
> > (which is variable a) the parm_offset_known has no meaning when
> > parm_index == MODREF_UNKNOWN_PARM.
> > 
> > If we want to avoid computing on these, perhaps this will work?
> > 
> > diff --git a/gcc/ipa-modref-tree.h b/gcc/ipa-modref-tree.h
> > index 0a097349ebd..97736d0d8a4 100644
> > --- a/gcc/ipa-modref-tree.h
> > +++ b/gcc/ipa-modref-tree.h
> > @@ -568,9 +568,13 @@ struct GTY((user)) modref_tree
> >   				      : (*parm_map) [a.parm_index];
> >   			    if (m.parm_index == MODREF_LOCAL_MEMORY_PARM)
> >   			      continue;
> > -			    a.parm_offset += m.parm_offset;
> > -			    a.parm_offset_known &= m.parm_offset_known;
> >   			    a.parm_index = m.parm_index;
> > +			    if (a.parm_index != MODREF_UNKNOWN_PARM)
> > +			      {
> > +				a.parm_offset_known &= m.parm_offset_known;
> > +				if (a.parm_offset_known)
> > +				  a.parm_offset += m.parm_offset;
> > +			      }
> >   			  }
> >   		      }
> >   		    changed |= insert (base_node->base, ref_node->ref, a,
> > >     /* Index of parameter we translate to.
> > >        Values from special_params enum are permitted too.  */
> > >     int parm_index;
> > > diff --git a/gcc/ipa-modref.c b/gcc/ipa-modref.c
> > > index c94f0589d44..630d202d5cf 100644
> > > --- a/gcc/ipa-modref.c
> > > +++ b/gcc/ipa-modref.c
> > > @@ -5020,8 +5020,7 @@ ipa_merge_modref_summary_after_inlining (cgraph_edge *edge)
> > >         auto_vec <modref_parm_map, 32> parm_map;
> > >         modref_parm_map chain_map;
> > >         /* TODO: Once we get jump functions for static chains we could
> > > -	 compute this.  */
> > > -      chain_map.parm_index = MODREF_UNKNOWN_PARM;
> > > +	 compute parm_index.  */
> > >         compute_parm_map (edge, &parm_map);
> > > -- 
> > > 2.33.1
> > > 
> 

  reply	other threads:[~2021-11-18 16:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-18 12:35 Martin Liška
2021-11-18 12:41 ` Jan Hubicka
2021-11-18 15:48   ` Martin Sebor
2021-11-18 16:22     ` Jan Hubicka [this message]
2021-11-18 16:54       ` Martin Sebor
2021-11-18 17:10         ` Jan Hubicka
2021-11-19 16:10           ` Martin Sebor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211118162203.GA76860@kam.mff.cuni.cz \
    --to=hubicka@kam.mff.cuni.cz \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=mliska@suse.cz \
    --cc=msebor@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).