Skip to content

Commit 12e972c

Browse files
committed
review: let handleIntLiteral properly handle a signed positive integer
- this code path will currently not ever get evaluated but for the sake of expected behaviour of a future user we will add this functionality
1 parent b507dba commit 12e972c

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

clang/lib/Parse/ParseHLSLRootSignature.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -903,10 +903,17 @@ std::optional<int32_t> RootSignatureParser::handleIntLiteral(bool Negated) {
903903

904904
llvm::APSInt Val(32, /*IsUnsigned=*/true);
905905
// GetIntegerValue will overwrite Val from the parsed Literal and return
906-
// true if it overflows as a 32-bit unsigned int. Then check that it also
907-
// doesn't overflow as a signed 32-bit int.
908-
int64_t MaxMagnitude = -int64_t(std::numeric_limits<int32_t>::min());
909-
if (Literal.GetIntegerValue(Val) || MaxMagnitude < Val.getExtValue()) {
906+
// true if it overflows as a 32-bit unsigned int
907+
bool Overflowed = Literal.GetIntegerValue(Val);
908+
909+
// So we then need to check that it doesn't overflow as a 32-bit signed int:
910+
int64_t MaxNegativeMagnitude = -int64_t(std::numeric_limits<int32_t>::min());
911+
Overflowed |= (Negated && MaxNegativeMagnitude < Val.getExtValue());
912+
913+
int64_t MaxPositiveMagnitude = int64_t(std::numeric_limits<int32_t>::max());
914+
Overflowed |= (!Negated && MaxPositiveMagnitude < Val.getExtValue());
915+
916+
if (Overflowed) {
910917
// Report that the value has overflowed
911918
PP.getDiagnostics().Report(CurToken.TokLoc,
912919
diag::err_hlsl_number_literal_overflow)

0 commit comments

Comments
 (0)