public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/54068] New: Compiler passes wrong argument to function when using -O3 and inline
@ 2012-07-22 23:39 vogu00 at gmail dot com
  2012-07-22 23:46 ` [Bug middle-end/54068] Compiler passes wrong argument to function when using optimize attribute with -O3 pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: vogu00 at gmail dot com @ 2012-07-22 23:39 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 54068
           Summary: Compiler passes wrong argument to function when using
                    -O3 and inline
    Classification: Unclassified
           Product: gcc
           Version: 4.6.3
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: vogu00@gmail.com


Created attachment 27855
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27855
Compile this ii file and run it; it shows the described problem

In the attached example, gcc passes the wrong parameter to a function. The
problem only was observed on a Ubuntu 12.04 i386 platform. It did not occur 
not on Ubuntu 12.04 amd64.

The problem can be avoided by a) omitting the inline statement or b) by
commenting out the optimisation attribute in the source code.

Here's the output of    gcc -v -save-temps -o it it.cpp

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/4.6/lto-wrapper
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.6 --enable-shared --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object
--enable-plugin --enable-objc-gc --enable-targets=all --disable-werror
--with-arch-32=i686 --with-tune=generic --enable-checking=release
--build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
Thread model: posix
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-o' 'it' '-mtune=generic' '-march=i686'
 /usr/lib/gcc/i686-linux-gnu/4.6/cc1plus -E -quiet -v -imultilib . -imultiarch
i386-linux-gnu -D_GNU_SOURCE it.cpp -mtune=generic -march=i686 -fpch-preprocess
-fstack-protector -o it.ii
ignoring nonexistent directory "/usr/local/include/i386-linux-gnu"
ignoring nonexistent directory
"/usr/lib/gcc/i686-linux-gnu/4.6/../../../../i686-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.6
 /usr/include/c++/4.6/i686-linux-gnu/.
 /usr/include/c++/4.6/backward
 /usr/lib/gcc/i686-linux-gnu/4.6/include
 /usr/local/include
 /usr/lib/gcc/i686-linux-gnu/4.6/include-fixed
 /usr/include/i386-linux-gnu
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-o' 'it' '-mtune=generic' '-march=i686'
 /usr/lib/gcc/i686-linux-gnu/4.6/cc1plus -fpreprocessed it.ii -quiet -dumpbase
it.cpp -mtune=generic -march=i686 -auxbase it -version -fstack-protector -o
it.s
GNU C++ (Ubuntu/Linaro 4.6.3-1ubuntu5) version 4.6.3 (i686-linux-gnu)
    compiled by GNU C version 4.6.3, GMP version 5.0.2, MPFR version 3.1.0-p3,
MPC version 0.9
GGC heuristics: --param ggc-min-expand=89 --param ggc-min-heapsize=111959
GNU C++ (Ubuntu/Linaro 4.6.3-1ubuntu5) version 4.6.3 (i686-linux-gnu)
    compiled by GNU C version 4.6.3, GMP version 5.0.2, MPFR version 3.1.0-p3,
MPC version 0.9
GGC heuristics: --param ggc-min-expand=89 --param ggc-min-heapsize=111959
Compiler executable checksum: 2ed62271b86e2b75137544459bab1a81
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-o' 'it' '-mtune=generic' '-march=i686'
 as --32 -o it.o it.s
COMPILER_PATH=/usr/lib/gcc/i686-linux-gnu/4.6/:/usr/lib/gcc/i686-linux-gnu/4.6/:/usr/lib/gcc/i686-linux-gnu/:/usr/lib/gcc/i686-linux-gnu/4.6/:/usr/lib/gcc/i686-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/i686-linux-gnu/4.6/:/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/:/usr/lib/gcc/i686-linux-gnu/4.6/../../../../lib/:/lib/i386-linux-gnu/:/lib/../lib/:/usr/lib/i386-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/i686-linux-gnu/4.6/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-o' 'it' '-mtune=generic' '-march=i686'
 /usr/lib/gcc/i686-linux-gnu/4.6/collect2 --sysroot=/ --build-id
--no-add-needed --as-needed --eh-frame-hdr -m elf_i386 --hash-style=gnu
-dynamic-linker /lib/ld-linux.so.2 -z relro -o it
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crt1.o
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crti.o
/usr/lib/gcc/i686-linux-gnu/4.6/crtbegin.o -L/usr/lib/gcc/i686-linux-gnu/4.6
-L/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu
-L/usr/lib/gcc/i686-linux-gnu/4.6/../../../../lib -L/lib/i386-linux-gnu
-L/lib/../lib -L/usr/lib/i386-linux-gnu -L/usr/lib/../lib
-L/usr/lib/gcc/i686-linux-gnu/4.6/../../.. it.o -lgcc --as-needed -lgcc_s
--no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed
/usr/lib/gcc/i686-linux-gnu/4.6/crtend.o
/usr/lib/gcc/i686-linux-gnu/4.6/../../../i386-linux-gnu/crtn.o


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

* [Bug middle-end/54068] Compiler passes wrong argument to function when using optimize attribute with  -O3
  2012-07-22 23:39 [Bug c/54068] New: Compiler passes wrong argument to function when using -O3 and inline vogu00 at gmail dot com
@ 2012-07-22 23:46 ` pinskia at gcc dot gnu.org
  2012-07-23  8:26 ` rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-07-22 23:46 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |middle-end
            Summary|Compiler passes wrong       |Compiler passes wrong
                   |argument to function when   |argument to function when
                   |using -O3 and inline        |using optimize attribute
                   |                            |with  -O3
           Severity|major                       |normal


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

* [Bug middle-end/54068] Compiler passes wrong argument to function when using optimize attribute with  -O3
  2012-07-22 23:39 [Bug c/54068] New: Compiler passes wrong argument to function when using -O3 and inline vogu00 at gmail dot com
  2012-07-22 23:46 ` [Bug middle-end/54068] Compiler passes wrong argument to function when using optimize attribute with -O3 pinskia at gcc dot gnu.org
