From: Rainer Orth Date: Sun, 15 Feb 2026 22:11:44 +0000 (+0100) Subject: Change int8_t to signed char on Solaris [PR113450,PR123176] X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0a48b1fe9866556ce41295d1e3b739c608ea5f22;p=thirdparty%2Fgcc.git Change int8_t to signed char on Solaris [PR113450,PR123176] int8_t is currently defined as char in Solaris /* * Basic / Extended integer types * * The following defines the basic fixed-size integer types. * * Implementations are free to typedef them to Standard C integer types or * extensions that they support. If an implementation does not support one * of the particular integer data types below, then it should not define the * typedefs and macros corresponding to that data type. Note that int8_t * is not defined in -Xs mode on ISAs for which the ABI specifies "char" * as an unsigned entity because there is no way to define an eight bit * signed integral. */ typedef char int8_t; typedef signed char int8_t; and _CHAR_IS_SIGNED defined as 1 in . As has long been known, this violates C99, 7.18.1.1, Exact-width integer types. While this works in general nonetheless, it creates constant trouble for C++ code as can be seen in PRs libstdc++/113450 and recently libstdc++/123176, but also in LLVM. While Oracle Solaris engineering is amenable to changing int8_t to signed char, this will take time. However, it proved easy to do so now using fixincludes. This works for a GCC bootstrap just fine with one exception: as documented in PR d/123509, libdruntime has its own definition of int8_t which is now inconsistent with GCC's. This leads to some gdc.test and libphobos testsuite failures, which can easily be fixed with the patch attached to that PR. I wouldn't consider this a showstopper for GCC 16 if that patch wouldn't make it to the release. However, the failures point to another problem: with this change, the mangling of void func(int8_t); changes in C++, creating an ABI break. Fortunately, this isn't seen in libstdc++, so the impact should be reasonable compared to the constant trouble the current definition causes for C++. Besides, clang already uses #define __INT8_TYPE__ signed char apparently without problems. In case users do run into the incompatiblity, the fixed definitions are wrapped in #if !defined(_LEGACY_INT8_T)/#endif so there's an easy way back to the original definition. Bootstrapped on i386-pc-solaris2.11, amd64-pc-solaris2.11, sparc-sun-solaris2.11, and sparcv9-sun-solaris2.11 with only the D failure described above. I've also run 1-stage and bootstrap builds of LLVM main using a patched GCC 16 as bootstrap compiler on amd64-pc-solaris2.11 and sparcv9-sun-solaris2.11 without regressions. 2026-01-07 Rainer Orth fixincludes: PR libstdc++/113450 PR libstdc++/123176 * inclhack.def (solaris_int8_t): New fix. * fixincl.x: Regenerate. gcc: PR libstdc++/113450 PR libstdc++/123176 * config/sol2.h (INT8_TYPE): Change to signed char. (INT_LEAST8_TYPE): Likewise. (INT_FAST8_TYPE): Likewise. --- diff --git a/fixincludes/fixincl.x b/fixincludes/fixincl.x index 6f2c1ffbefe..9db4d376a2e 100644 --- a/fixincludes/fixincl.x +++ b/fixincludes/fixincl.x @@ -2,11 +2,11 @@ * * DO NOT EDIT THIS FILE (fixincl.x) * - * It has been AutoGen-ed January 6, 2026 at 04:43:53 PM by AutoGen 5.18.12 + * It has been AutoGen-ed February 15, 2026 at 11:11:08 PM by AutoGen 5.18.12 * From the definitions inclhack.def * and the template file fixincl */ -/* DO NOT MERGE THIS FILE, EITHER Tue Jan 6 16:43:53 CET 2026 +/* DO NOT MERGE THIS FILE, EITHER Sun Feb 15 23:11:08 CET 2026 * * You must regenerate it. Use the ./genfixes script. * @@ -15,7 +15,7 @@ * certain ANSI-incompatible system header files which are fixed to work * correctly with ANSI C and placed in a directory that GNU C will search. * - * This file contains 250 fixup descriptions. + * This file contains 251 fixup descriptions. * * See README for more information. * @@ -7869,6 +7869,54 @@ static const char* apzSolaris_Int_Limits_3Patch[] = { "#define\tSIZE_MAX\t4294967295U", (char*)NULL }; +/* * * * * * * * * * * * * * * * * * * * * * * * * * + * + * Description of Solaris_Int8_T fix + */ +tSCC zSolaris_Int8_TName[] = + "solaris_int8_t"; + +/* + * File name selection pattern + */ +tSCC zSolaris_Int8_TList[] = + "sys/int_types.h\0"; +/* + * Machine/OS name selection pattern + */ +tSCC* apzSolaris_Int8_TMachs[] = { + "*-*-solaris2*", + (const char*)NULL }; + +/* + * content selection pattern - do fix if pattern found + */ +tSCC zSolaris_Int8_TSelect0[] = + "^[ \t]*typedef[ \t]*char[ \t]*int(|_fast|_least)8_t.*"; + +/* + * content bypass pattern - skip fix if pattern found + */ +tSCC zSolaris_Int8_TBypass0[] = + "_LEGACY_INT8_T"; + +#define SOLARIS_INT8_T_TEST_CT 2 +static tTestDesc aSolaris_Int8_TTests[] = { + { TT_NEGREP, zSolaris_Int8_TBypass0, (regex_t*)NULL }, + { TT_EGREP, zSolaris_Int8_TSelect0, (regex_t*)NULL }, }; + +/* + * Fix Command Arguments for Solaris_Int8_T + */ +static const char* apzSolaris_Int8_TPatch[] = { + "format", + "#if !defined(_LEGACY_INT8_T)\n\ +typedef signed char int%18_t;\n\ +#else\n\ +%0\n\ +#endif", + (char*)NULL }; + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * Description of Solaris_Math_12 fix @@ -10235,9 +10283,9 @@ static const char* apzX11_SprintfPatch[] = { * * List of all fixes */ -#define REGEX_COUNT 289 +#define REGEX_COUNT 291 #define MACH_LIST_SIZE_LIMIT 187 -#define FIX_COUNT 250 +#define FIX_COUNT 251 /* * Enumerate the fixes @@ -10434,6 +10482,7 @@ typedef enum { SOLARIS_INT_CONST_FIXIDX, SOLARIS_INT_LIMITS_1_FIXIDX, SOLARIS_INT_LIMITS_3_FIXIDX, + SOLARIS_INT8_T_FIXIDX, SOLARIS_MATH_12_FIXIDX, SOLARIS_POW_INT_OVERLOAD_FIXIDX, STATSSWTCH_FIXIDX, @@ -11451,6 +11500,11 @@ tFixDesc fixDescList[ FIX_COUNT ] = { SOLARIS_INT_LIMITS_3_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE, aSolaris_Int_Limits_3Tests, apzSolaris_Int_Limits_3Patch, 0 }, + { zSolaris_Int8_TName, zSolaris_Int8_TList, + apzSolaris_Int8_TMachs, + SOLARIS_INT8_T_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE, + aSolaris_Int8_TTests, apzSolaris_Int8_TPatch, 0 }, + { zSolaris_Math_12Name, zSolaris_Math_12List, apzSolaris_Math_12Machs, SOLARIS_MATH_12_TEST_CT, FD_MACH_ONLY, diff --git a/fixincludes/inclhack.def b/fixincludes/inclhack.def index 53022aaeee5..91f29a2ca7c 100644 --- a/fixincludes/inclhack.def +++ b/fixincludes/inclhack.def @@ -3930,6 +3930,28 @@ fix = { "#define SIZE_MAX 4294967295UL"; }; +/* + * Solaris defines int8_t as char which violates C99. + * Same for int_fast8_t and int_least8_t. + */ +fix = { + hackname = solaris_int8_t; + files = sys/int_types.h; + mach = '*-*-solaris2*'; + bypass = '_LEGACY_INT8_T'; + c_fix = format; + c_fix_arg = "#if !defined(_LEGACY_INT8_T)\n" + "typedef signed char int%18_t;\n" + "#else\n" + "%0\n" + "#endif"; + select = "^[ \t]*typedef[ \t]*char[ \t]*int(|_fast|_least)8_t.*"; + test_text = + "typedef char int8_t;\n" + "typedef char int_fast8_t;\n" + "typedef char int_least8_t;"; +}; + /* * Some versions of Solaris 10+ #undef libstdc++-internal macros. */ diff --git a/fixincludes/tests/base/sys/int_types.h b/fixincludes/tests/base/sys/int_types.h new file mode 100644 index 00000000000..dcde665bee5 --- /dev/null +++ b/fixincludes/tests/base/sys/int_types.h @@ -0,0 +1,28 @@ +/* DO NOT EDIT THIS FILE. + + It has been auto-edited by fixincludes from: + + "fixinc/tests/inc/sys/int_types.h" + + This had to be done to correct non-standard usages in the + original, manufacturer supplied header file. */ + + + +#if defined( SOLARIS_INT8_T_CHECK ) +#if !defined(_LEGACY_INT8_T) +typedef signed char int8_t; +#else +typedef char int8_t; +#endif +#if !defined(_LEGACY_INT8_T) +typedef signed char int_fast8_t; +#else +typedef char int_fast8_t; +#endif +#if !defined(_LEGACY_INT8_T) +typedef signed char int_least8_t; +#else +typedef char int_least8_t; +#endif +#endif /* SOLARIS_INT8_T_CHECK */ diff --git a/gcc/config/sol2.h b/gcc/config/sol2.h index 489c650495f..398aa383505 100644 --- a/gcc/config/sol2.h +++ b/gcc/config/sol2.h @@ -49,9 +49,11 @@ along with GCC; see the file COPYING3. If not see #define SIG_ATOMIC_TYPE "int" -/* ??? This definition of int8_t follows the system header but does - not conform to C99. Likewise int_fast8_t, int_least8_t. */ -#define INT8_TYPE "char" +/* uses char (which is signed) to define int8_t, which does + not conform to C99, 7.18.1.1 Exact-width integer types. Likewise + int_fast8_t, int_least8_t. Until this is fixed, it's handled by + fixincludes. */ +#define INT8_TYPE "signed char" #define INT16_TYPE "short int" #define INT32_TYPE "int" #define INT64_TYPE (LONG_TYPE_SIZE == 64 ? "long int" : "long long int") @@ -60,7 +62,7 @@ along with GCC; see the file COPYING3. If not see #define UINT32_TYPE "unsigned int" #define UINT64_TYPE (LONG_TYPE_SIZE == 64 ? "long unsigned int" : "long long unsigned int") -#define INT_LEAST8_TYPE "char" +#define INT_LEAST8_TYPE "signed char" #define INT_LEAST16_TYPE "short int" #define INT_LEAST32_TYPE "int" #define INT_LEAST64_TYPE (LONG_TYPE_SIZE == 64 ? "long int" : "long long int") @@ -69,7 +71,7 @@ along with GCC; see the file COPYING3. If not see #define UINT_LEAST32_TYPE "unsigned int" #define UINT_LEAST64_TYPE (LONG_TYPE_SIZE == 64 ? "long unsigned int" : "long long unsigned int") -#define INT_FAST8_TYPE "char" +#define INT_FAST8_TYPE "signed char" #define INT_FAST16_TYPE "int" #define INT_FAST32_TYPE "int" #define INT_FAST64_TYPE (LONG_TYPE_SIZE == 64 ? "long int" : "long long int")