Message ID | 20230801003456.994217-1-ppalka@redhat.com |
---|---|
State | New |
Headers | show |
Series | c++: improve debug_tree for templated types/decls | expand |
On 7/31/23 20:34, Patrick Palka wrote: > Tested on x86_64-pc-linux-gnu, does this look OK for trunk? > > -- >8 -- > > gcc/cp/ChangeLog: > > * ptree.cc (cxx_print_decl): Check for DECL_LANG_SPECIFIC and > TS_DECL_COMMON only when necessary. Print DECL_TEMPLATE_INFO > for all decls that have it, not just VAR_DECL or FUNCTION_DECL. > Also print DECL_USE_TEMPLATE. > (cxx_print_type): Print TYPE_TEMPLATE_INFO. > <case BOUND_TEMPLATE_TEMPLATE_PARM>: Don't print TYPE_TI_ARGS > anymore. > <case TEMPLATE_TYPE/TEMPLATE_PARM>: Print TEMPLATE_TYPE_PARM_INDEX > instead of printing the index, level and original level > individually. > --- > gcc/cp/ptree.cc | 32 +++++++++++++++++--------------- > 1 file changed, 17 insertions(+), 15 deletions(-) > > diff --git a/gcc/cp/ptree.cc b/gcc/cp/ptree.cc > index 33af7b81f58..13306fc8762 100644 > --- a/gcc/cp/ptree.cc > +++ b/gcc/cp/ptree.cc > @@ -38,10 +38,6 @@ cxx_print_decl (FILE *file, tree node, int indent) > return; > } > > - if (!CODE_CONTAINS_STRUCT (TREE_CODE (node), TS_DECL_COMMON) > - || !DECL_LANG_SPECIFIC (node)) > - return; > - > if (TREE_CODE (node) == FUNCTION_DECL) > { > int flags = TFF_DECL_SPECIFIERS|TFF_RETURN_TYPE > @@ -106,7 +102,10 @@ cxx_print_decl (FILE *file, tree node, int indent) > need_indent = false; > } > > - if (DECL_EXTERNAL (node) && DECL_NOT_REALLY_EXTERN (node)) > + if (CODE_CONTAINS_STRUCT (TREE_CODE (node), TS_DECL_COMMON) > + && DECL_LANG_SPECIFIC (node) > + && DECL_EXTERNAL (node) > + && DECL_NOT_REALLY_EXTERN (node)) > { > if (need_indent) > indent_to (file, indent + 3); > @@ -115,6 +114,7 @@ cxx_print_decl (FILE *file, tree node, int indent) > } > > if (TREE_CODE (node) == FUNCTION_DECL > + && DECL_LANG_SPECIFIC (node) > && DECL_PENDING_INLINE_INFO (node)) > { > if (need_indent) > @@ -124,27 +124,29 @@ cxx_print_decl (FILE *file, tree node, int indent) > need_indent = false; > } > > - if (VAR_OR_FUNCTION_DECL_P (node) > + if (DECL_LANG_SPECIFIC (node) Hmm, won't this crash on a non-COMMON decl? > && DECL_TEMPLATE_INFO (node)) > - print_node (file, "template-info", DECL_TEMPLATE_INFO (node), > - indent + 4); > + { > + print_node (file, "template-info", DECL_TEMPLATE_INFO (node), > + indent + 4); > + indent_to (file, indent + 3); > + fprintf (file, " use_template=%d", DECL_USE_TEMPLATE (node)); > + } > } > > void > cxx_print_type (FILE *file, tree node, int indent) > { > + if (TYPE_LANG_SPECIFIC (node) > + && TYPE_TEMPLATE_INFO (node)) > + print_node (file, "template-info", TYPE_TEMPLATE_INFO (node), indent + 4); > + > switch (TREE_CODE (node)) > { > case BOUND_TEMPLATE_TEMPLATE_PARM: > - print_node (file, "args", TYPE_TI_ARGS (node), indent + 4); > - gcc_fallthrough (); > - > case TEMPLATE_TYPE_PARM: > case TEMPLATE_TEMPLATE_PARM: > - indent_to (file, indent + 3); > - fprintf (file, "index %d level %d orig_level %d", > - TEMPLATE_TYPE_IDX (node), TEMPLATE_TYPE_LEVEL (node), > - TEMPLATE_TYPE_ORIG_LEVEL (node)); > + print_node (file, "tpi", TEMPLATE_TYPE_PARM_INDEX (node), indent + 4); > return; > > case FUNCTION_TYPE:
On Tue, 8 Aug 2023, Jason Merrill wrote: > On 7/31/23 20:34, Patrick Palka wrote: > > Tested on x86_64-pc-linux-gnu, does this look OK for trunk? > > > > -- >8 -- > > > > gcc/cp/ChangeLog: > > > > * ptree.cc (cxx_print_decl): Check for DECL_LANG_SPECIFIC and > > TS_DECL_COMMON only when necessary. Print DECL_TEMPLATE_INFO > > for all decls that have it, not just VAR_DECL or FUNCTION_DECL. > > Also print DECL_USE_TEMPLATE. > > (cxx_print_type): Print TYPE_TEMPLATE_INFO. > > <case BOUND_TEMPLATE_TEMPLATE_PARM>: Don't print TYPE_TI_ARGS > > anymore. > > <case TEMPLATE_TYPE/TEMPLATE_PARM>: Print TEMPLATE_TYPE_PARM_INDEX > > instead of printing the index, level and original level > > individually. > > --- > > gcc/cp/ptree.cc | 32 +++++++++++++++++--------------- > > 1 file changed, 17 insertions(+), 15 deletions(-) > > > > diff --git a/gcc/cp/ptree.cc b/gcc/cp/ptree.cc > > index 33af7b81f58..13306fc8762 100644 > > --- a/gcc/cp/ptree.cc > > +++ b/gcc/cp/ptree.cc > > @@ -38,10 +38,6 @@ cxx_print_decl (FILE *file, tree node, int indent) > > return; > > } > > - if (!CODE_CONTAINS_STRUCT (TREE_CODE (node), TS_DECL_COMMON) > > - || !DECL_LANG_SPECIFIC (node)) > > - return; > > - > > if (TREE_CODE (node) == FUNCTION_DECL) > > { > > int flags = TFF_DECL_SPECIFIERS|TFF_RETURN_TYPE > > @@ -106,7 +102,10 @@ cxx_print_decl (FILE *file, tree node, int indent) > > need_indent = false; > > } > > - if (DECL_EXTERNAL (node) && DECL_NOT_REALLY_EXTERN (node)) > > + if (CODE_CONTAINS_STRUCT (TREE_CODE (node), TS_DECL_COMMON) > > + && DECL_LANG_SPECIFIC (node) > > + && DECL_EXTERNAL (node) > > + && DECL_NOT_REALLY_EXTERN (node)) > > { > > if (need_indent) > > indent_to (file, indent + 3); > > @@ -115,6 +114,7 @@ cxx_print_decl (FILE *file, tree node, int indent) > > } > > if (TREE_CODE (node) == FUNCTION_DECL > > + && DECL_LANG_SPECIFIC (node) > > && DECL_PENDING_INLINE_INFO (node)) > > { > > if (need_indent) > > @@ -124,27 +124,29 @@ cxx_print_decl (FILE *file, tree node, int indent) > > need_indent = false; > > } > > - if (VAR_OR_FUNCTION_DECL_P (node) > > + if (DECL_LANG_SPECIFIC (node) > > Hmm, won't this crash on a non-COMMON decl? Oops yes, I overlooked that DECL_LANG_SPECIFIC requires DECL_COMMON. So we should just move the early exit test down a bit. > > > && DECL_TEMPLATE_INFO (node)) We also need to constrain the kinds of decls that we test DECL_TEMPLATE_INFO on according to template_info_decl_check. -- >8 -- Subject: [PATCH] c++: improve debug_tree for templated types/decls gcc/cp/ChangeLog: * ptree.cc (cxx_print_decl): Check for DECL_LANG_SPECIFIC and TS_DECL_COMMON only when necessary. Print DECL_TEMPLATE_INFO for all decls that have it, not just VAR_DECL or FUNCTION_DECL. Also print DECL_USE_TEMPLATE. (cxx_print_type): Print TYPE_TEMPLATE_INFO. <case BOUND_TEMPLATE_TEMPLATE_PARM>: Don't print TYPE_TI_ARGS anymore. <case TEMPLATE_TYPE/TEMPLATE_PARM>: Print TEMPLATE_TYPE_PARM_INDEX instead of printing the index, level and original level individually. --- gcc/cp/ptree.cc | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/gcc/cp/ptree.cc b/gcc/cp/ptree.cc index 33af7b81f58..b4001486701 100644 --- a/gcc/cp/ptree.cc +++ b/gcc/cp/ptree.cc @@ -38,10 +38,6 @@ cxx_print_decl (FILE *file, tree node, int indent) return; } - if (!CODE_CONTAINS_STRUCT (TREE_CODE (node), TS_DECL_COMMON) - || !DECL_LANG_SPECIFIC (node)) - return; - if (TREE_CODE (node) == FUNCTION_DECL) { int flags = TFF_DECL_SPECIFIERS|TFF_RETURN_TYPE @@ -106,6 +102,10 @@ cxx_print_decl (FILE *file, tree node, int indent) need_indent = false; } + if (!CODE_CONTAINS_STRUCT (TREE_CODE (node), TS_DECL_COMMON) + || !DECL_LANG_SPECIFIC (node)) + return; + if (DECL_EXTERNAL (node) && DECL_NOT_REALLY_EXTERN (node)) { if (need_indent) @@ -124,27 +124,33 @@ cxx_print_decl (FILE *file, tree node, int indent) need_indent = false; } - if (VAR_OR_FUNCTION_DECL_P (node) + if ((VAR_OR_FUNCTION_DECL_P (node) + || TREE_CODE (node) == FIELD_DECL + || TREE_CODE (node) == TYPE_DECL + || TREE_CODE (node) == CONCEPT_DECL + || TREE_CODE (node) == TEMPLATE_DECL) && DECL_TEMPLATE_INFO (node)) - print_node (file, "template-info", DECL_TEMPLATE_INFO (node), - indent + 4); + { + print_node (file, "template-info", DECL_TEMPLATE_INFO (node), + indent + 4); + indent_to (file, indent + 3); + fprintf (file, " use_template=%d", DECL_USE_TEMPLATE (node)); + } } void cxx_print_type (FILE *file, tree node, int indent) { + if (TYPE_LANG_SPECIFIC (node) + && TYPE_TEMPLATE_INFO (node)) + print_node (file, "template-info", TYPE_TEMPLATE_INFO (node), indent + 4); + switch (TREE_CODE (node)) { case BOUND_TEMPLATE_TEMPLATE_PARM: - print_node (file, "args", TYPE_TI_ARGS (node), indent + 4); - gcc_fallthrough (); - case TEMPLATE_TYPE_PARM: case TEMPLATE_TEMPLATE_PARM: - indent_to (file, indent + 3); - fprintf (file, "index %d level %d orig_level %d", - TEMPLATE_TYPE_IDX (node), TEMPLATE_TYPE_LEVEL (node), - TEMPLATE_TYPE_ORIG_LEVEL (node)); + print_node (file, "tpi", TEMPLATE_TYPE_PARM_INDEX (node), indent + 4); return; case FUNCTION_TYPE:
On 8/10/23 16:59, Patrick Palka wrote: > On Tue, 8 Aug 2023, Jason Merrill wrote: > >> On 7/31/23 20:34, Patrick Palka wrote: >>> Tested on x86_64-pc-linux-gnu, does this look OK for trunk? >>> >>> -- >8 -- >>> >>> gcc/cp/ChangeLog: >>> >>> * ptree.cc (cxx_print_decl): Check for DECL_LANG_SPECIFIC and >>> TS_DECL_COMMON only when necessary. Print DECL_TEMPLATE_INFO >>> for all decls that have it, not just VAR_DECL or FUNCTION_DECL. >>> Also print DECL_USE_TEMPLATE. >>> (cxx_print_type): Print TYPE_TEMPLATE_INFO. >>> <case BOUND_TEMPLATE_TEMPLATE_PARM>: Don't print TYPE_TI_ARGS >>> anymore. >>> <case TEMPLATE_TYPE/TEMPLATE_PARM>: Print TEMPLATE_TYPE_PARM_INDEX >>> instead of printing the index, level and original level >>> individually. >>> --- >>> gcc/cp/ptree.cc | 32 +++++++++++++++++--------------- >>> 1 file changed, 17 insertions(+), 15 deletions(-) >>> >>> diff --git a/gcc/cp/ptree.cc b/gcc/cp/ptree.cc >>> index 33af7b81f58..13306fc8762 100644 >>> --- a/gcc/cp/ptree.cc >>> +++ b/gcc/cp/ptree.cc >>> @@ -38,10 +38,6 @@ cxx_print_decl (FILE *file, tree node, int indent) >>> return; >>> } >>> - if (!CODE_CONTAINS_STRUCT (TREE_CODE (node), TS_DECL_COMMON) >>> - || !DECL_LANG_SPECIFIC (node)) >>> - return; >>> - >>> if (TREE_CODE (node) == FUNCTION_DECL) >>> { >>> int flags = TFF_DECL_SPECIFIERS|TFF_RETURN_TYPE >>> @@ -106,7 +102,10 @@ cxx_print_decl (FILE *file, tree node, int indent) >>> need_indent = false; >>> } >>> - if (DECL_EXTERNAL (node) && DECL_NOT_REALLY_EXTERN (node)) >>> + if (CODE_CONTAINS_STRUCT (TREE_CODE (node), TS_DECL_COMMON) >>> + && DECL_LANG_SPECIFIC (node) >>> + && DECL_EXTERNAL (node) >>> + && DECL_NOT_REALLY_EXTERN (node)) >>> { >>> if (need_indent) >>> indent_to (file, indent + 3); >>> @@ -115,6 +114,7 @@ cxx_print_decl (FILE *file, tree node, int indent) >>> } >>> if (TREE_CODE (node) == FUNCTION_DECL >>> + && DECL_LANG_SPECIFIC (node) >>> && DECL_PENDING_INLINE_INFO (node)) >>> { >>> if (need_indent) >>> @@ -124,27 +124,29 @@ cxx_print_decl (FILE *file, tree node, int indent) >>> need_indent = false; >>> } >>> - if (VAR_OR_FUNCTION_DECL_P (node) >>> + if (DECL_LANG_SPECIFIC (node) >> >> Hmm, won't this crash on a non-COMMON decl? > > Oops yes, I overlooked that DECL_LANG_SPECIFIC requires DECL_COMMON. So > we should just move the early exit test down a bit. > >> >>> && DECL_TEMPLATE_INFO (node)) > > We also need to constrain the kinds of decls that we test > DECL_TEMPLATE_INFO on according to template_info_decl_check. > > -- >8 -- > > Subject: [PATCH] c++: improve debug_tree for templated types/decls > > gcc/cp/ChangeLog: > > * ptree.cc (cxx_print_decl): Check for DECL_LANG_SPECIFIC and > TS_DECL_COMMON only when necessary. Print DECL_TEMPLATE_INFO > for all decls that have it, not just VAR_DECL or FUNCTION_DECL. > Also print DECL_USE_TEMPLATE. > (cxx_print_type): Print TYPE_TEMPLATE_INFO. > <case BOUND_TEMPLATE_TEMPLATE_PARM>: Don't print TYPE_TI_ARGS > anymore. > <case TEMPLATE_TYPE/TEMPLATE_PARM>: Print TEMPLATE_TYPE_PARM_INDEX > instead of printing the index, level and original level > individually. OK. Jason
diff --git a/gcc/cp/ptree.cc b/gcc/cp/ptree.cc index 33af7b81f58..13306fc8762 100644 --- a/gcc/cp/ptree.cc +++ b/gcc/cp/ptree.cc @@ -38,10 +38,6 @@ cxx_print_decl (FILE *file, tree node, int indent) return; } - if (!CODE_CONTAINS_STRUCT (TREE_CODE (node), TS_DECL_COMMON) - || !DECL_LANG_SPECIFIC (node)) - return; - if (TREE_CODE (node) == FUNCTION_DECL) { int flags = TFF_DECL_SPECIFIERS|TFF_RETURN_TYPE @@ -106,7 +102,10 @@ cxx_print_decl (FILE *file, tree node, int indent) need_indent = false; } - if (DECL_EXTERNAL (node) && DECL_NOT_REALLY_EXTERN (node)) + if (CODE_CONTAINS_STRUCT (TREE_CODE (node), TS_DECL_COMMON) + && DECL_LANG_SPECIFIC (node) + && DECL_EXTERNAL (node) + && DECL_NOT_REALLY_EXTERN (node)) { if (need_indent) indent_to (file, indent + 3); @@ -115,6 +114,7 @@ cxx_print_decl (FILE *file, tree node, int indent) } if (TREE_CODE (node) == FUNCTION_DECL + && DECL_LANG_SPECIFIC (node) && DECL_PENDING_INLINE_INFO (node)) { if (need_indent) @@ -124,27 +124,29 @@ cxx_print_decl (FILE *file, tree node, int indent) need_indent = false; } - if (VAR_OR_FUNCTION_DECL_P (node) + if (DECL_LANG_SPECIFIC (node) && DECL_TEMPLATE_INFO (node)) - print_node (file, "template-info", DECL_TEMPLATE_INFO (node), - indent + 4); + { + print_node (file, "template-info", DECL_TEMPLATE_INFO (node), + indent + 4); + indent_to (file, indent + 3); + fprintf (file, " use_template=%d", DECL_USE_TEMPLATE (node)); + } } void cxx_print_type (FILE *file, tree node, int indent) { + if (TYPE_LANG_SPECIFIC (node) + && TYPE_TEMPLATE_INFO (node)) + print_node (file, "template-info", TYPE_TEMPLATE_INFO (node), indent + 4); + switch (TREE_CODE (node)) { case BOUND_TEMPLATE_TEMPLATE_PARM: - print_node (file, "args", TYPE_TI_ARGS (node), indent + 4); - gcc_fallthrough (); - case TEMPLATE_TYPE_PARM: case TEMPLATE_TEMPLATE_PARM: - indent_to (file, indent + 3); - fprintf (file, "index %d level %d orig_level %d", - TEMPLATE_TYPE_IDX (node), TEMPLATE_TYPE_LEVEL (node), - TEMPLATE_TYPE_ORIG_LEVEL (node)); + print_node (file, "tpi", TEMPLATE_TYPE_PARM_INDEX (node), indent + 4); return; case FUNCTION_TYPE: