Bug 68079 - hppa: pointers to method types need canonicalization before comparison
Summary: hppa: pointers to method types need canonicalization before comparison
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 6.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-10-24 17:48 UTC by John David Anglin
Modified: 2015-10-25 15:46 UTC (History)
1 user (show)

See Also:
Host: hppa*-*-* (32-bit)
Target: hppa*-*-* (32-bit)
Build: hppa*-*-* (32-bit)
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Test program. (823 bytes, application/x-gzip)
2015-10-24 17:48 UTC, John David Anglin
Details
Patch for trunk (343 bytes, patch)
2015-10-24 17:52 UTC, John David Anglin
Details | Diff
Patch for gcc-5 (349 bytes, patch)
2015-10-24 17:52 UTC, John David Anglin
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description John David Anglin 2015-10-24 17:48:19 UTC
Created attachment 36573 [details]
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)
Comment 1 John David Anglin 2015-10-24 17:52:06 UTC
Created attachment 36574 [details]
Patch for trunk
Comment 2 John David Anglin 2015-10-24 17:52:40 UTC
Created attachment 36575 [details]
Patch for gcc-5
Comment 3 deller 2015-10-24 18:42:32 UTC
Hi Dave,

Thanks for creating this bug report.

On 24.10.2015 19:48, danglin at gcc dot gnu.org wrote:
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68079
> A number of kde packages (e.g., kitemmodels) fail to build because of this bug.

Nitpick:
The bug/miscompilation is actually in kdebase, but it's true that it then shows
up in kitemmodels first.

Helge
Comment 4 John David Anglin 2015-10-25 15:19:19 UTC
Author: danglin
Date: Sun Oct 25 15:18:48 2015
New Revision: 229299

URL: https://gcc.gnu.org/viewcvs?rev=229299&root=gcc&view=rev
Log:
	PR middle-end/68079
	* dojump.c (do_compare_and_jump): Canonicalize both function and
	method types.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/dojump.c
Comment 5 John David Anglin 2015-10-25 15:35:44 UTC
Fixed on trunk.
Comment 6 John David Anglin 2015-10-25 15:42:50 UTC
Author: danglin
Date: Sun Oct 25 15:42:19 2015
New Revision: 229300

URL: https://gcc.gnu.org/viewcvs?rev=229300&root=gcc&view=rev
Log:
	PR middle-end/68079
	* dojump.c (do_compare_and_jump): Canonicalize both function and
	method types.


Modified:
    branches/gcc-5-branch/gcc/ChangeLog
    branches/gcc-5-branch/gcc/dojump.c
Comment 7 John David Anglin 2015-10-25 15:46:05 UTC
Author: danglin
Date: Sun Oct 25 15:45:33 2015
New Revision: 229301

URL: https://gcc.gnu.org/viewcvs?rev=229301&root=gcc&view=rev
Log:
	PR middle-end/68079
	* dojump.c (do_compare_and_jump): Canonicalize both function and
	method types.


Modified:
    branches/gcc-4_9-branch/gcc/ChangeLog
    branches/gcc-4_9-branch/gcc/dojump.c