@ 2012-07-23  8:26 ` rguenth at gcc dot gnu.org
  2012-07-23 10:17 ` steven at gcc dot gnu.org
  2021-08-08 22:22 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-07-23  8:26 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|                            |i?86-*-*
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-07-23
                 CC|                            |hubicka at gcc dot gnu.org
     Ever Confirmed|0                           |1
      Known to fail|                            |4.4.7, 4.5.4, 4.6.3, 4.7.1,
                   |                            |4.8.0

--- Comment #1 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-07-23 08:25:58 UTC ---
Confirmed.  Note that I would not expect

void myfn (int a, int b) __attribute__((optimize("-O3")));

to work reliably.  Attribute optimize is supposed to be used for debugging
only.  C testcase, compile with -O0 -m32:

extern void abort (void);
void myfn (int a, int b) __attribute__((optimize("-O3")));
static inline void showme (int b)
{
   if (b != 12)
     abort ();
}
void myfn (int a, int b)
{
   showme (b);
}
int main ()
{
   myfn (5, 12);
   return 0;
}

I suppose this is the known issue with tail-call optimization which
may get upset if you have parts compiled with -O0 and parts with -O3.


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

* [Bug middle-end/54068] Compiler passes wrong argument to function when using optimize attribute with  -O3
  2012-07-22 23:39 [Bug c/54068] New: Compiler passes wrong argument to function when using -O3 and inline vogu00 at gmail dot com
  2012-07-22 23:46 ` [Bug middle-end/54068] Compiler passes wrong argument to function when using optimize attribute with -O3 pinskia at gcc dot gnu.org
  2012-07-23  8:26 ` rguenth at gcc dot gnu.org
@ 2012-07-23 10:17 ` steven at gcc dot gnu.org
  2021-08-08 22:22 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: steven at gcc dot gnu.org @ 2012-07-23 10:17 UTC (permalink / raw)
  To: gcc-bugs

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

Steven Bosscher <steven at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |steven at gcc dot gnu.org

--- Comment #2 from Steven Bosscher <steven at gcc dot gnu.org> 2012-07-23 10:17:07 UTC ---
(In reply to comment #1)
> I suppose this is the known issue with tail-call optimization which
> may get upset if you have parts compiled with -O0 and parts with -O3.

If this is a known issue, then I'd expect there is already a PR for this...?


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

* [Bug middle-end/54068] Compiler passes wrong argument to function when using optimize attribute with  -O3
  2012-07-22 23:39 [Bug c/54068] New: Compiler passes wrong argument to function when using -O3 and inline vogu00 at gmail dot com
                   ` (2 preceding siblings ...)
  2012-07-23 10:17 ` steven at gcc dot gnu.org
@ 2021-08-08 22:22 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-08 22:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54068

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
             Status|NEW                         |RESOLVED

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
251901a027bf (Jakub Jelinek            2014-02-06 11:54:20 +0100  6619)      
/* Caller and callee must agree on the calling convention, so
251901a027bf (Jakub Jelinek            2014-02-06 11:54:20 +0100  6620)        
 checking here just optimize means that with
251901a027bf (Jakub Jelinek            2014-02-06 11:54:20 +0100  6621)        
 __attribute__((optimize (...))) caller could use regparm convention
251901a027bf (Jakub Jelinek            2014-02-06 11:54:20 +0100  6622)        
 and callee not, or vice versa.  Instead look at whether the callee
251901a027bf (Jakub Jelinek            2014-02-06 11:54:20 +0100  6623)        
 is optimized or not.  */

So dup of bug 60062.

*** This bug has been marked as a duplicate of bug 60062 ***

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

end of thread, other threads:[~2021-08-08 22:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-22 23:39 [Bug c/54068] New: Compiler passes wrong argument to function when using -O3 and inline vogu00 at gmail dot com
2012-07-22 23:46 ` [Bug middle-end/54068] Compiler passes wrong argument to function when using optimize attribute with -O3 pinskia at gcc dot gnu.org
2012-07-23  8:26 ` rguenth at gcc dot gnu.org
2012-07-23 10:17 ` steven at gcc dot gnu.org
2021-08-08 22:22 ` pinskia at gcc dot gnu.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).