Paul Eggert <[email protected]> writes:

> Problem found with gcc 16.1.1 20260515 (Red Hat 16.1.1-2) on i686.
> * tests/test-stdc_rotate_left.c (test_stdc_rotate_left_ul):
> * tests/test-stdc_rotate_right.c (test_stdc_rotate_right_ul): Use
> preprocessor-time check, not a potentially runtime check, to see
> whether to use 32- or 64-bit tests.  This pacifies gcc -Woverflow.
> Include <limits.h> to get ULONG_MAX.
> ---
>  ChangeLog                      | 10 ++++++++++
>  tests/test-stdc_rotate_left.c  | 11 +++++++----
>  tests/test-stdc_rotate_right.c | 11 +++++++----
>  3 files changed, 24 insertions(+), 8 deletions(-)

Thanks, that reminds me that I was supposed to sync this with glibc
since I let Adhemerval use them there under the LGPLv2.1+ [1].

How does the attached patch look? I tested them in a glibc build as well
and they work fine there. So ideally, we can keep them in sync.

Collin

[1] https://lists.gnu.org/archive/html/bug-gnulib/2026-05/msg00005.html

>From ca9301a4b5a7059dd6b9d2364a1850d49dabf5f0 Mon Sep 17 00:00:00 2001
Message-ID: <ca9301a4b5a7059dd6b9d2364a1850d49dabf5f0.1786586667.git.collin.fu...@gmail.com>
From: Collin Funk <[email protected]>
Date: Wed, 12 Aug 2026 19:00:17 -0700
Subject: [PATCH] stdc_rotate_{left,right}-tests: adjust to share with glibc

* tests/from-glibc/tst-stdc_rotate_left.c: New file, based on
tests/test-stdc_rotate_left.c with changes to also work with the glibc
test framework. Relicense to LGPLv2.1+.
* tests/from-glibc/tst-stdc_rotate_right.c: New file, based on
tests/test-stdc_rotate_right.c with changes to also work with the glibc
test framework. Relicense to LGPLv2.1+.
* modules/stdc_rotate_left-tests (Files): List the new file.
(Depends-on): Add the new file as a source for the test program. Define
GNULIB_TEST_STDBIT when compiling.
* modules/stdc_rotate_right-tests (Files): List the new file.
(Depends-on): Add the new file as a source for the test program. Define
GNULIB_TEST_STDBIT when compiling.
---
 ChangeLog                                     | 16 ++++++
 modules/stdc_rotate_left-tests                |  4 +-
 modules/stdc_rotate_right-tests               |  4 +-
 .../tst-stdc_rotate_left.c}                   | 51 ++++++++++++-------
 .../tst-stdc_rotate_right.c}                  | 51 ++++++++++++-------
 5 files changed, 86 insertions(+), 40 deletions(-)
 rename tests/{test-stdc_rotate_left.c => from-glibc/tst-stdc_rotate_left.c} (96%)
 rename tests/{test-stdc_rotate_right.c => from-glibc/tst-stdc_rotate_right.c} (96%)

diff --git a/ChangeLog b/ChangeLog
index 4d08951061..0774c8725d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2026-08-12  Collin Funk  <[email protected]>
+
+	stdc_rotate_{left,right}-tests: adjust to share with glibc
+	* tests/from-glibc/tst-stdc_rotate_left.c: New file, based on
+	tests/test-stdc_rotate_left.c with changes to also work with the glibc
+	test framework. Relicense to LGPLv2.1+.
+	* tests/from-glibc/tst-stdc_rotate_right.c: New file, based on
+	tests/test-stdc_rotate_right.c with changes to also work with the glibc
+	test framework. Relicense to LGPLv2.1+.
+	* modules/stdc_rotate_left-tests (Files): List the new file.
+	(Depends-on): Add the new file as a source for the test program. Define
+	GNULIB_TEST_STDBIT when compiling.
+	* modules/stdc_rotate_right-tests (Files): List the new file.
+	(Depends-on): Add the new file as a source for the test program. Define
+	GNULIB_TEST_STDBIT when compiling.
+
 2026-08-12  Paul Eggert  <[email protected]>
 
 	stdc_rotate_left-tests: pacify -Woverflow
diff --git a/modules/stdc_rotate_left-tests b/modules/stdc_rotate_left-tests
index f88e0adf97..0739a719ea 100644
--- a/modules/stdc_rotate_left-tests
+++ b/modules/stdc_rotate_left-tests
@@ -1,5 +1,5 @@
 Files:
-tests/test-stdc_rotate_left.c
+tests/from-glibc/tst-stdc_rotate_left.c
 tests/macros.h
 
 Depends-on:
@@ -9,3 +9,5 @@ configure.ac:
 Makefile.am:
 TESTS += test-stdc_rotate_left
 check_PROGRAMS += test-stdc_rotate_left
+test_stdc_rotate_left_SOURCES = from-glibc/tst-stdc_rotate_left.c
+test_stdc_rotate_left_CPPFLAGS = $(AM_CPPFLAGS) -DGNULIB_TEST_STDBIT
diff --git a/modules/stdc_rotate_right-tests b/modules/stdc_rotate_right-tests
index 8a8047010e..2b440d0981 100644
--- a/modules/stdc_rotate_right-tests
+++ b/modules/stdc_rotate_right-tests
@@ -1,5 +1,5 @@
 Files:
-tests/test-stdc_rotate_right.c
+tests/from-glibc/tst-stdc_rotate_right.c
 tests/macros.h
 
 Depends-on:
@@ -9,3 +9,5 @@ configure.ac:
 Makefile.am:
 TESTS += test-stdc_rotate_right
 check_PROGRAMS += test-stdc_rotate_right
+test_stdc_rotate_right_SOURCES = from-glibc/tst-stdc_rotate_right.c
+test_stdc_rotate_right_CPPFLAGS = $(AM_CPPFLAGS) -DGNULIB_TEST_STDBIT
diff --git a/tests/test-stdc_rotate_left.c b/tests/from-glibc/tst-stdc_rotate_left.c
similarity index 96%
rename from tests/test-stdc_rotate_left.c
rename to tests/from-glibc/tst-stdc_rotate_left.c
index 10723d4afc..78af626173 100644
--- a/tests/test-stdc_rotate_left.c
+++ b/tests/from-glibc/tst-stdc_rotate_left.c
@@ -1,37 +1,46 @@
 /* Test the stdc_rotate_left_* functions and macro.
    Copyright (C) 2026 Free Software Foundation, Inc.
 
-   This file is free software: you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published
-   by the Free Software Foundation, either version 3 of the License,
-   or (at your option) any later version.
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
 
-   This file is distributed in the hope that it will be useful,
+   The GNU C Library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
 
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
 
-/* Written by Collin Funk <[email protected]>, 2026.  */
-
-#include <config.h>
+#ifdef GNULIB_TEST_STDBIT
+# include <config.h>
+#endif
 
 /* Specification.  */
 #include <stdbit.h>
 
 #include <limits.h>
 
-#include "macros.h"
+#ifdef GNULIB_TEST_STDBIT
+# include "macros.h"
+# define MAIN_STATIC
+# define MAIN main
+# define TEST_COMPARE(a, b) ASSERT ((a) == (b))
+#else
+# include <support/check.h>
+# define MAIN_STATIC static
+# define MAIN do_test
+#endif
 
 #define TEST_CASE(type, function, value, shift, expect)         \
   do                                                            \
     {                                                           \
       type v = value;                                           \
-      type e = expect;                                          \
-      ASSERT (function (v, shift) == e);                        \
-      ASSERT (stdc_rotate_left (v, shift) == e);                \
+      TEST_COMPARE (function (v, shift), expect);               \
+      TEST_COMPARE (stdc_rotate_left (v, shift), expect);       \
     }                                                           \
   while (false)
 
@@ -452,13 +461,17 @@ test_stdc_rotate_left_ull (void)
   TEST_CASES_64 (unsigned long long int, stdc_rotate_left_ull);
 }
 
-int
-main (void)
+MAIN_STATIC int
+MAIN (void)
 {
   test_stdc_rotate_left_uc ();
   test_stdc_rotate_left_us ();
   test_stdc_rotate_left_ui ();
   test_stdc_rotate_left_ul ();
   test_stdc_rotate_left_ull ();
-  return test_exit_status;
+  return 0;
 }
+
+#ifndef GNULIB_TEST_STDBIT
+# include <support/test-driver.c>
+#endif
diff --git a/tests/test-stdc_rotate_right.c b/tests/from-glibc/tst-stdc_rotate_right.c
similarity index 96%
rename from tests/test-stdc_rotate_right.c
rename to tests/from-glibc/tst-stdc_rotate_right.c
index 0ffdd928d5..b045ee9212 100644
--- a/tests/test-stdc_rotate_right.c
+++ b/tests/from-glibc/tst-stdc_rotate_right.c
@@ -1,37 +1,46 @@
 /* Test the stdc_rotate_right_* functions and macro.
    Copyright (C) 2026 Free Software Foundation, Inc.
 
-   This file is free software: you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published
-   by the Free Software Foundation, either version 3 of the License,
-   or (at your option) any later version.
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
 
-   This file is distributed in the hope that it will be useful,
+   The GNU C Library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
 
-   You should have received a copy of the GNU General Public License
-   along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
 
-/* Written by Collin Funk <[email protected]>, 2026.  */
-
-#include <config.h>
+#ifdef GNULIB_TEST_STDBIT
+# include <config.h>
+#endif
 
 /* Specification.  */
 #include <stdbit.h>
 
 #include <limits.h>
 
-#include "macros.h"
+#ifdef GNULIB_TEST_STDBIT
+# include "macros.h"
+# define MAIN_STATIC
+# define MAIN main
+# define TEST_COMPARE(a, b) ASSERT ((a) == (b))
+#else
+# include <support/check.h>
+# define MAIN_STATIC static
+# define MAIN do_test
+#endif
 
 #define TEST_CASE(type, function, value, shift, expect)         \
   do                                                            \
     {                                                           \
       type v = value;                                           \
-      type e = expect;                                          \
-      ASSERT (function (v, shift) == e);                        \
-      ASSERT (stdc_rotate_right (v, shift) == e);               \
+      TEST_COMPARE (function (v, shift), expect);               \
+      TEST_COMPARE (stdc_rotate_right (v, shift), expect);      \
     }                                                           \
   while (false)
 
@@ -452,13 +461,17 @@ test_stdc_rotate_right_ull (void)
   TEST_CASES_64 (unsigned long long int, stdc_rotate_right_ull);
 }
 
-int
-main (void)
+MAIN_STATIC int
+MAIN (void)
 {
   test_stdc_rotate_right_uc ();
   test_stdc_rotate_right_us ();
   test_stdc_rotate_right_ui ();
   test_stdc_rotate_right_ul ();
   test_stdc_rotate_right_ull ();
-  return test_exit_status;
+  return 0;
 }
+
+#ifndef GNULIB_TEST_STDBIT
+# include <support/test-driver.c>
+#endif
-- 
2.55.0

Reply via email to