dmitry-chirkov-dremio opened a new issue, #55613: URL: https://github.com/apache/arrow/issues/55613
### Describe the bug, including details regarding any error messages, version, and platform. To reproduce: 1. Create an int32 field `k` with rows 0, 1, 2. 2. Build a projector with `if (k == 0) 10 else -5`, int32 literals. 3. Use the default configuration (optimization on). 4. Evaluate. The result is `[-5, -5, -5]`. Expected `[10, -5, -5]`. With optimization off the result is correct. It is the same for int16 and for `if (k == 0) -5 else 10`. int64, `-1` and non-negative literals are fine. Seen on macOS ARM64 with LLVM 21.1.7, main at `ab5b42237d`. The symptom depends on the LLVM version: - LLVM 21.1.7: wrong results, as above. - LLVM 23.1.4: assertion `Value is not an N-bit unsigned value` in the `APInt` constructor, called from `int_constant`. - LLVM 18 (CI, Linux and macOS Intel): the `IF` case returns correct results, for 16, 32 and 64 bits. The `i128` constant is wrong on every version tested: `i128_constant(-1)` is not all ones, and `getSExtValue()` on it asserts. `LLVMTypes::int_constant` builds `llvm::APInt(N, val)` without the signed flag. In LLVM 21.1.7 the constructor clears the bits above the width only when the signed flag is set, so a negative value narrower than 64 bits is stored with bits set above its width. LLVM 18.1.8 always clears them. For `i128` the value is not sign-extended in either version unless the flag is set. GH-45999 hit an assertion on the same line (`i32_constant(-1)`, LLVM 20.1.1). That fix avoided the call and left `int_constant` unchanged. Passing `std::is_signed<ctype>::value` as the signed flag fixes all the cases above. Original issue was discovered during pre-AI era. ### Component(s) C++, Gandiva -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
