Output from "g++ -v":
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.3/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit 
--host=i386-redhat-linux
Thread model: posix
gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-20)

Compile the following code using "g++ -S bug.c":
---8<---bug.c------------------------------------------8<---
struct Foo
{
  int __attribute__((regparm(3)))
    (*p)(int);
};
extern struct Foo *foo;
extern const struct Foo *bar;

int
baz(int i)
{
  return (foo->p)(i);
}

int
zip(int i)
{
  return (bar->p)(i);
}
---8<--------------------------------------------------8<---

The only difference between baz() and zip() is that baz() uses a "struct Foo *"
while zip() uses a "const struct Foo *".  However, in the generated assembler
code, baz() passes parameters in registers as requested, and zip() doesn't.

_Z3bazi:
        [...]
        movl    foo, %eax
        movl    (%eax), %edx
        movl    8(%ebp), %eax
        call    *%edx

_Z3zipi:
        [...]
        movl    bar, %eax
        pushl   8(%ebp)
        movl    (%eax), %eax
        call    *%eax

Note: This bug is specific to the C++ compiler; the C compiler does the right
thing.

-- 
           Summary: G++ disregards __attribute__((regparm(3))) when calling
                    through a const pointer
           Product: gcc
           Version: 3.2.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jjk at acm dot org
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: i386-redhat-linux
GCC target triplet: i386-redhat-linux


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

Reply via email to