1
0
mirror of https://github.com/cc65/cc65.git synced 2024-11-15 11:05:56 +00:00
cc65/test/val/bug1562.c
2021-09-28 18:11:23 +02:00

31 lines
845 B
C

/* bug 1562: cc65 generates incorrect code for logical expression with -O */
#include <stdio.h>
#include <string.h>
int failures = 0;
char input[256];
#define DEBUGTRUE(x) printf("%s=%d\n", #x, (x)); failures += (x) ? 0 : 1
#define DEBUGFALSE(x) printf("%s=%d\n", #x, (x)); failures += (x) ? 1 : 0
int main(void) {
char* r;
strcpy(input, "\"XYZ\"");
r = input+4;
DEBUGFALSE(*r != '"'); // = false
DEBUGTRUE(*r == '"'); // = true
DEBUGFALSE(*(r+1) == '"'); // = false
// Next answer should be false because
// (false || true && false) is false, but it is true with -O.
DEBUGFALSE(*r != '"' || *r == '"' && *(r+1) == '"');
// Adding parens fixes it even with -O.
DEBUGFALSE(*r != '"' || (*r == '"' && *(r+1) == '"'));
printf("failures: %d\n", failures);
return failures;
}