From 16ba232d080cc107842fc5d794073b3edfa96bd7 Mon Sep 17 00:00:00 2001 From: acqn Date: Sun, 18 Sep 2022 22:29:01 +0800 Subject: [PATCH 1/3] Fixed some testcases. --- test/val/bug1838.c | 2 +- test/val/bug1847-struct-field-access.c | 2 +- test/val/mult1.c | 17 +++++++++++------ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/test/val/bug1838.c b/test/val/bug1838.c index ba3c1164f..ea2d39a81 100644 --- a/test/val/bug1838.c +++ b/test/val/bug1838.c @@ -12,7 +12,7 @@ int main(void) fn_t bar; foo(bar); - return 0; + return failures; } void foo(int func(int)) diff --git a/test/val/bug1847-struct-field-access.c b/test/val/bug1847-struct-field-access.c index 50ae32332..71575636f 100644 --- a/test/val/bug1847-struct-field-access.c +++ b/test/val/bug1847-struct-field-access.c @@ -42,5 +42,5 @@ int main(void) { printf("Failures: %u\n", failures); } - return 0; + return failures; } diff --git a/test/val/mult1.c b/test/val/mult1.c index 6d491a427..95141d76d 100644 --- a/test/val/mult1.c +++ b/test/val/mult1.c @@ -26,15 +26,17 @@ void done() void m1(void) { - c1 = c1*5; /* char = char * lit */ + c1 = c1*5; /* char = char * lit */ + c2 = c1*c3; /* char = char * char */ - c2 = c1 *c3; /* char = char * char */ - - uc1= uc1*5; /* uchar = uchar * lit * - uc2=uc1*uc3; /* uchar = uchar * uchar */ + uc1 = uc1*3; /* uchar = uchar * lit */ + uc2 = uc1*uc3; /* uchar = uchar * uchar */ if(c2 != 25) failures++; + + if(uc2 != 36) + failures++; } void m2(unsigned char uc) @@ -96,6 +98,9 @@ int main(void) c1 = 1; c3 = 5; + uc1 = 2; + uc3 = 6; + m1(); uc1 = 0x10; @@ -107,7 +112,7 @@ int main(void) ui3 = ui1*ui2; /* uint = uint * unit */ - /*m3(TESTLIT);*/ + m3(TESTLIT); success = failures; done(); From 080ec131d852cae576a2ef0bd2e51a673c1a0cc3 Mon Sep 17 00:00:00 2001 From: acqn Date: Sun, 18 Sep 2022 22:29:30 +0800 Subject: [PATCH 2/3] Added testcase for constant operands with side-effects. --- test/val/const-side-effect.c | 160 +++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 test/val/const-side-effect.c diff --git a/test/val/const-side-effect.c b/test/val/const-side-effect.c new file mode 100644 index 000000000..7c2f074f2 --- /dev/null +++ b/test/val/const-side-effect.c @@ -0,0 +1,160 @@ +/* Check code generation for constant operands with side-effects */ + +#include + +static int failures = 0; + +#define TEST(X, Y, L) \ + if (x != X || y != Y) { \ + printf("Failed: " L "\nExpected: x = " #X ", y = " #Y ", got: x = %d, y = %d\n\n", x, y); \ + ++failures; \ + } + +#define TEST_LINE_UNARY(OP, RH, ID) \ + "x = " #OP "(set(&y, " #ID "), " #RH ")" + +#define TEST_UNARY(OP, RH, RS, ID) \ + x = -!(RS), y = -!(RS); \ + x = OP (set(&y, ID), RH); \ + TEST(RS, ID, TEST_LINE_UNARY(OP, RH, ID)) + +#define TEST_LINE_RHS_EFFECT(LH, OP, RH, ID) \ + "x = " #LH " " #OP " (set(&y, " #ID "), " #RH ")" + +#define TEST_LINE_LHS_EFFECT(LH, OP, RH, ID) \ + "y = (set(&x, " #ID "), " #LH ") " #OP " " #RH + +#define TEST_BINARY(LH, OP, RH, RS, ID) \ + x = -!(RS), y = -!(RS); \ + x = LH OP (set(&y, ID), RH); \ + TEST(RS, ID, TEST_LINE_RHS_EFFECT(LH, OP, RH, ID)) \ + y = -!(RS), x = -!(RS); \ + y = (set(&x, ID), LH) OP RH; \ + TEST(ID, RS, TEST_LINE_LHS_EFFECT(LH, OP, RH, ID)) \ + y = -!(RS); \ + x = (set(&x, LH), x) OP (set(&y, ID), RH); \ + TEST(RS, ID, TEST_LINE_RHS_EFFECT((set(&x, LH), x), OP, RH, ID)) \ + x = -!(RS); \ + y = (set(&x, ID), LH) OP (set(&y, RH), y); \ + TEST(ID, RS, TEST_LINE_LHS_EFFECT(LH, OP, (set(&y, RH), y), ID)) + +#define TEST_LINE_RHS_EFFECT_WITH_CAST(LT, LH, OP, RT, RH, ID) \ + "x = (" #LT ")" #LH " " #OP " (" #RT ")(set(&y, " #ID "), " #RH ")" + +#define TEST_LINE_LHS_EFFECT_WITH_CAST(LT, LH, OP, RT, RH, ID) \ + "y = (" #LT ")(set(&x, " #ID "), " #LH ") " #OP " (" #RT ")" #RH + +#define TEST_BINARY_WITH_CAST(LT, LH, OP, RT, RH, RS, ID) \ + x = -!(RS), y = -!(RS); \ + x = (LT)LH OP (RT)(set(&y, ID), RH); \ + TEST(RS, ID, TEST_LINE_RHS_EFFECT_WITH_CAST(LT, LH, OP, RT, RH, ID)) \ + y = -!(RS), x = -!(RS); \ + y = (LT)(set(&x, ID), LH) OP (RT)RH; \ + TEST(ID, RS, TEST_LINE_LHS_EFFECT_WITH_CAST(LT, LH, OP, RT, RH, ID)) \ + y = -!(RS); \ + x = (LT)(set(&x, LH), x) OP (RT)(set(&y, ID), RH); \ + TEST(RS, ID, TEST_LINE_RHS_EFFECT_WITH_CAST(LT, (set(&x, LH), x), OP, RT, RH, ID)) \ + x = -!(RS); \ + y = (LT)(set(&x, ID), LH) OP (RT)(set(&y, RH), y); \ + TEST(ID, RS, TEST_LINE_LHS_EFFECT_WITH_CAST(LT, LH, OP, RT, (set(&y, RH), y), ID)) + +void set(int *p, int q) +{ + *p = q; +} + +int twice(int a) +{ + return a * 2; +} + +int (*twicep)(int) = twice; + +void test_unary(void) +{ + int x, y; + + TEST_UNARY(+, 42, 42, 1); + TEST_UNARY(-, -42, 42, 2); + TEST_UNARY(~, ~42, 42, 3); + TEST_UNARY(!, 42, 0, 4); +} + +void test_binary_arithmetic(void) +{ + int x, y; + + TEST_BINARY(41, +, 1, 42, 1) + TEST_BINARY(42, +, 0, 42, 1) + + TEST_BINARY(43, -, 1, 42, 2) + TEST_BINARY(42, -, 0, 42, 2) + + TEST_BINARY(6, *, 7, 42, 3) + TEST_BINARY(42, *, 1, 42, 3) + TEST_BINARY(-42, *, -1, 42, 3) + + TEST_BINARY(126, /, 3, 42, 4) + TEST_BINARY(42, /, 1, 42, 4) + TEST_BINARY(-42, /, -1, 42, 4) + + TEST_BINARY(85, %, 43, 42, 5) + TEST_BINARY(10794, %, 256, 42, 5) + + TEST_BINARY(84, >>, 1, 42, 6) + TEST_BINARY(42, >>, 0, 42, 6) + TEST_BINARY(10752, >>, 8, 42, 6) + TEST_BINARY(21504, >>, 9, 42, 6) + + TEST_BINARY(21, <<, 1, 42, 7) + TEST_BINARY(42, <<, 0, 42, 7) + TEST_BINARY(42, <<, 8, 10752, 7) + + TEST_BINARY(59, &, 238, 42, 8) + TEST_BINARY(42, &, 0, 0, 8) + TEST_BINARY(42, &, -1, 42, 8) + + TEST_BINARY(34, |, 10, 42, 9) + TEST_BINARY(42, |, 0, 42, 9) + TEST_BINARY(34, |, -1, -1, 9) + + TEST_BINARY(59, ^, 17, 42, 10) + TEST_BINARY(42, ^, 0, 42, 10) + TEST_BINARY(~42, ^, -1, 42, 10) +} + +void test_binary_comparison(void) +{ + int x, y; + + TEST_BINARY(42, ==, 42, 1, 11) + + TEST_BINARY(42, !=, 43, 1, 12) + TEST_BINARY_WITH_CAST(signed char, 42, !=, long, 65536L, 1, 12) + TEST_BINARY_WITH_CAST(long, 65536L, !=, signed char, 42, 1, 12) + + TEST_BINARY(42, >, 41, 1, 13) + TEST_BINARY_WITH_CAST(int, 0, >, unsigned, 42, 0, 13) + + TEST_BINARY(42, <, 43, 1, 14) + TEST_BINARY_WITH_CAST(unsigned, 42, <, int, 0, 0, 14) + + TEST_BINARY(42, >=, 0, 1, 15) + TEST_BINARY_WITH_CAST(unsigned, 42, >=, int, 0, 1, 15) + + TEST_BINARY(42, <=, 43, 1, 16) + TEST_BINARY_WITH_CAST(int, 0, <=, unsigned, 42, 1, 16) +} + +int main(void) +{ + test_unary(); + test_binary_arithmetic(); + test_binary_comparison(); + + if (failures != 0) { + printf("Failures: %d\n", failures); + } + + return failures; +} From 5e7d9b5fe3c14f5b705e9a17e3e133bf6004296a Mon Sep 17 00:00:00 2001 From: acqn Date: Sun, 18 Sep 2022 22:29:41 +0800 Subject: [PATCH 3/3] Renamed a few testcases. --- test/val/{bug1047.c => bug1047-bitfield-char.c} | 0 test/val/{bug1094.c => bug1094-nested-init.c} | 0 test/val/{bug1095.c => bug1095-bitfield-signed.c} | 0 test/val/{bug1139.c => bug1139-bitfield-in-if.c} | 0 test/val/{bug1178.c => bug1178-struct-copy.c} | 0 test/val/{bug1181.c => bug1181-struct-field-null-cmp.c} | 0 test/val/{bug1267.c => bug1267-bitfield-typedef-signedness.c} | 0 test/val/{bug1332.c => bug1332-bitfield.c} | 0 test/val/{bug1357.c => bug1357-pp.c} | 0 test/val/{bug1451.c => bug1451-struct-ptr-to-local.c} | 0 test/val/{bug1462.c => bug1462-biefield-assign-1.c} | 0 test/val/{bug1462-2.c => bug1462-biefield-assign-2.c} | 0 test/val/{bug1462-3.c => bug1462-biefield-assign-3.c} | 0 test/val/{bug1462-4.c => bug1462-biefield-assign-4.c} | 0 test/val/{anon-struct1.c => struct-anon1.c} | 0 test/val/{anon-struct2.c => struct-anon2.c} | 0 test/val/{return-struct.c => struct-returned.c} | 0 17 files changed, 0 insertions(+), 0 deletions(-) rename test/val/{bug1047.c => bug1047-bitfield-char.c} (100%) rename test/val/{bug1094.c => bug1094-nested-init.c} (100%) rename test/val/{bug1095.c => bug1095-bitfield-signed.c} (100%) rename test/val/{bug1139.c => bug1139-bitfield-in-if.c} (100%) rename test/val/{bug1178.c => bug1178-struct-copy.c} (100%) rename test/val/{bug1181.c => bug1181-struct-field-null-cmp.c} (100%) rename test/val/{bug1267.c => bug1267-bitfield-typedef-signedness.c} (100%) rename test/val/{bug1332.c => bug1332-bitfield.c} (100%) rename test/val/{bug1357.c => bug1357-pp.c} (100%) rename test/val/{bug1451.c => bug1451-struct-ptr-to-local.c} (100%) rename test/val/{bug1462.c => bug1462-biefield-assign-1.c} (100%) rename test/val/{bug1462-2.c => bug1462-biefield-assign-2.c} (100%) rename test/val/{bug1462-3.c => bug1462-biefield-assign-3.c} (100%) rename test/val/{bug1462-4.c => bug1462-biefield-assign-4.c} (100%) rename test/val/{anon-struct1.c => struct-anon1.c} (100%) rename test/val/{anon-struct2.c => struct-anon2.c} (100%) rename test/val/{return-struct.c => struct-returned.c} (100%) diff --git a/test/val/bug1047.c b/test/val/bug1047-bitfield-char.c similarity index 100% rename from test/val/bug1047.c rename to test/val/bug1047-bitfield-char.c diff --git a/test/val/bug1094.c b/test/val/bug1094-nested-init.c similarity index 100% rename from test/val/bug1094.c rename to test/val/bug1094-nested-init.c diff --git a/test/val/bug1095.c b/test/val/bug1095-bitfield-signed.c similarity index 100% rename from test/val/bug1095.c rename to test/val/bug1095-bitfield-signed.c diff --git a/test/val/bug1139.c b/test/val/bug1139-bitfield-in-if.c similarity index 100% rename from test/val/bug1139.c rename to test/val/bug1139-bitfield-in-if.c diff --git a/test/val/bug1178.c b/test/val/bug1178-struct-copy.c similarity index 100% rename from test/val/bug1178.c rename to test/val/bug1178-struct-copy.c diff --git a/test/val/bug1181.c b/test/val/bug1181-struct-field-null-cmp.c similarity index 100% rename from test/val/bug1181.c rename to test/val/bug1181-struct-field-null-cmp.c diff --git a/test/val/bug1267.c b/test/val/bug1267-bitfield-typedef-signedness.c similarity index 100% rename from test/val/bug1267.c rename to test/val/bug1267-bitfield-typedef-signedness.c diff --git a/test/val/bug1332.c b/test/val/bug1332-bitfield.c similarity index 100% rename from test/val/bug1332.c rename to test/val/bug1332-bitfield.c diff --git a/test/val/bug1357.c b/test/val/bug1357-pp.c similarity index 100% rename from test/val/bug1357.c rename to test/val/bug1357-pp.c diff --git a/test/val/bug1451.c b/test/val/bug1451-struct-ptr-to-local.c similarity index 100% rename from test/val/bug1451.c rename to test/val/bug1451-struct-ptr-to-local.c diff --git a/test/val/bug1462.c b/test/val/bug1462-biefield-assign-1.c similarity index 100% rename from test/val/bug1462.c rename to test/val/bug1462-biefield-assign-1.c diff --git a/test/val/bug1462-2.c b/test/val/bug1462-biefield-assign-2.c similarity index 100% rename from test/val/bug1462-2.c rename to test/val/bug1462-biefield-assign-2.c diff --git a/test/val/bug1462-3.c b/test/val/bug1462-biefield-assign-3.c similarity index 100% rename from test/val/bug1462-3.c rename to test/val/bug1462-biefield-assign-3.c diff --git a/test/val/bug1462-4.c b/test/val/bug1462-biefield-assign-4.c similarity index 100% rename from test/val/bug1462-4.c rename to test/val/bug1462-biefield-assign-4.c diff --git a/test/val/anon-struct1.c b/test/val/struct-anon1.c similarity index 100% rename from test/val/anon-struct1.c rename to test/val/struct-anon1.c diff --git a/test/val/anon-struct2.c b/test/val/struct-anon2.c similarity index 100% rename from test/val/anon-struct2.c rename to test/val/struct-anon2.c diff --git a/test/val/return-struct.c b/test/val/struct-returned.c similarity index 100% rename from test/val/return-struct.c rename to test/val/struct-returned.c