This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ARM compiler bug?



Hi,

 

Using Code composer 3.3 and 4.0 (compilers TMS470 4.6.4 and 4.6.5)

I have been trying to track down an issue with that appears to be a compiler issue.  I was wondering if any one can comment.

I have the following code (the 75: and 76 are line numbers for line reference in the assembly):

unsigned long a, b;

75: a = 0x956b3db8;
76: b = 0x7fffe695;

if (((int) (a - b)) > 0)
{
   status = 1;
}
else
{
   status = 2;
}

My understanding is that (a - b) should happen first, the result should be typecast to an int, and then that result compared to 0.

With compiler optimizations (no optimization), o1, o2, and o3 I get the following output (similar for each optimization):

  LDR       V9, $C$CON2           ; |75|
  STR       V9, [SP, #48]         ; |75|
  LDR       V9, $C$CON3           ; |76|
  STR       V9, [SP, #52]         ; |76|
  LDR       V9, [SP, #52]         ; |78|
  LDR       A1, [SP, #48]         ; |78|
  CMP       V9, A1                ; |78|
  BGE       ||$C$L1||             ; |78|

If I use optimization level 0 (o0) I get this:

     LDR       V9, $C$CON2  ; |75|
     STR       V9, [SP, #32]     ; |75|
     LDR       V9, $C$CON3  ; |76|
     STR       V9, [SP, #36]     ; |76|
     LDR       V9, [SP, #36]    ; |78|
     LDR       A1, [SP, #32]    ; |78|
    CMP       V9, A1                ; |78|
    BLT       ||$C$L1||             ; |78|

The problem is this: the first case the first code works correctly most of the time.  However, when a is a very large number (high bit set), the type cast is apparently happening first, so it becomes a very small number, and the equality doesn't work the way the 'C' code says it should.

Even with the difference for the o0 optimization, I will still get the wrong answer if a and b are equal.  I would expect the branch instruction to be BLE. 

Can someone tell me what I am missing, or is this an issue with the compiler?

 

Thanks,

Mike