Fix internal error on integer/char formatting of a null handle - #1944
Open
EylonKrause wants to merge 1 commit into
Open
Fix internal error on integer/char formatting of a null handle#1944EylonKrause wants to merge 1 commit into
EylonKrause wants to merge 1 commit into
Conversation
The integer and char format specifiers (%h %x %d %o %b %c) accept a class handle, a chandle, or the null literal: checkArgType() explicitly permits those types. But formatArg formatted them via arg.convertToInt().integer(), and convertToInt() yields an invalid (bad) ConstantValue for a null handle, so integer() does std::get<SVInt> on the wrong variant and aborts with "internal compiler error: std::get: wrong index for variant". Guard the conversion in a small helper: when convertToInt() produces no usable integer, format the null handle as its numeric value of zero (SVInt::Zero) instead of dereferencing the missing value. This mirrors the variant-aware fix in MikePopoloski#1916 for the %u/%z specifiers and matches how a null handle formats numerically. A class handle is already rejected earlier in a constant context, but the null literal and a chandle reach formatArg. Signed-off-by: Eylon Krause <eylon1909@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1944 +/- ##
=======================================
Coverage 96.03% 96.03%
=======================================
Files 247 247
Lines 56855 56860 +5
=======================================
+ Hits 54599 54605 +6
+ Misses 2256 2255 -1
... and 1 file with indirect coverage changes Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The integer and char format specifiers (
%h%x%d%o%b%c) accept a class handle, achandle, or thenullliteral —checkArgType()explicitly permits those types. In a constant context, though,formatArgformatted them viaarg.convertToInt().integer(), andconvertToInt()returns an invalid (bad)ConstantValuefor a null handle, sointeger()doesstd::get<SVInt>on the wrong variant and aborts withinternal compiler error: std::get: wrong index for variant.Repro
Also crashes with
%x/%o/%b/%h/%c, and with achandlein a constant function:Fix
Guard the conversion in a small helper: when
convertToInt()produces no usable integer, format the null handle as its numeric value of zero (SVInt::Zero) instead of dereferencing the missing value. This mirrors the variant-aware fix in #1916 for the%u/%zspecifiers and matches how a null handle formats numerically. (A class handle is already rejected earlier in a constant context, so thenullliteral and achandleare the values that actually reachformatArg.)Added a regression test in
EvalTests.cpp; the full unit test suite passes (22972 assertions in 2487 test cases).Disclosure: this contribution was authored with an AI coding assistant (Claude) and reviewed before submission.