public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/41355]  New: Type of ADDR_EXPR in CALL_EXPR not rebuilt when function is cloned
@ 2009-09-14 16:38 baldrick at free dot fr
  2010-07-05 18:44 ` [Bug tree-optimization/41355] " baldrick at gcc dot gnu dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: baldrick at free dot fr @ 2009-09-14 16:38 UTC (permalink / raw)
  To: gcc-bugs

Testcase, compile at -O2.  A clone "g.clone.0" is formed which is the same as
"g", only the second argument has been dropped.  The bug is that in the
CALL_EXPR the type of the called function is still the original type.

// begin testcase
static __attribute__((noinline)) int g(int i, int j) { 
   if (j != 0) return 0;
   return i;
}
int f(int i) { return g(i, 0); }
// end testcase

Breaking on verify_gimple_call, and waiting until after "Assembling functions:
g.clone.0 float" is printed, notice how the type of the addr_expr is a pointer
to "type <function_type 0x7ffff70c2540 type <integer_type 0x7ffff7e8c540 int>",
while the type of g.clone.0 (see arg 0) is "type <function_type 0x7ffff70c2e40
type <integer_type 0x7ffff7e8c540 int>", and these two types do not match,
though they should.

(gdb) call debug_tree(fn)
 <addr_expr 0x7ffff7ff0b00
    type <pointer_type 0x7ffff70c26c0
        type <function_type 0x7ffff70c2540 type <integer_type 0x7ffff7e8c540
int>
            QI
            size <integer_cst 0x7ffff7e7b7e0 constant 8>
            unit size <integer_cst 0x7ffff7e7b810 constant 1>
            align 8 symtab 0 alias set -1 canonical type 0x7ffff70c2540
            arg-types <tree_list 0x7ffff70da3c0 value <integer_type
0x7ffff7e8c540 int>
                chain <tree_list 0x7ffff70da390 value <integer_type
0x7ffff7e8c540 int>
                    chain <tree_list 0x7ffff7e999f0 value <void_type
0x7ffff7e9b3c0 void>>>>
            pointer_to_this <pointer_type 0x7ffff70c26c0>>
        unsigned DI
        size <integer_cst 0x7ffff7e7bb70 constant 64>
        unit size <integer_cst 0x7ffff7e7bba0 constant 8>
        align 64 symtab 0 alias set -1 canonical type 0x7ffff70c26c0>
    readonly constant
    arg 0 <function_decl 0x7ffff7123200 g.clone.0
        type <function_type 0x7ffff70c2e40 type <integer_type 0x7ffff7e8c540
int>
            QI size <integer_cst 0x7ffff7e7b7e0 8> unit size <integer_cst
0x7ffff7e7b810 1>
            align 8 symtab 0 alias set -1 canonical type 0x7ffff70c2540
            arg-types <tree_list 0x7ffff70daa20 value <integer_type
0x7ffff7e8c540 int> chain <tree_list 0x7ffff7e999f0>>
            pointer_to_this <pointer_type 0x7ffff70c26c0>>
        readonly addressable asm_written used nothrow static decl_5 QI file
clone.c line 1 col 38 align 8 attributes <tree_list 0x7ffff70da3f0> initial
<error_mark 0x7ffff7e86e60> abstract_origin <function_decl 0x7ffff70c1c00 g>
        arguments <parm_decl 0x7ffff7e84d80 i type <integer_type 0x7ffff7e8c540
int>
            used SI file clone.c line 1 col 44
            size <integer_cst 0x7ffff7e7ba80 constant 32>
            unit size <integer_cst 0x7ffff7e7b6f0 constant 4>
            align 32 context <function_decl 0x7ffff7123200 g.clone.0>
abstract_origin <parm_decl 0x7ffff7e846c0 i>
            (reg/v:SI 0 ax [orig:59 i ] [59]) arg-type <integer_type
0x7ffff7e8c540 int>
            incoming-rtl (reg:SI 5 di [ i ])>
        result <result_decl 0x7ffff70db100 D.2707 type <integer_type
0x7ffff7e8c540 int>
            used ignored regdecl SI file clone.c line 1 col 38 size
<integer_cst 0x7ffff7e7ba80 32> unit size <integer_cst 0x7ffff7e7b6f0 4>
            align 32 context <function_decl 0x7ffff7123200 g.clone.0>
abstract_origin <result_decl 0x7ffff70db000 D.1606>
            (reg:SI 58 [ <retval> ])>
        (mem:QI (symbol_ref:DI ("g.clone.0") [flags 0x3] <function_decl
0x7ffff7123200 g.clone.0>) [0 S1 A8])>
    clone.c:5:16>


-- 
           Summary: Type of ADDR_EXPR in CALL_EXPR not rebuilt when function
                    is cloned
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: baldrick at free dot fr


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


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

* [Bug tree-optimization/41355] Type of ADDR_EXPR in CALL_EXPR not rebuilt when function is cloned
  2009-09-14 16:38 [Bug tree-optimization/41355] New: Type of ADDR_EXPR in CALL_EXPR not rebuilt when function is cloned baldrick at free dot fr
@ 2010-07-05 18:44 ` baldrick at gcc dot gnu dot org
  2010-07-05 19:02 ` hubicka at ucw dot cz
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: baldrick at gcc dot gnu dot org @ 2010-07-05 18:44 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from baldrick at gcc dot gnu dot org  2010-07-05 18:43 -------
It turns out that the problem is that when build_function_type_skip_args
creates
the new type, TYPE_POINTER_TO for the new type is still pointing to the old
type.
When gimple_call_set_fndecl is used to change the fndecl to one with less
arguments, an ADDR_EXPR is built.  The type of the ADDR_EXPR is obtained from
the
TYPE_POINTER_TO field of the new type, and thus has type pointer-to-old-type
rather than pointer-to-new-type.  I'm testing the following patch.  The idea
here is that calling copy_node has no advantage.  In spite of the comment,
build_distinct_type_copy preserves attributes etc too, so it might as well
be used always.  [I think the comment refers to some earlier logic, since
the change introducing build_distinct_type_copy post-dates it].

Index: gcc-4.5/gcc/tree.c
===================================================================
--- gcc-4.5.orig/gcc/tree.c     2010-07-05 20:26:21.349376337 +0200
+++ gcc-4.5/gcc/tree.c  2010-07-05 20:29:11.582730610 +0200
@@ -7208,24 +7208,10 @@
        new_reversed = void_list_node;
     }

-  /* Use copy_node to preserve as much as possible from original type
-     (debug info, attribute lists etc.)
-     Exception is METHOD_TYPEs must have THIS argument.
-     When we are asked to remove it, we need to build new FUNCTION_TYPE
-     instead.  */
-  if (TREE_CODE (orig_type) != METHOD_TYPE
-      || !bitmap_bit_p (args_to_skip, 0))
-    {
-      new_type = copy_node (orig_type);
-      TYPE_ARG_TYPES (new_type) = new_reversed;
-    }
-  else
-    {
-      new_type
-        = build_distinct_type_copy (build_function_type (TREE_TYPE
(orig_type),
-                                                        new_reversed));
-      TYPE_CONTEXT (new_type) = TYPE_CONTEXT (orig_type);
-    }
+  new_type
+    = build_distinct_type_copy (build_function_type (TREE_TYPE (orig_type),
+                                                     new_reversed));
+  TYPE_CONTEXT (new_type) = TYPE_CONTEXT (orig_type);

   /* This is a new type, not a copy of an old type.  Need to reassociate
      variants.  We can handle everything except the main variant lazily.  */


-- 

baldrick at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hubicka at gcc dot gnu dot
                   |                            |org
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2010-07-05 18:43:39
               date|                            |


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


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

* [Bug tree-optimization/41355] Type of ADDR_EXPR in CALL_EXPR not rebuilt when function is cloned
  2009-09-14 16:38 [Bug tree-optimization/41355] New: Type of ADDR_EXPR in CALL_EXPR not rebuilt when function is cloned baldrick at free dot fr
  2010-07-05 18:44 ` [Bug tree-optimization/41355] " baldrick at gcc dot gnu dot org
