diff --git a/test/ref/pr1220.c b/test/ref/pr1220.c new file mode 100644 index 000000000..c594b5ac2 --- /dev/null +++ b/test/ref/pr1220.c @@ -0,0 +1,344 @@ +/* PR #1220 - test constant AND/OR */ + +#include + +#define CONTEXT_A(x) do {\ + s = 0, flags = 0, t = (x),\ + printf("%3d %2X: %d\n", s, flags, t);\ + } while (0) + +#define CONTEXT_B(x) do {\ + s = 0, flags = 0,\ + (x ? printf("%3d %2X: 1\n", s, flags) : printf("%3d %2X: 0\n", s, flags));\ + } while (0) + +int s, t; +void *p; +unsigned flags; + +int f(x) +{ + flags |= 1U << s; + ++s; + return x; +} + +#define _A f(a) +#define _B f(b) +#define _C f(c) +#define _D f(d) +#define _T (f(0), -1) +#define _F (f(-1), 0) + +void f0() +{ + printf("f0()\n"); + + CONTEXT_A(_T && _T && _T); + CONTEXT_A(_F && _F && _F); + + CONTEXT_A(_T || _T || _T); + CONTEXT_A(_F || _F || _F); + + CONTEXT_A(_T && _T || _T && _T); + CONTEXT_A(_F && _F || _F && _F); + CONTEXT_A(_T && _F || _T && _F); + CONTEXT_A(_F && _T || _F && _T); + + CONTEXT_A((_T && _T) || (_T && _T)); + CONTEXT_A((_F && _F) || (_F && _F)); + CONTEXT_A((_T && _F) || (_T && _F)); + CONTEXT_A((_F && _T) || (_F && _T)); + + CONTEXT_A((_T || _T) && (_T || _T)); + CONTEXT_A((_F || _F) && (_F || _F)); + CONTEXT_A((_T || _F) && (_T || _F)); + CONTEXT_A((_F || _T) && (_F || _T)); + + printf("\n"); +} + +void f1(int a, int b, int c) +{ + printf("f1(%d, %d, %d)\n", a, b, c); + + CONTEXT_A(_A && _B && _C); + + CONTEXT_A(_T && _B && _C); + CONTEXT_A(_A && _T && _C); + CONTEXT_A(_A && _B && _T); + + CONTEXT_A(_F && _B && _C); + CONTEXT_A(_A && _F && _C); + CONTEXT_A(_A && _B && _F); + + CONTEXT_A(_T && _T && _C); + CONTEXT_A(_A && _T && _T); + CONTEXT_A(_T && _B && _T); + + printf("\n"); +} + +void f2(int a, int b, int c) +{ + printf("f2(%d, %d, %d)\n", a, b, c); + + CONTEXT_A(_A || _B || _C); + + CONTEXT_A(_T || _B || _C); + CONTEXT_A(_A || _T || _C); + CONTEXT_A(_A || _B || _T); + + CONTEXT_A(_F || _B || _C); + CONTEXT_A(_A || _F || _C); + CONTEXT_A(_A || _B || _F); + + CONTEXT_A(_F || _F || _C); + CONTEXT_A(_A || _F || _F); + CONTEXT_A(_F || _B || _F); + + printf("\n"); +} + +void f3(int a, int b, int c, int d) +{ + printf("f3(%d, %d, %d, %d)\n", a, b, c, d); + + CONTEXT_A(_A && _B || _C && _D); + CONTEXT_A(_T && _T || _C && _D); + CONTEXT_A(_A && _B || _T && _T); + + CONTEXT_A(_T && _B || _C && _D); + CONTEXT_A(_A && _T || _C && _D); + CONTEXT_A(_A && _B || _T && _D); + CONTEXT_A(_A && _B || _C && _T); + + CONTEXT_A(_F && _B || _C && _D); + CONTEXT_A(_A && _F || _C && _D); + CONTEXT_A(_A && _B || _F && _D); + CONTEXT_A(_A && _B || _C && _F); + + printf("\n"); +} + +void f4(int a, int b, int c, int d) +{ + printf("f4(%d, %d, %d, %d)\n", a, b, c, d); + + CONTEXT_A((_A && _B) || (_C && _D)); + CONTEXT_A((_T && _T) || (_C && _D)); + CONTEXT_A((_A && _B) || (_T && _T)); + + CONTEXT_A((_T && _B) || (_C && _D)); + CONTEXT_A((_A && _T) || (_C && _D)); + CONTEXT_A((_A && _B) || (_T && _D)); + CONTEXT_A((_A && _B) || (_C && _T)); + + CONTEXT_A((_F && _B) || (_C && _D)); + CONTEXT_A((_A && _F) || (_C && _D)); + CONTEXT_A((_A && _B) || (_F && _D)); + CONTEXT_A((_A && _B) || (_C && _F)); + + printf("\n"); +} + +void f5(int a, int b, int c, int d) +{ + printf("f5(%d, %d, %d, %d)\n", a, b, c, d); + + CONTEXT_A((_A || _B) && (_C || _D)); + CONTEXT_A((_F || _F) && (_C || _D)); + CONTEXT_A((_A || _B) && (_F || _F)); + + CONTEXT_A((_T || _B) && (_C || _D)); + CONTEXT_A((_A || _T) && (_C || _D)); + CONTEXT_A((_A || _B) && (_T || _D)); + CONTEXT_A((_A || _B) && (_C || _T)); + + CONTEXT_A((_F || _B) && (_C || _D)); + CONTEXT_A((_A || _F) && (_C || _D)); + CONTEXT_A((_A || _B) && (_F || _D)); + CONTEXT_A((_A || _B) && (_C || _F)); + + printf("\n"); +} + +void f0_B() +{ + printf("f0()\n"); + + CONTEXT_B(_T && _T && _T); + CONTEXT_B(_F && _F && _F); + + CONTEXT_B(_T || _T || _T); + CONTEXT_B(_F || _F || _F); + + CONTEXT_B(_T && _T || _T && _T); + CONTEXT_B(_F && _F || _F && _F); + CONTEXT_B(_T && _F || _T && _F); + CONTEXT_B(_F && _T || _F && _T); + + CONTEXT_B((_T && _T) || (_T && _T)); + CONTEXT_B((_F && _F) || (_F && _F)); + CONTEXT_B((_T && _F) || (_T && _F)); + CONTEXT_B((_F && _T) || (_F && _T)); + + CONTEXT_B((_T || _T) && (_T || _T)); + CONTEXT_B((_F || _F) && (_F || _F)); + CONTEXT_B((_T || _F) && (_T || _F)); + CONTEXT_B((_F || _T) && (_F || _T)); + + printf("\n"); +} + +void f1_B(int a, int b, int c) +{ + printf("f1(%d, %d, %d)\n", a, b, c); + + CONTEXT_B(_A && _B && _C); + + CONTEXT_B(_T && _B && _C); + CONTEXT_B(_A && _T && _C); + CONTEXT_B(_A && _B && _T); + + CONTEXT_B(_F && _B && _C); + CONTEXT_B(_A && _F && _C); + CONTEXT_B(_A && _B && _F); + + CONTEXT_B(_T && _T && _C); + CONTEXT_B(_A && _T && _T); + CONTEXT_B(_T && _B && _T); + + printf("\n"); +} + +void f2_B(int a, int b, int c) +{ + printf("f2(%d, %d, %d)\n", a, b, c); + + CONTEXT_B(_A || _B || _C); + + CONTEXT_B(_T || _B || _C); + CONTEXT_B(_A || _T || _C); + CONTEXT_B(_A || _B || _T); + + CONTEXT_B(_F || _B || _C); + CONTEXT_B(_A || _F || _C); + CONTEXT_B(_A || _B || _F); + + CONTEXT_B(_F || _F || _C); + CONTEXT_B(_A || _F || _F); + CONTEXT_B(_F || _B || _F); + + printf("\n"); +} + +void f3_B(int a, int b, int c, int d) +{ + printf("f3(%d, %d, %d, %d)\n", a, b, c, d); + + CONTEXT_B(_A && _B || _C && _D); + CONTEXT_B(_T && _T || _C && _D); + CONTEXT_B(_A && _B || _T && _T); + + CONTEXT_B(_T && _B || _C && _D); + CONTEXT_B(_A && _T || _C && _D); + CONTEXT_B(_A && _B || _T && _D); + CONTEXT_B(_A && _B || _C && _T); + + CONTEXT_B(_F && _B || _C && _D); + CONTEXT_B(_A && _F || _C && _D); + CONTEXT_B(_A && _B || _F && _D); + CONTEXT_B(_A && _B || _C && _F); + + printf("\n"); +} + +void f4_B(int a, int b, int c, int d) +{ + printf("f4(%d, %d, %d, %d)\n", a, b, c, d); + + CONTEXT_B((_A && _B) || (_C && _D)); + CONTEXT_B((_T && _T) || (_C && _D)); + CONTEXT_B((_A && _B) || (_T && _T)); + + CONTEXT_B((_T && _B) || (_C && _D)); + CONTEXT_B((_A && _T) || (_C && _D)); + CONTEXT_B((_A && _B) || (_T && _D)); + CONTEXT_B((_A && _B) || (_C && _T)); + + CONTEXT_B((_F && _B) || (_C && _D)); + CONTEXT_B((_A && _F) || (_C && _D)); + CONTEXT_B((_A && _B) || (_F && _D)); + CONTEXT_B((_A && _B) || (_C && _F)); + + printf("\n"); +} + +void f5_B(int a, int b, int c, int d) +{ + printf("f5(%d, %d, %d, %d)\n", a, b, c, d); + + CONTEXT_B((_A || _B) && (_C || _D)); + CONTEXT_B((_F || _F) && (_C || _D)); + CONTEXT_B((_A || _B) && (_F || _F)); + + CONTEXT_B((_T || _B) && (_C || _D)); + CONTEXT_B((_A || _T) && (_C || _D)); + CONTEXT_B((_A || _B) && (_T || _D)); + CONTEXT_B((_A || _B) && (_C || _T)); + + CONTEXT_B((_F || _B) && (_C || _D)); + CONTEXT_B((_A || _F) && (_C || _D)); + CONTEXT_B((_A || _B) && (_F || _D)); + CONTEXT_B((_A || _B) && (_C || _F)); + + printf("\n"); +} + +int main() +{ + f0(); + + f1(0, 0, 0); + f2(0, 0, 0); + f3(0, 0, 0, 0); + f4(0, 0, 0, 0); + f5(0, 0, 0, 0); + + f1(1, 1, 1); + f2(1, 1, 1); + f3(1, 1, 1, 1); + f4(1, 1, 1, 1); + f5(1, 1, 1, 1); + + f3(1, 0, 1, 0); + f4(1, 0, 1, 0); + f5(1, 0, 1, 0); + f3(0, 1, 0, 1); + f4(0, 1, 0, 1); + f5(0, 1, 0, 1); + + f0_B(); + + f1_B(0, 0, 0); + f2_B(0, 0, 0); + f3_B(0, 0, 0, 0); + f4_B(0, 0, 0, 0); + f5_B(0, 0, 0, 0); + + f1_B(1, 1, 1); + f2_B(1, 1, 1); + f3_B(1, 1, 1, 1); + f4_B(1, 1, 1, 1); + f5_B(1, 1, 1, 1); + + f3_B(1, 0, 1, 0); + f4_B(1, 0, 1, 0); + f5_B(1, 0, 1, 0); + f3_B(0, 1, 0, 1); + f4_B(0, 1, 0, 1); + f5_B(0, 1, 0, 1); + + return 0; +}