[RFC] c++: Fix print-tree module handling for TEMPLATE_DECL

Message ID 20210403145408.725513-1-jason@redhat.com
State New
Headers show
Series
  • [RFC] c++: Fix print-tree module handling for TEMPLATE_DECL
Related show

Commit Message

Richard Biener via Gcc-patches April 3, 2021, 2:54 p.m.
The if allows TEMPLATE_DECL, but then checking DECL_MODULE_IMPORT_P crashes
on TEMPLATE_DECL.  Fixed by stripping TEMPLATE_DECL first.

Nathan, does this look right to you?

gcc/cp/ChangeLog:

	* ptree.c (cxx_print_decl): Check DECL_MODULE_IMPORT_P on
	template result.
---
 gcc/cp/ptree.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)


base-commit: a40015780f8cc49476741b6914bd5ee97bd10f1d
-- 
2.27.0

Comments

Nathan Sidwell April 5, 2021, 11:52 a.m. | #1
On 4/3/21 10:54 AM, Jason Merrill wrote:
> The if allows TEMPLATE_DECL, but then checking DECL_MODULE_IMPORT_P crashes

> on TEMPLATE_DECL.  Fixed by stripping TEMPLATE_DECL first.

> 

> Nathan, does this look right to you?

> 

> gcc/cp/ChangeLog:

> 

> 	* ptree.c (cxx_print_decl): Check DECL_MODULE_IMPORT_P on

> 	template result.


Yes, this is probably more useful than just not looking at 
template_decl's instance of these flags.  Just shows how little I've had 
to use the printer recently :)

> ---

>   gcc/cp/ptree.c | 18 +++++++++---------

>   1 file changed, 9 insertions(+), 9 deletions(-)

> 

> diff --git a/gcc/cp/ptree.c b/gcc/cp/ptree.c

> index 95a4fdf284a..33b73fb24b6 100644

> --- a/gcc/cp/ptree.c

> +++ b/gcc/cp/ptree.c

> @@ -59,16 +59,16 @@ cxx_print_decl (FILE *file, tree node, int indent)

>   

>     bool need_indent = true;

>   

> -  if (TREE_CODE (node) == FUNCTION_DECL

> -      || TREE_CODE (node) == VAR_DECL

> -      || TREE_CODE (node) == TYPE_DECL

> -      || TREE_CODE (node) == TEMPLATE_DECL

> -      || TREE_CODE (node) == CONCEPT_DECL

> -      || TREE_CODE (node) == NAMESPACE_DECL)

> +  tree ntnode = STRIP_TEMPLATE (node);

> +  if (TREE_CODE (ntnode) == FUNCTION_DECL

> +      || TREE_CODE (ntnode) == VAR_DECL

> +      || TREE_CODE (ntnode) == TYPE_DECL

> +      || TREE_CODE (ntnode) == CONCEPT_DECL

> +      || TREE_CODE (ntnode) == NAMESPACE_DECL)

>       {

>         unsigned m = 0;

> -      if (DECL_LANG_SPECIFIC (node) && DECL_MODULE_IMPORT_P (node))

> -	m = get_importing_module (node, true);

> +      if (DECL_LANG_SPECIFIC (ntnode) && DECL_MODULE_IMPORT_P (ntnode))

> +	m = get_importing_module (ntnode, true);

>   

>         if (const char *name = m == ~0u ? "" : module_name (m, true))

>   	{

> @@ -78,7 +78,7 @@ cxx_print_decl (FILE *file, tree node, int indent)

>   	  need_indent = false;

>   	}

>   

> -      if (DECL_LANG_SPECIFIC (node) && DECL_MODULE_PURVIEW_P (node))

> +      if (DECL_LANG_SPECIFIC (ntnode) && DECL_MODULE_PURVIEW_P (ntnode))

>   	{

>   	  if (need_indent)

>   	    indent_to (file, indent + 3);

> 

> base-commit: a40015780f8cc49476741b6914bd5ee97bd10f1d

> 



-- 
Nathan Sidwell

Patch

diff --git a/gcc/cp/ptree.c b/gcc/cp/ptree.c
index 95a4fdf284a..33b73fb24b6 100644
--- a/gcc/cp/ptree.c
+++ b/gcc/cp/ptree.c
@@ -59,16 +59,16 @@  cxx_print_decl (FILE *file, tree node, int indent)
 
   bool need_indent = true;
 
-  if (TREE_CODE (node) == FUNCTION_DECL
-      || TREE_CODE (node) == VAR_DECL
-      || TREE_CODE (node) == TYPE_DECL
-      || TREE_CODE (node) == TEMPLATE_DECL
-      || TREE_CODE (node) == CONCEPT_DECL
-      || TREE_CODE (node) == NAMESPACE_DECL)
+  tree ntnode = STRIP_TEMPLATE (node);
+  if (TREE_CODE (ntnode) == FUNCTION_DECL
+      || TREE_CODE (ntnode) == VAR_DECL
+      || TREE_CODE (ntnode) == TYPE_DECL
+      || TREE_CODE (ntnode) == CONCEPT_DECL
+      || TREE_CODE (ntnode) == NAMESPACE_DECL)
     {
       unsigned m = 0;
-      if (DECL_LANG_SPECIFIC (node) && DECL_MODULE_IMPORT_P (node))
-	m = get_importing_module (node, true);
+      if (DECL_LANG_SPECIFIC (ntnode) && DECL_MODULE_IMPORT_P (ntnode))
+	m = get_importing_module (ntnode, true);
 
       if (const char *name = m == ~0u ? "" : module_name (m, true))
 	{
@@ -78,7 +78,7 @@  cxx_print_decl (FILE *file, tree node, int indent)
 	  need_indent = false;
 	}
 
-      if (DECL_LANG_SPECIFIC (node) && DECL_MODULE_PURVIEW_P (node))
+      if (DECL_LANG_SPECIFIC (ntnode) && DECL_MODULE_PURVIEW_P (ntnode))
 	{
 	  if (need_indent)
 	    indent_to (file, indent + 3);