Author: Timm Bäder Date: 2022-09-13T10:41:34+02:00 New Revision: 53d8687a13e76b5a387e8df59ae231ab53ab9279
URL: https://github.com/llvm/llvm-project/commit/53d8687a13e76b5a387e8df59ae231ab53ab9279 DIFF: https://github.com/llvm/llvm-project/commit/53d8687a13e76b5a387e8df59ae231ab53ab9279.diff LOG: [clang][Interp][NFC] Use constexpr if in OffsetHelper Add is a template parameter, so we can use constexpr if here. Added: Modified: clang/lib/AST/Interp/Interp.h Removed: ################################################################################ diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h index 0a5c8dc847c3..5c96cd8d2340 100644 --- a/clang/lib/AST/Interp/Interp.h +++ b/clang/lib/AST/Interp/Interp.h @@ -788,18 +788,24 @@ template <class T, bool Add> 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<int64_t>(Index); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits