This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/45502] New: Passing multi-dimensional array to function using C99 VLA function parameter format fails if function is inlined


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 <stdio.h>
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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]