Topic : Compiler bug in a 16 bit numeric test

Forum : 8051

Original Post
Post Information Post
April 4, 2008 - 3:51pm
Guest

Please consider this piece of code:

void testif(unsigned int a) {
   data unsigned int b = 0;

   if (10 > (a - b)) {
      _nop_(); // correct
   } else {
      _nop_(); // wrong result !!!!
   }   
}

void main() {
   testif(5);
}

Obviously 10 > (5 - 0) , but this test is compiled in a bad way, and the result is wrong.

If I initialize b with 1 everything is ok, and the compiled code became very different

void testif(unsigned int a) {
   data unsigned int b = 1;  // ***** with this value the test is working ******

   if (10 > (a - b)) {
      _nop_(); // correct
   } else {
      _nop_(); // wrong result !!!!
   }   
}

void main() {
   testif(5);
}

This is the assembly code of the not working test:

            ; FUNCTION _testif (BEGIN)
              ; Register R6R7 is assigned to parameter a
                                           ; SOURCE LINE # 1083 
0000 EE             MOV    A,R6
0001 9400           SUBB   A,#000H    ; here the carry is setted, and so the accumulator became 0xFF, probably the CLR C istruction is missing
0003 B40003         CJNE   A,#000H,?LAB283     
0006 BF0A00         CJNE   R7,#00AH,?LAB283
0009         ?LAB283:
0009 5002           JNC    ?ELSE109
                                           ; SOURCE LINE # 1084 
000B 00             NOP    
000C 22             RET    
000D         ?ELSE109:
                                           ; SOURCE LINE # 1086 
000D 00             NOP    
                                           ; SOURCE LINE # 1088 
000E 22             RET    

            ; FUNCTION _testif (END)

Please let me know what do you think.

Thank you

Replies
Post Information Post
+1
0
-1
April 7, 2008 - 11:51am
Guest

You are right. There is a bug due to the constant folding (substract with 0 should remove the two SUBB instructions, not only one in this specific case).

+1
0
-1
April 7, 2008 - 12:01pm
Guest

can you suggest a workaround ?

+1
0
-1
April 7, 2008 - 3:10pm
Raisonance Support Team

Massimo,

Can you provide your RC51 version or your Ride Build Number (BN) ?

Stéphane

+1
0
-1
April 7, 2008 - 3:25pm
Guest

Build number: BN746-51

RC51 Compiler: Version 3.03.42

+1
0
-1
April 7, 2008 - 6:25pm
Guest

Massimo,

Obviously the bug is due to the 'null value' for b that is improperly propagated. And 'a-0' is of course equivalent to a. Therefore the first workaround consists in not subtracting b from a when you are sure that b is zero.
Anyway we will send yo a patch.

+1
0
-1
April 8, 2008 - 9:17am
Guest

Ok,
please give me the time frame for the patch, I have to schedule my activities.
I'd like also to receive a complete list of the known bugs, even if are not yet fixed.
We are using your compiler with hardwares that can be dangerous for human beings, so I must be informed about every trouble with the compiler.

+1
0
-1
April 8, 2008 - 9:26am
Guest

For the last few years, there are only a few bugs reported within the 8051 compiler. You can find with each release the list of the fixed bugs. They are generally very specific (in your case, substracting a value known as 0 is not so frequent and it seems not to be present in our test suites...). Anyway, the patch you will receive does not contain any known bug...

+1
0
-1
April 8, 2008 - 9:38am
Guest

good news....
when can you send me the patch ?

+1
0
-1
April 8, 2008 - 12:21pm
Guest

When the tests will be passed... It takes several hours.

+1
0
-1
April 8, 2008 - 3:42pm
Guest

The patch is ok.
Thank you very much for your support.