change line endings to unix style, should fix #1858

This commit is contained in:
mrdudz
2022-09-22 20:29:57 +02:00
parent 65ce036b2e
commit 846d51db72
14 changed files with 557 additions and 557 deletions

View File

@@ -1,41 +1,41 @@
/* Bug #1408: Signed char type comparisons with unsigned numeric constants */ /* Bug #1408: Signed char type comparisons with unsigned numeric constants */
#include <stdio.h> #include <stdio.h>
static int failures = 0; static int failures = 0;
static signed char x = -1; static signed char x = -1;
int main(void) int main(void)
{ {
if (!(x > -2u)) { if (!(x > -2u)) {
printf("x > -2u should be true\n"); printf("x > -2u should be true\n");
++failures; ++failures;
} }
if (!(x > 0u)) { if (!(x > 0u)) {
printf("x > 0u should be true\n"); printf("x > 0u should be true\n");
++failures; ++failures;
} }
if (!(x > 255u)) { if (!(x > 255u)) {
printf("x > 255u should be true\n"); printf("x > 255u should be true\n");
++failures; ++failures;
} }
if (!(-2u < x)) { if (!(-2u < x)) {
printf("-2u < x should be true\n"); printf("-2u < x should be true\n");
++failures; ++failures;
} }
if (!(0u < x)) { if (!(0u < x)) {
printf("0u < x should be true\n"); printf("0u < x should be true\n");
++failures; ++failures;
} }
if (!(255u < x)) { if (!(255u < x)) {
printf("255u < x should be true\n"); printf("255u < x should be true\n");
++failures; ++failures;
} }
if (failures != 0) { if (failures != 0) {
printf("Failures: %d\n", failures); printf("Failures: %d\n", failures);
} }
return failures; return failures;
} }

View File

@@ -1,39 +1,39 @@
/* Bug #1451 - local struct field access via the address of the struct */ /* Bug #1451 - local struct field access via the address of the struct */
#include <stdio.h> #include <stdio.h>
typedef struct { typedef struct {
int a; int a;
int b; int b;
} S; } S;
int failures = 0; int failures = 0;
int main(void) int main(void)
{ {
S a = {2, 5}; S a = {2, 5};
S b = {1, 4}; S b = {1, 4};
S m[1] = {{6, 3}}; S m[1] = {{6, 3}};
S *p = &a; S *p = &a;
(&a)->a += b.a; (&a)->a += b.a;
p->b += b.b; p->b += b.b;
m->a += b.a; m->a += b.a;
if ((&a)->a != 3) { if ((&a)->a != 3) {
++failures; ++failures;
printf("Expected 3, got %d\n", (&a)->a); printf("Expected 3, got %d\n", (&a)->a);
} }
if (p->b != 9) { if (p->b != 9) {
++failures; ++failures;
printf("Expected 9, got %d\n", p->b); printf("Expected 9, got %d\n", p->b);
} }
if (m->a != 7) { if (m->a != 7) {
++failures; ++failures;
printf("Expected 7, got %d\n", m->a); printf("Expected 7, got %d\n", m->a);
} }
return failures; return failures;
} }

View File

@@ -1,12 +1,12 @@
/* bug #1643, macro expansion in #include */ /* bug #1643, macro expansion in #include */
#define MKSTR(a) MKSTR_IMPL(a) #define MKSTR(a) MKSTR_IMPL(a)
#define MKSTR_IMPL(a) #a #define MKSTR_IMPL(a) #a
#define BUG1643_H bug1643.h #define BUG1643_H bug1643.h
#include MKSTR(BUG1643_H) #include MKSTR(BUG1643_H)
int main(void) int main(void)
{ {
return BUG1643_RESULT; return BUG1643_RESULT;
} }

View File

@@ -1,13 +1,13 @@
/* bug #1643, macro expansion in #include */ /* bug #1643, macro expansion in #include */
#define STDIO_H <stdio.h> #define STDIO_H <stdio.h>
#include STDIO_H #include STDIO_H
#ifdef string #ifdef string
#undef string #undef string
#endif #endif
#define string 0!%^&*/_= #define string 0!%^&*/_=
#include <string.h> #include <string.h>
#define BUG1643_RESULT 0 #define BUG1643_RESULT 0

