public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/95848] New: missing -Wuninitialized passing structs by value
@ 2020-06-23 21:01 msebor at gcc dot gnu.org
  2020-09-03 18:29 ` [Bug middle-end/95848] missing -Wuninitialized passing structs by value (VOPS) manu at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-06-23 21:01 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95848
           Summary: missing -Wuninitialized passing structs by value
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

In the test case below, -Wuninitialized only detects the first instances of
using an uninitialized struct.  It does not detect passing it as an argument by
value.

$ cat q.c && gcc -O2 -S -Wall q.c
struct S { int i; };

struct S sf (void)
{
  struct S s;
  return s;        // -Wuninitialized (good)
}

void fp (const struct S*);

void g (void)
{
  struct S s;
  fp (&s);         // -Wuninitialized (good)
}

void fs (struct S);

void h (void)
{
  struct S s;
  fs (s);          // missing -Wuninitialized
}
q.c: In function ‘sf’:
q.c:6:10: warning: ‘s’ is used uninitialized [-Wuninitialized]
    6 |   return s;        // -Wuninitialized (good)
      |          ^
q.c:5:12: note: ‘s’ declared here
    5 |   struct S s;
      |            ^
q.c: In function ‘g’:
q.c:14:3: warning: ‘s’ may be used uninitialized [-Wmaybe-uninitialized]
   14 |   fp (&s);         // -Wuninitialized (good)
      |   ^~~~~~~
q.c:9:6: note: by argument 1 of type ‘const struct S *’ to ‘fp’ declared here
    9 | void fp (const struct S*);
      |      ^~
q.c:13:12: note: ‘s’ declared here
   13 |   struct S s;
      |            ^

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

* [Bug middle-end/95848] missing -Wuninitialized passing structs by value (VOPS)
  2020-06-23 21:01 [Bug middle-end/95848] New: missing -Wuninitialized passing structs by value msebor at gcc dot gnu.org
@ 2020-09-03 18:29 ` manu at gcc dot gnu.org
  2021-01-12 17:15 ` msebor at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: manu at gcc dot gnu.org @ 2020-09-03 18:29 UTC (permalink / raw)
  To: gcc-bugs

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

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu.org
            Summary|missing -Wuninitialized     |missing -Wuninitialized
                   |passing structs by value    |passing structs by value
                   |                            |(VOPS)

--- Comment #1 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
This uses VOPS, so it probably needs new code to handle that.  Perhaps PR41953

h ()
{
  struct S s;

  <bb 2> [local count: 1073741824]:
  [./example.cpp:7:3] # DEBUG BEGIN_STMT
  [./example.cpp:8:3] # DEBUG BEGIN_STMT
  [./example.cpp:8:6] # .MEM_2 = VDEF <.MEM_1(D)>
  fs (s); [tail call]
  # .MEM_3 = VDEF <.MEM_2>
  s ={v} {CLOBBER};
  [./example.cpp:9:1] # VUSE <.MEM_3>
  return;
}

There is no difference in the logs that explain why g() is treated differently,
so that must be a special case for const* parameters.

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

* [Bug middle-end/95848] missing -Wuninitialized passing structs by value (VOPS)
  2020-06-23 21:01 [Bug middle-end/95848] New: missing -Wuninitialized passing structs by value msebor at gcc dot gnu.org
  2020-09-03 18:29 ` [Bug middle-end/95848] missing -Wuninitialized passing structs by value (VOPS) manu at gcc dot gnu.org