@ 2010-07-05 19:02 ` hubicka at ucw dot cz
  2010-07-05 19:14 ` baldrick at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: hubicka at ucw dot cz @ 2010-07-05 19:02 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from hubicka at ucw dot cz  2010-07-05 19:02 -------
Subject: Re:  Type of ADDR_EXPR in CALL_EXPR
        not rebuilt when function is cloned

> It turns out that the problem is that when build_function_type_skip_args
> creates
> the new type, TYPE_POINTER_TO for the new type is still pointing to the old
> type.
> When gimple_call_set_fndecl is used to change the fndecl to one with less
> arguments, an ADDR_EXPR is built.  The type of the ADDR_EXPR is obtained from
> the
> TYPE_POINTER_TO field of the new type, and thus has type pointer-to-old-type
> rather than pointer-to-new-type.  I'm testing the following patch.  The idea
> here is that calling copy_node has no advantage.  In spite of the comment,

The conditional you removed is about case where METHOD_TYPE is passed and
"this" pointer
is not removed.  In this case we still want to produce METHOD_TYPE just with
args
adjusted.  I think this functionality should be preserved.

Are attributes attached to decl (not type) also copied?

Honza


-- 


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


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

* [Bug tree-optimization/41355] Type of ADDR_EXPR in CALL_EXPR not rebuilt when function is cloned
  2009-09-14 16:38 [Bug tree-optimization/41355] New: Type of ADDR_EXPR in CALL_EXPR not rebuilt when function is cloned baldrick at free dot fr
  2010-07-05 18:44 ` [Bug tree-optimization/41355] " baldrick at gcc dot gnu dot org
  2010-07-05 19:02 ` hubicka at ucw dot cz
