Skip to content

Commit

Permalink
Add test case for issue cc65#2395
Browse files Browse the repository at this point in the history
  • Loading branch information
colinleroy committed Feb 1, 2024
1 parent eb1741d commit 5a2d5ef
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions test/todo/bug2395.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

/* bug #927: format specifiers related to leading zeros do not work as expected */

/* expected output:
0023
0023
-0023
-023
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

unsigned char a, b;
unsigned char c = 199;
unsigned char d = 100;

/* Bitwise operators with a boolean expression fail when optimized */
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);

/* Force exit failure, otherwise the -g version, which works,
* breaks the build
*/
return 1;
}

0 comments on commit 5a2d5ef

Please sign in to comment.