From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25840 invoked by alias); 30 Jul 2011 18:33:42 -0000 Received: (qmail 25832 invoked by uid 22791); 30 Jul 2011 18:33:41 -0000 X-SWARE-Spam-Status: No, hits=-2.7 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TW_CX,TW_GC,TW_LG X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 30 Jul 2011 18:33:28 +0000 From: "jquinsey at entrenet dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/49915] New: Function call with 2-D arrays and -O2 (or strict-aliasing and inlining) gives random results X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jquinsey at entrenet dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Sat, 30 Jul 2011 18:33:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-07/txt/msg02635.txt.bz2 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