Uploaded image for project: 'Embedded Software & Tools'
  1. Embedded Software & Tools
  2. EXT_EP-12185

Equality comparison for C++ enum class with specified type smaller than an int is correct with optimization, incorrect without optimization

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Not Prioritized Not Prioritized

      The attached C++ source file has these lines ...

      enum class A : unsigned short
      {
          A1 = 0xFFFFu
      };
      

      The test case includes a switch statement that compares a variable of the enum type for equality with the value A1. Build it ...

      % cl6x --src_interlist file.cpp
      

      Inspect file.asm to see these lines ...

                 LDHU    .D2T2   *SP(4),B4         ; [B_D64P] |8| 
                 NOP             4                 ; [A_L64P] 
                 CMPEQ   .L2     B4,-1,B0          ; [B_L64P] |8| 
         [ B0]   BNOP            $C$L1,5           ; [] |8| 
      

      The LDHU causes the upper 16-bits of B4 to be 0. Then it is compared against -1. This is wrong. Either the value in B4 should be sign extended, or the comparison should be against 0xffff.

      When built with any level of optimization, these problems do not occur.

            syncuser TI User
            syncuser TI User
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: