public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/16670] New: struct { type:0; } passing bugs
@ 2004-07-22 10:19 jakub at gcc dot gnu dot org
  2004-07-22 10:26 ` [Bug middle-end/16670] " jakub at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: jakub at gcc dot gnu dot org @ 2004-07-22 10:19 UTC (permalink / raw)
  To: gcc-bugs

extern void abort (void);
struct S { int:0; } a, b;
void foo (struct S x, struct S *y)
{
  if (y != &b)
    abort ();
}
int main (void)
{
  foo (a, &b);
  return 0;
}

is miscompiled on IA-32.
Argument layout code reserves 0 bytes on the stack for the type
(the same as for struct { } that works correctly), but the &b argument is later
overwritten by 4 bytes at &a:

(insn 23 21 24 1 (set (mem/f/i:SI (reg/f:SI 56 virtual-outgoing-args) [0 S4 A32])
        (symbol_ref:SI ("b") <var_decl 0x2a97d677e0 b>)) -1 (nil)
    (nil))

(insn 24 23 25 1 (set (reg:SI 70)
        (mem/s:SI (symbol_ref:SI ("a") <var_decl 0x2a97d67700 a>) [2 a+0 S0 A8]))
-1 (nil)
    (nil))

(insn 25 24 26 1 (set (mem/s:SI (reg/f:SI 56 virtual-outgoing-args) [0 S0 A8])
        (reg:SI 70)) -1 (nil)
    (nil))

(call_insn 26 25 27 1 (call (mem:QI (symbol_ref:SI ("foo") [flags 0x3]
<function_decl 0x2a97d67c40 foo>) [0 S1 A8])
        (const_int 4 [0x4])) -1 (nil)
    (expr_list:REG_EH_REGION (const_int 0 [0x0])
        (nil))
    (nil))

The problem is that this structure is given SImode, not BLKmode and some routines
play with size_in_bytes while others just look at the mode.
Interesting thing happen with -mregparm=X with such structures as well.
On x86-64, although this testcase works,
extern void abort (void);
struct S { int:0; } a, b;
void foo (int a, int b, int c, int d, int e, int f, struct S x, struct S *y)
{
  if (y != &b)
    abort ();
}
int main (void)
{
  foo (0, 1, 2, 3, 4, 5, a, &b);
  return 0;
}
does not.

-- 
           Summary: struct { type:0; } passing bugs
           Product: gcc
           Version: 3.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jakub at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org
GCC target triplet: i386-*-linux*, x86_64-*-linux*


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


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

* [Bug middle-end/16670] struct { type:0; } passing bugs
  2004-07-22 10:19 [Bug middle-end/16670] New: struct { type:0; } passing bugs jakub at gcc dot gnu dot org
@ 2004-07-22 10:26 ` jakub at gcc dot gnu dot org
  2004-07-22 11:43 ` giovannibajo at libero dot it
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu dot org @ 2004-07-22 10:26 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From jakub at gcc dot gnu dot org  2004-07-22 10:26 -------
Argh, make the testcase for x86-64 instead:
extern void abort (void);
struct S { int:0; } a, b;
void foo (int c, int d, int e, int f, int g, int h, struct S x, struct S *y)
{
  if (y != &b)
    abort ();
}
int main (void)
{
  foo (0, 1, 2, 3, 4, 5, a, &b);
  return 0;
}

(there was a collision between the dummy arg names and structure variables).

-- 


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


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

* [Bug middle-end/16670] struct { type:0; } passing bugs
  2004-07-22 10:19 [Bug middle-end/16670] New: struct { type:0; } passing bugs jakub at gcc dot gnu dot org
  2004-07-22 10:26 ` [Bug middle-end/16670] " jakub at gcc dot gnu dot org
@ 2004-07-22 11:43 ` giovannibajo at libero dot it
  2004-09-27 16:26 ` reichelt at gcc dot gnu dot org
  2005-04-16 22:37 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: giovannibajo at libero dot it @ 2004-07-22 11:43 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From giovannibajo at libero dot it  2004-07-22 11:42 -------
Confirmed, not a regression though. 2.95 and then 3.3 up to mainline compile 
the testcase but aborts at runtime. 3.0-3.2 could not even compile it (ICE).

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |wrong-code
      Known to fail|                            |2.95.3 3.0.4 3.2.3 3.3.3
                   |                            |3.4.0 3.5.0
   Last reconfirmed|0000-00-00 00:00:00         |2004-07-22 11:42:57
               date|                            |


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


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

* [Bug middle-end/16670] struct { type:0; } passing bugs
  2004-07-22 10:19 [Bug middle-end/16670] New: struct { type:0; } passing bugs jakub at gcc dot gnu dot org
  2004-07-22 10:26 ` [Bug middle-end/16670] " jakub at gcc dot gnu dot org
  2004-07-22 11:43 ` giovannibajo at libero dot it
@ 2004-09-27 16:26 ` reichelt at gcc dot gnu dot org
  2005-04-16 22:37 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: reichelt at gcc dot gnu dot org @ 2004-09-27 16:26 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From reichelt at gcc dot gnu dot org  2004-09-27 16:26 -------
The bug seems to be fixed on mainline by Roger's patch
http://gcc.gnu.org/ml/gcc-cvs/2004-09/msg01232.html

I can only test i686-pc-linux-gnu, though.

The question is whether to apply this patch to the 3.4 and 3.3 branch
as well, although the problem is not really a regression.

I'd vote for fixing this on the 3.4 branch and the 3.3 branch as well, since
a) the code seems to be the same on those branches, i.e. a backport seems
   to be trivial
b) the bug is really a bad one: Sometimes it shows as wrong-code,
   sometimes the compiler crashes depending on the optimization switches
   (it crashes since 3.0 when compiled with -Os, but gives wrong code
   when compiled with -O0 for some versions and works fine with -O3).
   This makes it really painful to track down the bug.


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sayle at gcc dot gnu dot
                   |                            |org, gdr at gcc dot gnu dot
                   |                            |org, mark at codesourcery
                   |                            |dot com, reichelt at gcc dot
                   |                            |gnu dot org
           Keywords|                            |ice-on-valid-code
      Known to fail|2.95.3 3.0.4 3.2.3 3.3.3    |2.95.3 3.0.4 3.2.3 3.3.3
                   |3.4.0 4.0                   |3.4.0
      Known to work|                            |4.0.0


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


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

* [Bug middle-end/16670] struct { type:0; } passing bugs
  2004-07-22 10:19 [Bug middle-end/16670] New: struct { type:0; } passing bugs jakub at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2004-09-27 16:26 ` reichelt at gcc dot gnu dot org
@ 2005-04-16 22:37 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-04-16 22:37 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-04-16 22:37 -------
Fixed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.0.0


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


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

end of thread, other threads:[~2005-04-16 22:37 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-22 10:19 [Bug middle-end/16670] New: struct { type:0; } passing bugs jakub at gcc dot gnu dot org
2004-07-22 10:26 ` [Bug middle-end/16670] " jakub at gcc dot gnu dot org
2004-07-22 11:43 ` giovannibajo at libero dot it
2004-09-27 16:26 ` reichelt at gcc dot gnu dot org
2005-04-16 22:37 ` pinskia 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).