public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/41382]  New: Memory corruption observed in executable generated from struct array with compiler option -O
@ 2009-09-16 20:44 xqi at mathworks dot com
  2009-09-16 21:20 ` [Bug c/41382] " rguenth at gcc dot gnu dot org
  2009-09-16 21:21 ` rguenth at gcc dot gnu dot org
  0 siblings, 2 replies; 3+ messages in thread
From: xqi at mathworks dot com @ 2009-09-16 20:44 UTC (permalink / raw)
  To: gcc-bugs

My source file contains some manipulation on struct arrays. After the
initialization of some local data, there is a call to a dummy function which
has its actual argument being the value of a field of one element of such an
array. 

In running the executable compiled with -O, memory corruption can be observed.
Note that if the call to the dummy function is removed, the generated code runs
correctly.

Here is the example:

% cat tst.c
#include <stdio.h>

typedef struct {
      int re, im;
} cint32_T;

static void m_foo(int i)
{}

int main()
{
    static cint32_T sdata[3] = { { 504094, -1909779 }, { 658988, -552759 }, {
-15591, -896799 } };

    cint32_T ldata[3];
    cint32_T odata[3];
    int i;

    for(i = 0; i < 3; i++) {// assign ldata from sdata
        ldata[i] = sdata[i];
    }

    for(i = 0; i < 3; i++) {// assign odata from ldata
        odata[i] = ldata[i];
    }

    m_foo(ldata[2].re);    // make a dummy call

    // Now data stored in odata[0] is corrupted.
    printf("%d, %d\n", odata[0].re, odata[0].im);

    return 0;
}


% gcc -Wall tst.c -o correct
% correct
504094, -1909779
% gcc -Wall tst.c -O -o wrong
% wrong
0, 0
%


-- 
           Summary: Memory corruption observed in executable generated from
                    struct array with compiler option -O
           Product: gcc
           Version: 4.2.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: xqi at mathworks dot com
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


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


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

* [Bug c/41382] Memory corruption observed in executable generated from struct array with compiler option -O
  2009-09-16 20:44 [Bug c/41382] New: Memory corruption observed in executable generated from struct array with compiler option -O xqi at mathworks dot com
@ 2009-09-16 21:20 ` rguenth at gcc dot gnu dot org
  2009-09-16 21:21 ` rguenth at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-09-16 21:20 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2009-09-16 21:19 -------
Works on all active release branches.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
      Known to work|                            |4.3.3 4.4.1 4.5.0
         Resolution|                            |FIXED


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


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

* [Bug c/41382] Memory corruption observed in executable generated from struct array with compiler option -O
  2009-09-16 20:44 [Bug c/41382] New: Memory corruption observed in executable generated from struct array with compiler option -O xqi at mathworks dot com
  2009-09-16 21:20 ` [Bug c/41382] " rguenth at gcc dot gnu dot org
@ 2009-09-16 21:21 ` rguenth at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-09-16 21:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rguenth at gcc dot gnu dot org  2009-09-16 21:20 -------
Confirmed with 4.2.4 btw.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |4.2.4


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


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

end of thread, other threads:[~2009-09-16 21:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-16 20:44 [Bug c/41382] New: Memory corruption observed in executable generated from struct array with compiler option -O xqi at mathworks dot com
2009-09-16 21:20 ` [Bug c/41382] " rguenth at gcc dot gnu dot org
2009-09-16 21:21 ` rguenth 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).