This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 1/4] Support lambda templates.


On 03.09.2013 04:50, Jason Merrill wrote:
On 09/02/2013 05:18 PM, Adam Butcher wrote:
> will focus on the parameter pack stuff (when I get a chance).
>
Sounds good.

I had a quick hack at getting pack expansion working for the conversion op. The syntactic side seems to be okay. It gets all the way to finalizing the tu. It generates suitable diagnostics if I force warnings in various places in my
testcase.

I've done what amounts to the following (diff hand edited to removing noisy
debug logging and temporaries):

------------------
@@ -795,20 +794,39 @@ maybe_add_lambda_conv_op (tree type)

     while (src)
       {
-       if (FUNCTION_PARAMETER_PACK_P (src))
-         return;
+       tree new_node = copy_node (src);

        if (!fn_args)
-         fn_args = tgt = copy_node (src);
+         fn_args = tgt = new_node;
        else
          {
-           TREE_CHAIN (tgt) = copy_node (src);
-           tgt = TREE_CHAIN (tgt);
+           TREE_CHAIN (tgt) = new_node;
+           tgt = new_node;
          }

        mark_exp_read (tgt);
+
+       if (FUNCTION_PARAMETER_PACK_P (tgt))
+           vec_safe_push (argvec, make_pack_expansion (tgt));
+       else
            vec_safe_push (argvec,
generic_lambda_p ? convert_from_reference (tgt) : tgt);

        src = TREE_CHAIN (src);
       }
------------------


Problem is that no RTL is set for the incoming parms in the instantiation of the expansion. It ICEs in gimple_expand_cfg because 'DECL_RTL_IF_SET (var)' returns nullptr for the incoming parms resulting in a failed assertion that
SA.partition_to_pseudo[i] is non-null.

What follows below is basically a dump of various info that may help you to point me in the right direction or may be completely useless or unnecessary to
you.

Any ideas appreciated.

Cheers,
Adam


The error diagnostic is:


/home/ajb/t7-variadic-ptr.cpp: In static member function âstatic decltype (((main()::<lambda(P ...)>)0u).operator()(main::__lambda1::_FUN::<unnamed> ...)) main()::<lambda(P ...)>::_FUN(P ...) [with P = {double, double, double}; decltype (((main()::<lambda(P ...)>)0u).operator()(main::__lambda1::_FUN::<unnamed> ...)) = float]â:

/home/ajb/t7-variadic-ptr.cpp:13:37: internal compiler error: in gimple_expand_cfg, at cfgexpand.c:4649
    auto g = [] <typename... P> (P...) { return 3.f; };
                                     ^

This only occurs if I instantiate the conversion op.


I added the following tracing to gimple_expand_cfg:

--------------
@@ -4635,9 +4635,17 @@ gimple_expand_cfg (void)
     {
       tree var = SSA_NAME_VAR (partition_to_var (SA.map, i));

+      debug_tree (var);
+
+      if (TREE_CODE (var) != VAR_DECL)
+ fprintf (stderr, "SA.partition_to_pseudo[%d] == %p\n", i, SA.partition_to_pseudo[i]);
+
       if (TREE_CODE (var) != VAR_DECL
          && !SA.partition_to_pseudo[i])
+       {
          SA.partition_to_pseudo[i] = DECL_RTL_IF_SET (var);
+ fprintf (stderr, "SA.partition_to_pseudo[%d] => %p\n", i, SA.partition_to_pseudo[i]);
+       }
       gcc_assert (SA.partition_to_pseudo[i]);

       /* If this decl was marked as living in multiple places, reset
--------------


I expected the instantiated parm_decl for the pack expansion parms to look
similar to this (from a 'normal' non-pack parm) ...

 <parm_decl 0x7f38340e1f80 D.2134
    type <real_type 0x7f3833f83f18 float type_6 SF
        size <integer_cst 0x7f3833f85340 constant 32>
        unit size <integer_cst 0x7f3833f85360 constant 4>
align 32 symtab 0 alias set -1 canonical type 0x7f3833f83f18 precision 32
        pointer_to_this <pointer_type 0x7f3833f8d150>>
used SF file /home/ajb/t7-variadic-ptr.cpp line 12 col 30 size <integer_cst 0x7f3833f85340 32> unit size <integer_cst 0x7f3833f85360 4>
    align 32 context <function_decl 0x7f38340e0900 _FUN>

    (mem/c:SF (plus:DI (reg/f:DI 70 virtual-stack-vars)
(const_int -20 [0xffffffffffffffec])) [0 D.2134+0 S4 A32]) arg-type <real_type 0x7f3833f83f18 float>
    incoming-rtl (reg:SF 21 xmm0 [ D.2134 ])>


... but instead it looks like this:


 <parm_decl 0x7f38340e4600 D.2145
    type <real_type 0x7f3833f8d000 double type_6 DF
        size <integer_cst 0x7f3833f67fc0 constant 64>
        unit size <integer_cst 0x7f3833f67fe0 constant 8>
align 64 symtab 0 alias set -1 canonical type 0x7f3833f8d000 precision 64
        pointer_to_this <pointer_type 0x7f3833f8d1f8>>
    used VOID file /home/ajb/t7-variadic-ptr.cpp line 13 col 34
    align 8
arg-type <real_type 0x7f3833f8d000 double> chain <parm_decl 0x7f38340e4680 D.2146>>


Everything under the tree type seems to be 'default' and I note that context
 has gone (it is there in the pack expansion expression prior to
 instantiation).  I'm not sure if this is relevant.

(note I was passing 3 doubles into the variadic template and a float into the 'plain' single arg template)


Here's some dumps of the expansion creation from maybe_add_lambda_conv_op:


SRC =>
  <parm_decl 0x7f0ae009e880 D.2062
    type <type_pack_expansion 0x7f0ae00a0498
        type <template_type_parm 0x7f0ae00a03f0 P VOID
            align 8 symtab 0 alias set -1 canonical type 0x7f0ae008c150
           index 0 level 1 orig_level 1
            chain <type_decl 0x7f0ae0098cf0 P>>
        type_0 type_6 VOID
        align 8 symtab 0 alias set -1 structural equality>
    decl_1 VOID file /home/ajb/t7-variadic-ptr.cpp line 13 col 34
    align 8 context <function_decl 0x7f0ae009f800 operator()>
   >
NEW_NODE =>
  <parm_decl 0x7f0ae009ea00 D.2068
    type <type_pack_expansion 0x7f0ae00a0498
        type <template_type_parm 0x7f0ae00a03f0 P VOID
            align 8 symtab 0 alias set -1 canonical type 0x7f0ae008c150
           index 0 level 1 orig_level 1
            chain <type_decl 0x7f0ae0098cf0 P>>
        type_0 type_6 VOID
        align 8 symtab 0 alias set -1 structural equality>
    decl_1 VOID file /home/ajb/t7-variadic-ptr.cpp line 13 col 34
    align 8 context <function_decl 0x7f0ae009f800 operator()>
   >
MAKE_PACK_EXPANSION =>
  <expr_pack_expansion 0x7f0ae009d270
    type <type_pack_expansion 0x7f0ae00a0498
        type <template_type_parm 0x7f0ae00a03f0 P VOID
            align 8 symtab 0 alias set -1 canonical type 0x7f0ae008c150
           index 0 level 1 orig_level 1
            chain <type_decl 0x7f0ae0098cf0 P>>
        type_0 type_6 VOID
        align 8 symtab 0 alias set -1 structural equality>

arg 0 <parm_decl 0x7f0ae009ea00 D.2068 type <type_pack_expansion 0x7f0ae00a0498>
        decl_1 VOID file /home/ajb/t7-variadic-ptr.cpp line 13 col 34
        align 8 context <function_decl 0x7f0ae009f800 operator()>
       >
arg 1 <tree_list 0x7f0ae00a12d0 value <parm_decl 0x7f0ae009ea00 D.2068>>>


(note the decl context is updated to _FUN instead of operator() after this was logged).


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]