diff mbox series

[RFA] attribs: fix typedefs in generic code [PR105492]

Message ID 20220505180728.2791914-1-jason@redhat.com
State New
Headers show
Series [RFA] attribs: fix typedefs in generic code [PR105492] | expand

Commit Message

Jason Merrill May 5, 2022, 6:07 p.m. UTC
In my patch for PR100545 I added an assert to check for broken typedefs in
set_underlying_type, and it found one in this case:
rs6000_handle_altivec_attribute had the same problem as
handle_mode_attribute.  So let's move the fixup into decl_attributes.

Tested that this fixes the ICE on a cross compiler, regression tested
x86_64-pc-linux-gnu, OK for trunk?

	PR c/105492

gcc/ChangeLog:

	* attribs.cc (decl_attributes): Fix broken typedefs here.

gcc/c-family/ChangeLog:

	* c-attribs.cc (handle_mode_attribute): Don't fix broken typedefs
	here.
---
 gcc/attribs.cc            | 15 +++++++++++++++
 gcc/c-family/c-attribs.cc | 10 ----------
 2 files changed, 15 insertions(+), 10 deletions(-)


base-commit: 000f4480005035d0811e009a7cb25b42721f0a6e

Comments

Jason Merrill May 10, 2022, 8:48 p.m. UTC | #1
Ping?

