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

            Bug ID: 87188
           Summary: Function pointer canonicalization optimized away
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: danglin at gcc dot gnu.org
  Target Milestone: ---
              Host: hppa*-*-* (32-bit)
            Target: hppa*-*-* (32-bit)
             Build: hppa*-*-* (32-bit)

Created attachment 44647
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=44647&action=edit
c++ testcase

This is debian bug #907586 reported by Mattias Ellert:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=907586

Compilation is as follows:

g++ -O2 -g -c -o main.o main.cpp
g++ -O2 -g -fPIC -c -o S.o S.cpp
g++ -shared -fPIC -o libS.so S.o
g++ -o main main.o -L. -lS
g++ -o altmain main.o S.o

-- Running using shared library
LD_LIBRARY_PATH=. ./main
not OK
-- Running using static build
./altmain
OK

If S.cpp is compiled at -O0, the test passes.

The problem in the optimized code is here:

        .align 4
.LC0:
        .word   P%_ZNK2SVneERKS_
        .text
        .align 4
.globl _ZNK2SR4findEv
        .type   _ZNK2SR4findEv, @function
.LFB1721:
        .cfi_startproc
_ZNK2SR4findEv:
        .PROC
        .CALLINFO FRAME=0,NO_CALLS
        .ENTRY
        ldw 0(%r26),%r21
        comb,=,n %r26,%r21,.L14
        ldw 12(%r21),%r20
        ldw 8(%r21),%r28
        addil LT'.LC0,%r19
        ldw RT'.LC0(%r1),%r31
        ldw 0(%r31),%r22
        comclr,<> %r22,%r28,%r28
        ldi 1,%r28

The comclr instruction compares the function pointer at .LC0 with the one
indirectly passed via this.

The code needs to call __canonicalize_funcptr_for_compare().

Reply via email to