1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-27 15:29:46 +00:00
cc65/test/val/bug2395.c
2024-02-02 13:13:57 +01:00

45 lines
840 B
C

/* bug #2395: Bitwise operators with a boolean expression fail when optimized */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
unsigned char a, b;
unsigned char c = 199;
unsigned char d = 100;
int main(void) {
int fails = 0;
a = c ^ (d != 0);
b = c ^ 1;
printf("%u ^ (%u != 0) => %u\n", c, d, a);
if (a != b) {
printf("XOR error: a %d instead of %d\n", a, b);
fails++;
}
a = c | (d != 0);
b = c | 1;
printf("%u | (%u != 0) => %u\n", c, d, a);
if (a != b) {
printf("OR error: a %d instead of %d\n", a, b);
fails++;
}
a = c & (d != 0);
b = c & 1;
printf("%u & (%u != 0) => %u\n", c, d, a);
if (a != b) {
printf("AND error: a %d instead of %d\n", a, b);
fails++;
}
printf("%d errors\n", fails);
return fails;
}