Thanks to @acqn
This commit is contained in:
Colin Leroy-Mira 2024-02-02 13:54:58 +01:00
parent a7ac9b7ef2
commit c548bbbcf3
3 changed files with 48 additions and 10 deletions

View File

@ -1488,7 +1488,7 @@ static const OptFuncDesc FuncTable[] = {
};
static const OptFuncDesc FuncRegATable[] = {
{ "tosandax", Opt_a_tosand, REG_NONE, OP_NONE },
{ "tosandax", Opt_a_tosand, REG_NONE, OP_RHS_REMOVE_DIRECT | OP_RHS_LOAD_DIRECT },
{ "toseqax", Opt_a_toseq, REG_NONE, OP_NONE },
{ "tosgeax", Opt_a_tosuge, REG_NONE, OP_NONE },
{ "tosgtax", Opt_a_tosugt, REG_NONE, OP_NONE },
@ -1496,13 +1496,13 @@ static const OptFuncDesc FuncRegATable[] = {
{ "tosleax", Opt_a_tosule, REG_NONE, OP_NONE },
{ "tosltax", Opt_a_tosult, REG_NONE, OP_NONE },
{ "tosneax", Opt_a_tosne, REG_NONE, OP_NONE },
{ "tosorax", Opt_a_tosor, REG_NONE, OP_NONE },
{ "tosorax", Opt_a_tosor, REG_NONE, OP_RHS_REMOVE_DIRECT | OP_RHS_LOAD_DIRECT },
{ "tossubax", Opt_a_tossub, REG_NONE, OP_RHS_REMOVE_DIRECT | OP_RHS_LOAD_DIRECT },
{ "tosugeax", Opt_a_tosuge, REG_NONE, OP_NONE },
{ "tosugtax", Opt_a_tosugt, REG_NONE, OP_NONE },
{ "tosuleax", Opt_a_tosule, REG_NONE, OP_NONE },
{ "tosultax", Opt_a_tosult, REG_NONE, OP_NONE },
{ "tosxorax", Opt_a_tosxor, REG_NONE, OP_NONE },
{ "tosxorax", Opt_a_tosxor, REG_NONE, OP_RHS_REMOVE_DIRECT | OP_RHS_LOAD_DIRECT },
};
#define FUNC_COUNT(Table) (sizeof(Table) / sizeof(Table[0]))

View File

@ -40,12 +40,5 @@ int main(void) {
}
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
}

45
test/val/bug2395.c Normal file
View File

@ -0,0 +1,45 @@
/* 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++;
}
b = c | d;
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;
}