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:
acqn
2021-05-27 15:44:52 +08:00
committed by Oliver Schmidt
parent 5adb29ce31
commit d69e81cd66
5 changed files with 122 additions and 18 deletions

View File

@@ -1,51 +0,0 @@
/* issue #1462 - Bit-fields are still broken */
/* even the = operation is buggy in certain ways */
#include <stdio.h>
typedef struct {
signed int a : 3;
signed int b : 3;
signed int c : 3;
} T;
int failures = 0;
T *f(T *t)
{
t->a = 0;
t->c = 0;
return t;
}
void test(void)
{
T a = { 7, 0, 7 };
T *p = &a;
a.b = f(p)->a;
if (a.a != 0) {
++failures;
}
printf("%d\n", a.a);
if (p->b != 0) {
++failures;
}
printf("%d\n", p->b);
if ((&a)->c != 0) {
++failures;
}
printf("%d\n", (&a)->c);
printf("Failures: %d\n", failures);
}
int main(void)
{
test();
return failures;
}

View File

@@ -1,95 +0,0 @@
/* issue #1462 - Bit-fields are still broken */
/* More testson "op= expression result value" that a naive fix might fail with */
#include <stdio.h>
typedef struct {
signed int a : 3;
unsigned int b : 3;
signed int c : 3;
unsigned int d : 3;
} T1;
typedef struct {
signed int a : 3;
signed int b : 3;
signed int c : 3;
signed int d : 3;
} T2;
int failures1 = 0;
int failures2 = 0;
void test1(void)
{
T1 a = { 3, 3, 3, 3 };
int i;
i = a.a += a.b + a.c;
if (i != 1) {
++failures1;
}
printf("i = %d, a.a = %d\n", i, a.a);
i = a.b *= -1;
if (i != 5 || a.b != 5) {
++failures1;
}
printf("i = %d, a.b = %d\n", i, a.b);
i = a.c * -1;
if (i != -3) {
++failures1;
}
printf("i = %d, a.c = %d\n", i, a.c);
i = a.d ^= -1;
if (i != 4 || a.d != 4) {
++failures1;
}
printf("i = %d, a.d = %d\n", i, a.d);
printf("Failures: %d\n", failures1);
}
void test2(void)
{
T2 b = { 3, 3, 4, 4 };
int i;
i = b.a++;
if (i != 3 || b.a != -4) {
++failures2;
}
printf("i = %d, b.a = %d\n", i, b.a);
i = ++b.b;
if (i != -4 || b.b != -4) {
++failures2;
}
printf("i = %d, b.b = %d\n", i, b.b);
i = b.c--;
if (i != -4 || b.c != 3) {
++failures2;
}
printf("i = %d, b.c = %d\n", i, b.c);
i = --b.d;
if (i != 3 || b.d != 3) {
++failures2;
}
printf("i = %d, b.d = %d\n", i, b.d);
printf("Failures: %d\n", failures2);
}
int main(void)
{
test1();
test2();
return failures1 + failures2;
}

View File

@@ -1,67 +0,0 @@
/* issue #1462 - Bit-fields are still broken */
#include <stdio.h>
typedef struct {
signed int a : 3;
signed int b : 3;
signed int c : 3;
} T;
int failures = 0;
void test()
{
T a = {2, 5, -1};
T b = {1, 4, -1};
T m[1] = {{6, 3, -1}};
T *p = &a;
a.c += b.a;
p->c += b.b;
m->c += b.c;
if (a.c != -4) {
++failures;
}
printf("%d\n", a.c);
if (p->c != -4) {
++failures;
}
printf("%d\n", p->c);
if (m->c != -2) {
++failures;
}
printf("%d\n", m->c);
++a.a;
p->b++;
m->c--;
if (a.a != 3) {
++failures;
}
printf("%d\n", a.a);
if (p->b != -2) {
++failures;
}
printf("%d\n", p->b);
if (m->c != -3) {
++failures;
}
printf("%d\n", m->c);
printf("Failures: %d\n", failures);
}
int main(void)
{
test();
return failures;
}