public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/24931]  New: uninitialized structure member after assignment
@ 2005-11-18  5:53 dylan at dylex dot net
  2005-11-18  6:19 ` [Bug tree-optimization/24931] [4.0/4.1 Regression] " pinskia at gcc dot gnu dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: dylan at dylex dot net @ 2005-11-18  5:53 UTC (permalink / raw)
  To: gcc-bugs

Consider this code:

struct p {
        short x, y;
};

struct s {
        int i;
        struct p p;
};

struct s f()
{
        struct s s;
        s.p = (struct p){};
        s.i = (s.p.x || s.p.y);
        return s;
}

When compiled with gcc -Wall -O -c, it reports:
t.c: In function 'f':
t.c:14: warning: 's.i' is used uninitialized in this function

That's not right.  Furthermore, I think the generated assembly might be wrong
(this is with -O):

f:
        movl    $0, %eax
        ret

The return value should be a full 64 bits (%rax), but only the bottom 32 are
initialized (unless this clears the high ones on x86_64 or the calling
convention says they are already -- I don't really know).


-- 
           Summary: uninitialized structure member after assignment
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dylan at dylex dot net
 GCC build triplet: x86_64-pc-linux-gnu
  GCC host triplet: x86_64-pc-linux-gnu
GCC target triplet: x86_64-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24931


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

* [Bug tree-optimization/24931] [4.0/4.1 Regression] uninitialized structure member after assignment
  2005-11-18  5:53 [Bug c/24931] New: uninitialized structure member after assignment dylan at dylex dot net
@ 2005-11-18  6:19 ` pinskia at gcc dot gnu dot org
  2005-11-19  2:21 ` mmitchel at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-11-18  6:19 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2005-11-18 06:19 -------
First this is a very bogus warning.
Second this is caused by SRA and BIT_FIELD_REF:
  D.1509.x = 0;
  D.1509.y = 0;
  s.p = D.1509;
  D.1511_10 = BIT_FIELD_REF <s, 32, 32>;
  D.1512_12 = D.1511_10 != 0;
  s.i = D.1512_12;
  D.1513 = s;

The problem is that SRA does not look into seeing if s.i is needed so it does:
  SR.25_11 = 0;
  SR.24_26 = 0;
  s$p$y_27 = SR.24_26;
  s$p$x_28 = SR.25_11;
  s.i = s$i_29;
  s.p.y = s$p$y_27;
  s.p.x = s$p$x_28;
  D.1511_10 = BIT_FIELD_REF <s, 32, 32>;
  D.1512_12 = D.1511_10 != 0;
  s$i_33 = D.1512_12;
  s.i = s$i_33;
  s.p.y = s$p$y_27;
  s.p.x = s$p$x_28;
  D.1513 = s;

The wrong code part is not really wrong code, just a misunderstanding of what
the instruction does:
(insn 43 40 49 (set (reg/i:DI 0 ax [ <result> ]) 
        (const_int 0 [0x0])) 81 {*movdi_1_rex64} (insn_list:REG_DEP_TRUE 35
(nil))
    (nil))

It sign extends to the full register which means rax is 0 and not just the
bottom part.

Hmm, even the struct aliasing code does not know either:
  #   VUSE <SFT.3_7>;
  #   VUSE <SFT.4_8>;
  #   VUSE <SFT.5_9>;
  D.1511_10 = BIT_FIELD_REF <s, 32, 32>;


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rth at gcc dot gnu dot org,
                   |                            |dberlin at gcc dot gnu dot
                   |                            |org
OtherBugsDependingO|                            |24639
              nThis|                            |
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
  GCC build triplet|x86_64-pc-linux-gnu         |
   GCC host triplet|x86_64-pc-linux-gnu         |
 GCC target triplet|x86_64-pc-linux-gnu         |x86_64-*-* i?86-*-*
   Last reconfirmed|0000-00-00 00:00:00         |2005-11-18 06:19:39
               date|                            |
            Summary|uninitialized structure     |[4.0/4.1 Regression]
                   |member after assignment     |uninitialized structure
                   |                            |member after assignment
   Target Milestone|---                         |4.0.3


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24931


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

* [Bug tree-optimization/24931] [4.0/4.1 Regression] uninitialized structure member after assignment
  2005-11-18  5:53 [Bug c/24931] New: uninitialized structure member after assignment dylan at dylex dot net
  2005-11-18  6:19 ` [Bug tree-optimization/24931] [4.0/4.1 Regression] " pinskia at gcc dot gnu dot org
