From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3403 invoked by alias); 2 Sep 2010 17:48:44 -0000 Received: (qmail 3334 invoked by uid 48); 2 Sep 2010 17:48:23 -0000 Date: Thu, 02 Sep 2010 17:48:00 -0000 Subject: [Bug c/45502] New: Passing multi-dimensional array to function using C99 VLA function parameter format fails if function is inlined X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "r dot j dot hogan at reading dot ac dot uk" 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: 2010-09/txt/msg00329.txt.bz2 The following code passes a multidimensional array to a function that uses the C99 format for accepting an array when the size is not known at compile time. The code outputs incorrect numbers (like 6.91992e-310) if the function "show" gets inlined, which happens if I do one of these: gcc -Wall -save-temps -std=c99 -O2 -finline-functions bug.c -o bug gcc -Wall -save-temps -std=c99 -O3 bug.c -o bug Using less optimization (e.g. -O1) or using the __attribute__((noinline)) on the "show" function results in correct operation, so I presume it is the inlining that is not working. -------------- bug.c ------------------------------------- #include void show(int n, int m, double a[n][m]) { int i, j; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { fprintf(stderr, "a[%d][%d] = %g\n", i, j, a[i][j]); } } } int main(int argc, char** argv) { double b[3][2] = {{1.1, 2.1}, {3.1, 4.1}, {5.1, 6.1}}; show(3,2,b); return 0; } ------------------------------------------------------------ >> gcc -v Using built-in specs. Target: x86_64-suse-linux Configured with: ../configure --prefix=/usr --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64 --enable-languages=c,c++,objc,fortran,obj-c++,java,ada --enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.3 --enable-ssp --disable-libssp --with-bugurl=http://bugs.opensuse.org/ --with-pkgversion='SUSE Linux' --disable-libgcj --disable-libmudflap --with-slibdir=/lib64 --with-system-zlib --enable-__cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch --enable-version-specific-runtime-libs --program-suffix=-4.3 --enable-linux-futex --without-system-libunwind --with-cpu=generic --build=x86_64-suse-linux Thread model: posix gcc version 4.3.2 [gcc-4_3-branch revision 141291] (SUSE Linux) -- Summary: Passing multi-dimensional array to function using C99 VLA function parameter format fails if function is inlined Product: gcc Version: 4.3.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: r dot j dot hogan at reading dot ac dot uk GCC build triplet: x86_64-suse-linux GCC host triplet: x86_64-suse-linux GCC target triplet: x86_64-suse-linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45502