public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/49915] New: Function call with 2-D arrays and -O2 (or strict-aliasing and inlining) gives random results
@ 2011-07-30 18:33 jquinsey at entrenet dot com
  2011-07-30 18:56 ` [Bug c/49915] " mikpe at it dot uu.se
  2011-07-30 19:24 ` paolo.carlini at oracle dot com
  0 siblings, 2 replies; 3+ messages in thread
From: jquinsey at entrenet dot com @ 2011-07-30 18:33 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: Function call with 2-D arrays and -O2 (or
                    strict-aliasing and inlining) gives random results
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: jquinsey@entrenet.com


Created attachment 24872
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24872
test.i from gcc -v -save-temps -O2 test.c

A function call with two-dimensional arrays and -O2 (or the switches
-fstrict-aliasing and -finline) gives random results.

Complete source code (14 lines):

static void copy(int n, int a[][n], int b[][n]) {
   int i, j;
   for (i = 0; i < 2; i++)    // 'n' not used in this example
      for (j = 0; j < 2; j++) // 'n' hard-coded to 2 for simplicity
         b[i][j] = a[i][j];
}

int main(int argc, char *argv[]) {
   int a[2][2] = {{1, 2},{3, 4}};
   int b[2][2];
   copy(2, a, b);    
   printf("%d %d %d %d\n", b[0][0], b[0][1], b[1][0], b[1][1]);
   return 0;
}

Test results:

gcc -O1 test.c && a.out
1 2 3 4
gcc -O2 test.c && a.out
12173125 -1079787588 -1079787736 13389812
gcc -O1 -fstrict-aliasing -finline test.c && a.out
12173125 -1080040260 -1080040408 13389812

All three tests also produced the (obvious) warning:

test.c: In function 'main':
test.c:12: warning: incompatible implicit declaration of built-in function
'printf'

gcc -v -save-temps -O2 test.c         
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-libgcj-multifile
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk
--disable-dssi --disable-plugin
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic
--host=i386-redhat-linux
Thread model: posix
gcc version 4.1.2 20080704 (Red Hat 4.1.2-50)
 /usr/libexec/gcc/i386-redhat-linux/4.1.2/cc1 -E -quiet -v test.c
-mtune=generic -O2 -fpch-preprocess -o test.i
ignoring nonexistent directory
"/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../i386-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/lib/gcc/i386-redhat-linux/4.1.2/include
 /usr/include
End of search list.
 /usr/libexec/gcc/i386-redhat-linux/4.1.2/cc1 -fpreprocessed test.i -quiet
-dumpbase test.c -mtune=generic -auxbase test -O2 -version -o test.s
GNU C version 4.1.2 20080704 (Red Hat 4.1.2-50) (i386-redhat-linux)
        compiled by GNU C version 4.1.2 20080704 (Red Hat 4.1.2-50).
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: d8d95095eb3c93dae4bed2137d559f95
test.c: In function 'main':
test.c:12: warning: incompatible implicit declaration of built-in function
'printf'
 as -V -Qy -o test.o test.s
GNU assembler version 2.17.50.0.6-14.el5 (i386-redhat-linux) using BFD version
2.17.50.0.6-14.el5 20061020
 /usr/libexec/gcc/i386-redhat-linux/4.1.2/collect2 --eh-frame-hdr -m elf_i386
--hash-style=gnu -dynamic-linker /lib/ld-linux.so.2
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crt1.o
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crti.o
/usr/lib/gcc/i386-redhat-linux/4.1.2/crtbegin.o
-L/usr/lib/gcc/i386-redhat-linux/4.1.2 -L/usr/lib/gcc/i386-redhat-linux/4.1.2
-L/usr/lib/gcc/i386-redhat-linux/4.1.2/../../.. test.o -lgcc --as-needed
-lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed
/usr/lib/gcc/i386-redhat-linux/4.1.2/crtend.o
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../crtn.o


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

* [Bug c/49915] Function call with 2-D arrays and -O2 (or strict-aliasing and inlining) gives random results
  2011-07-30 18:33 [Bug c/49915] New: Function call with 2-D arrays and -O2 (or strict-aliasing and inlining) gives random results jquinsey at entrenet dot com
@ 2011-07-30 18:56 ` mikpe at it dot uu.se
  2011-07-30 19:24 ` paolo.carlini at oracle dot com
  1 sibling, 0 replies; 3+ messages in thread
From: mikpe at it dot uu.se @ 2011-07-30 18:56 UTC (permalink / raw)
  To: gcc-bugs

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

Mikael Pettersson <mikpe at it dot uu.se> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mikpe at it dot uu.se

--- Comment #1 from Mikael Pettersson <mikpe at it dot uu.se> 2011-07-30 18:56:05 UTC ---
I can reproduce this error with gcc 4.0.4 and 4.1.2 on i686-linux, but 4.2.4 up
to 4.6.1 work, as do 3.4.6/3.3.6/3.2.3/2.95.3.

4.1.2 is no longer supported upstream, please update to 4.4.6 or newer, or
report this problem to your vendor (Red Hat?).


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

* [Bug c/49915] Function call with 2-D arrays and -O2 (or strict-aliasing and inlining) gives random results
  2011-07-30 18:33 [Bug c/49915] New: Function call with 2-D arrays and -O2 (or strict-aliasing and inlining) gives random results jquinsey at entrenet dot com
  2011-07-30 18:56 ` [Bug c/49915] " mikpe at it dot uu.se
@ 2011-07-30 19:24 ` paolo.carlini at oracle dot com
  1 sibling, 0 replies; 3+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-07-30 19:24 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |WORKSFORME

--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-07-30 19:24:15 UTC ---
Let's close this, then.


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

end of thread, other threads:[~2011-07-30 19:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-30 18:33 [Bug c/49915] New: Function call with 2-D arrays and -O2 (or strict-aliasing and inlining) gives random results jquinsey at entrenet dot com
2011-07-30 18:56 ` [Bug c/49915] " mikpe at it dot uu.se
2011-07-30 19:24 ` paolo.carlini at oracle dot com

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).