mirror of
https://github.com/cc65/cc65.git
synced 2025-04-08 19:38:55 +00:00
change line endings to unix style, should fix #1858
This commit is contained in:
parent
65ce036b2e
commit
846d51db72
@ -1,41 +1,41 @@
|
||||
/* Bug #1408: Signed char type comparisons with unsigned numeric constants */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
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 <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -1,39 +1,39 @@
|
||||
/* Bug #1451 - local struct field access via the address of the struct */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
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 <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
/* bug #1643, macro expansion in #include */
|
||||
|
||||
#define STDIO_H <stdio.h>
|
||||
#include STDIO_H
|
||||
|
||||
#ifdef string
|
||||
#undef string
|
||||
#endif
|
||||
|
||||
#define string 0!%^&*/_=
|
||||
#include <string.h>
|
||||
|
||||
#define BUG1643_RESULT 0
|
||||
/* bug #1643, macro expansion in #include */
|
||||
|
||||
#define STDIO_H <stdio.h>
|
||||
#include STDIO_H
|
||||
|
||||
#ifdef string
|
||||
#undef string
|
||||
#endif
|
||||
|
||||
#define string 0!%^&*/_=
|
||||
#include <string.h>
|
||||
|
||||
#define BUG1643_RESULT 0
|
||||
|
@ -1,30 +1,30 @@
|
||||
/* OptCmp1 messed up with labels */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
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 <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -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 <stdio.h>
|
||||
|
||||
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 <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
if (F != 0)
|
||||
{
|
||||
printf("failed: F = %d\n", F);
|
||||
}
|
||||
return F;
|
||||
}
|
||||
|
@ -1,35 +1,35 @@
|
||||
/* Bug 1838 - function parameters declared as function types rather than function pointers */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
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 <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -1,46 +1,46 @@
|
||||
/* Bug #1847 - struct field access */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
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 <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -1,160 +1,160 @@
|
||||
/* Check code generation for constant operands with side-effects */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
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 <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -1,60 +1,60 @@
|
||||
/* Tests for predefined macro __COUNTER__ */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
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 <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -1,33 +1,33 @@
|
||||
|
||||
/* Test for result types of certain unary operations */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
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 <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 <stdio.h>
|
||||
|
||||
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 <stdio.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user