@ 2021-01-12 17:15 ` msebor at gcc dot gnu.org
  2021-01-20 15:03 ` manu at gcc dot gnu.org
  2021-01-20 18:23 ` msebor at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-01-12 17:15 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
      Known to fail|                            |10.2.0, 11.0, 9.3.0
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2021-01-12

--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
No improvement in GCC 11, even though passing structs by reference to const
pointer/reference arguments is diagnosed:

$ cat a.c && gcc -O2 -S -Wall -Wextra -fdump-tree-optimized=/dev/stdout a.c
struct S { int i; };

void f (const struct S*);
void g (struct S);

void ff (void)
{
  struct S s;
  f (&s);    // -Wmaybe-uninitialized (good)
}

void gg (void)
{
  struct S s;
  g (s);     // missing warning
}

a.c: In function ‘ff’:
a.c:9:3: warning: ‘s’ may be used uninitialized [-Wmaybe-uninitialized]
    9 |   f (&s);    // -Wmaybe-uninitialized (good)
      |   ^~~~~~
a.c:3:6: note: by argument 1 of type ‘const struct S *’ to ‘f’ declared here
    3 | void f (const struct S*);
      |      ^
a.c:8:12: note: ‘s’ declared here
    8 |   struct S s;
      |            ^

;; Function ff (ff, funcdef_no=0, decl_uid=1949, cgraph_uid=1, symbol_order=0)

void ff ()
{
  struct S s;

  <bb 2> [local count: 1073741824]:
  f (&s);
  s ={v} {CLOBBER};
  return;

}



;; Function gg (gg, funcdef_no=1, decl_uid=1953, cgraph_uid=2, symbol_order=1)

void gg ()
{
  struct S s;

  <bb 2> [local count: 1073741824]:
  g (s); [tail call]
  s ={v} {CLOBBER};
  return;

}

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

* [Bug middle-end/95848] missing -Wuninitialized passing structs by value (VOPS)
  2020-06-23 21:01 [Bug middle-end/95848] New: missing -Wuninitialized passing structs by value msebor at gcc dot gnu.org
  2020-09-03 18:29 ` [Bug middle-end/95848] missing -Wuninitialized passing structs by value (VOPS) manu at gcc dot gnu.org
  2021-01-12 17:15 ` msebor at gcc dot gnu.org
@ 2021-01-20 15:03 ` manu at gcc dot gnu.org
  2021-01-20 18:23 ` msebor at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: manu at gcc dot gnu.org @ 2021-01-20 15:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Manuel López-Ibáñez <manu at gcc dot gnu.org> ---
Martin, it is not clear from the dumps what is the difference between the two
cases. Also, this warning triggers even with -O0, so it must come pretty
earlier even before we have VOPS. What is the difference at the level of
GIMPLE?

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

* [Bug middle-end/95848] missing -Wuninitialized passing structs by value (VOPS)
  2020-06-23 21:01 [Bug middle-end/95848] New: missing -Wuninitialized passing structs by value msebor at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2021-01-20 15:03 ` manu at gcc dot gnu.org
@ 2021-01-20 18:23 ` msebor at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-01-20 18:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
There's no code code to handle the last case.  The first case is handled
because the local s is assigned to a temporary and there is code to detect
uninitialized sources of assignments.  The second case is handled in the new 
maybe_warn_pass_by_reference() function.  The third case enters the function
but is excluded because the argument is passed by value and nothing else checks
passing non-SSA_NAME operands.

In the test case below passing the uninitialized i is diagnosed because i's an
SSA_NAME.  Passing s isn't because it's not one. 
maybe_warn_pass_by_reference() should handle this case as well (and be renamed
appropriately).

$ gcc -S -Wall -fdump-tree-ssa=/dev/stdout ../t.c

;; Function h (h, funcdef_no=0, decl_uid=1948, cgraph_uid=1, symbol_order=0)

void h ()
{
  int i;
  struct S s;

  <bb 2> :
  fs (s, i_2(D));
  s ={v} {CLOBBER};
  return;

}


../t.c: In function ‘h’:
../t.c:9:3: warning: ‘i’ is used uninitialized [-Wuninitialized]
    9 |   fs (s, i);
      |   ^~~~~~~~~

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

end of thread, other threads:[~2021-01-20 18:23 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-23 21:01 [Bug middle-end/95848] New: missing -Wuninitialized passing structs by value msebor at gcc dot gnu.org
2020-09-03 18:29 ` [Bug middle-end/95848] missing -Wuninitialized passing structs by value (VOPS) manu at gcc dot gnu.org
2021-01-12 17:15 ` msebor at gcc dot gnu.org
2021-01-20 15:03 ` manu at gcc dot gnu.org
2021-01-20 18:23 ` msebor 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).