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

Compiler may reassociate mixed-width addition and lose implicit wider-than-int conversion

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Medium Medium
    • Code Generation Tools
    • CODEGEN-6362
    • Hide
      ARM_18.1.0.LTS
      ARM_18.12.0.LTS
      ARM_19.6.0.STS
      Show
      ARM_18.1.0.LTS ARM_18.12.0.LTS ARM_19.6.0.STS
    • Hide
      ARM_18.12.3.LTS
      ARM_18.1.7.LTS
      ARM_20.2.0.beta
      Show
      ARM_18.12.3.LTS ARM_18.1.7.LTS ARM_20.2.0.beta
    • default
    • Hide
      The given case does "carry += *x++; carry += *y++;". One workaround is to rewrite that as "carry = (carry + *x++) + *y++;". The parens force the first addition to be 64-bit, which in turn forces the second to be 64-bit, while preventing the reassociation that allowed the erroneous 32-bit addition.
      Show
      The given case does "carry += *x++; carry += *y++;". One workaround is to rewrite that as "carry = (carry + *x++) + *y++;". The parens force the first addition to be 64-bit, which in turn forces the second to be 64-bit, while preventing the reassociation that allowed the erroneous 32-bit addition.
    • Hide
      The compiler is allowed to combine and reassociate additions and other associative operations. However, some combinations of mixed-width operations, where the desired type is wider than int, may be reassociated incorrectly in a way that allows the operation in a narrow type than intended.

      In this case, it's expressed as "c += X; c += Y", where X and Y are int32_t and c is int64_t. The compiler is turning that into "c += X + Y", which adds X and Y as int32_t and thus doesn't keep the 33rd bit.
      Show
      The compiler is allowed to combine and reassociate additions and other associative operations. However, some combinations of mixed-width operations, where the desired type is wider than int, may be reassociated incorrectly in a way that allows the operation in a narrow type than intended. In this case, it's expressed as "c += X; c += Y", where X and Y are int32_t and c is int64_t. The compiler is turning that into "c += X + Y", which adds X and Y as int32_t and thus doesn't keep the 33rd bit.

      Compiler may reassociate mixed-width addition and lose implicit wider-than-int conversion

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

              Created:
              Updated:
              Resolved: