Re: [arm-gnu] bug or me doing something wrong?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [arm-gnu] bug or me doing something wrong?



Gene Smith wrote:
I have a function that accepts a uint16_t parameter. And I have a global variable of type int16_t. They are both set to zero. But inside the function I compare them, if (a==b), and they compare not equal. In the assembly language the compare is actually "cmp r0, r2" where r0 is 0xc000000 and r2 0x0 so they compare not equal.

Note: r2 is the global var and gets setup with ldrh r2, [r3, #4] and it looks correct. while r0 is the function parameter and gets set from r6 at beginning of function and r6 contain 0xc000000. (Don't immediately see where r6 is set.)

Also, should I see a warning about comparing signed to unsigned with -Wall -Wextra --pedantic ?

This is with opt level -0s.

-gene

--- bad	2010-02-12 13:51:12.000000000 -0500
+++ good	2010-02-12 13:57:40.000000000 -0500
@@ -26,10 +26,11 @@
  8000128:       0c40            lsrs    r0, r0, #17
         }

-        if (rcvd_seq == exp_seq)
+        if ((uint16_t)rcvd_seq == exp_seq)
800012a: 4b1b ldr r3, [pc, #108] (8000198 <program_segment+0x84>)
  800012c:       889a            ldrh    r2, [r3, #4]
- 800012e:       4290            cmp     r0, r2
- 8000130:       d127            bne.n   8000182 <program_segment+0x6e>
+ 800012e:       b283            uxth    r3, r0
+ 8000130:       4293            cmp     r3, r2
+ 8000132:       d127            bne.n   8000184 <program_segment+0x70>
         {

If I don't cast rcvd_seq (the function param) it fails to see rcvd_seq and exp_seq as equal when they are both zero. Also, no warning that this might be a problem with -Wall -Wextra and -pedantic.