On 5/5/22 14:07, Jason Merrill wrote:
> In my patch for PR100545 I added an assert to check for broken typedefs in
> set_underlying_type, and it found one in this case:
> rs6000_handle_altivec_attribute had the same problem as
> handle_mode_attribute.  So let's move the fixup into decl_attributes.
> 
> Tested that this fixes the ICE on a cross compiler, regression tested
> x86_64-pc-linux-gnu, OK for trunk?
> 
> 	PR c/105492
> 
> gcc/ChangeLog:
> 
> 	* attribs.cc (decl_attributes): Fix broken typedefs here.
> 
> gcc/c-family/ChangeLog:
> 
> 	* c-attribs.cc (handle_mode_attribute): Don't fix broken typedefs
> 	here.
> ---
>   gcc/attribs.cc            | 15 +++++++++++++++
>   gcc/c-family/c-attribs.cc | 10 ----------
>   2 files changed, 15 insertions(+), 10 deletions(-)
> 
> diff --git a/gcc/attribs.cc b/gcc/attribs.cc
> index b219f878042..0648391f0c6 100644
> --- a/gcc/attribs.cc
> +++ b/gcc/attribs.cc
> @@ -872,6 +872,21 @@ decl_attributes (tree *node, tree attributes, int flags,
>   	  tree ret = (spec->handler) (cur_and_last_decl, name, args,
>   				      flags|cxx11_flag, &no_add_attrs);
>   
> +	  /* Fix up typedefs clobbered by attribute handlers.  */
> +	  if (TREE_CODE (*node) == TYPE_DECL
> +	      && anode == &TREE_TYPE (*node)
> +	      && DECL_ORIGINAL_TYPE (*node)
> +	      && TYPE_NAME (*anode) == *node
> +	      && TYPE_NAME (cur_and_last_decl[0]) != *node)
> +	    {
> +	      tree t = cur_and_last_decl[0];
> +	      DECL_ORIGINAL_TYPE (*node) = t;
> +	      tree tt = build_variant_type_copy (t);
> +	      cur_and_last_decl[0] = tt;
> +	      TREE_TYPE (*node) = tt;
> +	      TYPE_NAME (tt) = *node;
> +	    }
> +
>   	  *anode = cur_and_last_decl[0];
>   	  if (ret == error_mark_node)
>   	    {
> diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc
> index b1953a45f9b..a280987c111 100644
> --- a/gcc/c-family/c-attribs.cc
> +++ b/gcc/c-family/c-attribs.cc
> @@ -2204,16 +2204,6 @@ handle_mode_attribute (tree *node, tree name, tree args,
>   						 TYPE_QUALS (type));
>         if (TYPE_USER_ALIGN (type))
>   	*node = build_aligned_type (*node, TYPE_ALIGN (type));
> -
> -      tree decl = node[2];
> -      if (decl && TYPE_NAME (type) == decl)
> -	{
> -	  /* Set up the typedef all over again.  */
> -	  DECL_ORIGINAL_TYPE (decl) = NULL_TREE;
> -	  TREE_TYPE (decl) = *node;
> -	  set_underlying_type (decl);
> -	  *node = TREE_TYPE (decl);
> -	}
>       }
>   
>     return NULL_TREE;
> 
> base-commit: 000f4480005035d0811e009a7cb25b42721f0a6e
Jason Merrill May 16, 2022, 3:15 p.m. UTC | #2
Ping.

On 5/10/22 16:48, Jason Merrill wrote:
> Ping?
> 
> On 5/5/22 14:07, Jason Merrill wrote:
>> In my patch for PR100545 I added an assert to check for broken 
>> typedefs in
>> set_underlying_type, and it found one in this case:
>> rs6000_handle_altivec_attribute had the same problem as
>> handle_mode_attribute.  So let's move the fixup into decl_attributes.
>>
>> Tested that this fixes the ICE on a cross compiler, regression tested
>> x86_64-pc-linux-gnu, OK for trunk?
>>
>>     PR c/105492
>>
>> gcc/ChangeLog:
>>
>>     * attribs.cc (decl_attributes): Fix broken typedefs here.
>>
>> gcc/c-family/ChangeLog:
>>
>>     * c-attribs.cc (handle_mode_attribute): Don't fix broken typedefs
>>     here.
>> ---
>>   gcc/attribs.cc            | 15 +++++++++++++++
>>   gcc/c-family/c-attribs.cc | 10 ----------
>>   2 files changed, 15 insertions(+), 10 deletions(-)
>>
>> diff --git a/gcc/attribs.cc b/gcc/attribs.cc
>> index b219f878042..0648391f0c6 100644
>> --- a/gcc/attribs.cc
>> +++ b/gcc/attribs.cc
>> @@ -872,6 +872,21 @@ decl_attributes (tree *node, tree attributes, int 
>> flags,
>>         tree ret = (spec->handler) (cur_and_last_decl, name, args,
>>                         flags|cxx11_flag, &no_add_attrs);
>> +      /* Fix up typedefs clobbered by attribute handlers.  */
>> +      if (TREE_CODE (*node) == TYPE_DECL
>> +          && anode == &TREE_TYPE (*node)
>> +          && DECL_ORIGINAL_TYPE (*node)
>> +          && TYPE_NAME (*anode) == *node
>> +          && TYPE_NAME (cur_and_last_decl[0]) != *node)
>> +        {
>> +          tree t = cur_and_last_decl[0];
>> +          DECL_ORIGINAL_TYPE (*node) = t;
>> +          tree tt = build_variant_type_copy (t);
>> +          cur_and_last_decl[0] = tt;
>> +          TREE_TYPE (*node) = tt;
>> +          TYPE_NAME (tt) = *node;
>> +        }
>> +
>>         *anode = cur_and_last_decl[0];
>>         if (ret == error_mark_node)
>>           {
>> diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc
>> index b1953a45f9b..a280987c111 100644
>> --- a/gcc/c-family/c-attribs.cc
>> +++ b/gcc/c-family/c-attribs.cc
>> @@ -2204,16 +2204,6 @@ handle_mode_attribute (tree *node, tree name, 
>> tree args,
>>                            TYPE_QUALS (type));
>>         if (TYPE_USER_ALIGN (type))
>>       *node = build_aligned_type (*node, TYPE_ALIGN (type));
>> -
>> -      tree decl = node[2];
>> -      if (decl && TYPE_NAME (type) == decl)
>> -    {
>> -      /* Set up the typedef all over again.  */
>> -      DECL_ORIGINAL_TYPE (decl) = NULL_TREE;
>> -      TREE_TYPE (decl) = *node;
>> -      set_underlying_type (decl);
>> -      *node = TREE_TYPE (decl);
>> -    }
>>       }
>>     return NULL_TREE;
>>
>> base-commit: 000f4480005035d0811e009a7cb25b42721f0a6e
>
Joseph Myers May 16, 2022, 9:18 p.m. UTC | #3
On Mon, 16 May 2022, Jason Merrill via Gcc-patches wrote:

> Ping.

OK.
diff mbox series

Patch

diff --git a/gcc/attribs.cc b/gcc/attribs.cc
index b219f878042..0648391f0c6 100644
--- a/gcc/attribs.cc
+++ b/gcc/attribs.cc
@@ -872,6 +872,21 @@  decl_attributes (tree *node, tree attributes, int flags,
 	  tree ret = (spec->handler) (cur_and_last_decl, name, args,
 				      flags|cxx11_flag, &no_add_attrs);
 
+	  /* Fix up typedefs clobbered by attribute handlers.  */
+	  if (TREE_CODE (*node) == TYPE_DECL
+	      && anode == &TREE_TYPE (*node)
+	      && DECL_ORIGINAL_TYPE (*node)
+	      && TYPE_NAME (*anode) == *node
+	      && TYPE_NAME (cur_and_last_decl[0]) != *node)
+	    {
+	      tree t = cur_and_last_decl[0];
+	      DECL_ORIGINAL_TYPE (*node) = t;
+	      tree tt = build_variant_type_copy (t);
+	      cur_and_last_decl[0] = tt;
+	      TREE_TYPE (*node) = tt;
+	      TYPE_NAME (tt) = *node;
+	    }
+
 	  *anode = cur_and_last_decl[0];
 	  if (ret == error_mark_node)
 	    {
diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc
index b1953a45f9b..a280987c111 100644
--- a/gcc/c-family/c-attribs.cc
+++ b/gcc/c-family/c-attribs.cc
@@ -2204,16 +2204,6 @@  handle_mode_attribute (tree *node, tree name, tree args,
 						 TYPE_QUALS (type));
       if (TYPE_USER_ALIGN (type))
 	*node = build_aligned_type (*node, TYPE_ALIGN (type));
-
-      tree decl = node[2];
-      if (decl && TYPE_NAME (type) == decl)
-	{
-	  /* Set up the typedef all over again.  */
-	  DECL_ORIGINAL_TYPE (decl) = NULL_TREE;
-	  TREE_TYPE (decl) = *node;
-	  set_underlying_type (decl);
-	  *node = TREE_TYPE (decl);
-	}
     }
 
   return NULL_TREE;