[clang] [llvm] Add support for template as type parameter (PR #127654)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 11 12:53:30 PDT 2025
ykhatav wrote:
> > I am not sure that I understand your concern completely. Consider the following DWARF output based on my implementation. How would you say "v1" should be represented ideally?
> > ```
> > 0x00000042: DW_TAG_structure_type
> > DW_AT_calling_convention (DW_CC_pass_by_value)
> > DW_AT_name ("other")
> > DW_AT_byte_size (0x08)
> > DW_AT_decl_file ("")
> > DW_AT_decl_line (6)
> >
> > 0x00000048: DW_TAG_template_type_parameter
> > DW_AT_type (0x0000003e "int")
> > DW_AT_name ("T")
> >
> > 0x0000004e: DW_TAG_member
> > DW_AT_name ("v1")
> > DW_AT_type (0x0000006d "trait<int>::type")
> > DW_AT_decl_file ("")
> > DW_AT_decl_line (7)
> > DW_AT_data_member_location (0x00)
> >
> > 0x00000057: DW_TAG_member
> > DW_AT_name ("v2")
> > DW_AT_type (0x00000048 "other<int>::T")
> > DW_AT_decl_file ("")
> > DW_AT_decl_line (8)
> > DW_AT_data_member_location (0x04)
> > ```
>
> That's basically my point, sorry, that v1 must be represented as "trait::type" (because it has to be canonical) and so if many uses, like this one, of a type in a template can't reference the DW_TAG_template_type_parameter, because it's non-canonical - I'm not sure there's a lot of value in making it work for the subset of cases where it is workable.
>
Are you suggesting that for the implementation to be considered as complete, both v1 and v2 should have the same type information? I.e "v1" type should point to 0x48 instead of 0x6d? As per my understanding based on the DWARF output below, the type for "trait<int>::type"(0x6d) DOES reference a DW_TAG_template_type_parameter(0x67) entry:
````x0000000c: DW_TAG_compile_unit
DW_AT_producer ("clang version 21.0.0git (https://github.com/llvm/llvm-project.git 270fe3076a362b1e4746c86dee1a4f5b887d0f93)")
DW_AT_language (DW_LANG_C_plus_plus_14)
DW_AT_name ("test_db.cpp")
DW_AT_str_offsets_base (0x00000008)
DW_AT_stmt_list (0x00000000)
DW_AT_comp_dir ("")
DW_AT_low_pc (0x0000000000001130)
DW_AT_high_pc (0x000000000000113f)
DW_AT_addr_base (0x00000008)
0x00000023: DW_TAG_subprogram
DW_AT_low_pc (0x0000000000001130)
DW_AT_high_pc (0x000000000000113f)
DW_AT_frame_base (DW_OP_reg6 RBP)
DW_AT_name ("main")
DW_AT_decl_file ("")
DW_AT_decl_line (10)
DW_AT_type (0x0000003e "int")
DW_AT_external (true)
0x00000032: DW_TAG_variable
DW_AT_location (DW_OP_fbreg -12)
DW_AT_name ("local")
DW_AT_decl_file ("")
DW_AT_decl_line (11)
DW_AT_type (0x00000042 "other<int>")
0x0000003d: NULL
0x0000003e: DW_TAG_base_type
DW_AT_name ("int")
DW_AT_encoding (DW_ATE_signed)
DW_AT_byte_size (0x04)
0x00000042: DW_TAG_structure_type
DW_AT_calling_convention (DW_CC_pass_by_value)
DW_AT_name ("other<int>")
DW_AT_byte_size (0x08)
DW_AT_decl_file ("")
DW_AT_decl_line (6)
0x00000048: DW_TAG_template_type_parameter
DW_AT_type (0x0000003e "int")
DW_AT_name ("T")
0x0000004e: DW_TAG_member
DW_AT_name ("v1")
DW_AT_type (0x0000006d "trait<int>::type")
DW_AT_decl_file ("")
DW_AT_decl_line (7)
DW_AT_data_member_location (0x00)
0x00000057: DW_TAG_member
DW_AT_name ("v2")
DW_AT_type (0x00000048 "other<int>::T")
DW_AT_decl_file ("")
DW_AT_decl_line (8)
DW_AT_data_member_location (0x04)
0x00000060: NULL
0x00000061: DW_TAG_structure_type
DW_AT_calling_convention (DW_CC_pass_by_value)
DW_AT_name ("trait<int>")
DW_AT_byte_size (0x01)
DW_AT_decl_file ("")
DW_AT_decl_line (2)
0x00000067: DW_TAG_template_type_parameter
DW_AT_type (0x0000003e "int")
DW_AT_name ("T")
0x0000006d: DW_TAG_typedef
DW_AT_type (0x00000067 "trait<int>::T")
DW_AT_name ("type")
DW_AT_decl_file ("")
DW_AT_decl_line (3)
0x00000075: NULL
0x00000076: NULL
````
https://github.com/llvm/llvm-project/pull/127654
More information about the cfe-commits
mailing list