Repository navigation
fix(translate): diagnose out-of-range numeric literals - #127
Merged
Merged
Conversation
Integer and float literals outside the i64/f64 range threw an uncaught std::out_of_range from std::stoll/std::stod and aborted the compiler. Parse integers with StringRef::getAsInteger and floats with llvm::to_float, and emit a located parser error when the value does not fit. Float literals that overflow to infinity are rejected; literals that underflow round to zero or a subnormal, as in C.
tetsuo-cpp
force-pushed
the
fix/literal-overflow
branch
from
October 24, 2026 10:03
052cfe3 to
1c82d40
Compare
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 parser converted number tokens with
std::stollandstd::stod. Both throwstd::out_of_rangewhen the value does not fit, and nothing caught it, so the compiler aborted.Change
StringRef::getAsInteger(a leading+is stripped first, asisNumberallows it). Out-of-range values reportinteger literal out of range for i64at the token.llvm::to_float, the same routine the lexer uses to classify them. A value that overflows to infinity reportsfloat literal out of range for f64. Underflow is accepted and rounds to zero or a subnormal, as in C. Before this change underflow also crashed, becausestd::stodthrows on anyERANGE.isFloatseparately).Before
After
Tests
integer-literal-overflow-error.forth,integer-literal-underflow-error.forth,float-literal-overflow-error.forth. Each one crashed before this change.basic-literals.forthnow covers+5,INT64_MAXandINT64_MIN.float-literals.forthnow coversDBL_MAXand1e-400, which underflows to zero.Fixes #111