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

Incorrect code generated for reading bit field that is larger than 16-bits

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: Not Prioritized Not Prioritized

      The attached file has these lines ...

      struct bit_field_tag {
         uint32_t u8  :  8;
         uint32_t u24 : 24;
      } global_bit_field;
      
      uint32_t fxn() { return global_bit_field.u24; }
      

      Build it ...

      % cl2000 -s bf_bug.c
      

      Inspect the resulting assembly to see these lines.

      ;----------------------------------------------------------------------
      ;   8 | uint32_t fxn() { return global_bit_field.u24; }
      ;----------------------------------------------------------------------
              MOVW      DP,#_global_bit_field ; [CPU_ARAU]
              CLRC      SXM                   ; [CPU_ALU]
              MOVL      ACC,@_global_bit_field ; [CPU_ALU] |8|
              SFR       ACC,8                 ; [CPU_ALU] |8|
              ANDB      AH,#255               ; [CPU_ALU] |8|
      

      The ANDB should not be present. For confirmation, build the same code with optimization ...

      % cl2000 -s -o bf_bug.c
      

      This generates ...

      ;*** 8  -----------------------    return *&global_bit_field>>8;
              MOVW      DP,#_global_bit_field ; [CPU_ARAU]
              CLRC      SXM                   ; [CPU_ALU]
              .dwpsn  file "bf_bug.c",line 8,column 18,is_stmt,isa 0
              MOVL      ACC,@_global_bit_field ; [CPU_ALU] |8|
              SFR       ACC,8                 ; [CPU_ALU] |8|
      

      Note the ANDB is not present.

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

              Created:
              Updated:
              Resolved: