public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/45502]  New: Passing multi-dimensional array to function using C99 VLA function parameter format fails if function is inlined
@ 2010-09-02 17:48 r dot j dot hogan at reading dot ac dot uk
  2010-09-02 17:56 ` [Bug c/45502] " r dot j dot hogan at reading dot ac dot uk
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: r dot j dot hogan at reading dot ac dot uk @ 2010-09-02 17:48 UTC (permalink / raw)
  To: gcc-bugs

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


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

* [Bug c/45502] Passing multi-dimensional array to function using C99 VLA function parameter format fails if function is inlined
  2010-09-02 17:48 [Bug c/45502] New: Passing multi-dimensional array to function using C99 VLA function parameter format fails if function is inlined r dot j dot hogan at reading dot ac dot uk
@ 2010-09-02 17:56 ` r dot j dot hogan at reading dot ac dot uk
  2010-09-02 18:35 ` paolo dot carlini at oracle dot com
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: r dot j dot hogan at reading dot ac dot uk @ 2010-09-02 17:56 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from r dot j dot hogan at reading dot ac dot uk  2010-09-02 17:56 -------
Created an attachment (id=21675)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=21675&action=view)
Output from "-save-temps"


-- 


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


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

* [Bug c/45502] Passing multi-dimensional array to function using C99 VLA function parameter format fails if function is inlined
  2010-09-02 17:48 [Bug c/45502] New: Passing multi-dimensional array to function using C99 VLA function parameter format fails if function is inlined r dot j dot hogan at reading dot ac dot uk
  2010-09-02 17:56 ` [Bug c/45502] " r dot j dot hogan at reading dot ac dot uk
@ 2010-09-02 18:35 ` paolo dot carlini at oracle dot com
  2010-09-02 22:16 ` r dot j dot hogan at reading dot ac dot uk
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: paolo dot carlini at oracle dot com @ 2010-09-02 18:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from paolo dot carlini at oracle dot com  2010-09-02 18:35 -------
I can't reproduce this with FSF 4.3.2, neither 4.3.3, neither anything more
recent.


-- 

paolo dot carlini at oracle dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|r dot j dot hogan at reading|
                   |dot ac dot uk               |


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


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

* [Bug c/45502] Passing multi-dimensional array to function using C99 VLA function parameter format fails if function is inlined
  2010-09-02 17:48 [Bug c/45502] New: Passing multi-dimensional array to function using C99 VLA function parameter format fails if function is inlined r dot j dot hogan at reading dot ac dot uk
  2010-09-02 17:56 ` [Bug c/45502] " r dot j dot hogan at reading dot ac dot uk
  2010-09-02 18:35 ` paolo dot carlini at oracle dot com
@ 2010-09-02 22:16 ` r dot j dot hogan at reading dot ac dot uk
  2010-09-02 22:31 ` paolo dot carlini at oracle dot com
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: r dot j dot hogan at reading dot ac dot uk @ 2010-09-02 22:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from r dot j dot hogan at reading dot ac dot uk  2010-09-02 22:16 -------
Subject: Re:  Passing multi-dimensional array to function using
 C99 VLA function parameter format fails if function is inlined

Thanks - I guess it must be quite specific to that build - I've now tested 
some other x86_64 machines with the same version of SuSE and they do show 
the bug, but the other machines I've tried don't:

i586-suse-linux gcc-4.2.1
i386-redhat-linux gcc-4.1.2
sparc-sun-solaris2.8 gcc-3.2.2

Robin.


On Thu, 2 Sep 2010, paolo dot carlini at oracle dot com wrote:

> 
> 
> ------- Comment #2 from paolo dot carlini at oracle dot com  2010-09-02 18:35 -------
> I can't reproduce this with FSF 4.3.2, neither 4.3.3, neither anything more
> recent.
> 
> 
> -- 
> 
> paolo dot carlini at oracle dot com changed:
> 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>                  CC|r dot j dot hogan at reading|
>                    |dot ac dot uk               |
> 
> 
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45502
> 
> ------- You are receiving this mail because: -------
> You are on the CC list for the bug, or are watching someone who is.
> You reported the bug, or are watching the reporter.
> You are on the CC list for the bug, or are watching someone who is.
> 

-----------------------------------------------------------------
Robin J. Hogan
Room 2L77                          Tel: +44 118 378 6416
Dept of Meteorology                Fax: +44 118 378 8905
University of Reading            Email: r.j.hogan@reading.ac.uk
PO Box 243                         Web: www.met.rdg.ac.uk/clouds
READING RG6 6BB, UK
-----------------------------------------------------------------


-- 


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


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

* [Bug c/45502] Passing multi-dimensional array to function using C99 VLA function parameter format fails if function is inlined
  2010-09-02 17:48 [Bug c/45502] New: Passing multi-dimensional array to function using C99 VLA function parameter format fails if function is inlined r dot j dot hogan at reading dot ac dot uk
                   ` (2 preceding siblings ...)
  2010-09-02 22:16 ` r dot j dot hogan at reading dot ac dot uk
@ 2010-09-02 22:31 ` paolo dot carlini at oracle dot com
  2010-09-02 22:34 ` r dot j dot hogan at reading dot ac dot uk
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: paolo dot carlini at oracle dot com @ 2010-09-02 22:31 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from paolo dot carlini at oracle dot com  2010-09-02 22:31 -------
Note that if the problem affects only the GCC delivered with that SUSE distro
should be reported to SUSE, not here. Personally, I can't reproduce it with
stock 4.3.2 or 4.3.3 or current FSF releases from 4.4 or 4.5 branches, thus
unless we have contrary evidence this PR will be closed soon, I'm sorry.


-- 


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


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

* [Bug c/45502] Passing multi-dimensional array to function using C99 VLA function parameter format fails if function is inlined
  2010-09-02 17:48 [Bug c/45502] New: Passing multi-dimensional array to function using C99 VLA function parameter format fails if function is inlined r dot j dot hogan at reading dot ac dot uk
                   ` (3 preceding siblings ...)
  2010-09-02 22:31 ` paolo dot carlini at oracle dot com
@ 2010-09-02 22:34 ` r dot j dot hogan at reading dot ac dot uk
  2010-09-03  9:39 ` rguenth at gcc dot gnu dot org
  2010-09-03 12:55 ` rguenth at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: r dot j dot hogan at reading dot ac dot uk @ 2010-09-02 22:34 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from r dot j dot hogan at reading dot ac dot uk  2010-09-02 22:34 -------
Subject: Re:  Passing multi-dimensional array to function using
 C99 VLA function parameter format fails if function is inlined

Of course, that's fine.

On Thu, 2 Sep 2010, paolo dot carlini at oracle dot com wrote:

> 
> 
> ------- Comment #4 from paolo dot carlini at oracle dot com  2010-09-02 22:31 -------
> Note that if the problem affects only the GCC delivered with that SUSE distro
> should be reported to SUSE, not here. Personally, I can't reproduce it with
> stock 4.3.2 or 4.3.3 or current FSF releases from 4.4 or 4.5 branches, thus
> unless we have contrary evidence this PR will be closed soon, I'm sorry.
> 
> 
> -- 
> 
> 
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45502
> 
> ------- You are receiving this mail because: -------
> You reported the bug, or are watching the reporter.
> 

-----------------------------------------------------------------
Robin J. Hogan
Room 2L77                          Tel: +44 118 378 6416
Dept of Meteorology                Fax: +44 118 378 8905
University of Reading            Email: r.j.hogan@reading.ac.uk
PO Box 243                         Web: www.met.rdg.ac.uk/clouds
READING RG6 6BB, UK
-----------------------------------------------------------------


-- 


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


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

* [Bug c/45502] Passing multi-dimensional array to function using C99 VLA function parameter format fails if function is inlined
  2010-09-02 17:48 [Bug c/45502] New: Passing multi-dimensional array to function using C99 VLA function parameter format fails if function is inlined r dot j dot hogan at reading dot ac dot uk
                   ` (4 preceding siblings ...)
  2010-09-02 22:34 ` r dot j dot hogan at reading dot ac dot uk
@ 2010-09-03  9:39 ` rguenth at gcc dot gnu dot org
  2010-09-03 12:55 ` rguenth at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-09-03  9:39 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from rguenth at gcc dot gnu dot org  2010-09-03 09:39 -------
I can reproduce it with the SUSE release, it seems to be one of the backported
alias fixes that causes this (and it vanishes with -fno-strict-aliasing).

Works for all FSF releases I tried.


-- 

rguenth at gcc dot gnu dot org changed:

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


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


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

* [Bug c/45502] Passing multi-dimensional array to function using C99 VLA function parameter format fails if function is inlined
  2010-09-02 17:48 [Bug c/45502] New: Passing multi-dimensional array to function using C99 VLA function parameter format fails if function is inlined r dot j dot hogan at reading dot ac dot uk
                   ` (5 preceding siblings ...)
  2010-09-03  9:39 ` rguenth at gcc dot gnu dot org
@ 2010-09-03 12:55 ` rguenth at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-09-03 12:55 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from rguenth at gcc dot gnu dot org  2010-09-03 12:55 -------
A fix will appear in the repositories beyond
http://download.opensuse.org/repositories/devel:/gcc/


-- 


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


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

end of thread, other threads:[~2010-09-03 12:55 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-02 17:48 [Bug c/45502] New: Passing multi-dimensional array to function using C99 VLA function parameter format fails if function is inlined r dot j dot hogan at reading dot ac dot uk
2010-09-02 17:56 ` [Bug c/45502] " r dot j dot hogan at reading dot ac dot uk
2010-09-02 18:35 ` paolo dot carlini at oracle dot com
2010-09-02 22:16 ` r dot j dot hogan at reading dot ac dot uk
2010-09-02 22:31 ` paolo dot carlini at oracle dot com
2010-09-02 22:34 ` r dot j dot hogan at reading dot ac dot uk
2010-09-03  9:39 ` rguenth at gcc dot gnu dot org
2010-09-03 12:55 ` 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).