public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/57546] New: templated gnu multiversion function pointer returns wrong value
@ 2013-06-06 17:54 mib.bugzilla at gmail dot com
  2013-08-02 14:41 ` [Bug c++/57546] " mib.bugzilla at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: mib.bugzilla at gmail dot com @ 2013-06-06 17:54 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 57546
           Summary: templated gnu multiversion function pointer returns
                    wrong value
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mib.bugzilla at gmail dot com

/rdrive/ref/gcc/bin/g++48  fum.cpp -std=c++0x
-bash-4.1$ ./a.out
FAILED i:0 j:0x80499c6
-bash-4.1$ cat fum.cpp
template <typename T>
class Foo
{
public:
  /* Default version of foo.  */
  __attribute__ ((target("default")))
  T foo () { return 0; }

  /* corei7 version of foo.  */
  __attribute__ ((target("arch=corei7")))
  T foo () { return 0; }

  T (Foo::*p)() = &Foo::foo;   // pointer to member
};
#include <stdio.h>
int main ()
{
  Foo<int> f;
  int i = f.foo();
  int j = (f.*(f.p))();   // pointer to member call
  if (i==j && j==0) {
    printf("PASSED\n");
    return 0;
  } else {
    printf("FAILED i:%d j:0x%x\n", i, j);
    return -1;
  }
}
-bash-4.1$  /rdrive/ref/gcc/bin/g++48 -v
Using built-in specs.
COLLECT_GCC=/rdrive/ref/gcc/4.8.1/rhel60/x86/bin/g++
COLLECT_LTO_WRAPPER=/site/spt/rdrive/ref/gcc/4.8.1/rhel60/x86/bin/../libexec/gcc/i686-pc-linux-gnu/4.8.1/lto-wrapper
Target: i686-pc-linux-gnu
Configured with:
/rusers/sys_cron/grab_gcc/downloads_rel/4.8.1/gcc-4.8.1/configure
--prefix=/rdrive/ref/gcc/4.8.1/rhel60/x86 --enable-languages=c,c++,objc,fortran
--disable-multilib --target=i686-pc-linux-gnu --disable-bootstrap
--enable-decimal-float
--with-gmp=/rusers/sys_cron/grab_gcc/downloads_rel/lib/x86
--with-mpfr=/rusers/sys_cron/grab_gcc/downloads_rel/lib/x86
--with-mpc=/rusers/sys_cron/grab_gcc/downloads_rel/lib/x86
Thread model: posix
gcc version 4.8.1 (GCC)


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

* [Bug c++/57546] templated gnu multiversion function pointer returns wrong value
  2013-06-06 17:54 [Bug c++/57546] New: templated gnu multiversion function pointer returns wrong value mib.bugzilla at gmail dot com
@ 2013-08-02 14:41 ` mib.bugzilla at gmail dot com
  2013-08-02 14:43 ` mib.bugzilla at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: mib.bugzilla at gmail dot com @ 2013-08-02 14:41 UTC (permalink / raw)
  To: gcc-bugs

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

mib.bugzilla at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mib.bugzilla at gmail dot com

--- Comment #1 from mib.bugzilla at gmail dot com ---
Created attachment 30591
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30591&action=edit
test case without template, also segfault


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

* [Bug c++/57546] templated gnu multiversion function pointer returns wrong value
  2013-06-06 17:54 [Bug c++/57546] New: templated gnu multiversion function pointer returns wrong value mib.bugzilla at gmail dot com
  2013-08-02 14:41 ` [Bug c++/57546] " mib.bugzilla at gmail dot com
@ 2013-08-02 14:43 ` mib.bugzilla at gmail dot com
  2021-08-12  4:36 ` [Bug c++/57546] gnu multiversion function pointer returns wrong value or gets rejected pinskia at gcc dot gnu.org
  2021-08-12  4:37 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: mib.bugzilla at gmail dot com @ 2013-08-02 14:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from mib.bugzilla at gmail dot com ---
I rerun this test today and the program segfaults.

Also get the same behavior (segfault) if the template is removed. I'll attach
the non-templated test case

 g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/site/spt/rdrive/ref/gcc/4.8.1/rhel60/efi2/bin/../libexec/gcc/x86_64-unknown-linux-gnu/4.8.1/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with:
