[Bug c++/80613] [8 Regression] ICE in is_gimple_reg_type with -O2

2017-05-04 Thread prathamesh3492 at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80613

--- Comment #7 from prathamesh3492 at gcc dot gnu.org ---
Created attachment 41313
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41313=edit
untested fix

Hi,
The issue can be reproduced with following test-case:

char f(void)
{
  char *a();
  void bar(char *);

  char d = *a();
  char *p = __builtin_strdup ();
  __builtin_free (p);
  bar ();
}

cddce1 marks the call to __builtin_strdup as necessary:
marking necessary through .MEM_6 stmt p_7 = __builtin_strdup ();

and since p_7 doesn't get added to worklist in propagate_necessity
because it's used only within free(), it's treated as "dead"
and wrongly gets released.
The patch fixes that by adding strdup/strndup in corresponding condition
in eliminate_unnecessary_stmts.

I am not sure though why call to strdup is marked necessary.
I suppose it's safe to remove calls to strdup and free in above case since
strdup won't modify d ?

Another issue I found was that my patch failed to remove multiple calls to
strdup:
char *f(char **tt)
{
  char *t = *tt;
  char *p;

  p = __builtin_strdup (t);
  p = __builtin_strdup (t);
  return p;
}

That's fixed in patch by adding strdup/strndup to another corresponding
condition in propagate_necessity
so that only one instance of strdup would be kept.

Validation in progress, will post it to the list if it passes.

Thanks,
Prathamesh

[Bug c++/80613] [8 Regression] ICE in is_gimple_reg_type with -O2

2017-05-04 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80613

--- Comment #6 from Richard Biener  ---
Hmm, cddce leaves us with free (_11) and the def of _11 removed.  _11 was

Deleting LHS of call: _11 = strdup ();

so caused by

2017-04-29  Prathamesh Kulkarni  

PR tree-optimization/79697
* tree-ssa-dce.c (mark_stmt_if_obviously_necessary): Check if callee
is BUILT_IN_STRDUP, BUILT_IN_STRNDUP, BUILT_IN_REALLOC.
(propagate_necessity): Check if def_callee is BUILT_IN_STRDUP or
BUILT_IN_STRNDUP.
* gimple-fold.c (gimple_fold_builtin_realloc): New function.
(gimple_fold_builtin): Call gimple_fold_builtin_realloc.

which failed to update BUILT_IN_FREE handling properly.

[Bug c++/80613] [8 Regression] ICE in is_gimple_reg_type with -O2

2017-05-04 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80613

Richard Biener  changed:

   What|Removed |Added

   Priority|P3  |P1
Version|7.0 |8.0
   Target Milestone|--- |8.0

[Bug c++/80613] [8 Regression] ICE in is_gimple_reg_type with -O2

2017-05-04 Thread prathamesh3492 at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80613

--- Comment #5 from prathamesh3492 at gcc dot gnu.org ---
Sorry for the breakage, I will take a look.

Regards,
Prathamesh

[Bug c++/80613] [8 Regression] ICE in is_gimple_reg_type with -O2

2017-05-04 Thread marxin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80613

Martin Liška  changed:

   What|Removed |Added

Summary|8ice in is_gimple_reg_type  |[8 Regression] ICE in
   |with -O2|is_gimple_reg_type with -O2

--- Comment #4 from Martin Liška  ---
Confirmed, started with r247407.