Compiler incorrectly identifies test as "always true" even when it shouldn't and compiles incorrect code. See sample
code below. Note that the variables a and b are unsigned chars, which appears to be the source of the problem, while c and d are signed chars and are treated correctly.
If you look at the generated code, you'll see that there is no test generated for (a != ~b) but there is for (c != d).
Also (ANOTHER CW10.6 BUG), if I try to single step (F6) through the code, the debugger fails (hangs) at the (a != ~b) line
unless I put it into "Instruction Stepping Mode".
At the end of running, error should be 0, but it's 1.
Obviously, this code snippet is uninteresting...the original in my software involved reading values from FRAM to test whether they really were complements of each other.
I've reported this bug as a "service request" to Freescale.
CodeWarrior for MCU
Version: 10.6
Build Id:140329
========== SAMPLE CODE ==========
int error;
char m[2] = {0, ~0};
unsigned char fn(unsigned char k) {
return m[k];
}
void compilerError(void) {
// variables are declared volatile so the debugger shows them.
volatile unsigned char a, b;
volatile signed char c, d;
// m is initialized here, because I've turned off auto initialization
m[0] = 0;
m[1] = ~0;
error = 0;
a = fn(0);
b = fn(1);
if (a != ~b) // incorrectly marked "Condition always TRUE"
error |= 1;
c = fn(0);
d = fn(1);
if (c != ~d)
error |= 2;
} // at this point, error should be 0 but is 1