Compiler generates bad code for logical or expression containing two uses of the same boolean value

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: Medium

      The compiler will miscompile a complicated boolean expression of a very particular form. Given a single boolean value y where y was initialized by (either explicitly or implictly) comparing some scalar value to zero, and you have a logical or expression or a logical and expression where one operand is y, and the other operand is a comparison between y and another boolean value, the compiler may generate bad code.

      The keys points are:
      1. x and y are boolean values (maybe "bool", but not necessarily)
      2. You have a logical or (||) or logical and (&&) expression
      3. y is used twice in the expression
      4. The expression is of the form
      a. ((x == y) || y) or
      b. ((x == y) && y)

      That is, if your code matches this pattern:

      bool x = ??
      bool y = (data != 0);
      bool z = ((x == y) || y);

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

              Created:
              Updated:
              Resolved:

                Connection: Intermediate to External PROD System
                EXTSYNC-5154 - Compiler generates bad code for log...
                SYNCHRONIZED
                • Last Sync Date: