public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/103920] New: No warning for large structs passed by value ?
@ 2022-01-05 16:48 dcb314 at hotmail dot com
  2022-01-05 17:15 ` [Bug c/103920] " redi at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: dcb314 at hotmail dot com @ 2022-01-05 16:48 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 103920
           Summary: No warning for large structs passed by value ?
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dcb314 at hotmail dot com
  Target Milestone: ---

For the following code:

$ more jan5c.cc

struct S
{
        long a;
        long b;
        long c;
        long d;
        long a2;
        long b2;
        long c2;
        long d2;
};

void f1( const S s);
void f2( S s);

gcc has not a lot to say:

$ /home/dcb/gcc/results/bin/gcc -c -O2 -Wall -Wextra -pedantic jan5c.cc
$

cppcheck does a slightly better job:

$ /home/dcb/cppcheck/trunk.git/cppcheck --enable=all jan5c.cc
jan5c.cc:14:18: performance: Function parameter 's' should be passed by const
reference. [passedByValue]
void f1( const S s);
                 ^
Also, clang-13 doesn't say anything. 

Judgement call, but "large" might mean four words or more. 

Example code derived from code in the Linux kernel, so even kernel programmers
do this kind of thing in practice.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/103920] No warning for large structs passed by value ?
  2022-01-05 16:48 [Bug c/103920] New: No warning for large structs passed by value ? dcb314 at hotmail dot com
@ 2022-01-05 17:15 ` redi at gcc dot gnu.org
  2022-01-05 20:05 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2022-01-05 17:15 UTC (permalink / raw)
  To: gcc-bugs

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

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic
             Blocks|                            |87403
           Severity|normal                      |enhancement


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87403
[Bug 87403] [Meta-bug] Issues that suggest a new warning

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/103920] No warning for large structs passed by value ?
  2022-01-05 16:48 [Bug c/103920] New: No warning for large structs passed by value ? dcb314 at hotmail dot com
  2022-01-05 17:15 ` [Bug c/103920] " redi at gcc dot gnu.org
@ 2022-01-05 20:05 ` pinskia at gcc dot gnu.org
  2022-01-10 10:34 ` rguenth at gcc dot gnu.org
  2022-02-04  8:08 ` egallager at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-05 20:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Actually I think the warning is incorrect as there are aliasing implications if
passed by reference instead of by value.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/103920] No warning for large structs passed by value ?
  2022-01-05 16:48 [Bug c/103920] New: No warning for large structs passed by value ? dcb314 at hotmail dot com
  2022-01-05 17:15 ` [Bug c/103920] " redi at gcc dot gnu.org
  2022-01-05 20:05 ` pinskia at gcc dot gnu.org
@ 2022-01-10 10:34 ` rguenth at gcc dot gnu.org
  2022-02-04  8:08 ` egallager at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-01-10 10:34 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Also consider

void f1 (const S s, S * __restrict q);

where obeying the warning would create a false alias when called as

 f1 (x, &x);

whether passing by value or reference is more efficient also depends on the
context - if the aggregate doesn't live in memory at (all) callers and
register passing conventions are in effect then passing by reference requires
materializing the argument on the stack.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c/103920] No warning for large structs passed by value ?
  2022-01-05 16:48 [Bug c/103920] New: No warning for large structs passed by value ? dcb314 at hotmail dot com
                   ` (2 preceding siblings ...)
  2022-01-10 10:34 ` rguenth at gcc dot gnu.org
@ 2022-02-04  8:08 ` egallager at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: egallager at gcc dot gnu.org @ 2022-02-04  8:08 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=59552,
                   |                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=70047
                 CC|                            |egallager at gcc dot gnu.org

--- Comment #3 from Eric Gallager <egallager at gcc dot gnu.org> ---
related to bug 59552 and/or bug 70047 perhaps?

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-02-04  8:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-05 16:48 [Bug c/103920] New: No warning for large structs passed by value ? dcb314 at hotmail dot com
2022-01-05 17:15 ` [Bug c/103920] " redi at gcc dot gnu.org
2022-01-05 20:05 ` pinskia at gcc dot gnu.org
2022-01-10 10:34 ` rguenth at gcc dot gnu.org
2022-02-04  8:08 ` egallager at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).