Skip to content

[C++][Gandiva] Wrong results with negative integer constants when JIT optimization is on #55613

Done

Description

@dmitry-chirkov-dremio

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

Activity

  1. changed the title [-]Wrong results with negative integer constants when JIT optimization is on[/-] [+][C++][Gandiva] Wrong results with negative integer constants when JIT optimization is on[/+] on Nov 14, 2026
  2. added 2 commits that reference this issue on Nov 14, 2026
  3. added a commit that references this issue on Nov 27, 2026
  4. added this to the 27.0.0 milestone on Nov 27, 2026
  5. kou commented on Nov 27, 2026

    @kou
    Member

    Issue resolved by pull request 55607
    #55607

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions