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

Incorrect optimization of expression that mixes the types long and short

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Medium Medium
    • Code Generation Tools
    • CODEGEN-7098
    • Hide
      MSP430_18.1.0.LTS
      C2000_18.1.0.LTS
      MSP430_20.2.0.LTS
      MSP430_18.12.0.LTS
      C2000_18.12.0.LTS
      C2000_20.2.0.LTS
      Show
      MSP430_18.1.0.LTS C2000_18.1.0.LTS MSP430_20.2.0.LTS MSP430_18.12.0.LTS C2000_18.12.0.LTS C2000_20.2.0.LTS
    • Hide
      C2000_20.2.1.LTS*
      MSP430_20.2.1.LTS*
      C2000_18.12.6.LTS*
      MSP430_18.12.6.LTS*
      C2000_18.1.8.LTS*
      MSP430_18.1.8.LTS*
      Show
      C2000_20.2.1.LTS* MSP430_20.2.1.LTS* C2000_18.12.6.LTS* MSP430_18.12.6.LTS* C2000_18.1.8.LTS* MSP430_18.1.8.LTS*
    • default
    • Avoid mixing int and wider-than-int types in += and -= expressions. When accumulating into a wider-than-int variable, use wider-than-int operands.
    • Hide
      The compiler may rearrange a sequence of accumulations (using += and -=) into a single accumulation with a sum of the operands. If the accumulator variable is wider than int and the operands are int or narrower, the rearrangement can produce the wrong answer.
      Show
      The compiler may rearrange a sequence of accumulations (using += and -=) into a single accumulation with a sum of the operands. If the accumulator variable is wider than int and the operands are int or narrower, the rearrangement can produce the wrong answer.

      The attached test case contains this source line ...

          l += a;    l -= b;
      

      Variable l is long. Variables a and b are short.

      Build it ...

      cl430 -o -s try1.c
      

      The resulting assembly is incorrect ...

      ;** 6	-----------------------    l += a-b;
      	.dwpsn	file "try1.c",line 6,column 5,is_stmt,isa 0
              MOV.W     &a+0,r15              ; [] |6| 
              SUB.W     &b+0,r15              ; [] |6| 
              ADD.W     r15,&l+0              ; [] |6| 
              ADDC.W    #0,&l+2               ; [] |6| 
      

      Both a and b should be converted to long, then the expression computed in long. For some reason, that does not occur.

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

              Created:
              Updated:
              Resolved: