[Bug tree-optimization/92867] Use ERF_RETURNS_ARG in more places

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

Andrew Pinski  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |DUPLICATE

--- Comment #7 from Andrew Pinski  ---
Dup of bug 67797.

*** This bug has been marked as a duplicate of bug 67797 ***

[Bug tree-optimization/92867] Use ERF_RETURNS_ARG in more places

2021-05-04 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92867

Richard Biener  changed:

   What|Removed |Added

 Status|NEW |ASSIGNED

[Bug tree-optimization/92867] Use ERF_RETURNS_ARG in more places

2019-12-09 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92867

Martin Sebor  changed:

   What|Removed |Added

 CC||msebor at gcc dot gnu.org

--- Comment #6 from Martin Sebor  ---
The "returns-argument" attribute should also be used to help detect buffer
overflow after returning from functions declared with it (either built-ins or
user-defined):

__attribute__ ((returns_arg (1))) char* f (char*);

char a[4], b[8];

void g (void)
{
  memcpy (b, f (a), sizeof b);   // reads 8 bytes from a
}

[Bug tree-optimization/92867] Use ERF_RETURNS_ARG in more places

2019-12-09 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92867

--- Comment #5 from Jakub Jelinek  ---
GCC already has various attributes that take argument positions, e.g. the
nonnull, alloc_size, format, format_arg, so we should follow what is used for
those for this argument.
E.g. for format_arg we document:
 The parameter STRING-INDEX specifies which argument is the format
 string argument (starting from one).  Since non-static C++ methods
 have an implicit 'this' argument, the arguments of such methods
 should be counted from two.
and similarly for format, for nonnull and alloc_size we don't, so it might be
worth checking what we actually do.
There is also the case of an artificial argument holding address to the return
slot, I think that is what comes up only in RTL and would hope RTL handles it
right, but it is worth checking that too.

[Bug tree-optimization/92867] Use ERF_RETURNS_ARG in more places

2019-12-09 Thread drepper.fsp+rhbz at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92867

Ulrich Drepper  changed:

   What|Removed |Added

 CC||drepper.fsp+rhbz at gmail dot 
com

--- Comment #4 from Ulrich Drepper  ---
This BZ came out of a discussion around C++ function call chaining along the
line of:

void f1(std::string& s, int a)
{
  std::cout << "hello " << s;
  if (a != 0)
std::cout << a;
  std::cout << '\n';
}

The 'if' prevents one single series of calls through operator<< from being used
and the compiler has reload std::cout from memory every time.  There are ugly
work-arounds in the source to get the desired behaviour but this should happen
automatically.  The work-arounds are too ugly and there is lots of code out
there.

One way would be to expose a way to specify one of the arguments is returned. 
Jakub mentioned that there is already internally a way to use the "fn spec"
attribute.  How about exposing this explicitly as a function attribute?

Jakub also raised the point how this should be applied to member functions.  I
suggest that the parameter for the attribute is really a number (not parameter
name) and that argument 1 (or 0, if you want the count start at zero) refers to
'this' in case of member functions.

How about this?

[Bug tree-optimization/92867] Use ERF_RETURNS_ARG in more places

2019-12-09 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92867

--- Comment #3 from Jakub Jelinek  ---
Sure, go ahead.

[Bug tree-optimization/92867] Use ERF_RETURNS_ARG in more places

2019-12-09 Thread prathamesh3492 at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92867

prathamesh3492 at gcc dot gnu.org changed:

   What|Removed |Added

 CC||prathamesh3492 at gcc dot 
gnu.org

--- Comment #2 from prathamesh3492 at gcc dot gnu.org ---
If it's OK, I will try to implement this.

Thanks,
Prathamesh

[Bug tree-optimization/92867] Use ERF_RETURNS_ARG in more places

2019-12-09 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92867

Richard Biener  changed:

   What|Removed |Added

   Keywords||missed-optimization
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2019-12-09
 Ever confirmed|0   |1

--- Comment #1 from Richard Biener  ---
Yes, yes and yes.