On Fri, Apr 29, 2022 at 11:52:37AM +0200, Richard Biener wrote:
> On Fri, 29 Apr 2022, Jakub Jelinek wrote:
>
> > On Fri, Apr 29, 2022 at 11:32:15AM +0200, Richard Biener wrote:
> > > I think that's reasonable (we indeed shouldn't create a varpool node
> > > here). I do think that we eventually want to retain removed nodes
> > > but mark them so. In fact any debug references will be thrown away
> > > because of this anyway.
> > >
> > > So I wonder if we can instead simply do if (!x_node) return 0;?
> >
> > I had that in my first version, but after finding out that it triggers
> > so often for the constant pool decls I thought better to just use
> > x_decl in that case instead of x_node->decl.
> > I must say I'm unsure if constant pool decls always stay out of section
> > anchors or if they can be put there too.
> >
> > > The question is also why sched does any queries for debug-insns,
> > > does it merely reset them based on the answer? That said,
> > > it would be nice to be able to assert that x_node is not NULL
> > > and catch this in the callers somehow.
> >
> > Unfortunately, several layers of callers don't really know it is for debug
> > insn. And the touched code is solely for the section anchors, so e.g. just
> > checking symtab_node::get (decl) on all mentioned decls when we perhaps can
> > see if it is debug insn or not would be quite costly and we wouldn't know
> > if the other reference is anchored.
>
> We might want to reset debug stmts at the time we RTL expand them
> if referred symbols have no cgraph node? As said, ->get () instead
> of ->get_create () is obviously OK but the way we deal with the fallout
> is a bit suspicious there IMHO.
So, what about doing that if (!x_node) return 0; in alias.c with the
exception of DECL_IN_CONSTANT_POOL, plus in cfgexpand.cc throw away
VAR_DECLs without symtab node?
I'll need to do some extra checking on whether we don't really lose any
useful debug info with the second patch.
Jakub
2022-04-29 Jakub Jelinek <[email protected]>
PR debug/105415
* alias.cc (compare_base_symbol_refs): Avoid creating new symtab
nodes, if it doesn't exist, punt. For DECL_IN_CONSTANT_POOL decls
use x_decl instead of x_node->decl.
* gcc.dg/pr105415.c: New test.
--- gcc/alias.cc.jj 2022-02-21 16:51:50.261232505 +0100
+++ gcc/alias.cc 2022-04-29 12:25:02.022392689 +0200
@@ -2219,12 +2219,19 @@ compare_base_symbol_refs (const_rtx x_ba
|| (!TREE_STATIC (x_decl) && !TREE_PUBLIC (x_decl)))
return 0;
- symtab_node *x_node = symtab_node::get_create (x_decl)
- ->ultimate_alias_target ();
- /* External variable cannot be in section anchor. */
- if (!x_node->definition)
- return 0;
- x_base = XEXP (DECL_RTL (x_node->decl), 0);
+ tree x_decl2 = x_decl;
+ if (!DECL_IN_CONSTANT_POOL (x_decl))
+ {
+ symtab_node *x_node = symtab_node::get (x_decl);
+ if (!x_node)
+ return 0;
+ x_node = x_node->ultimate_alias_target ();
+ /* External variable cannot be in section anchor. */
+ if (!x_node->definition)
+ return 0;
+ x_decl2 = x_node->decl;
+ }
+ x_base = XEXP (DECL_RTL (x_decl2), 0);
/* If not in anchor, we can disambiguate. */
if (!SYMBOL_REF_HAS_BLOCK_INFO_P (x_base))
return 0;
--- gcc/testsuite/gcc.dg/pr105415.c.jj 2022-04-28 12:26:13.174302870 +0200
+++ gcc/testsuite/gcc.dg/pr105415.c 2022-04-28 12:25:36.770809149 +0200
@@ -0,0 +1,26 @@
+/* PR debug/105415 */
+/* { dg-do compile } */
+/* { dg-require-effective-target pthread } */
+/* { dg-options "-O2 -ftree-parallelize-loops=2 -fcompare-debug" } */
+
+int m;
+static int n;
+
+void
+foo (void)
+{
+ int s = 0;
+
+ while (m < 1)
+ {
+ s += n;
+ ++m;
+ }
+}
+
+void
+bar (int *arr, int i)
+{
+ while (i < 1)
+ arr[i++] = 1;
+}
2022-04-29 Jakub Jelinek <[email protected]>
* cfgexpand.cc (expand_debug_expr): Don't make_decl_rtl_for_debug
if there is no symtab node for the VAR_DECL.
--- gcc/cfgexpand.cc.jj 2022-03-09 19:54:17.112284770 +0100
+++ gcc/cfgexpand.cc 2022-04-29 12:33:32.585363999 +0200
@@ -4565,7 +4565,8 @@ expand_debug_expr (tree exp)
|| !DECL_NAME (exp)
|| DECL_HARD_REGISTER (exp)
|| DECL_IN_CONSTANT_POOL (exp)
- || mode == VOIDmode)
+ || mode == VOIDmode
+ || symtab_node::get (exp) == NULL)
return NULL;
op0 = make_decl_rtl_for_debug (exp);