GH-55613: [C++][Gandiva] Fix wrong results for negative integer constants #55607
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
kou
Rationale for this change
LLVMTypes::int_constantbuildsllvm::APInt(N, val)without the signed flag. For a negative value narrower than 64 bits, theAPInthas bits set above its width, and ani128value is not sign-extended. The effect depends on the LLVM version:if (k == 0) 10 else -5returns-5for every row.Value is not an N-bit unsigned valuein theAPIntconstructor.i128constant 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: passstd::is_signed<ctype>::valueas the signed flag ofAPIntinLLVMTypes::int_constant.The PR has two commits: the tests first, then the fix.
Are these changes tested?
Yes. Two new tests:
TestLLVMTypes.SignedIntegerConstantschecks the 8, 16, 32, 64 and 128 bit constants. Before the fix it fails on every LLVM version tested (18, 21, 23).TestIfExpr.TestNegativeConstantsevaluatesif (k == 0) 10 else -5andif (k == 0) -5 else 10forint16,int32andint64, 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 theAPIntconstructor 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:
Reviewed before submission by: