[Bug ipa/103766] [12 Regression] Initialization of variable passed via static chain is lost.

2021-12-21 Thread fxcoudert at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103766

Francois-Xavier Coudert  changed:

   What|Removed |Added

 CC||fxcoudert at gcc dot gnu.org

--- Comment #13 from Francois-Xavier Coudert  ---
I think this is a Fortran reproducer that does not depend on printing to
stdout:

program crash
  implicit none
  real :: a
  a = 1.
  call sub()
contains
  subroutine sub()
character(len=100) :: s
real :: x

write(s,*) a
read(s,*) x
if (x /= 1.) stop 1
  end subroutine sub
end program crash


It fails for me with trunk (before patch), but passed with 11.2.0
Could it be added to the testsuite please?

[Bug ipa/103766] [12 Regression] Initialization of variable passed via static chain is lost.

2021-12-19 Thread hubicka at kam dot mff.cuni.cz via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103766

--- Comment #12 from hubicka at kam dot mff.cuni.cz ---
> Even trying to find a Fortran testsuite friendly version is hard because the
> issue can only happen with print, I tried even doing internal write to a 
> string
> it is passing without any changes.
Yep, any reads that happen in the code visible to compiler will prevent
the bug from happening.   It is a hard case - but as I said I think
there is quite low chance of it going back.

[Bug ipa/103766] [12 Regression] Initialization of variable passed via static chain is lost.

2021-12-19 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103766

--- Comment #11 from Andrew Pinski  ---
(In reply to Iain Sandoe from comment #7)
> (In reply to Jan Hubicka from comment #6)
> 
> > I would welcome a testuite friendly version of the fortran testcase
> 
> Both Andrew and I failed to make a C reproducer - what about just taking the
> -fdump-tree-gimple, as input would that work ?

Even trying to find a Fortran testsuite friendly version is hard because the
issue can only happen with print, I tried even doing internal write to a string
it is passing without any changes.

[Bug ipa/103766] [12 Regression] Initialization of variable passed via static chain is lost.

2021-12-19 Thread hubicka at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103766

Jan Hubicka  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #10 from Jan Hubicka  ---
Fixed.

[Bug ipa/103766] [12 Regression] Initialization of variable passed via static chain is lost.

2021-12-19 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103766

--- Comment #9 from CVS Commits  ---
The master branch has been updated by Jan Hubicka :

https://gcc.gnu.org/g:fcbf94a5be9e0c1ecad92da773a6632b86b7f70a

commit r12-6067-gfcbf94a5be9e0c1ecad92da773a6632b86b7f70a
Author: Jan Hubicka 
Date:   Sun Dec 19 22:28:40 2021 +0100

Fix early exit in modref_merge_call_site_flags

When adding support for static chain and return slot flags I forgot to
update
early exit condition in modref_merge_call_site_flags.  This yields to wrong
code as demonstrated by the Fortran testcase attached to PR (which I hope
someone will help me to turn into testuite one).

gcc/ChangeLog:

2021-12-19  Jan Hubicka  

PR ipa/103766
* ipa-modref.c (modref_merge_call_site_flags): Fix early exit
condition

[Bug ipa/103766] [12 Regression] Initialization of variable passed via static chain is lost.

2021-12-19 Thread hubicka at kam dot mff.cuni.cz via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103766

--- Comment #8 from hubicka at kam dot mff.cuni.cz ---
> > I would welcome a testuite friendly version of the fortran testcase
> 
> Both Andrew and I failed to make a C reproducer - what about just taking the
> -fdump-tree-gimple, as input would that work ?
Me too.  The testcase depends on fnspec annotations produced by Fortran
so we get both noescape and noread to trigger the wrong code.  I guess
we may try to feed fnspec to gimple frontend but I am not even sure it
is possible, since fnspec is internal attribute

I suppose we can also live without a testcase - I hope I will not do
again such a stupid oversight.

[Bug ipa/103766] [12 Regression] Initialization of variable passed via static chain is lost.

2021-12-19 Thread iains at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103766

--- Comment #7 from Iain Sandoe  ---
(In reply to Jan Hubicka from comment #6)

> I would welcome a testuite friendly version of the fortran testcase

Both Andrew and I failed to make a C reproducer - what about just taking the
-fdump-tree-gimple, as input would that work ?

[Bug ipa/103766] [12 Regression] Initialization of variable passed via static chain is lost.

2021-12-19 Thread hubicka at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103766

--- Comment #6 from Jan Hubicka  ---
This is yet another stupid early exit in the propagation code (next stage1 i
guess I will want to go through them and make it more systematic - those
originate from quite early versions of modref when it was easier to rule out
cases where propagation is no longer useful)

I would welcome a testuite friendly version of the fortran testcase
diff --git a/gcc/ipa-modref.c b/gcc/ipa-modref.c
index d3590f0b62b..7152d66c251 100644
--- a/gcc/ipa-modref.c
+++ b/gcc/ipa-modref.c
@@ -5020,8 +5020,14 @@ modref_merge_call_site_flags (escape_summary *sum,
   bool ignore_stores = ignore_stores_p (caller, callee_ecf_flags);

   /* If we have no useful info to propagate.  */
-  if ((!cur_summary || !cur_summary->arg_flags.length ())
-  && (!cur_summary_lto || !cur_summary_lto->arg_flags.length ()))
+  if ((!cur_summary
+   || (!cur_summary->arg_flags.length ()
+  && !cur_summary->static_chain_flags
+  && !cur_summary->retslot_flags))
+  && (!cur_summary_lto
+ || (!cur_summary_lto->arg_flags.length ()
+ && !cur_summary_lto->static_chain_flags
+ && !cur_summary_lto->retslot_flags)))
 return false;

   FOR_EACH_VEC_ELT (sum->esc, i, ee)

[Bug ipa/103766] [12 Regression] Initialization of variable passed via static chain is lost.

2021-12-19 Thread hubicka at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103766

Jan Hubicka  changed:

   What|Removed |Added

   Assignee|unassigned at gcc dot gnu.org  |hubicka at gcc dot 
gnu.org
 Status|NEW |ASSIGNED

--- Comment #5 from Jan Hubicka  ---
There seems to be wrong no_direct_read flag on the static chain parameter
comming out of the ipa propagation.  I will take a look.

[Bug ipa/103766] [12 Regression] Initialization of variable passed via static chain is lost.

2021-12-19 Thread kargl at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103766

kargl at gcc dot gnu.org changed:

   What|Removed |Added

   Priority|P3  |P1
 CC||kargl at gcc dot gnu.org

--- Comment #4 from kargl at gcc dot gnu.org ---
Host association is fundamental to Fortran.
This has worked for 20 years.  Looks like a P1
issue.

[Bug ipa/103766] [12 Regression] Initialization of variable passed via static chain is lost.

2021-12-18 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103766

Andrew Pinski  changed:

   What|Removed |Added

 Ever confirmed|0   |1
   Last reconfirmed||2021-12-19
 Status|UNCONFIRMED |NEW

--- Comment #3 from Andrew Pinski  ---
-fno-ipa-modref fixes the issue though. 

I can't figure out why the store to the frame is being removed.

[Bug ipa/103766] [12 Regression] Initialization of variable passed via static chain is lost.

2021-12-18 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103766

--- Comment #2 from Andrew Pinski  ---
I tried to reproduce it with the following GNU C code but it still
worked:struct __st_parameter_dt
{
  const char *filename ;
  int linenum;
  int flags;
  int unit;
};
[[gnu::noinline, gnu::access(read_only, 1), gnu::access(read_only, 2, 3),
gnu::noclone, gnu::leaf]]
void print(struct __st_parameter_dt *b, void *a, int);
[[gnu::noinline, gnu::access(read_only, 1), gnu::noclone, gnu::leaf]]
void print1(struct __st_parameter_dt *b);
[[gnu::noinline, gnu::access(read_only, 1), gnu::noclone, gnu::leaf]]
void print2(struct __st_parameter_dt *b);

int main(void)
{
  double a;
  a = 1;
  [[gnu::noinline]]
  void f()
  {
  struct __st_parameter_dt b;
  b.filename = "a.c";
  b.linenum = 20;
  b.flags =128;
  b.unit = 1;
  print1();
  print(, , sizeof(a));
  print2();
  }
  f();
}