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

            Bug ID: 68079
           Summary: hppa: pointers to method types need canonicalization
                    before comparison
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: danglin at gcc dot gnu.org
                CC: deller at gmx dot de
  Target Milestone: ---
              Host: hppa*-*-* (32-bit)
            Target: hppa*-*-* (32-bit)
             Build: hppa*-*-* (32-bit)

Created attachment 36573
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36573&action=edit
Test program.

On 32-bit hppa targets, pointers to functions need canonicalization prior
to comparison as they point to non unique function descriptors and not directly
to the functions themselves.

The attached testcase demonstrates the problem.  The test passes on x86
but fails on hppa.

A number of kde packages (e.g., kitemmodels) fail to build because of this bug.

Currently, we have the following code in dojump.c to canonicalize function
pointers:

  if (HAVE_canonicalize_funcptr_for_compare
      && TREE_CODE (TREE_TYPE (treeop0)) == POINTER_TYPE
      && TREE_CODE (TREE_TYPE (TREE_TYPE (treeop0)))
          == FUNCTION_TYPE
      && TREE_CODE (TREE_TYPE (treeop1)) == POINTER_TYPE
      && TREE_CODE (TREE_TYPE (TREE_TYPE (treeop1)))
          == FUNCTION_TYPE)
    {

At this point, we have using the testcase:

1209      if (targetm.have_canonicalize_funcptr_for_compare ()
(gdb) p debug_tree (treeop0)
<ssa_name 0xfb7f5e60
   type <pointer_type 0xfb644120
       type <method_type 0xfb644000 type <integer_type 0xfd508420 int>
           SI
           size <integer_cst 0xfd4f5c90 constant 32>
           unit size <integer_cst 0xfd4f5ca8 constant 4>
           align 32 symtab 0 alias set -1 canonical type 0xfb640b40 method
basetype <record_type 0xfb640960 testlib>
           arg-types <tree_list 0xfb6424f8 value <pointer_type 0xfb644060>
               chain <tree_list 0xfd50d4c8 value <void_type 0xfd508a20 void>>>
           pointer_to_this <pointer_type 0xfb644120>>
       public unsigned SI size <integer_cst 0xfd4f5c90 32> unit size
<integer_cst 0xfd4f5ca8 4>
       align 32 symtab 0 alias set -1 canonical type 0xfb644180>
   visiteddef_stmt _6 = MEM[(struct _t *)func_5].__pfn;

   version 6>
$1 = void
(gdb) p debug_tree (treeop1)
<addr_expr 0xfb642600
   type <pointer_type 0xfb644180
       type <method_type 0xfb640b40 type <integer_type 0xfd508420 int>
           SI
           size <integer_cst 0xfd4f5c90 constant 32>
           unit size <integer_cst 0xfd4f5ca8 constant 4>
           align 32 symtab 0 alias set -1 canonical type 0xfb640b40 method
basetype <record_type 0xfb640960 testlib>
           arg-types <tree_list 0xfb6421f8 value <pointer_type 0xfb640ba0>
               chain <tree_list 0xfd50d4c8 value <void_type 0xfd508a20 void>>>
           pointer_to_this <pointer_type 0xfb644180>>
       unsigned SI size <integer_cst 0xfd4f5c90 32> unit size <integer_cst
0xfd4f5ca8 4>
       align 32 symtab 0 alias set -1 canonical type 0xfb644180>
   constant
   arg 0 <function_decl 0xfb63cb00 func1 type <method_type 0xfb640b40>
       addressable asm_written used public static decl_5 SI file testlib.cpp
line 5 col 5 align 32 context <record_type 0xfb640960 testlib> initial
<error_mark 0xfd504220>
       full-name "int testlib::func1()"
       pending-inline-info 0xfc330a20
       (mem:SI (symbol_ref/v:SI ("@_ZN7testlib5func1Ev") [flags 0x1]
<function_decl 0xfb63cb00 func1>) [0  S4 A32])
       chain <function_decl 0xfb63cb80 findfunc type <function_type 0xfb640c60>
           public static decl_5 decl_6 SI file testlib.cpp line 10 col 6 align
32 context <record_type 0xfb640960 testlib> initial <block 0xfb61d930> result
<result_decl 0xfb643230 D.34957>
           full-name "static void testlib::findfunc(void**)"
           pending-inline-info 0xfb9fd3f0 arguments <parm_decl 0xfb643190 _a>
           struct-function 0xfbbf5d00>>>
$2 = void

A METHOD_TYPE is also a function and pointers to method types point at function
descriptors on hppa.  So, we also need to canonicalize pointers to methods.

The current code also fails to canonicalize REFERENCE_TYPEs that refer to
functions:

#define POINTER_TYPE_P(TYPE) \
  (TREE_CODE (TYPE) == POINTER_TYPE || TREE_CODE (TYPE) == REFERENCE_TYPE)

Reply via email to