Compiler incorrectly reorders struct assign for small, volatile structs with bit-fields

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: High
    • Code Generation Tools
    • CODEGEN-2053
    • Hide
      ARM_15.12.0.LTS
      C2000_16.9.0.LTS
      C6000_8.2.0
      C2000_6.4.0B1
      ARP32_1.0.0
      C2000_15.12.3.LTS
      MSP430_15.12.0.LTS
      ARP32_1.1.0*
      PRU_2.1.0
      ARM_16.9.0.LTS
      C2000_16.12.0.STS
      C6000_8.1.0B1
      C6000_7.4.0B1
      MSP430_16.12.0.STS
      ARM_16.12.0.STS
      MSP430_16.9.0.LTS
      Show
      ARM_15.12.0.LTS C2000_16.9.0.LTS C6000_8.2.0 C2000_6.4.0B1 ARP32_1.0.0 C2000_15.12.3.LTS MSP430_15.12.0.LTS ARP32_1.1.0* PRU_2.1.0 ARM_16.9.0.LTS C2000_16.12.0.STS C6000_8.1.0B1 C6000_7.4.0B1 MSP430_16.12.0.STS ARM_16.12.0.STS MSP430_16.9.0.LTS
    • Hide
      ARM_15.12.5.LTS
      C2000_17.3.0.STS
      C2000_16.9.2.LTS
      C6000_8.1.4
      MSP430_15.12.5.LTS
      C6000_7.4.21
      ARP32_1.0.9
      C2000_15.12.5.LTS
      ARM_17.3.0.STS
      MSP430_17.3.0.STS
      ARM_16.9.2.LTS
      PRU_2.1.5
      MSP430_16.9.2.LTS
      Show
      ARM_15.12.5.LTS C2000_17.3.0.STS C2000_16.9.2.LTS C6000_8.1.4 MSP430_15.12.5.LTS C6000_7.4.21 ARP32_1.0.9 C2000_15.12.5.LTS ARM_17.3.0.STS MSP430_17.3.0.STS ARM_16.9.2.LTS PRU_2.1.5 MSP430_16.9.2.LTS
    • Use optimization level 0 or off (option --opt_level)
    • Hide
      For a very specific optimization, the optimizer may drop a volatile qualifier from a struct assignment. In some cases, the compiler may later perform an incorrect optimization, most commonly incorrectly reordering volatile assignments.

      This bug can only happen in a function compiled with optimization level 1 or higher which contains both of the following: 1) A struct assign where the destination is volatile, and the source is a known constant, and the struct contains a bit-field, and the struct is of size "int" or smaller. 2) Any bit-field access (read or write) other than as part of a struct assign or initialization expression. That is, the name of the bit-field is present in the access expression. Note that the optimizer can create this situation by inlining functions, so 1 and 2 might be in different functions in the source code.

      Consider a tree x = y where x and y are of type struct S. If the value of y is known at compile time (e.g. a const value), the optimizer will try to turn the struct constant into an integer constant (possibly combining bit-fields) and rewrite the tree to look like this: "(unsigned *)x = 32;" However, if y is volatile, that should be "*(volatile unsigned *)x = 32;" Because the access is not volatile, instruction scheduling could cause this instruction to drift past nearby volatile accesses.
      Show
      For a very specific optimization, the optimizer may drop a volatile qualifier from a struct assignment. In some cases, the compiler may later perform an incorrect optimization, most commonly incorrectly reordering volatile assignments. This bug can only happen in a function compiled with optimization level 1 or higher which contains both of the following: 1) A struct assign where the destination is volatile, and the source is a known constant, and the struct contains a bit-field, and the struct is of size "int" or smaller. 2) Any bit-field access (read or write) other than as part of a struct assign or initialization expression. That is, the name of the bit-field is present in the access expression. Note that the optimizer can create this situation by inlining functions, so 1 and 2 might be in different functions in the source code. Consider a tree x = y where x and y are of type struct S. If the value of y is known at compile time (e.g. a const value), the optimizer will try to turn the struct constant into an integer constant (possibly combining bit-fields) and rewrite the tree to look like this: "(unsigned *)x = 32;" However, if y is volatile, that should be "*(volatile unsigned *)x = 32;" Because the access is not volatile, instruction scheduling could cause this instruction to drift past nearby volatile accesses.

      Compiler incorrectly reorders struct assign for small, volatile structs with bit-fields

            Assignee:
            TI User
            Reporter:
            TI User
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:

                Connection: Intermediate to External PROD System
                EXTSYNC-759 - Compiler incorrectly reorders struc...
                SYNCHRONIZED
                • Last Sync Date: