From 846d51db722509539136b961b982ad6d07747c75 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Thu, 22 Sep 2022 20:29:57 +0200 Subject: [PATCH] change line endings to unix style, should fix #1858 --- test/val/bug1408.c | 82 +++---- test/val/bug1451-struct-ptr-to-local.c | 78 +++--- test/val/bug1643.c | 24 +- test/val/bug1643.h | 26 +- test/val/bug1690.c | 60 ++--- test/val/bug1822-pptest.c | 50 ++-- test/val/bug1838.c | 70 +++--- test/val/bug1847-struct-field-access.c | 92 +++---- test/val/const-side-effect.c | 320 ++++++++++++------------- test/val/counter.c | 120 +++++----- test/val/counter.h | 8 +- test/val/opsize.c | 66 ++--- test/val/pr1833.c | 26 +- test/val/uneval.c | 92 +++---- 14 files changed, 557 insertions(+), 557 deletions(-) diff --git a/test/val/bug1408.c b/test/val/bug1408.c index 8ecc1be68..137899315 100644 --- a/test/val/bug1408.c +++ b/test/val/bug1408.c @@ -1,41 +1,41 @@ -/* Bug #1408: Signed char type comparisons with unsigned numeric constants */ - -#include - -static int failures = 0; -static signed char x = -1; - -int main(void) -{ - if (!(x > -2u)) { - printf("x > -2u should be true\n"); - ++failures; - } - if (!(x > 0u)) { - printf("x > 0u should be true\n"); - ++failures; - } - if (!(x > 255u)) { - printf("x > 255u should be true\n"); - ++failures; - } - - if (!(-2u < x)) { - printf("-2u < x should be true\n"); - ++failures; - } - if (!(0u < x)) { - printf("0u < x should be true\n"); - ++failures; - } - if (!(255u < x)) { - printf("255u < x should be true\n"); - ++failures; - } - - if (failures != 0) { - printf("Failures: %d\n", failures); - } - - return failures; -} +/* Bug #1408: Signed char type comparisons with unsigned numeric constants */ + +#include + +static int failures = 0; +static signed char x = -1; + +int main(void) +{ + if (!(x > -2u)) { + printf("x > -2u should be true\n"); + ++failures; + } + if (!(x > 0u)) { + printf("x > 0u should be true\n"); + ++failures; + } + if (!(x > 255u)) { + printf("x > 255u should be true\n"); + ++failures; + } + + if (!(-2u < x)) { + printf("-2u < x should be true\n"); + ++failures; + } + if (!(0u < x)) { + printf("0u < x should be true\n"); + ++failures; + } + if (!(255u < x)) { + printf("255u < x should be true\n"); + ++failures; + } + + if (failures != 0) { + printf("Failures: %d\n", failures); + } + + return failures; +} diff --git a/test/val/bug1451-struct-ptr-to-local.c b/test/val/bug1451-struct-ptr-to-local.c index f9cca2561..2148e034d 100644 --- a/test/val/bug1451-struct-ptr-to-local.c +++ b/test/val/bug1451-struct-ptr-to-local.c @@ -1,39 +1,39 @@ -/* Bug #1451 - local struct field access via the address of the struct */ - -#include - -typedef struct { - int a; - int b; -} S; - -int failures = 0; - -int main(void) -{ - S a = {2, 5}; - S b = {1, 4}; - S m[1] = {{6, 3}}; - S *p = &a; - - (&a)->a += b.a; - p->b += b.b; - m->a += b.a; - - if ((&a)->a != 3) { - ++failures; - printf("Expected 3, got %d\n", (&a)->a); - } - - if (p->b != 9) { - ++failures; - printf("Expected 9, got %d\n", p->b); - } - - if (m->a != 7) { - ++failures; - printf("Expected 7, got %d\n", m->a); - } - - return failures; -} +/* Bug #1451 - local struct field access via the address of the struct */ + +#include + +typedef struct { + int a; + int b; +} S; + +int failures = 0; + +int main(void) +{ + S a = {2, 5}; + S b = {1, 4}; + S m[1] = {{6, 3}}; + S *p = &a; + + (&a)->a += b.a; + p->b += b.b; + m->a += b.a; + + if ((&a)->a != 3) { + ++failures; + printf("Expected 3, got %d\n", (&a)->a); + } + + if (p->b != 9) { + ++failures; + printf("Expected 9, got %d\n", p->b); + } + + if (m->a != 7) { + ++failures; + printf("Expected 7, got %d\n", m->a); + } + + return failures; +} diff --git a/test/val/bug1643.c b/test/val/bug1643.c index eba733511..c6237b7fb 100644 --- a/test/val/bug1643.c +++ b/test/val/bug1643.c @@ -1,12 +1,12 @@ -/* bug #1643, macro expansion in #include */ - -#define MKSTR(a) MKSTR_IMPL(a) -#define MKSTR_IMPL(a) #a -#define BUG1643_H bug1643.h - -#include MKSTR(BUG1643_H) - -int main(void) -{ - return BUG1643_RESULT; -} +/* bug #1643, macro expansion in #include */ + +#define MKSTR(a) MKSTR_IMPL(a) +#define MKSTR_IMPL(a) #a +#define BUG1643_H bug1643.h + +#include MKSTR(BUG1643_H) + +int main(void) +{ + return BUG1643_RESULT; +} diff --git a/test/val/bug1643.h b/test/val/bug1643.h index fe0423688..068263436 100644 --- a/test/val/bug1643.h +++ b/test/val/bug1643.h @@ -1,13 +1,13 @@ -/* bug #1643, macro expansion in #include */ - -#define STDIO_H -#include STDIO_H - -#ifdef string -#undef string -#endif - -#define string 0!%^&*/_= -#include - -#define BUG1643_RESULT 0 +/* bug #1643, macro expansion in #include */ + +#define STDIO_H +#include STDIO_H + +#ifdef string +#undef string +#endif + +#define string 0!%^&*/_= +#include + +#define BUG1643_RESULT 0 diff --git a/test/val/bug1690.c b/test/val/bug1690.c index 499dc6b35..78c0cda41 100644 --- a/test/val/bug1690.c +++ b/test/val/bug1690.c @@ -1,30 +1,30 @@ -/* OptCmp1 messed up with labels */ - -#include - -static int failures = 0; -static unsigned int z = 0xFF23; - -int main(void) -{ - register unsigned int x = 0x200; - register unsigned int y = 0; - - do { - ++y; - } while (--x); - if (y != 0x200) { - printf("y should be 0x200, not 0x%X.\n", y); - ++failures;; - } - - if ((z -= 0x23)) { - /* Passed -- non-zero z looks like non-zero. */ - } else { - /* Failed -- only the low byte of z was tested. */ - printf("Test thinks non-zero z is zero.\n"); - ++failures; - } - - return failures; -} +/* OptCmp1 messed up with labels */ + +#include + +static int failures = 0; +static unsigned int z = 0xFF23; + +int main(void) +{ + register unsigned int x = 0x200; + register unsigned int y = 0; + + do { + ++y; + } while (--x); + if (y != 0x200) { + printf("y should be 0x200, not 0x%X.\n", y); + ++failures;; + } + + if ((z -= 0x23)) { + /* Passed -- non-zero z looks like non-zero. */ + } else { + /* Failed -- only the low byte of z was tested. */ + printf("Test thinks non-zero z is zero.\n"); + ++failures; + } + + return failures; +} diff --git a/test/val/bug1822-pptest.c b/test/val/bug1822-pptest.c index eb4d23391..133d69f6b 100644 --- a/test/val/bug1822-pptest.c +++ b/test/val/bug1822-pptest.c @@ -1,25 +1,25 @@ -/* Bug #1822 - Redefined macros failed to be all undefined with a single #undef */ - -#undef F -#undef F - -#define F 1 -#define F 1 - -#undef F -#if defined F -#error #undef F fails! -#endif - -#define F 0 - -#include - -int main(void) -{ - if (F != 0) - { - printf("failed: F = %d\n", F); - } - return F; -} +/* Bug #1822 - Redefined macros failed to be all undefined with a single #undef */ + +#undef F +#undef F + +#define F 1 +#define F 1 + +#undef F +#if defined F +#error #undef F fails! +#endif + +#define F 0 + +#include + +int main(void) +{ + if (F != 0) + { + printf("failed: F = %d\n", F); + } + return F; +} diff --git a/test/val/bug1838.c b/test/val/bug1838.c index ea2d39a81..45978dca4 100644 --- a/test/val/bug1838.c +++ b/test/val/bug1838.c @@ -1,35 +1,35 @@ -/* Bug 1838 - function parameters declared as function types rather than function pointers */ - -#include - -static int failures = 0; - -typedef int fn_t(int); - -int main(void) -{ - void foo(fn_t*); - fn_t bar; - - foo(bar); - return failures; -} - -void foo(int func(int)) -{ - int n = func(42); - - if (n != 12) { - printf("n = %d, expected: 12\n", n); - ++failures; - } -} - -int bar(int a) -{ - if (a != 42) { - printf("a = %d, expected: 42\n", a); - ++failures; - } - return 12; -} +/* Bug 1838 - function parameters declared as function types rather than function pointers */ + +#include + +static int failures = 0; + +typedef int fn_t(int); + +int main(void) +{ + void foo(fn_t*); + fn_t bar; + + foo(bar); + return failures; +} + +void foo(int func(int)) +{ + int n = func(42); + + if (n != 12) { + printf("n = %d, expected: 12\n", n); + ++failures; + } +} + +int bar(int a) +{ + if (a != 42) { + printf("a = %d, expected: 42\n", a); + ++failures; + } + return 12; +} diff --git a/test/val/bug1847-struct-field-access.c b/test/val/bug1847-struct-field-access.c index 71575636f..55ead7ec7 100644 --- a/test/val/bug1847-struct-field-access.c +++ b/test/val/bug1847-struct-field-access.c @@ -1,46 +1,46 @@ -/* Bug #1847 - struct field access */ - -#include - -struct TestStruct { - char a; - char b; - char c; -}; - -struct TestStruct s0[2] = { {0xFF, 0, 0xFF}, {0, 0x42, 0xFF} }; -struct TestStruct* s0Ptr = s0; - -#define TEST_READ_SUB(X, E) \ - if ((X) != (E)) { \ - printf(#X ": 0x%X, expected: 0x%X\n", (X), (E)); \ - ++failures; \ - } - -#define TEST_READ(S, I, F, E) \ - TEST_READ_SUB(S[I].F, E) \ - TEST_READ_SUB((&S[I])->F, E) \ - TEST_READ_SUB((&S[I])[0].F, E) \ - TEST_READ_SUB(S##Ptr[I].F, E) \ - TEST_READ_SUB((&S##Ptr[I])->F, E) \ - TEST_READ_SUB((&(S##Ptr[I]))[0].F, E) \ - TEST_READ_SUB((&(*S##Ptr))[I].F, E) \ - TEST_READ_SUB((&(*S##Ptr)+I)->F, E) \ - TEST_READ_SUB((S##Ptr+I)->F, E) \ - TEST_READ_SUB((S##Ptr+I)[0].F, E) - -static unsigned failures = 0; - -int main(void) { - struct TestStruct s1[2] = { {0xFF, 0, 0xFF}, {0, 42, 0xFF} }; - struct TestStruct* s1Ptr = s1; - - TEST_READ(s0, 1, b, 0x42) - TEST_READ(s1, 1, b, 42) - - if (failures > 0) { - printf("Failures: %u\n", failures); - } - - return failures; -} +/* Bug #1847 - struct field access */ + +#include + +struct TestStruct { + char a; + char b; + char c; +}; + +struct TestStruct s0[2] = { {0xFF, 0, 0xFF}, {0, 0x42, 0xFF} }; +struct TestStruct* s0Ptr = s0; + +#define TEST_READ_SUB(X, E) \ + if ((X) != (E)) { \ + printf(#X ": 0x%X, expected: 0x%X\n", (X), (E)); \ + ++failures; \ + } + +#define TEST_READ(S, I, F, E) \ + TEST_READ_SUB(S[I].F, E) \ + TEST_READ_SUB((&S[I])->F, E) \ + TEST_READ_SUB((&S[I])[0].F, E) \ + TEST_READ_SUB(S##Ptr[I].F, E) \ + TEST_READ_SUB((&S##Ptr[I])->F, E) \ + TEST_READ_SUB((&(S##Ptr[I]))[0].F, E) \ + TEST_READ_SUB((&(*S##Ptr))[I].F, E) \ + TEST_READ_SUB((&(*S##Ptr)+I)->F, E) \ + TEST_READ_SUB((S##Ptr+I)->F, E) \ + TEST_READ_SUB((S##Ptr+I)[0].F, E) + +static unsigned failures = 0; + +int main(void) { + struct TestStruct s1[2] = { {0xFF, 0, 0xFF}, {0, 42, 0xFF} }; + struct TestStruct* s1Ptr = s1; + + TEST_READ(s0, 1, b, 0x42) + TEST_READ(s1, 1, b, 42) + + if (failures > 0) { + printf("Failures: %u\n", failures); + } + + return failures; +} diff --git a/test/val/const-side-effect.c b/test/val/const-side-effect.c index 7c2f074f2..cebc6f099 100644 --- a/test/val/const-side-effect.c +++ b/test/val/const-side-effect.c @@ -1,160 +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; -} +/* 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; +} diff --git a/test/val/counter.c b/test/val/counter.c index 4efa18359..1867b1a66 100644 --- a/test/val/counter.c +++ b/test/val/counter.c @@ -1,60 +1,60 @@ -/* Tests for predefined macro __COUNTER__ */ - -#include - -static int failures = 0; - -#if __COUNTER__ /* 0 */ -# error __COUNTER__ should begin at 0! -#elif __COUNTER__ == 1 /* 1 */ -# define CONCAT(a,b) CONCAT_impl_(a,b) -# define CONCAT_impl_(a,b) a##b -#endif - -#line 42 "What is the answer?" -int CONCAT(ident,__COUNTER__)[0+__LINE__] = {__LINE__}, CONCAT(ident,__COUNTER__)[0+__LINE__] = {__LINE__}; /* 2,3 */ - -#if __COUNTER__ == 4 ? 1 || __COUNTER__ : 0 && __COUNTER__ /* 4,5,6 */ -_Static_assert(__COUNTER__ == 7, "__COUNTER__ should be 7 here!"); /* 7 */ -# define GET_COUNTER() __COUNTER__ -# define GET_LINE() __LINE__ -# warning __COUNTER__ in #warning is just output as text and will never increase! -#else -# if __COUNTER__ + __COUNTER__ + __COUNTER__ /* Skipped as a whole and not incrementing */ -# endif -# error __COUNTER__ is skipped along with the whole #error line and will never increase anyways! */ -#endif - -#include "counter.h" -#include "counter.h" - -_Static_assert(GET_COUNTER() == 10, "__COUNTER__ should be 10 here!"); /* 10 */ - -int main(void) -{ - if (ident2[0] != 42) { - printf("Expected ident2[0]: %s, got: %s\n", 42, ident2[0]); - ++failures; - } - - if (ident3[0] != 42) { - printf("Expected ident3[0]: %s, got: %s\n", 42, ident3[0]); - ++failures; - } - - if (ident8 != 8) { - printf("Expected ident8: %s, got: %s\n", 8, ident8); - ++failures; - } - - if (ident9 != 9) { - printf("Expected ident9: %s, got: %s\n", 9, ident9); - ++failures; - } - - if (failures != 0) { - printf("Failures: %d\n", failures); - } - - return failures; -} +/* Tests for predefined macro __COUNTER__ */ + +#include + +static int failures = 0; + +#if __COUNTER__ /* 0 */ +# error __COUNTER__ should begin at 0! +#elif __COUNTER__ == 1 /* 1 */ +# define CONCAT(a,b) CONCAT_impl_(a,b) +# define CONCAT_impl_(a,b) a##b +#endif + +#line 42 "What is the answer?" +int CONCAT(ident,__COUNTER__)[0+__LINE__] = {__LINE__}, CONCAT(ident,__COUNTER__)[0+__LINE__] = {__LINE__}; /* 2,3 */ + +#if __COUNTER__ == 4 ? 1 || __COUNTER__ : 0 && __COUNTER__ /* 4,5,6 */ +_Static_assert(__COUNTER__ == 7, "__COUNTER__ should be 7 here!"); /* 7 */ +# define GET_COUNTER() __COUNTER__ +# define GET_LINE() __LINE__ +# warning __COUNTER__ in #warning is just output as text and will never increase! +#else +# if __COUNTER__ + __COUNTER__ + __COUNTER__ /* Skipped as a whole and not incrementing */ +# endif +# error __COUNTER__ is skipped along with the whole #error line and will never increase anyways! */ +#endif + +#include "counter.h" +#include "counter.h" + +_Static_assert(GET_COUNTER() == 10, "__COUNTER__ should be 10 here!"); /* 10 */ + +int main(void) +{ + if (ident2[0] != 42) { + printf("Expected ident2[0]: %s, got: %s\n", 42, ident2[0]); + ++failures; + } + + if (ident3[0] != 42) { + printf("Expected ident3[0]: %s, got: %s\n", 42, ident3[0]); + ++failures; + } + + if (ident8 != 8) { + printf("Expected ident8: %s, got: %s\n", 8, ident8); + ++failures; + } + + if (ident9 != 9) { + printf("Expected ident9: %s, got: %s\n", 9, ident9); + ++failures; + } + + if (failures != 0) { + printf("Failures: %d\n", failures); + } + + return failures; +} diff --git a/test/val/counter.h b/test/val/counter.h index b6b5a98e2..b97cbf54d 100644 --- a/test/val/counter.h +++ b/test/val/counter.h @@ -1,4 +1,4 @@ -/* Tests for predefined macro __COUNTER__ */ - -#line GET_COUNTER() /* 1st: 8; 2nd: 9 */ -int CONCAT(ident,GET_LINE()) = GET_LINE(); +/* Tests for predefined macro __COUNTER__ */ + +#line GET_COUNTER() /* 1st: 8; 2nd: 9 */ +int CONCAT(ident,GET_LINE()) = GET_LINE(); diff --git a/test/val/opsize.c b/test/val/opsize.c index 20c7f0511..8ec49e8a8 100644 --- a/test/val/opsize.c +++ b/test/val/opsize.c @@ -1,33 +1,33 @@ - -/* Test for result types of certain unary operations */ - -#include - -signed char x; -struct S { - unsigned char a : 3; - unsigned int b : 3; -} s; - -int main(void) -{ - _Static_assert(sizeof (++x) == sizeof (char), "++x result should not have promoted type"); - _Static_assert(sizeof (--x) == sizeof (char), "--x result should not have promoted type"); - _Static_assert(sizeof (x++) == sizeof (char), "x++ result should not have promoted type"); - _Static_assert(sizeof (x--) == sizeof (char), "x-- result should not have promoted type"); - _Static_assert(sizeof (x=0) == sizeof (char), "x=0 result should not have promoted type"); - - _Static_assert(sizeof (+x) == sizeof (int), "+x result should have promoted type"); - _Static_assert(sizeof (-x) == sizeof (int), "-x result should have promoted type"); - _Static_assert(sizeof (~x) == sizeof (int), "~x result should have promoted type"); - - _Static_assert(sizeof (+s.a) == sizeof (int), "+s.a result should have promoted type"); - _Static_assert(sizeof (-s.a) == sizeof (int), "-s.a result should have promoted type"); - _Static_assert(sizeof (~s.a) == sizeof (int), "~s.a result should have promoted type"); - - _Static_assert(sizeof (+s.b) == sizeof (int), "+s.b result should have promoted type"); - _Static_assert(sizeof (-s.b) == sizeof (int), "-s.b result should have promoted type"); - _Static_assert(sizeof (~s.b) == sizeof (int), "~s.b result should have promoted type"); - - return 0; -} + +/* Test for result types of certain unary operations */ + +#include + +signed char x; +struct S { + unsigned char a : 3; + unsigned int b : 3; +} s; + +int main(void) +{ + _Static_assert(sizeof (++x) == sizeof (char), "++x result should not have promoted type"); + _Static_assert(sizeof (--x) == sizeof (char), "--x result should not have promoted type"); + _Static_assert(sizeof (x++) == sizeof (char), "x++ result should not have promoted type"); + _Static_assert(sizeof (x--) == sizeof (char), "x-- result should not have promoted type"); + _Static_assert(sizeof (x=0) == sizeof (char), "x=0 result should not have promoted type"); + + _Static_assert(sizeof (+x) == sizeof (int), "+x result should have promoted type"); + _Static_assert(sizeof (-x) == sizeof (int), "-x result should have promoted type"); + _Static_assert(sizeof (~x) == sizeof (int), "~x result should have promoted type"); + + _Static_assert(sizeof (+s.a) == sizeof (int), "+s.a result should have promoted type"); + _Static_assert(sizeof (-s.a) == sizeof (int), "-s.a result should have promoted type"); + _Static_assert(sizeof (~s.a) == sizeof (int), "~s.a result should have promoted type"); + + _Static_assert(sizeof (+s.b) == sizeof (int), "+s.b result should have promoted type"); + _Static_assert(sizeof (-s.b) == sizeof (int), "-s.b result should have promoted type"); + _Static_assert(sizeof (~s.b) == sizeof (int), "~s.b result should have promoted type"); + + return 0; +} diff --git a/test/val/pr1833.c b/test/val/pr1833.c index bdc820811..177069eb4 100644 --- a/test/val/pr1833.c +++ b/test/val/pr1833.c @@ -1,13 +1,13 @@ -/* Test for PR #1833 fixes */ - -#define char 1 - -#if char && !int && L'A' - L'B' == 'A' - 'B' && L'A' == 'A' -#else -#error -#endif - -int main(void) -{ - return 0; -} +/* Test for PR #1833 fixes */ + +#define char 1 + +#if char && !int && L'A' - L'B' == 'A' - 'B' && L'A' == 'A' +#else +#error +#endif + +int main(void) +{ + return 0; +} diff --git a/test/val/uneval.c b/test/val/uneval.c index 50e00973a..fe42cc592 100644 --- a/test/val/uneval.c +++ b/test/val/uneval.c @@ -1,46 +1,46 @@ -/* - Copyright 2021, The cc65 Authors - - This software is provided "as-is", without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications; and, to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated, but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -/* - Test of deferred operations in unevaluated context resulted from 'sizeof' and - short-circuited code-paths in AND, OR and tenary operations. - - https://github.com/cc65/cc65/issues/1406 -*/ - -#include - -int main(void) -{ - int i = 0; - int j = 0; - - sizeof(i++ | j--); - 0 && (i++ | j--); - 1 || (i++ | j--); - 0 ? i++ | j-- : 0; - 1 ? 0 : i++ | j--; - - if (i != 0 || j != 0) { - printf("i = %d, j = %d\n", i, j); - printf("Failures: %d\n", i - j); - } - return i - j; -} +/* + Copyright 2021, The cc65 Authors + + This software is provided "as-is", without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications; and, to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated, but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. +*/ + +/* + Test of deferred operations in unevaluated context resulted from 'sizeof' and + short-circuited code-paths in AND, OR and tenary operations. + + https://github.com/cc65/cc65/issues/1406 +*/ + +#include + +int main(void) +{ + int i = 0; + int j = 0; + + sizeof(i++ | j--); + 0 && (i++ | j--); + 1 || (i++ | j--); + 0 ? i++ | j-- : 0; + 1 ? 0 : i++ | j--; + + if (i != 0 || j != 0) { + printf("i = %d, j = %d\n", i, j); + printf("Failures: %d\n", i - j); + } + return i - j; +}