https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122591

--- Comment #5 from Alejandro Colomar <[email protected]> ---
(In reply to Andrew Pinski from comment #4)
> (In reply to Andrew Pinski from comment #3)
> > c_sizeof_or_alignof_type has this towards the end:
> >   /* VALUE will have the middle-end integer type sizetype.
> >      However, we should really return a value of type `size_t',
> >      which is just a typedef for an ordinary integer type.  */
> >   value = fold_convert_loc (loc, size_type_node, value);
> > 
> > Which c_countof_type should be added there too.
> 
> That is this:
> ```
> [apinski@xeond2 c]$ git diff ../c-family/c-common.cc
> diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc
> index f2eed033706..fe387725523 100644
> --- a/gcc/c-family/c-common.cc
> +++ b/gcc/c-family/c-common.cc
> @@ -4127,7 +4127,12 @@ c_countof_type (location_t loc, tree type)
>        return error_mark_node;
>      }
> 
> -  return array_type_nelts_top (type);
> +  tree value = array_type_nelts_top (type);
> +  /* VALUE will have the middle-end integer type sizetype.
> +     However, we should really return a value of type `size_t',
> +     which is just a typedef for an ordinary integer type.  */
> +  value = fold_convert_loc (loc, size_type_node, value);
> +  return value;
>  }
>  ^L
>  /* Handle C and C++ default attributes.  */
> 
> ```

Thanks!  I've put this in a patch, and also added a test, and am now testing
for regressions.  I'll send a patch later today.  (My mail issues have been
resolved already, BTW.)

Reply via email to