@ 2005-11-19  2:21 ` mmitchel at gcc dot gnu dot org
  2005-11-20 20:08 ` rth at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2005-11-19  2:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from mmitchel at gcc dot gnu dot org  2005-11-19 02:21 -------
This is annoying warning; let's fix.


-- 

mmitchel at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24931


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

* [Bug tree-optimization/24931] [4.0/4.1 Regression] uninitialized structure member after assignment
  2005-11-18  5:53 [Bug c/24931] New: uninitialized structure member after assignment dylan at dylex dot net
  2005-11-18  6:19 ` [Bug tree-optimization/24931] [4.0/4.1 Regression] " pinskia at gcc dot gnu dot org
  2005-11-19  2:21 ` mmitchel at gcc dot gnu dot org
@ 2005-11-20 20:08 ` rth at gcc dot gnu dot org
  2005-11-21  0:51 ` [Bug tree-optimization/24931] [4.0/4.1/4.2 " rth at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rth at gcc dot gnu dot org @ 2005-11-20 20:08 UTC (permalink / raw)
  To: gcc-bugs



-- 

rth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |rth at gcc dot gnu dot org
                   |dot org                     |
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2005-11-18 06:19:39         |2005-11-20 20:08:55
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24931


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

* [Bug tree-optimization/24931] [4.0/4.1/4.2 Regression] uninitialized structure member after assignment
  2005-11-18  5:53 [Bug c/24931] New: uninitialized structure member after assignment dylan at dylex dot net
                   ` (2 preceding siblings ...)
  2005-11-20 20:08 ` rth at gcc dot gnu dot org
@ 2005-11-21  0:51 ` rth at gcc dot gnu dot org
  2005-11-21  0:56 ` rth at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rth at gcc dot gnu dot org @ 2005-11-21  0:51 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from rth at gcc dot gnu dot org  2005-11-21 00:51 -------
Subject: Bug 24931

Author: rth
Date: Mon Nov 21 00:51:39 2005
New Revision: 107271

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=107271
Log:
        PR 24931
        * tree-sra.c (struct sra_elt): Add all_no_warning.
        (struct sra_walk_fns) <use>: Add use_all argument.
        (sra_walk_expr): Pass it.
        (sra_walk_modify_expr): Likewise.
        (scalarize_ldst): Likewise.
        (scan_use): Update for new argument.
        (mark_no_warning): New.
        (scalarize_use): Use it.

Added:
    trunk/gcc/testsuite/gcc.dg/uninit-14.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/tree-sra.c


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24931


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

* [Bug tree-optimization/24931] [4.0/4.1/4.2 Regression] uninitialized structure member after assignment
  2005-11-18  5:53 [Bug c/24931] New: uninitialized structure member after assignment dylan at dylex dot net
                   ` (3 preceding siblings ...)
  2005-11-21  0:51 ` [Bug tree-optimization/24931] [4.0/4.1/4.2 " rth at gcc dot gnu dot org
@ 2005-11-21  0:56 ` rth at gcc dot gnu dot org
  2005-11-22  0:06 ` [Bug tree-optimization/24931] [4.0 " pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rth at gcc dot gnu dot org @ 2005-11-21  0:56 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from rth at gcc dot gnu dot org  2005-11-21 00:56 -------
Subject: Bug 24931

Author: rth
Date: Mon Nov 21 00:55:57 2005
New Revision: 107272

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=107272
Log:
        PR 24931
        * tree-sra.c (struct sra_elt): Add all_no_warning.
        (struct sra_walk_fns) <use>: Add use_all argument.
        (sra_walk_expr): Pass it.
        (sra_walk_modify_expr): Likewise.
        (scalarize_ldst): Likewise.
        (scan_use): Update for new argument.
        (mark_no_warning): New.
        (scalarize_use): Use it.

Added:
    branches/gcc-4_1-branch/gcc/testsuite/gcc.dg/uninit-14.c
      - copied unchanged from r107271, trunk/gcc/testsuite/gcc.dg/uninit-14.c
Modified:
    branches/gcc-4_1-branch/gcc/ChangeLog
    branches/gcc-4_1-branch/gcc/tree-sra.c


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24931


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

* [Bug tree-optimization/24931] [4.0 Regression] uninitialized structure member after assignment
  2005-11-18  5:53 [Bug c/24931] New: uninitialized structure member after assignment dylan at dylex dot net
                   ` (4 preceding siblings ...)
  2005-11-21  0:56 ` rth at gcc dot gnu dot org
@ 2005-11-22  0:06 ` pinskia at gcc dot gnu dot org
  2006-03-11  3:19 ` mmitchel at gcc dot gnu dot org
  2007-02-03 16:02 ` gdr at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-11-22  0:06 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from pinskia at gcc dot gnu dot org  2005-11-22 00:06 -------
Fixed at least on the mainline and 4.1 branch for now.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |4.0.0 4.0.2
      Known to work|                            |4.1.0 4.2.0 3.4.4
            Summary|[4.0/4.1/4.2 Regression]    |[4.0 Regression]
                   |uninitialized structure     |uninitialized structure
                   |member after assignment     |member after assignment


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24931


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

* [Bug tree-optimization/24931] [4.0 Regression] uninitialized structure member after assignment
  2005-11-18  5:53 [Bug c/24931] New: uninitialized structure member after assignment dylan at dylex dot net
                   ` (5 preceding siblings ...)
  2005-11-22  0:06 ` [Bug tree-optimization/24931] [4.0 " pinskia at gcc dot gnu dot org
@ 2006-03-11  3:19 ` mmitchel at gcc dot gnu dot org
  2007-02-03 16:02 ` gdr at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2006-03-11  3:19 UTC (permalink / raw)
  To: gcc-bugs



-- 

mmitchel at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.0.3                       |4.0.4


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24931


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

* [Bug tree-optimization/24931] [4.0 Regression] uninitialized structure member after assignment
  2005-11-18  5:53 [Bug c/24931] New: uninitialized structure member after assignment dylan at dylex dot net
                   ` (6 preceding siblings ...)
  2006-03-11  3:19 ` mmitchel at gcc dot gnu dot org
@ 2007-02-03 16:02 ` gdr at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: gdr at gcc dot gnu dot org @ 2007-02-03 16:02 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from gdr at gcc dot gnu dot org  2007-02-03 16:02 -------
Fixed in GCC-4.1.0


-- 

gdr at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|4.0.4                       |4.1.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24931


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

end of thread, other threads:[~2007-02-03 16:02 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-18  5:53 [Bug c/24931] New: uninitialized structure member after assignment dylan at dylex dot net
2005-11-18  6:19 ` [Bug tree-optimization/24931] [4.0/4.1 Regression] " pinskia at gcc dot gnu dot org
2005-11-19  2:21 ` mmitchel at gcc dot gnu dot org
2005-11-20 20:08 ` rth at gcc dot gnu dot org
2005-11-21  0:51 ` [Bug tree-optimization/24931] [4.0/4.1/4.2 " rth at gcc dot gnu dot org
2005-11-21  0:56 ` rth at gcc dot gnu dot org
2005-11-22  0:06 ` [Bug tree-optimization/24931] [4.0 " pinskia at gcc dot gnu dot org
2006-03-11  3:19 ` mmitchel at gcc dot gnu dot org
2007-02-03 16:02 ` gdr at gcc dot gnu dot 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).