https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59552

Eric Gallager <egallager at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |NEW

--- Comment #3 from Eric Gallager <egallager at gcc dot gnu.org> ---
(In reply to Martin Sebor from comment #2)
> The request refers to arguments of non-trivial types but I think it's just
> as applicable to trivial types, if not more.  A test case for an
> expensive-to-copy trivial type might look something like this.  The caller
> of f0() must make a copy of x but the caller of g0() need not, and GCC just
> passes the address of x to it.  Since the definition of f0() doesn't change
> the argument, it would be more efficient if the caller didn't have to make
> the copy.  In C++, GCC could suggest to declare f0() to take its argument by
> const reference instead.  (In C, it could suggest to take it by const
> pointer.)  In addition, declaring the const reference or pointer argument
> restrict would make it clear that the callee doesn't change the argument
> when it's passed by reference (this optimization is the subject of pr81009).
> 
> typedef struct Big {
>   char a[32];
> } Big;
> 
> int __attribute__ ((noclone, noinline))
> f0 (Big x)   // suggest to declare f0 (const Big&) instead
> { return __builtin_strlen (x.a); }
> 
> int __attribute__ ((noclone, noinline))
> g0 (const Big *x) { return __builtin_strlen (x->a); }
> 
> extern Big x;
> 
> int f1 (void)
> {
>   int n = f0 (x);
>   return n + 1;
> }
> 
> int g1 (void)
> {
>   int n = g0 (&x);
>   return n + 1;
> }
> 
> I suspect the request for a warning for non-trivial types is based on the
> assumption that such a type is expensive to copy.  That may or may not be
> true depending on the definition of the type but regardless, I think there
> is an opportunity here for GCC to help users write more efficient code.

OK, thanks, confirmed then.

Reply via email to