View File

@@ -1,30 +1,30 @@
/* OptCmp1 messed up with labels */ /* OptCmp1 messed up with labels */
#include <stdio.h> #include <stdio.h>
static int failures = 0; static int failures = 0;
static unsigned int z = 0xFF23; static unsigned int z = 0xFF23;
int main(void) int main(void)
{ {
register unsigned int x = 0x200; register unsigned int x = 0x200;
register unsigned int y = 0; register unsigned int y = 0;
do { do {
++y; ++y;
} while (--x); } while (--x);
if (y != 0x200) { if (y != 0x200) {
printf("y should be 0x200, not 0x%X.\n", y); printf("y should be 0x200, not 0x%X.\n", y);
++failures;; ++failures;;
} }
if ((z -= 0x23)) { if ((z -= 0x23)) {
/* Passed -- non-zero z looks like non-zero. */ /* Passed -- non-zero z looks like non-zero. */
} else { } else {
/* Failed -- only the low byte of z was tested. */ /* Failed -- only the low byte of z was tested. */
printf("Test thinks non-zero z is zero.\n"); printf("Test thinks non-zero z is zero.\n");
++failures; ++failures;
} }
return failures; return failures;
} }

View File

@@ -1,25 +1,25 @@
/* Bug #1822 - Redefined macros failed to be all undefined with a single #undef */ /* Bug #1822 - Redefined macros failed to be all undefined with a single #undef */
#undef F #undef F
#undef F #undef F
#define F 1 #define F 1
#define F 1 #define F 1
#undef F #undef F
#if defined F #if defined F
#error #undef F fails! #error #undef F fails!
#endif #endif
#define F 0 #define F 0
#include <stdio.h> #include <stdio.h>
int main(void) int main(void)
{ {
if (F != 0) if (F != 0)
{ {
printf("failed: F = %d\n", F); printf("failed: F = %d\n", F);
} }
return F; return F;
} }

View File

@@ -1,35 +1,35 @@
/* Bug 1838 - function parameters declared as function types rather than function pointers */ /* Bug 1838 - function parameters declared as function types rather than function pointers */
#include <stdio.h> #include <stdio.h>
static int failures = 0; static int failures = 0;
typedef int fn_t(int); typedef int fn_t(int);
int main(void) int main(void)
{ {
void foo(fn_t*); void foo(fn_t*);
fn_t bar; fn_t bar;
foo(bar); foo(bar);
return failures; return failures;
} }
void foo(int func(int)) void foo(int func(int))
{ {
int n = func(42); int n = func(42);
if (n != 12) { if (n != 12) {
printf("n = %d, expected: 12\n", n); printf("n = %d, expected: 12\n", n);
++failures; ++failures;
} }
} }
int bar(int a) int bar(int a)
{ {
if (a != 42) { if (a != 42) {
printf("a = %d, expected: 42\n", a); printf("a = %d, expected: 42\n", a);
++failures; ++failures;
} }
return 12; return 12;
} }

View File

@@ -1,46 +1,46 @@
/* Bug #1847 - struct field access */ /* Bug #1847 - struct field access */
#include <stdio.h> #include <stdio.h>
struct TestStruct { struct TestStruct {
char a; char a;
char b; char b;
char c; char c;
}; };
struct TestStruct s0[2] = { {0xFF, 0, 0xFF}, {0, 0x42, 0xFF} }; struct TestStruct s0[2] = { {0xFF, 0, 0xFF}, {0, 0x42, 0xFF} };
struct TestStruct* s0Ptr = s0; struct TestStruct* s0Ptr = s0;
#define TEST_READ_SUB(X, E) \ #define TEST_READ_SUB(X, E) \
if ((X) != (E)) { \ if ((X) != (E)) { \
printf(#X ": 0x%X, expected: 0x%X\n", (X), (E)); \ printf(#X ": 0x%X, expected: 0x%X\n", (X), (E)); \
++failures; \ ++failures; \
} }
#define TEST_READ(S, I, F, E) \ #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])->F, E) \ TEST_READ_SUB((&S[I])->F, E) \
TEST_READ_SUB((&S[I])[0].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])->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]))[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)->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)[0].F, E)
static unsigned failures = 0; static unsigned failures = 0;
int main(void) { int main(void) {
struct TestStruct s1[2] = { {0xFF, 0, 0xFF}, {0, 42, 0xFF} }; struct TestStruct s1[2] = { {0xFF, 0, 0xFF}, {0, 42, 0xFF} };
struct TestStruct* s1Ptr = s1; struct TestStruct* s1Ptr = s1;
TEST_READ(s0, 1, b, 0x42) TEST_READ(s0, 1, b, 0x42)
TEST_READ(s1, 1, b, 42) TEST_READ(s1, 1, b, 42)
if (failures > 0) { if (failures > 0) {
printf("Failures: %u\n", failures); printf("Failures: %u\n", failures);
} }
return failures; return failures;
} }

