Fixed optimization for char-size bitwise XOR/OR/AND when the rhs operand is complicated.

This commit is contained in:
acqn
2024-02-02 19:00:33 +08:00
parent a7ac9b7ef2
commit 96d55e3703
2 changed files with 3 additions and 3 deletions

View File

@@ -1,51 +0,0 @@
/* 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
}