Hi Joseph,

This is a fix for _Countof(), to make it return a size_t.  Previously,
it was returning a 'sizetype', some GCC internal stuff incompatible with
all standard integer types.

The first patch adds a test, and the second one makes the test succeed.
My reproducer posted on the GCC bugzilla also succeeds after this patch,
as a sanity check.

It passes regression testing:

        alx@devuan:~/src/gnu/gcc/sizetype$ git log --oneline 
gnu/master..sizetype1 
        052e8b60c9c6 (HEAD -> sizetype, tag: sizetype1) c: Fix return type of 
_Countof [PR112591]
        b891e6e55035 testsuite: Test return type of _Countof [PR112591]
        alx@devuan:~/src/gnu/gcc/sizetype$ git reset gnu/master --hard 
        HEAD is now at 7197d8062fdd aarch64: Add support for preserve_none 
function attribute [PR target/118328]
        alx@devuan:~/src/gnu/gcc/sizetype$ mkdir ../sizetype1
        alx@devuan:~/src/gnu/gcc/sizetype$ cd ../sizetype1/
        alx@devuan:~/src/gnu/gcc/sizetype1$ set -o pipefail
        alx@devuan:~/src/gnu/gcc/sizetype1$ ../sizetype/configure 
--disable-multilib --prefix=/opt/local/gnu/gcc/sizetype1 |& ts -s | tail -n1; 
echo $?
        00:00:01 config.status: creating Makefile
        0
        alx@devuan:~/src/gnu/gcc/sizetype1$ make -j24 bootstrap |& ts -s | tail 
-n1; echo $?
        00:22:12 make[1]: Leaving directory '/srv/alx/src/gnu/gcc/sizetype1'
        0
        alx@devuan:~/src/gnu/gcc/sizetype1$ make -j24 check |& ts -s | tail 
-n1; echo $?
        00:36:00 make[1]: Leaving directory '/srv/alx/src/gnu/gcc/sizetype1'
        0
        alx@devuan:~/src/gnu/gcc/sizetype1$ cd ../sizetype
        alx@devuan:~/src/gnu/gcc/sizetype$ git merge --ff-only sizetype1
        Updating 7197d8062fdd..052e8b60c9c6
        Fast-forward
         gcc/c-family/c-common.cc               | 8 +++++++-
         gcc/testsuite/gcc.dg/countof-compile.c | 6 ++++++
         2 files changed, 13 insertions(+), 1 deletion(-)
        alx@devuan:~/src/gnu/gcc/sizetype$ cd ..
        alx@devuan:~/src/gnu/gcc$ mv sizetype1/ sizetype1_b4
        alx@devuan:~/src/gnu/gcc$ mkdir sizetype1
        alx@devuan:~/src/gnu/gcc$ cd sizetype1
        alx@devuan:~/src/gnu/gcc/sizetype1$ ../sizetype/configure 
--disable-multilib --prefix=/opt/local/gnu/gcc/sizetype1 |& ts -s | tail -n1; 
echo $?
        00:00:01 config.status: creating Makefile
        0
        alx@devuan:~/src/gnu/gcc/sizetype1$ make -j24 bootstrap |& ts -s | tail 
-n1; echo $?
        00:26:38 make[1]: Leaving directory '/srv/alx/src/gnu/gcc/sizetype1'
        0
        alx@devuan:~/src/gnu/gcc/sizetype1$ make -j24 check |& ts -s | tail 
-n1; echo $?
        00:35:07 make[1]: Leaving directory '/srv/alx/src/gnu/gcc/sizetype1'
        0
        alx@devuan:~/src/gnu/gcc/sizetype1$ find -type f | grep '\.sum$' | 
while read f; do diff -u "../sizetype1_b4/$f" "$f"; done;
        --- ../sizetype1_b4/./x86_64-pc-linux-gnu/libitm/testsuite/libitm.sum   
2025-11-07 13:10:31.839768451 +0100
        +++ ./x86_64-pc-linux-gnu/libitm/testsuite/libitm.sum   2025-11-07 
15:32:04.810912210 +0100
        @@ -1,4 +1,4 @@
        -Test run by alx on Fri Nov  7 13:10:29 2025
        +Test run by alx on Fri Nov  7 15:32:02 2025
         Native configuration is x86_64-pc-linux-gnu
         
                        === libitm tests ===
        --- 
../sizetype1_b4/./x86_64-pc-linux-gnu/libatomic/testsuite/libatomic.sum     
2025-11-07 13:10:30.904793739 +0100
        +++ ./x86_64-pc-linux-gnu/libatomic/testsuite/libatomic.sum     
2025-11-07 15:32:03.844511692 +0100
        @@ -1,4 +1,4 @@
        -Test run by alx on Fri Nov  7 13:10:29 2025
        +Test run by alx on Fri Nov  7 15:32:02 2025
         Native configuration is x86_64-pc-linux-gnu
         
                        === libatomic tests ===
        --- ../sizetype1_b4/./x86_64-pc-linux-gnu/libgomp/testsuite/libgomp.sum 
2025-11-07 13:12:46.435724064 +0100
        +++ ./x86_64-pc-linux-gnu/libgomp/testsuite/libgomp.sum 2025-11-07 
15:34:07.455735770 +0100
        @@ -1,4 +1,4 @@
        -Test run by alx on Fri Nov  7 13:10:29 2025
        +Test run by alx on Fri Nov  7 15:32:02 2025
         Native configuration is x86_64-pc-linux-gnu
         
                        === libgomp tests ===
        --- 
../sizetype1_b4/./x86_64-pc-linux-gnu/libstdc++-v3/testsuite/libstdc++.sum  
2025-11-07 13:46:28.129868603 +0100
        +++ ./x86_64-pc-linux-gnu/libstdc++-v3/testsuite/libstdc++.sum  
2025-11-07 16:07:08.892875295 +0100
        @@ -1,4 +1,4 @@
        -Test run by alx on Fri Nov  7 13:10:30 2025
        +Test run by alx on Fri Nov  7 15:32:03 2025
         Native configuration is x86_64-pc-linux-gnu
         
                        === libstdc++ tests ===
        --- ../sizetype1_b4/./gcc/testsuite/objc/objc.sum       2025-11-07 
13:11:03.939353701 +0100
        +++ ./gcc/testsuite/objc/objc.sum       2025-11-07 15:35:18.184083907 
+0100
        @@ -1,4 +1,4 @@
        -Test run by alx on Fri Nov  7 13:10:30 2025
        +Test run by alx on Fri Nov  7 15:34:02 2025
         Native configuration is x86_64-pc-linux-gnu
         
                        === objc tests ===
        --- ../sizetype1_b4/./gcc/testsuite/g++/g++.sum 2025-11-07 
13:18:09.154026850 +0100
        +++ ./gcc/testsuite/g++/g++.sum 2025-11-07 16:06:01.196264695 +0100
        @@ -1,4 +1,4 @@
        -Test run by alx on Fri Nov  7 13:10:30 2025
        +Test run by alx on Fri Nov  7 15:33:50 2025
         Native configuration is x86_64-pc-linux-gnu
         
                        === g++ tests ===
        --- ../sizetype1_b4/./gcc/testsuite/gcc/gcc.sum 2025-11-07 
13:27:32.183842110 +0100
        +++ ./gcc/testsuite/gcc/gcc.sum 2025-11-07 15:50:57.456163950 +0100
        @@ -1,4 +1,4 @@
        -Test run by alx on Fri Nov  7 13:10:30 2025
        +Test run by alx on Fri Nov  7 15:32:03 2025
         Native configuration is x86_64-pc-linux-gnu
         
                        === gcc tests ===
        --- ../sizetype1_b4/./gcc/testsuite/gfortran/gfortran.sum       
2025-11-07 13:19:44.191912596 +0100
        +++ ./gcc/testsuite/gfortran/gfortran.sum       2025-11-07 
15:54:52.994261026 +0100
        @@ -1,4 +1,4 @@
        -Test run by alx on Fri Nov  7 13:10:30 2025
        +Test run by alx on Fri Nov  7 15:33:50 2025
         Native configuration is x86_64-pc-linux-gnu
         
                        === gfortran tests ===


Have a lovely day!
Alex

Alejandro Colomar (2):
  testsuite: Test return type of _Countof [PR112591]
  c: Fix return type of _Countof [PR112591]

 gcc/c-family/c-common.cc               | 8 +++++++-
 gcc/testsuite/gcc.dg/countof-compile.c | 6 ++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

Range-diff against v0:
-:  ------------ > 1:  b891e6e55035 testsuite: Test return type of _Countof 
[PR112591]
-:  ------------ > 2:  052e8b60c9c6 c: Fix return type of _Countof [PR112591]
-- 
2.51.0

Reply via email to