/rusers/sys_cron/grab_gcc/downloads_rel/4.8.1/gcc-4.8.1/configure
--prefix=/rdrive/ref/gcc/4.8.1/rhel60/efi2
--enable-languages=c,c++,objc,fortran --disable-multilib --enable-bootstrap
--target=x86_64-unknown-linux-gnu --disable-bootstrap --enable-decimal-float
--with-gmp=/rusers/sys_cron/grab_gcc/downloads_rel/lib/efi2
--with-mpfr=/rusers/sys_cron/grab_gcc/downloads_rel/lib/efi2
--with-mpc=/rusers/sys_cron/grab_gcc/downloads_rel/lib/efi2
Thread model: posix
gcc version 4.8.1 (GCC)


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

* [Bug c++/57546] gnu multiversion function pointer returns wrong value or gets rejected
  2013-06-06 17:54 [Bug c++/57546] New: templated gnu multiversion function pointer returns wrong value mib.bugzilla at gmail dot com
  2013-08-02 14:41 ` [Bug c++/57546] " mib.bugzilla at gmail dot com
  2013-08-02 14:43 ` mib.bugzilla at gmail dot com
@ 2021-08-12  4:36 ` pinskia at gcc dot gnu.org
  2021-08-12  4:37 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-12  4:36 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid, wrong-code
     Ever confirmed|0                           |1
            Summary|templated gnu multiversion  |gnu multiversion function
                   |function pointer returns    |pointer returns wrong value
                   |wrong value                 |or gets rejected
   Last reconfirmed|                            |2021-08-12
             Status|UNCONFIRMED                 |NEW

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed, starting in GCC 6.4 (and 7+), GCC rejects it (even a non-template
version):
<source>: In constructor 'constexpr Foo<int>::Foo()':
<source>:3:7: error: cannot convert 'int (*)(Foo<int>*)' to 'int
(Foo<int>::*)()' in initialization
 class Foo
       ^~~
<source>: In function 'int main()':
<source>:19:12: note: synthesized method 'constexpr Foo<int>::Foo()' first
required here 
   Foo<int> f;
            ^

Which is totally bogus.
note even the non-templated version is wrong.
Here is that:

class Foo
{
public:
  /* Default version of foo.  */
  __attribute__ ((target("default")))
  int foo () { return 0; }

  /* corei7 version of foo.  */
  __attribute__ ((target("arch=corei7")))
  int foo () { return 0; }
};
#include <stdio.h>
int main ()
{
  Foo f;
  int i = f.foo();
  int (Foo::*p1)() = &Foo::foo;
  int j = (f.*p1)();
  if (i==j && j==0) {
    printf("PASSED\n");
    return 0;
  } else {
    printf("FAILED i:%d j:0x%x\n", i, j);
    return -1;
  }
}
----- CUT ----
Note for the above testcase GCC 6.4.0 and 7.1.0 both actually pass at -O0 but
ICEs at -O2 and they actually do the right thing for -O0:
        mov     QWORD PTR [rbp-32], OFFSET FLAT:_ZN3Foo3fooEv.ifunc(Foo*)

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

* [Bug c++/57546] gnu multiversion function pointer returns wrong value or gets rejected
  2013-06-06 17:54 [Bug c++/57546] New: templated gnu multiversion function pointer returns wrong value mib.bugzilla at gmail dot com
                   ` (2 preceding siblings ...)
  2021-08-12  4:36 ` [Bug c++/57546] gnu multiversion function pointer returns wrong value or gets rejected pinskia at gcc dot gnu.org
@ 2021-08-12  4:37 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-12  4:37 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |egor.kochetov at intel dot com

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 68098 has been marked as a duplicate of this bug. ***

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

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

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-06 17:54 [Bug c++/57546] New: templated gnu multiversion function pointer returns wrong value mib.bugzilla at gmail dot com
2013-08-02 14:41 ` [Bug c++/57546] " mib.bugzilla at gmail dot com
2013-08-02 14:43 ` mib.bugzilla at gmail dot com
2021-08-12  4:36 ` [Bug c++/57546] gnu multiversion function pointer returns wrong value or gets rejected pinskia at gcc dot gnu.org
2021-08-12  4:37 ` 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).