Message ID | 52E2F3B6.4050003@oracle.com |
---|---|
State | New |
Headers | show |
> in this bug we ICE in dwarf2out.c:is_base_type with -g, because it doesn't > know how to handle the TEMPLATE_TYPE_PARM coming from the C++ front-end and > representing 'auto' in this kind of C++1y code. > > That it shouldn't ICE and return 0 instead I'm pretty sure, I'm less sure > about the next problem, that is what gen_type_die_with_usage should do: > build a DW_TAG_unspecified_type, like happens for NULLPTR_TYPE or > LANG_TYPE?!? Anyway, my wild guessing resulted in adding an hook, per the > below draft (in any case, tentative names and comments but passes testing). > Or we want something completely different? We've been discussing this in the DWARF workgroup, and the current proposal on the table is to use DW_TAG_unspecified_type, as you have done here. This looks OK to me (although I kind of wish we had a better way of testing for "auto" than doing a string compare!). Depending on further discussions in the workgroup, we'll probably need to do a bit more work to support auto return types, but I think this is the right direction. -cary
On 01/29/2014 06:41 PM, Cary Coutant wrote: >> in this bug we ICE in dwarf2out.c:is_base_type with -g, because it doesn't >> know how to handle the TEMPLATE_TYPE_PARM coming from the C++ front-end and >> representing 'auto' in this kind of C++1y code. >> >> That it shouldn't ICE and return 0 instead I'm pretty sure, I'm less sure >> about the next problem, that is what gen_type_die_with_usage should do: >> build a DW_TAG_unspecified_type, like happens for NULLPTR_TYPE or >> LANG_TYPE?!? Anyway, my wild guessing resulted in adding an hook, per the >> below draft (in any case, tentative names and comments but passes testing). >> Or we want something completely different? > We've been discussing this in the DWARF workgroup, and the current > proposal on the table is to use DW_TAG_unspecified_type, as you have > done here. This looks OK to me (although I kind of wish we had a > better way of testing for "auto" than doing a string compare!). > Depending on further discussions in the workgroup, we'll probably need > to do a bit more work to support auto return types, but I think this > is the right direction. Thanks Cary. I think Jason already proceeded in this direction in his patch for c++/53756: http://gcc.gnu.org/ml/gcc-patches/2014-01/msg01806.html and I'm following up with some additional bits for this bug. By the way, this recycling of TEMPLATE_TYPE_PARM + name seems weird to me too, I noticed it a couple of times already (I think it shows in an open diagnostic issue too). I think the alternative would an additional TREE_CODE and a lot of uses of it wherever now we just say TEMPLATE_TYPE_PARM (eg, in pt.c). Maybe it's worth it, maybe not, I don't know if Jason *actually* tried the idea in his local trees. Paolo.
On 01/29/2014 12:49 PM, Paolo Carlini wrote: > By the way, > this recycling of TEMPLATE_TYPE_PARM + name seems weird to me too, I > noticed it a couple of times already (I think it shows in an open > diagnostic issue too). I think the alternative would an additional > TREE_CODE and a lot of uses of it wherever now we just say > TEMPLATE_TYPE_PARM (eg, in pt.c). Maybe it's worth it, maybe not, I > don't know if Jason *actually* tried the idea in his local trees. I didn't. We represent auto as a TEMPLATE_TYPE_PARM because auto deduction works like template deduction, and if we wanted to call it something else we would need to replace it with a TEMPLATE_TYPE_PARM in order to do deduction, plus check for auto when checking whether a type is dependent. So, doable, but kind of a pain. Jason
Index: cp/cp-lang.c =================================================================== --- cp/cp-lang.c (revision 207048) +++ cp/cp-lang.c (working copy) @@ -68,6 +68,9 @@ static tree get_template_argument_pack_elems_folde #undef LANG_HOOKS_GENERIC_GENERIC_PARAMETER_DECL_P #define LANG_HOOKS_GENERIC_GENERIC_PARAMETER_DECL_P \ template_template_parameter_p +#undef LANG_HOOKS_IS_AUTO +#define LANG_HOOKS_IS_AUTO \ + is_auto #undef LANG_HOOKS_FUNCTION_PARM_EXPANDED_FROM_PACK_P #define LANG_HOOKS_FUNCTION_PARM_EXPANDED_FROM_PACK_P \ function_parameter_expanded_from_pack_p Index: dwarf2out.c =================================================================== --- dwarf2out.c (revision 207048) +++ dwarf2out.c (working copy) @@ -10222,6 +10222,9 @@ base_type_die (tree type) static inline int is_base_type (tree type) { + if (lang_hooks.decls.is_auto (type)) + return 0; + switch (TREE_CODE (type)) { case ERROR_MARK: @@ -19653,6 +19656,23 @@ gen_tagged_type_die (tree type, when appropriate. */ } +/* Generate a DIE for an unspecified type. */ + +static void +gen_unspecified_type_die (tree type) +{ + dw_die_ref type_die = lookup_type_die (type); + if (type_die == NULL) + { + tree name = TYPE_NAME (type); + if (TREE_CODE (name) == TYPE_DECL) + name = DECL_NAME (name); + type_die = new_die (DW_TAG_unspecified_type, comp_unit_die (), type); + add_name_attribute (type_die, IDENTIFIER_POINTER (name)); + equate_type_number_to_die (type, type_die); + } +} + /* Generate a type description DIE. */ static void @@ -19718,6 +19738,13 @@ gen_type_die_with_usage (tree type, dw_die_ref con return; } + if (lang_hooks.decls.is_auto (type)) + { + gen_unspecified_type_die (type); + TREE_ASM_WRITTEN (type) = 1; + return; + } + /* We are going to output a DIE to represent the unqualified version of this type (i.e. without any const or volatile qualifiers) so get the main variant (i.e. the unqualified version) of this type @@ -19805,18 +19832,7 @@ gen_type_die_with_usage (tree type, dw_die_ref con case NULLPTR_TYPE: case LANG_TYPE: /* Just use DW_TAG_unspecified_type. */ - { - dw_die_ref type_die = lookup_type_die (type); - if (type_die == NULL) - { - tree name = TYPE_NAME (type); - if (TREE_CODE (name) == TYPE_DECL) - name = DECL_NAME (name); - type_die = new_die (DW_TAG_unspecified_type, comp_unit_die (), type); - add_name_attribute (type_die, IDENTIFIER_POINTER (name)); - equate_type_number_to_die (type, type_die); - } - } + gen_unspecified_type_die (type); break; default: Index: langhooks-def.h =================================================================== --- langhooks-def.h (revision 207048) +++ langhooks-def.h (working copy) @@ -159,6 +159,7 @@ extern tree lhd_make_node (enum tree_code); #define LANG_HOOKS_FUNCTION_PARAMETER_PACK_P hook_bool_const_tree_false #define LANG_HOOKS_GET_ARGUMENT_PACK_ELEMS hook_tree_const_tree_null #define LANG_HOOKS_GENERIC_GENERIC_PARAMETER_DECL_P hook_bool_const_tree_false +#define LANG_HOOKS_IS_AUTO hook_bool_const_tree_false #define LANG_HOOKS_FUNCTION_PARM_EXPANDED_FROM_PACK_P \ hook_bool_tree_tree_false #define LANG_HOOKS_GET_GENERIC_FUNCTION_DECL hook_tree_const_tree_null @@ -220,6 +221,7 @@ extern tree lhd_make_node (enum tree_code); LANG_HOOKS_GETDECLS, \ LANG_HOOKS_FUNCTION_DECL_EXPLICIT_P, \ LANG_HOOKS_GENERIC_GENERIC_PARAMETER_DECL_P, \ + LANG_HOOKS_IS_AUTO, \ LANG_HOOKS_FUNCTION_PARM_EXPANDED_FROM_PACK_P, \ LANG_HOOKS_GET_GENERIC_FUNCTION_DECL, \ LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL, \ Index: langhooks.h =================================================================== --- langhooks.h (revision 207048) +++ langhooks.h (working copy) @@ -164,6 +164,9 @@ struct lang_hooks_for_decls of a generic type, e.g a template template parameter for the C++ FE. */ bool (*generic_generic_parameter_decl_p) (const_tree); + /* Returns true if the parameter represents 'auto' or 'decltype(auto)'. */ + bool (*is_auto) (const_tree); + /* Determine if a function parameter got expanded from a function parameter pack. */ bool (*function_parm_expanded_from_pack_p) (tree, tree); Index: testsuite/g++.dg/cpp1y/auto-fn22.C =================================================================== --- testsuite/g++.dg/cpp1y/auto-fn22.C (revision 0) +++ testsuite/g++.dg/cpp1y/auto-fn22.C (working copy) @@ -0,0 +1,9 @@ +// PR c++/58561 +// { dg-options "-std=c++1y -g" } + +auto foo(); + +namespace N +{ + using ::foo; +}