JuliaHubOSS / llvm-cbe

resurrected LLVM "C Backend", with improvements
Other
838 stars 144 forks source link

Generating an invert operation for boolean xor is invalid in most contexts due to integer promotion #192

Closed bcoppens closed 8 months ago

bcoppens commented 8 months ago

The problem with generating ~(boolean_var) for a 'not' pattern match is that, in the context of an if-statement, this results in if (~(boolean_var)). However, ~ promotes it to an integer. In case boolean_var is true, this operation thus results in a value of 111111[...]110, which evaluates to true, not false.

This isn't noticeable when the end result is immediately returned from a function as an i1 itself; but in cases where the end result is used in an if-statement it is incorrect.

By removing this pattern match, xor is just used for the code generation, which does work in this case.