From: Timm Bäder Date: Sun, 11 Sep 2022 12:39:52 +0000 (+0200) Subject: [clang][Interp][NFC] Use constexpr if in OffsetHelper X-Git-Tag: upstream/17.0.6~33690 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=53d8687a13e76b5a387e8df59ae231ab53ab9279;p=platform%2Fupstream%2Fllvm.git [clang][Interp][NFC] Use constexpr if in OffsetHelper Add is a template parameter, so we can use constexpr if here. --- diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h index 0a5c8dc..5c96cd8 100644 --- a/clang/lib/AST/Interp/Interp.h +++ b/clang/lib/AST/Interp/Interp.h @@ -788,18 +788,24 @@ template bool OffsetHelper(InterpState &S, CodePtr OpPC) { return false; }; - // If the new offset would be negative, bail out. - if (Add && Offset.isNegative() && (Offset.isMin() || -Offset > Index)) - return InvalidOffset(); - if (!Add && Offset.isPositive() && Index < Offset) - return InvalidOffset(); - - // If the new offset would be out of bounds, bail out. unsigned MaxOffset = MaxIndex - Ptr.getIndex(); - if (Add && Offset.isPositive() && Offset > MaxOffset) - return InvalidOffset(); - if (!Add && Offset.isNegative() && (Offset.isMin() || -Offset > MaxOffset)) - return InvalidOffset(); + if constexpr (Add) { + // If the new offset would be negative, bail out. + if (Offset.isNegative() && (Offset.isMin() || -Offset > Index)) + return InvalidOffset(); + + // If the new offset would be out of bounds, bail out. + if (Offset.isPositive() && Offset > MaxOffset) + return InvalidOffset(); + } else { + // If the new offset would be negative, bail out. + if (Offset.isPositive() && Index < Offset) + return InvalidOffset(); + + // If the new offset would be out of bounds, bail out. + if (Offset.isNegative() && (Offset.isMin() || -Offset > MaxOffset)) + return InvalidOffset(); + } // Offset is valid - compute it on unsigned. int64_t WideIndex = static_cast(Index);