mirror of
https://github.com/cc65/cc65.git
synced 2025-01-12 17:30:50 +00:00
Merge branch 'cc65:master' into master
This commit is contained in:
commit
fa6a5d9b72
@ -12,7 +12,7 @@ int main(void)
|
||||
fn_t bar;
|
||||
|
||||
foo(bar);
|
||||
return 0;
|
||||
return failures;
|
||||
}
|
||||
|
||||
void foo(int func(int))
|
||||
|
@ -42,5 +42,5 @@ int main(void) {
|
||||
printf("Failures: %u\n", failures);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return failures;
|
||||
}
|
||||
|
160
test/val/const-side-effect.c
Normal file
160
test/val/const-side-effect.c
Normal file
@ -0,0 +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;
|
||||
}
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user