View File

@@ -1,160 +1,160 @@
/* Check code generation for constant operands with side-effects */ /* Check code generation for constant operands with side-effects */
#include <stdio.h> #include <stdio.h>
static int failures = 0; static int failures = 0;
#define TEST(X, Y, L) \ #define TEST(X, Y, L) \
if (x != X || y != Y) { \ if (x != X || y != Y) { \
printf("Failed: " L "\nExpected: x = " #X ", y = " #Y ", got: x = %d, y = %d\n\n", x, y); \ printf("Failed: " L "\nExpected: x = " #X ", y = " #Y ", got: x = %d, y = %d\n\n", x, y); \
++failures; \ ++failures; \
} }
#define TEST_LINE_UNARY(OP, RH, ID) \ #define TEST_LINE_UNARY(OP, RH, ID) \
"x = " #OP "(set(&y, " #ID "), " #RH ")" "x = " #OP "(set(&y, " #ID "), " #RH ")"
#define TEST_UNARY(OP, RH, RS, ID) \ #define TEST_UNARY(OP, RH, RS, ID) \
x = -!(RS), y = -!(RS); \ x = -!(RS), y = -!(RS); \
x = OP (set(&y, ID), RH); \ x = OP (set(&y, ID), RH); \
TEST(RS, ID, TEST_LINE_UNARY(OP, RH, ID)) TEST(RS, ID, TEST_LINE_UNARY(OP, RH, ID))
#define TEST_LINE_RHS_EFFECT(LH, OP, RH, ID) \ #define TEST_LINE_RHS_EFFECT(LH, OP, RH, ID) \
"x = " #LH " " #OP " (set(&y, " #ID "), " #RH ")" "x = " #LH " " #OP " (set(&y, " #ID "), " #RH ")"
#define TEST_LINE_LHS_EFFECT(LH, OP, RH, ID) \ #define TEST_LINE_LHS_EFFECT(LH, OP, RH, ID) \
"y = (set(&x, " #ID "), " #LH ") " #OP " " #RH "y = (set(&x, " #ID "), " #LH ") " #OP " " #RH
#define TEST_BINARY(LH, OP, RH, RS, ID) \ #define TEST_BINARY(LH, OP, RH, RS, ID) \
x = -!(RS), y = -!(RS); \ x = -!(RS), y = -!(RS); \
x = LH OP (set(&y, ID), RH); \ x = LH OP (set(&y, ID), RH); \
TEST(RS, ID, TEST_LINE_RHS_EFFECT(LH, OP, RH, ID)) \ TEST(RS, ID, TEST_LINE_RHS_EFFECT(LH, OP, RH, ID)) \
y = -!(RS), x = -!(RS); \ y = -!(RS), x = -!(RS); \
y = (set(&x, ID), LH) OP RH; \ y = (set(&x, ID), LH) OP RH; \
TEST(ID, RS, TEST_LINE_LHS_EFFECT(LH, OP, RH, ID)) \ TEST(ID, RS, TEST_LINE_LHS_EFFECT(LH, OP, RH, ID)) \
y = -!(RS); \ y = -!(RS); \
x = (set(&x, LH), x) OP (set(&y, ID), RH); \ x = (set(&x, LH), x) OP (set(&y, ID), RH); \
TEST(RS, ID, TEST_LINE_RHS_EFFECT((set(&x, LH), x), OP, RH, ID)) \ TEST(RS, ID, TEST_LINE_RHS_EFFECT((set(&x, LH), x), OP, RH, ID)) \
x = -!(RS); \ x = -!(RS); \
y = (set(&x, ID), LH) OP (set(&y, RH), y); \ y = (set(&x, ID), LH) OP (set(&y, RH), y); \
TEST(ID, RS, TEST_LINE_LHS_EFFECT(LH, OP, (set(&y, RH), y), ID)) 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) \ #define TEST_LINE_RHS_EFFECT_WITH_CAST(LT, LH, OP, RT, RH, ID) \
"x = (" #LT ")" #LH " " #OP " (" #RT ")(set(&y, " #ID "), " #RH ")" "x = (" #LT ")" #LH " " #OP " (" #RT ")(set(&y, " #ID "), " #RH ")"
#define TEST_LINE_LHS_EFFECT_WITH_CAST(LT, LH, OP, RT, RH, ID) \ #define TEST_LINE_LHS_EFFECT_WITH_CAST(LT, LH, OP, RT, RH, ID) \
"y = (" #LT ")(set(&x, " #ID "), " #LH ") " #OP " (" #RT ")" #RH "y = (" #LT ")(set(&x, " #ID "), " #LH ") " #OP " (" #RT ")" #RH
#define TEST_BINARY_WITH_CAST(LT, LH, OP, RT, RH, RS, ID) \ #define TEST_BINARY_WITH_CAST(LT, LH, OP, RT, RH, RS, ID) \
x = -!(RS), y = -!(RS); \ x = -!(RS), y = -!(RS); \
x = (LT)LH OP (RT)(set(&y, ID), RH); \ x = (LT)LH OP (RT)(set(&y, ID), RH); \
TEST(RS, ID, TEST_LINE_RHS_EFFECT_WITH_CAST(LT, LH, OP, RT, RH, ID)) \ TEST(RS, ID, TEST_LINE_RHS_EFFECT_WITH_CAST(LT, LH, OP, RT, RH, ID)) \
y = -!(RS), x = -!(RS); \ y = -!(RS), x = -!(RS); \
y = (LT)(set(&x, ID), LH) OP (RT)RH; \ y = (LT)(set(&x, ID), LH) OP (RT)RH; \
TEST(ID, RS, TEST_LINE_LHS_EFFECT_WITH_CAST(LT, LH, OP, RT, RH, ID)) \ TEST(ID, RS, TEST_LINE_LHS_EFFECT_WITH_CAST(LT, LH, OP, RT, RH, ID)) \
y = -!(RS); \ y = -!(RS); \
x = (LT)(set(&x, LH), x) OP (RT)(set(&y, ID), RH); \ 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)) \ TEST(RS, ID, TEST_LINE_RHS_EFFECT_WITH_CAST(LT, (set(&x, LH), x), OP, RT, RH, ID)) \
x = -!(RS); \ x = -!(RS); \
y = (LT)(set(&x, ID), LH) OP (RT)(set(&y, RH), y); \ 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)) TEST(ID, RS, TEST_LINE_LHS_EFFECT_WITH_CAST(LT, LH, OP, RT, (set(&y, RH), y), ID))
void set(int *p, int q) void set(int *p, int q)
{ {
*p = q; *p = q;
} }
int twice(int a) int twice(int a)
{ {
return a * 2; return a * 2;
} }
int (*twicep)(int) = twice; int (*twicep)(int) = twice;
void test_unary(void) void test_unary(void)
{ {
int x, y; int x, y;
TEST_UNARY(+, 42, 42, 1); TEST_UNARY(+, 42, 42, 1);
TEST_UNARY(-, -42, 42, 2); TEST_UNARY(-, -42, 42, 2);
TEST_UNARY(~, ~42, 42, 3); TEST_UNARY(~, ~42, 42, 3);
TEST_UNARY(!, 42, 0, 4); TEST_UNARY(!, 42, 0, 4);
} }
void test_binary_arithmetic(void) void test_binary_arithmetic(void)
{ {
int x, y; int x, y;
TEST_BINARY(41, +, 1, 42, 1) TEST_BINARY(41, +, 1, 42, 1)
TEST_BINARY(42, +, 0, 42, 1) TEST_BINARY(42, +, 0, 42, 1)
TEST_BINARY(43, -, 1, 42, 2) TEST_BINARY(43, -, 1, 42, 2)
TEST_BINARY(42, -, 0, 42, 2) TEST_BINARY(42, -, 0, 42, 2)
TEST_BINARY(6, *, 7, 42, 3) TEST_BINARY(6, *, 7, 42, 3)
TEST_BINARY(42, *, 1, 42, 3) TEST_BINARY(42, *, 1, 42, 3)
TEST_BINARY(-42, *, -1, 42, 3) TEST_BINARY(-42, *, -1, 42, 3)
TEST_BINARY(126, /, 3, 42, 4) TEST_BINARY(126, /, 3, 42, 4)
TEST_BINARY(42, /, 1, 42, 4) TEST_BINARY(42, /, 1, 42, 4)
TEST_BINARY(-42, /, -1, 42, 4) TEST_BINARY(-42, /, -1, 42, 4)
TEST_BINARY(85, %, 43, 42, 5) TEST_BINARY(85, %, 43, 42, 5)
TEST_BINARY(10794, %, 256, 42, 5) TEST_BINARY(10794, %, 256, 42, 5)
TEST_BINARY(84, >>, 1, 42, 6) TEST_BINARY(84, >>, 1, 42, 6)
TEST_BINARY(42, >>, 0, 42, 6) TEST_BINARY(42, >>, 0, 42, 6)
TEST_BINARY(10752, >>, 8, 42, 6) TEST_BINARY(10752, >>, 8, 42, 6)
TEST_BINARY(21504, >>, 9, 42, 6) TEST_BINARY(21504, >>, 9, 42, 6)
TEST_BINARY(21, <<, 1, 42, 7) TEST_BINARY(21, <<, 1, 42, 7)
TEST_BINARY(42, <<, 0, 42, 7) TEST_BINARY(42, <<, 0, 42, 7)
TEST_BINARY(42, <<, 8, 10752, 7) TEST_BINARY(42, <<, 8, 10752, 7)
TEST_BINARY(59, &, 238, 42, 8) TEST_BINARY(59, &, 238, 42, 8)
TEST_BINARY(42, &, 0, 0, 8) TEST_BINARY(42, &, 0, 0, 8)
TEST_BINARY(42, &, -1, 42, 8) TEST_BINARY(42, &, -1, 42, 8)
TEST_BINARY(34, |, 10, 42, 9) TEST_BINARY(34, |, 10, 42, 9)
TEST_BINARY(42, |, 0, 42, 9) TEST_BINARY(42, |, 0, 42, 9)
TEST_BINARY(34, |, -1, -1, 9) TEST_BINARY(34, |, -1, -1, 9)
TEST_BINARY(59, ^, 17, 42, 10) TEST_BINARY(59, ^, 17, 42, 10)
TEST_BINARY(42, ^, 0, 42, 10) TEST_BINARY(42, ^, 0, 42, 10)
TEST_BINARY(~42, ^, -1, 42, 10) TEST_BINARY(~42, ^, -1, 42, 10)
} }
void test_binary_comparison(void) void test_binary_comparison(void)
{ {
int x, y; int x, y;
TEST_BINARY(42, ==, 42, 1, 11) TEST_BINARY(42, ==, 42, 1, 11)
TEST_BINARY(42, !=, 43, 1, 12) TEST_BINARY(42, !=, 43, 1, 12)
TEST_BINARY_WITH_CAST(signed char, 42, !=, long, 65536L, 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_WITH_CAST(long, 65536L, !=, signed char, 42, 1, 12)
TEST_BINARY(42, >, 41, 1, 13) TEST_BINARY(42, >, 41, 1, 13)
TEST_BINARY_WITH_CAST(int, 0, >, unsigned, 42, 0, 13) TEST_BINARY_WITH_CAST(int, 0, >, unsigned, 42, 0, 13)
TEST_BINARY(42, <, 43, 1, 14) TEST_BINARY(42, <, 43, 1, 14)
TEST_BINARY_WITH_CAST(unsigned, 42, <, int, 0, 0, 14) TEST_BINARY_WITH_CAST(unsigned, 42, <, int, 0, 0, 14)
TEST_BINARY(42, >=, 0, 1, 15) TEST_BINARY(42, >=, 0, 1, 15)
TEST_BINARY_WITH_CAST(unsigned, 42, >=, int, 0, 1, 15) TEST_BINARY_WITH_CAST(unsigned, 42, >=, int, 0, 1, 15)
TEST_BINARY(42, <=, 43, 1, 16) TEST_BINARY(42, <=, 43, 1, 16)
TEST_BINARY_WITH_CAST(int, 0, <=, unsigned, 42, 1, 16) TEST_BINARY_WITH_CAST(int, 0, <=, unsigned, 42, 1, 16)
} }
int main(void) int main(void)
{ {
test_unary(); test_unary();
test_binary_arithmetic(); test_binary_arithmetic();
test_binary_comparison(); test_binary_comparison();
if (failures != 0) { if (failures != 0) {
printf("Failures: %d\n", failures); printf("Failures: %d\n", failures);
} }
return failures; return failures;
} }

View File

@@ -1,60 +1,60 @@
/* Tests for predefined macro __COUNTER__ */ /* Tests for predefined macro __COUNTER__ */
#include <stdio.h> #include <stdio.h>
static int failures = 0; static int failures = 0;
#if __COUNTER__ /* 0 */ #if __COUNTER__ /* 0 */
# error __COUNTER__ should begin at 0! # error __COUNTER__ should begin at 0!
#elif __COUNTER__ == 1 /* 1 */ #elif __COUNTER__ == 1 /* 1 */
# define CONCAT(a,b) CONCAT_impl_(a,b) # define CONCAT(a,b) CONCAT_impl_(a,b)
# define CONCAT_impl_(a,b) a##b # define CONCAT_impl_(a,b) a##b
#endif #endif
#line 42 "What is the answer?" #line 42 "What is the answer?"
int CONCAT(ident,__COUNTER__)[0+__LINE__] = {__LINE__}, CONCAT(ident,__COUNTER__)[0+__LINE__] = {__LINE__}; /* 2,3 */ 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 */ #if __COUNTER__ == 4 ? 1 || __COUNTER__ : 0 && __COUNTER__ /* 4,5,6 */
_Static_assert(__COUNTER__ == 7, "__COUNTER__ should be 7 here!"); /* 7 */ _Static_assert(__COUNTER__ == 7, "__COUNTER__ should be 7 here!"); /* 7 */
# define GET_COUNTER() __COUNTER__ # define GET_COUNTER() __COUNTER__
# define GET_LINE() __LINE__ # define GET_LINE() __LINE__
# warning __COUNTER__ in #warning is just output as text and will never increase! # warning __COUNTER__ in #warning is just output as text and will never increase!
#else #else
# if __COUNTER__ + __COUNTER__ + __COUNTER__ /* Skipped as a whole and not incrementing */ # if __COUNTER__ + __COUNTER__ + __COUNTER__ /* Skipped as a whole and not incrementing */
# endif # endif
# error __COUNTER__ is skipped along with the whole #error line and will never increase anyways! */ # error __COUNTER__ is skipped along with the whole #error line and will never increase anyways! */
#endif #endif
#include "counter.h" #include "counter.h"
#include "counter.h" #include "counter.h"
_Static_assert(GET_COUNTER() == 10, "__COUNTER__ should be 10 here!"); /* 10 */ _Static_assert(GET_COUNTER() == 10, "__COUNTER__ should be 10 here!"); /* 10 */
int main(void) int main(void)
{ {
if (ident2[0] != 42) { if (ident2[0] != 42) {
printf("Expected ident2[0]: %s, got: %s\n", 42, ident2[0]); printf("Expected ident2[0]: %s, got: %s\n", 42, ident2[0]);
++failures; ++failures;
} }
if (ident3[0] != 42) { if (ident3[0] != 42) {
printf("Expected ident3[0]: %s, got: %s\n", 42, ident3[0]); printf("Expected ident3[0]: %s, got: %s\n", 42, ident3[0]);
++failures; ++failures;
} }
if (ident8 != 8) { if (ident8 != 8) {
printf("Expected ident8: %s, got: %s\n", 8, ident8); printf("Expected ident8: %s, got: %s\n", 8, ident8);
++failures; ++failures;
} }
if (ident9 != 9) { if (ident9 != 9) {
printf("Expected ident9: %s, got: %s\n", 9, ident9); printf("Expected ident9: %s, got: %s\n", 9, ident9);
++failures; ++failures;
} }
if (failures != 0) { if (failures != 0) {
printf("Failures: %d\n", failures); printf("Failures: %d\n", failures);
} }
return failures; return failures;
} }

View File

@@ -1,4 +1,4 @@
/* Tests for predefined macro __COUNTER__ */ /* Tests for predefined macro __COUNTER__ */
#line GET_COUNTER() /* 1st: 8; 2nd: 9 */ #line GET_COUNTER() /* 1st: 8; 2nd: 9 */
int CONCAT(ident,GET_LINE()) = GET_LINE(); int CONCAT(ident,GET_LINE()) = GET_LINE();

View File

@@ -1,33 +1,33 @@
/* Test for result types of certain unary operations */ /* Test for result types of certain unary operations */
#include <stdio.h> #include <stdio.h>
signed char x; signed char x;
struct S { struct S {
unsigned char a : 3; unsigned char a : 3;
unsigned int b : 3; unsigned int b : 3;
} s; } s;
int main(void) 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++) == 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=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 (-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.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"); _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; return 0;
} }

View File

@@ -1,13 +1,13 @@
/* Test for PR #1833 fixes */ /* Test for PR #1833 fixes */
#define char 1 #define char 1
#if char && !int && L'A' - L'B' == 'A' - 'B' && L'A' == 'A' #if char && !int && L'A' - L'B' == 'A' - 'B' && L'A' == 'A'
#else #else
#error #error
#endif #endif
int main(void) int main(void)
{ {
return 0; return 0;
} }

View File

@@ -1,46 +1,46 @@
/* /*
Copyright 2021, The cc65 Authors Copyright 2021, The cc65 Authors
This software is provided "as-is", without any express or implied This software is provided "as-is", without any express or implied
warranty. In no event will the authors be held liable for any damages warranty. In no event will the authors be held liable for any damages
arising from the use of this software. arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, Permission is granted to anyone to use this software for any purpose,
including commercial applications; and, to alter it and redistribute it including commercial applications; and, to alter it and redistribute it
freely, subject to the following restrictions: freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not 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 claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be in a product, an acknowledgment in the product documentation would be
appreciated, but is not required. appreciated, but is not required.
2. Altered source versions must be plainly marked as such, and must not be 2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software. misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution. 3. This notice may not be removed or altered from any source distribution.
*/ */
/* /*
Test of deferred operations in unevaluated context resulted from 'sizeof' and Test of deferred operations in unevaluated context resulted from 'sizeof' and
short-circuited code-paths in AND, OR and tenary operations. short-circuited code-paths in AND, OR and tenary operations.
https://github.com/cc65/cc65/issues/1406 https://github.com/cc65/cc65/issues/1406
*/ */
#include <stdio.h> #include <stdio.h>
int main(void) int main(void)
{ {
int i = 0; int i = 0;
int j = 0; int j = 0;
sizeof(i++ | j--); sizeof(i++ | j--);
0 && (i++ | j--); 0 && (i++ | j--);
1 || (i++ | j--); 1 || (i++ | j--);
0 ? i++ | j-- : 0; 0 ? i++ | j-- : 0;
1 ? 0 : i++ | j--; 1 ? 0 : i++ | j--;
if (i != 0 || j != 0) { if (i != 0 || j != 0) {
printf("i = %d, j = %d\n", i, j); printf("i = %d, j = %d\n", i, j);
printf("Failures: %d\n", i - j); printf("Failures: %d\n", i - j);
} }
return i - j; return i - j;
} }