Skip to content

Enum Display OR Decomposition Missing Parens #8239

@utkonos

Description

@utkonos

Version and Platform (required):

  • Binary Ninja Version: 5.4.9755-dev Ultimate, fc27395f
  • OS: macos
  • OS Version: 26.5.1
  • CPU Architecture: arm64

Bug Description:
Under certain circumstances, based on surrounding tokens, using an enum that decomposes to more than one member OR'd together results in a code representation that is wrong.

Example

Original Source

            if ((flags & (DEL_DIR | DEL_RECURSE)) == (DEL_DIR | DEL_RECURSE))
            {
              myDelete(buf,flags);
            }

Binary Ninja HLIL

00405b98                        else if ((flags.b & DEL_DIR | DEL_RECURSE) == DEL_DIR | DEL_RECURSE)
00405ba8                            myDelete(buf: buf, flags: flags)

According to precedence, the HLIL parses as the following which is logically different from the original code.

(((flags.b & DEL_DIR) | DEL_RECURSE) == DEL_DIR) | DEL_RECURSE

Steps To Reproduce:

  1. Open this database: just brook strikes fluently
  2. Look at HLIL here: 0x405b98

Expected Behavior:
Add parens as needed to make sure the result doesn't have a subtle precedence problem.

Screenshots:
Image

Binary:
Database: just brook strikes fluently

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions