Files
binutils-gdb/gdb/testsuite/gdb.base/bitfields2.c
Simon Marchi a5cbe67512 gdb, gdbserver, gdbsupport: trim trailing whitespaces
I noticed my IDE (VSCode) starting to automatically trim trailing
whitespaces on save, despite the setting for it being disabled.  I
realized that this is because the .editorconfig file now has

    trim_trailing_whitespace = true

for many file types.  If we have this EditorConfig setting forcing
editors to trim trailing whitespaces, I think it would make sense to
clean up trailing whitespaces from our files.  Otherwise, people will
always get spurious whitespace changes when editing these files.

I did a mass cleanup using this command:

$ find gdb gdbserver gdbsupport -type f \( \
    -name "*.c" -o \
    -name "*.h" -o \
    -name "*.cc" -o \
    -name "*.texi" -o \
    -name "*.exp" -o \
    -name "*.tcl" -o \
    -name "*.py" -o \
    -name "*.s" -o \
    -name "*.S" -o \
    -name "*.asm" -o \
    -name "*.awk" -o \
    -name "*.ac" -o \
    -name "Makefile*" -o \
    -name "*.sh" -o \
    -name "*.adb" -o \
    -name "*.ads" -o \
    -name "*.d" -o \
    -name "*.go" -o \
    -name "*.F90" -o \
    -name "*.f90" \
\) -exec sed -ri 's/[ \t]+$//' {} +

I then did an autotools regen, because we don't actually want to change
the Makefile and Makefile.in files that are generated.

Change-Id: I6f91b83e3b8c4dc7d5d51a2ebf60706120efe691
2025-10-20 15:44:08 -04:00

170 lines
2.7 KiB
C

/* Test program to test bit field operations on bit fields of large
integer types. */
/* This file is expected to fail to compile if the type long long int
is not supported, but in that case it is irrelevant. */
#include <stdlib.h>
#include <string.h>
#if !defined(__STDC__) && !defined(__cplusplus)
#define signed /**/
#endif
struct fields
{
unsigned long long u1 : 15;
unsigned long long u2 : 33;
unsigned long long u3 : 16;
signed long long s1 : 15;
signed long long s2 : 33;
signed long long s3 : 16;
} flags;
void break1 ()
{
}
void break2 ()
{
}
void break3 ()
{
}
void break4 ()
{
}
void break5 ()
{
}
void break6 ()
{
}
void break7 ()
{
}
void break8 ()
{
}
void break9 ()
{
}
void break10 ()
{
}
/* This is used by bitfields.exp to determine if the target understands
signed bitfields. */
int i;
void tester ()
{
memset ((char *) &flags, 0, sizeof (flags));
/* For each member, set that member to 1, allow gdb to verify that the
member (and only that member) is 1, and then reset it back to 0. */
flags.s1 = 1;
break1 ();
flags.s1 = 0;
flags.u1 = 1;
break1 ();
flags.u1 = 0;
flags.s2 = 1;
break1 ();
flags.s2 = 0;
flags.u2 = 1;
break1 ();
flags.u2 = 0;
flags.s3 = 1;
break1 ();
flags.s3 = 0;
flags.u3 = 1;
break1 ();
flags.u3 = 0;
/* Fill alternating fields with all 1's and verify that none of the bits
"bleed over" to the other fields. */
flags.u1 = 0x7FFF;
flags.u3 = 0xFFFF;
flags.s2 = -1LL;
break2 ();
flags.u1 = 0;
flags.u3 = 0;
flags.s2 = 0;
flags.u2 = 0x1FFFFFFFFLL;
flags.s1 = -1;
flags.s3 = -1;
break2 ();
flags.u2 = 0;
flags.s1 = 0;
flags.s3 = 0;
/* Fill the unsigned fields with the maximum positive value and verify
that the values are printed correctly. */
flags.u1 = 0x7FFF;
flags.u2 = 0x1FFFFFFFFLL;
flags.u3 = 0xFFFF;
break3 ();
flags.u1 = 0;
flags.u2 = 0;
flags.u3 = 0;
/* Fill the signed fields with the maximum positive value, then the maximally
negative value, then -1, and verify in each case that the values are
printed correctly. */
/* Maximum positive values */
flags.s1 = 0x3FFF;
flags.s2 = 0xFFFFFFFFLL;
flags.s3 = 0x7FFF;
break4 ();
/* Maximally negative values */
flags.s1 = -0x4000;
flags.s2 = -0x100000000LL;
flags.s3 = -0x8000;
/* Extract bitfield value so that bitfield.exp can check if the target
understands signed bitfields. */
i = flags.s3;
break4 ();
/* -1 */
flags.s1 = -1;
flags.s2 = -1;
flags.s3 = -1;
break4 ();
flags.s1 = 0;
flags.s2 = 0;
flags.s3 = 0;
break5 ();
}
int main ()
{
int i;
for (i = 0; i < 5; i += 1)
tester ();
return 0;
}