@ 2010-07-05 19:14 ` baldrick at gcc dot gnu dot org
  2010-07-05 19:19 ` hubicka at ucw dot cz
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: baldrick at gcc dot gnu dot org @ 2010-07-05 19:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from baldrick at gcc dot gnu dot org  2010-07-05 19:14 -------
Hi Honza, my original patch was silly, I'm trying this instead:

@@ -7216,7 +7216,7 @@
   if (TREE_CODE (orig_type) != METHOD_TYPE
       || !bitmap_bit_p (args_to_skip, 0))
     {
-      new_type = copy_node (orig_type);
+      new_type = build_distinct_type_copy (orig_type);
       TYPE_ARG_TYPES (new_type) = new_reversed;
     }
   else


-- 


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


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

* [Bug tree-optimization/41355] Type of ADDR_EXPR in CALL_EXPR not rebuilt when function is cloned
  2009-09-14 16:38 [Bug tree-optimization/41355] New: Type of ADDR_EXPR in CALL_EXPR not rebuilt when function is cloned baldrick at free dot fr
                   ` (2 preceding siblings ...)
  2010-07-05 19:14 ` baldrick at gcc dot gnu dot org
@ 2010-07-05 19:19 ` hubicka at ucw dot cz
  2010-07-06  8:23 ` baldrick at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: hubicka at ucw dot cz @ 2010-07-05 19:19 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from hubicka at ucw dot cz  2010-07-05 19:18 -------
Subject: Re:  Type of ADDR_EXPR in CALL_EXPR
        not rebuilt when function is cloned

> Hi Honza, my original patch was silly, I'm trying this instead:
This seems fine, thanks!  
Honza


-- 


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


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

* [Bug tree-optimization/41355] Type of ADDR_EXPR in CALL_EXPR not rebuilt when function is cloned
  2009-09-14 16:38 [Bug tree-optimization/41355] New: Type of ADDR_EXPR in CALL_EXPR not rebuilt when function is cloned baldrick at free dot fr
                   ` (3 preceding siblings ...)
  2010-07-05 19:19 ` hubicka at ucw dot cz
@ 2010-07-06  8:23 ` baldrick at gcc dot gnu dot org
  2010-07-07 15:25 ` baldrick at gcc dot gnu dot org
  2010-07-07 21:24 ` ebotcazou at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: baldrick at gcc dot gnu dot org @ 2010-07-06  8:23 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from baldrick at gcc dot gnu dot org  2010-07-06 08:23 -------
Even better, it actually works! :)


-- 


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


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

* [Bug tree-optimization/41355] Type of ADDR_EXPR in CALL_EXPR not rebuilt when function is cloned
  2009-09-14 16:38 [Bug tree-optimization/41355] New: Type of ADDR_EXPR in CALL_EXPR not rebuilt when function is cloned baldrick at free dot fr
                   ` (4 preceding siblings ...)
  2010-07-06  8:23 ` baldrick at gcc dot gnu dot org
@ 2010-07-07 15:25 ` baldrick at gcc dot gnu dot org
  2010-07-07 21:24 ` ebotcazou at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: baldrick at gcc dot gnu dot org @ 2010-07-07 15:25 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from baldrick at gcc dot gnu dot org  2010-07-07 15:25 -------
Fixed in commits 161918 (mainline) and 161919 (gcc-4.5 branch).


-- 

baldrick at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


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


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

* [Bug tree-optimization/41355] Type of ADDR_EXPR in CALL_EXPR not rebuilt when function is cloned
  2009-09-14 16:38 [Bug tree-optimization/41355] New: Type of ADDR_EXPR in CALL_EXPR not rebuilt when function is cloned baldrick at free dot fr
                   ` (5 preceding siblings ...)
  2010-07-07 15:25 ` baldrick at gcc dot gnu dot org
@ 2010-07-07 21:24 ` ebotcazou at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: ebotcazou at gcc dot gnu dot org @ 2010-07-07 21:24 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from ebotcazou at gcc dot gnu dot org  2010-07-07 21:24 -------
> Fixed in commits 161918 (mainline) and 161919 (gcc-4.5 branch).

The right procedure is to copy-and-paste the ChangeLog entry in the commit log,
this will automatically add a cross-reference with an URL to this audit trail.


-- 


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


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

end of thread, other threads:[~2010-07-07 21:24 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-14 16:38 [Bug tree-optimization/41355] New: Type of ADDR_EXPR in CALL_EXPR not rebuilt when function is cloned baldrick at free dot fr
2010-07-05 18:44 ` [Bug tree-optimization/41355] " baldrick at gcc dot gnu dot org
2010-07-05 19:02 ` hubicka at ucw dot cz
2010-07-05 19:14 ` baldrick at gcc dot gnu dot org
2010-07-05 19:19 ` hubicka at ucw dot cz
2010-07-06  8:23 ` baldrick at gcc dot gnu dot org
2010-07-07 15:25 ` baldrick at gcc dot gnu dot org
2010-07-07 21:24 ` ebotcazou at gcc dot gnu dot 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).