← Back to Pull requests

GH-55613: [C++][Gandiva] Fix wrong results for negative integer constants #55607

Closed
unknown closed this pull request without merging on Nov 27, 2026 14:56 UTC
View on GitHub
unknown unknown commented on Nov 14, 2026 08:40 UTC
Author

Rationale for this change

LLVMTypes::int_constant builds llvm::APInt(N, val) without the signed flag. For a negative value narrower than 64 bits, the APInt has bits set above its width, and an i128 value is not sign-extended. The effect depends on the LLVM version:

  • LLVM 21, optimization on: Gandiva returns wrong results. For example if (k == 0) 10 else -5 returns -5 for every row.

  • LLVM 23: assertion Value is not an N-bit unsigned value in the APInt constructor.

  • LLVM 18: the constructor always clears the unused bits, so 16, 32 and 64 bit constants are correct. An i128 constant is wrong on every version.
  • The same fix exists in the Dremio fork (dremio/arrow 3950ea6e41).

    What changes are included in this PR?

    The fix is a one-line change in llvm_types.h: pass std::is_signed<ctype>::value as the signed flag of APInt in LLVMTypes::int_constant.

    The PR has two commits: the tests first, then the fix.

    Are these changes tested?

    Yes. Two new tests:

  • TestLLVMTypes.SignedIntegerConstants checks the 8, 16, 32, 64 and 128 bit constants. Before the fix it fails on every LLVM version tested (18, 21, 23).

  • TestIfExpr.TestNegativeConstants evaluates if (k == 0) 10 else -5 and if (k == 0) -5 else 10 for int16, int32 and int64, with optimization off and on. Before the fix it returns wrong results on LLVM 21 and aborts on LLVM 23. It passes on LLVM 18, where the APInt constructor already clears the unused bits.
  • Both pass with the fix. The CI run on the tests-only commit shows the results per platform.

    Are there any user-facing changes?

    No.

    This PR contains a "Critical Fix". It fixes a bug that produced incorrect data on recent LLVM versions.

    Was AI used for this PR?

    AI tools helped investigate the bug and write the tests and description.

    PR code and description written by:

  • Human

  • AI
  • Reviewed before submission by:

  • Human

  • AI

  • Not reviewed
  • GitHub Issue: #55613
  • Diff: 249 lines (+186 / -63) across 3 files Reviewer: kou Review duration: 19095m
    All Vouch review confidence checks passed
    Residual risk 0.15 = Change Risk (0.39) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.39 · 249 lines diff across 3 files
    0.39
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.330
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #55607"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 39.0% (MEDIUM) · Higher = larger blast radius
    39.0%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 15.4% · Safe to merge
    15.4%
    Repository