-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request cc65#2397 from colinleroy/bug-2395-test
Add test case for issue cc65#2395
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
|
||
/* 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); | ||
|
||
#ifdef __OPT__ | ||
return fails; | ||
#else | ||
/* Force exit failure on non-optimised version, which works, | ||
* otherwise it breaks the build | ||
*/ | ||
return 1; | ||
#endif | ||
} |