PR c/122591

gcc/c-family/ChangeLog:

        * c-common.cc (c_countof_type): Convert return value to size_t.

Reported-by: Sam James <[email protected]>
Suggested-by: Andrew Pinski <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
---
 gcc/c-family/c-common.cc | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc
index f2eed0337065..3b418ffba25b 100644
--- a/gcc/c-family/c-common.cc
+++ b/gcc/c-family/c-common.cc
@@ -4112,6 +4112,7 @@ tree
 c_countof_type (location_t loc, tree type)
 {
   enum tree_code type_code;
+  tree value;
 
   type_code = TREE_CODE (type);
   if (type_code != ARRAY_TYPE)
@@ -4127,7 +4128,12 @@ c_countof_type (location_t loc, tree type)
       return error_mark_node;
     }
 
-  return array_type_nelts_top (type);
+  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;
 }
 
 /* Handle C and C++ default attributes.  */
-- 
2.51.0

Reply via email to