Skip to content

Commit 0546a8d

Browse files
committed
Add warning on some cases of integer literal coercion
Fix misisng warnings on: int x3 = 18446744073709551615; int x4 = 0xFFFFFFFFFFFFFFFF;
1 parent bca772c commit 0546a8d

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

source/slang/slang-parser.cpp

+4-10
Original file line numberDiff line numberDiff line change
@@ -6897,7 +6897,7 @@ static IntegerLiteralValue _fixIntegerLiteral(
68976897
// If the masked value is 0 or equal to the mask, we 'assume' no information is
68986898
// lost
68996899
// This allows for example -1u, to give 0xffffffff
6900-
// It also means 0xfffffffffffffffffu will give 0xffffffff, without a warning.
6900+
// It also means 0xffffffffffffffffu will give 0xffffffff, without a warning.
69016901
if ((!(maskedValue == 0 || maskedValue == mask)) && sink && token)
69026902
{
69036903
// Output a warning that number has been altered
@@ -6954,16 +6954,10 @@ static BaseType _determineNonSuffixedIntegerLiteralType(
69546954
{
69556955
baseType = BaseType::UInt64;
69566956

6957-
if (isDecimalBase)
6957+
// Emit warning if the value is too large for signed 64-bit, regardless of base
6958+
// This fixes the inconsistency between decimal and hex literals
6959+
if (sink && token)
69586960
{
6959-
// There is an edge case here where 9223372036854775808 or INT64_MAX + 1
6960-
// brings us here, but the complete literal is -9223372036854775808 or INT64_MIN and is
6961-
// valid. Unfortunately because the lexer handles the negative(-) part of the literal
6962-
// separately it is impossible to know whether the literal has a negative sign or not.
6963-
// We emit the warning and initially process it as a uint64 anyways, and the negative
6964-
// sign will be properly parsed and the value will still be properly stored as a
6965-
// negative INT64_MIN.
6966-
69676961
// Decimal integer is too large to be represented as signed.
69686962
// Output warning that it is represented as unsigned instead.
69696963
sink->diagnose(*token, Diagnostics::integerLiteralTooLarge);

0 commit comments

Comments
 (0)