https://gcc.gnu.org/g:41dd4aac1b1af310494870af0b6467192ba88609
commit 41dd4aac1b1af310494870af0b6467192ba88609 Author: Alexandre Oliva <ol...@adacore.com> Date: Mon Jan 6 18:40:27 2025 -0300 testsuite: generalized field-merge tests for <32-bit int [PR118025] Explicitly convert constants to the desired types, so as to not elicit warnings about implicit truncations, nor execution errors, on targets whose ints are narrower than 32 bits. for gcc/testsuite/ChangeLog PR testsuite/118025 * gcc.dg/field-merge-1.c: Convert constants to desired types. * gcc.dg/field-merge-3.c: Likewise. * gcc.dg/field-merge-4.c: Likewise. * gcc.dg/field-merge-5.c: Likewise. * gcc.dg/field-merge-11.c: Likewise. * gcc.dg/field-merge-17.c: Don't mess with padding bits. Diff: --- gcc/testsuite/gcc.dg/field-merge-1.c | 4 ++-- gcc/testsuite/gcc.dg/field-merge-11.c | 10 +++++++--- gcc/testsuite/gcc.dg/field-merge-17.c | 4 +++- gcc/testsuite/gcc.dg/field-merge-3.c | 4 ++-- gcc/testsuite/gcc.dg/field-merge-4.c | 6 +++--- gcc/testsuite/gcc.dg/field-merge-5.c | 6 +++--- 6 files changed, 20 insertions(+), 14 deletions(-) diff --git a/gcc/testsuite/gcc.dg/field-merge-1.c b/gcc/testsuite/gcc.dg/field-merge-1.c index 4405d40ee79d..4e7f6ae9332a 100644 --- a/gcc/testsuite/gcc.dg/field-merge-1.c +++ b/gcc/testsuite/gcc.dg/field-merge-1.c @@ -25,8 +25,8 @@ struct TB { unsigned char s; } __attribute__ ((packed, aligned (4), scalar_storage_order ("big-endian"))); -#define vc 0xaa -#define vi 0x12345678 +#define vc (unsigned char)0xaa +#define vi (unsigned int)0x12345678 struct TL vL = { vc, vi, vc, vi, vc, vi, vc }; struct TB vB = { vc, vi, vc, vi, vc, vi, vc }; diff --git a/gcc/testsuite/gcc.dg/field-merge-11.c b/gcc/testsuite/gcc.dg/field-merge-11.c index fe627cddd7fd..9e606e3bef16 100644 --- a/gcc/testsuite/gcc.dg/field-merge-11.c +++ b/gcc/testsuite/gcc.dg/field-merge-11.c @@ -10,7 +10,11 @@ struct s { int c; } __attribute__ ((aligned (4))); -struct s p = { 42, (short)(0xef1 - 0x1000), 0x12345678 }; +struct s p = { + (short)(unsigned short)42, + (short)(unsigned short)(0xef1 - 0x1000), + (int)(unsigned int)0x12345678 +}; void f (void) { if (0 @@ -19,9 +23,9 @@ void f (void) { || (int)(signed char)p.b != (int)(signed char)(0xef1 - 0x1000) || (unsigned)(unsigned char)p.b != (unsigned)(unsigned char)(0xef1 - 0x1000) || (unsigned)p.b != (unsigned short)(0xef1 - 0x1000) - || (int)(short)p.b != (int)(0xef1 - 0x1000) + || (int)(short)p.b != (int)(short)(unsigned short)(0xef1 - 0x1000) || (long)(unsigned char)(p.c >> 8) != (long)(unsigned char)0x123456 - || p.c != 0x12345678 + || p.c != (int)(unsigned int)0x12345678 ) __builtin_abort (); } diff --git a/gcc/testsuite/gcc.dg/field-merge-17.c b/gcc/testsuite/gcc.dg/field-merge-17.c index a42658ac5c51..35ead9540606 100644 --- a/gcc/testsuite/gcc.dg/field-merge-17.c +++ b/gcc/testsuite/gcc.dg/field-merge-17.c @@ -3,6 +3,8 @@ /* Check that we can optimize misaligned double-words. */ +#include <stddef.h> + struct s { short a; long long b; @@ -33,7 +35,7 @@ int main () { if (fp () > 0) __builtin_abort (); unsigned char *pc = (unsigned char *)&p; - for (int i = 0; i < sizeof (p); i++) + for (int i = 0; i < offsetof (struct s, e) + sizeof (p.e); i++) { pc[i] = 1; if (fp () < 0) diff --git a/gcc/testsuite/gcc.dg/field-merge-3.c b/gcc/testsuite/gcc.dg/field-merge-3.c index a9fe404fa426..e9af4915ad8c 100644 --- a/gcc/testsuite/gcc.dg/field-merge-3.c +++ b/gcc/testsuite/gcc.dg/field-merge-3.c @@ -15,8 +15,8 @@ struct T2 { unsigned int z; } __attribute__((__aligned__(8))); -#define vc 0xaa -#define vi 0x12345678 +#define vc (unsigned char)0xaa +#define vi (unsigned int)0x12345678 struct T1 v1 = { { vc + !BIG_ENDIAN_P, vc + BIG_ENDIAN_P }, vc, vi }; struct T2 v2 = { (vc << 8) | (vc - 1), vc, vi }; diff --git a/gcc/testsuite/gcc.dg/field-merge-4.c b/gcc/testsuite/gcc.dg/field-merge-4.c index c629069e52b2..7c63123a282d 100644 --- a/gcc/testsuite/gcc.dg/field-merge-4.c +++ b/gcc/testsuite/gcc.dg/field-merge-4.c @@ -18,9 +18,9 @@ struct T2 { unsigned int z; } __attribute__((__packed__, __aligned__(4))); -#define vc 0xaa -#define vs 0xccdd -#define vi 0x12345678 +#define vc (unsigned char)0xaa +#define vs (unsigned short)0xccdd +#define vi (unsigned int)0x12345678 struct T1 v1 = { -1, vc, 1, vs, vi }; struct T2 v2 = { -1, 0, vc, 1, vs, vi }; diff --git a/gcc/testsuite/gcc.dg/field-merge-5.c b/gcc/testsuite/gcc.dg/field-merge-5.c index 1580b14bcc93..1b5d1a8cb16e 100644 --- a/gcc/testsuite/gcc.dg/field-merge-5.c +++ b/gcc/testsuite/gcc.dg/field-merge-5.c @@ -18,9 +18,9 @@ struct T2 { unsigned int z; } __attribute__((__packed__, __aligned__(8))); -#define vc 0xaa -#define vs 0xccdd -#define vi 0x12345678 +#define vc (unsigned char)0xaa +#define vs (unsigned short)0xccdd +#define vi (unsigned int)0x12345678 struct T1 v1 = { -1, vc, 1, vs, vi }; struct T2 v2 = { -1, 0, vc, 1, vs, vi };