Moved and improved test cases for Issue #1462.
Fixed an old test case for unsigned enum bit-fields that are supposed to be int-promoted.
This commit is contained in:
parent
5adb29ce31
commit
d69e81cd66
5 changed files with 122 additions and 18 deletions
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
/* issue #1462 - Bit-fields are still broken */
|
/* issue #1462 - Bit-fields are still broken */
|
||||||
/* More testson "op= expression result value" that a naive fix might fail with */
|
/* More tests on "op= expression result value" that a naive fix might fail with */
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
@ -27,26 +27,26 @@ void test1(void)
|
||||||
T1 a = { 3, 3, 3, 3 };
|
T1 a = { 3, 3, 3, 3 };
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
i = a.a += a.b + a.c;
|
i = a.a -= a.b + a.c;
|
||||||
if (i != 1) {
|
if (i != -3 || a.a != -3) {
|
||||||
++failures1;
|
++failures1;
|
||||||
}
|
}
|
||||||
printf("i = %d, a.a = %d\n", i, a.a);
|
printf("i = %d, a.a = %d\n", i, a.a);
|
||||||
|
|
||||||
i = a.b *= -1;
|
a.b = i = a.b / -1;
|
||||||
if (i != 5 || a.b != 5) {
|
if (i != -3 || a.b != 5) {
|
||||||
++failures1;
|
++failures1;
|
||||||
}
|
}
|
||||||
printf("i = %d, a.b = %d\n", i, a.b);
|
printf("i = %d, a.b = %d\n", i, a.b);
|
||||||
|
|
||||||
i = a.c * -1;
|
i = a.c = 0;
|
||||||
if (i != -3) {
|
if (i != 0 || a.c != 0) {
|
||||||
++failures1;
|
++failures1;
|
||||||
}
|
}
|
||||||
printf("i = %d, a.c = %d\n", i, a.c);
|
printf("i = %d, a.c = %d\n", i, a.c);
|
||||||
|
|
||||||
i = a.d ^= -1;
|
i = a.d /= -1;
|
||||||
if (i != 4 || a.d != 4) {
|
if (i != 5 || a.d != 5) {
|
||||||
++failures1;
|
++failures1;
|
||||||
}
|
}
|
||||||
printf("i = %d, a.d = %d\n", i, a.d);
|
printf("i = %d, a.d = %d\n", i, a.d);
|
85
test/val/bug1462-4.c
Normal file
85
test/val/bug1462-4.c
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
|
||||||
|
/* issue #1462 - Bit-fields are still broken */
|
||||||
|
/* More tests on "op= expression result value" that a naive fix might fail with */
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
|
#define SMALL_WIDTH 4
|
||||||
|
#define LARGE_WIDTH (CHAR_BIT * sizeof (unsigned int))
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
unsigned int a : SMALL_WIDTH;
|
||||||
|
unsigned int b : SMALL_WIDTH;
|
||||||
|
unsigned int c : SMALL_WIDTH;
|
||||||
|
unsigned int d : SMALL_WIDTH;
|
||||||
|
} T1;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
unsigned int a : LARGE_WIDTH;
|
||||||
|
unsigned int b : LARGE_WIDTH;
|
||||||
|
unsigned int c : LARGE_WIDTH;
|
||||||
|
unsigned int d : LARGE_WIDTH;
|
||||||
|
} T2;
|
||||||
|
|
||||||
|
|
||||||
|
int failures1 = 0;
|
||||||
|
int failures2 = 0;
|
||||||
|
|
||||||
|
void test1(void)
|
||||||
|
{
|
||||||
|
T1 a = { 0, 0, 0, 0 };
|
||||||
|
|
||||||
|
printf("\nunsigned int : %d\n", SMALL_WIDTH);
|
||||||
|
if (!(~a.a < 0)) {
|
||||||
|
++failures1;
|
||||||
|
}
|
||||||
|
printf("~a.a < 0 : %d\n", ~a.a < 0);
|
||||||
|
if (!(0 > ~a.b)) {
|
||||||
|
++failures1;
|
||||||
|
}
|
||||||
|
printf("0 > ~a.b : %d\n",0 > ~a.b);
|
||||||
|
if (!(a.c > -1)) {
|
||||||
|
++failures1;
|
||||||
|
}
|
||||||
|
printf("a.c > -1 : %d\n", a.c > -1);
|
||||||
|
if (!(-1 < a.d)) {
|
||||||
|
++failures1;
|
||||||
|
}
|
||||||
|
printf("-1 < a.d : %d\n", -1 < a.d);
|
||||||
|
|
||||||
|
printf("Failures: %d\n", failures1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test2(void)
|
||||||
|
{
|
||||||
|
T1 b = { 0, 0, 0, 0 };
|
||||||
|
|
||||||
|
printf("\nunsigned int : %d\n", LARGE_WIDTH);
|
||||||
|
if (!(~b.a < 0)) {
|
||||||
|
++failures2;
|
||||||
|
}
|
||||||
|
printf("~b.a < 0 : %d\n", ~b.a < 0);
|
||||||
|
if (!(0 > ~b.b)) {
|
||||||
|
++failures2;
|
||||||
|
}
|
||||||
|
printf("0 > ~b.b : %d\n", 0 > ~b.b);
|
||||||
|
if (!(b.c > -1)) {
|
||||||
|
++failures2;
|
||||||
|
}
|
||||||
|
printf("b.c > -1 : %d\n", b.c > -1);
|
||||||
|
if (!(-1 < b.d)) {
|
||||||
|
++failures2;
|
||||||
|
}
|
||||||
|
printf("-1 < b.d : %d\n", -1 < b.d);
|
||||||
|
|
||||||
|
printf("Failures: %d\n", failures2);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
test1();
|
||||||
|
test2();
|
||||||
|
return failures1 + failures2;
|
||||||
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
static unsigned char failures = 0;
|
static unsigned char failures = 0;
|
||||||
|
|
||||||
|
@ -35,7 +36,7 @@ enum e10u {
|
||||||
static struct enum_bitfield_uint {
|
static struct enum_bitfield_uint {
|
||||||
enum e10u x : 1;
|
enum e10u x : 1;
|
||||||
enum e10u y : 8;
|
enum e10u y : 8;
|
||||||
enum e10u z : 16;
|
enum e10u z : CHAR_BIT * sizeof (enum e10u);
|
||||||
} e10ubf = {0, E10U_200, E10U_1000};
|
} e10ubf = {0, E10U_200, E10U_1000};
|
||||||
|
|
||||||
static void test_enum_bitfield_uint(void)
|
static void test_enum_bitfield_uint(void)
|
||||||
|
@ -68,11 +69,11 @@ static void test_enum_bitfield_uint(void)
|
||||||
failures++;
|
failures++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check signedness, should be unsigned. */
|
/* Check signedness, should be signed. */
|
||||||
{
|
{
|
||||||
long v = e10ubf.x - 2;
|
long v = e10ubf.x - 2;
|
||||||
if (v < 0) {
|
if (v >= 0) {
|
||||||
printf ("Got negative v = %ld, expected large positive.\n", v);
|
printf ("Got non-negative v (= e10ubf.x - 2) = %ld, expected negative.\n", v);
|
||||||
failures++;
|
failures++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -85,6 +86,15 @@ static void test_enum_bitfield_uint(void)
|
||||||
printf ("Got e10ubf.z = %u, expected 1023.\n", e10ubf.z);
|
printf ("Got e10ubf.z = %u, expected 1023.\n", e10ubf.z);
|
||||||
failures++;
|
failures++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check signedness, should be unsigned. */
|
||||||
|
{
|
||||||
|
long v = e10ubf.z - 1024;
|
||||||
|
if (v < 0) {
|
||||||
|
printf ("Got negative v (= e10ubf.z - 1024) = %ld, expected positive.\n", v);
|
||||||
|
failures++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Enum with underlying type signed int. */
|
/* Enum with underlying type signed int. */
|
||||||
|
@ -97,7 +107,7 @@ enum e11i {
|
||||||
static struct enum_bitfield_int {
|
static struct enum_bitfield_int {
|
||||||
enum e11i x : 2;
|
enum e11i x : 2;
|
||||||
enum e11i y : 8;
|
enum e11i y : 8;
|
||||||
enum e11i z : 16;
|
enum e11i z : CHAR_BIT * sizeof (enum e11i);
|
||||||
} e11ibf = {E11I_M1, E11I_100, E11I_1000};
|
} e11ibf = {E11I_M1, E11I_100, E11I_1000};
|
||||||
|
|
||||||
static void test_enum_bitfield_int(void)
|
static void test_enum_bitfield_int(void)
|
||||||
|
@ -133,8 +143,8 @@ static void test_enum_bitfield_int(void)
|
||||||
/* Check signedness, should be signed. */
|
/* Check signedness, should be signed. */
|
||||||
{
|
{
|
||||||
long v = e11ibf.x - 2;
|
long v = e11ibf.x - 2;
|
||||||
if (v > 0) {
|
if (v >= 0) {
|
||||||
printf ("Got positive v = %ld, expected negative.\n", v);
|
printf ("Got non-negative v (= e11ibf.x - 2) = %ld, expected negative.\n", v);
|
||||||
failures++;
|
failures++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,6 +157,15 @@ static void test_enum_bitfield_int(void)
|
||||||
printf ("Got e11ibf.z = %d, expected 1023.\n", e11ibf.z);
|
printf ("Got e11ibf.z = %d, expected 1023.\n", e11ibf.z);
|
||||||
failures++;
|
failures++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check signedness, should be signed. */
|
||||||
|
{
|
||||||
|
long v = e11ibf.z - 1024;
|
||||||
|
if (v >= 0) {
|
||||||
|
printf ("Got non-negative v (= e11ibf.z - 1024) = %ld, expected negative.\n", v);
|
||||||
|
failures++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Enum with underlying type unsigned char. */
|
/* Enum with underlying type unsigned char. */
|
||||||
|
@ -157,7 +176,7 @@ enum e7uc {
|
||||||
static struct enum_bitfield_uchar {
|
static struct enum_bitfield_uchar {
|
||||||
enum e7uc x : 1;
|
enum e7uc x : 1;
|
||||||
enum e7uc y : 4;
|
enum e7uc y : 4;
|
||||||
enum e7uc z : 8;
|
enum e7uc z : CHAR_BIT;
|
||||||
} e7ucbf = {0, 10, E7UC_100};
|
} e7ucbf = {0, 10, E7UC_100};
|
||||||
|
|
||||||
static void test_enum_bitfield_uchar(void)
|
static void test_enum_bitfield_uchar(void)
|
||||||
|
@ -212,7 +231,7 @@ enum e8sc {
|
||||||
static struct enum_bitfield_char {
|
static struct enum_bitfield_char {
|
||||||
enum e8sc x : 1;
|
enum e8sc x : 1;
|
||||||
enum e8sc y : 4;
|
enum e8sc y : 4;
|
||||||
enum e8sc z : 8;
|
enum e8sc z : CHAR_BIT;
|
||||||
} e8scbf = {0, 5, E8SC_100};
|
} e8scbf = {0, 5, E8SC_100};
|
||||||
|
|
||||||
static void test_enum_bitfield_char(void)
|
static void test_enum_bitfield_char(void)
|
||||||
|
|
Loading…
Add table
Reference in a new issue