Author: Timm Bäder Date: 2023-01-19T12:18:34+01:00 New Revision: 9ee0d7494eb35f5addefcb730cdf5c002ddeacd2
URL: https://github.com/llvm/llvm-project/commit/9ee0d7494eb35f5addefcb730cdf5c002ddeacd2 DIFF: https://github.com/llvm/llvm-project/commit/9ee0d7494eb35f5addefcb730cdf5c002ddeacd2.diff LOG: [clang][Interp][NFC] Move CheckDivRem() implementation into Interp.cpp Just like we do with all the other Check* functions. Added: Modified: clang/lib/AST/Interp/Interp.cpp clang/lib/AST/Interp/Interp.h Removed: ################################################################################ diff --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp index 76ade4401e08..d7195148d015 100644 --- a/clang/lib/AST/Interp/Interp.cpp +++ b/clang/lib/AST/Interp/Interp.cpp @@ -422,6 +422,26 @@ bool CheckShift(InterpState &S, CodePtr OpPC, const RT &RHS, unsigned Bits) { return true; } +template <typename T> +bool CheckDivRem(InterpState &S, CodePtr OpPC, const T &LHS, const T &RHS) { + if (RHS.isZero()) { + const SourceInfo &Loc = S.Current->getSource(OpPC); + S.FFDiag(Loc, diag::note_expr_divide_by_zero); + return false; + } + + if (LHS.isSigned() && LHS.isMin() && RHS.isNegative() && RHS.isMinusOne()) { + APSInt LHSInt = LHS.toAPSInt(); + SmallString<32> Trunc; + (-LHSInt.extend(LHSInt.getBitWidth() + 1)).toString(Trunc, 10); + const SourceInfo &Loc = S.Current->getSource(OpPC); + const Expr *E = S.Current->getExpr(OpPC); + S.CCEDiag(Loc, diag::note_constexpr_overflow) << Trunc << E->getType(); + return false; + } + return true; +} + static void DiagnoseUninitializedSubobject(InterpState &S, const SourceInfo &SI, QualType SubObjType, SourceLocation SubObjLoc) { diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h index 903c68f4511c..3fa977d4a02e 100644 --- a/clang/lib/AST/Interp/Interp.h +++ b/clang/lib/AST/Interp/Interp.h @@ -100,24 +100,7 @@ bool CheckShift(InterpState &S, CodePtr OpPC, const RT &RHS, unsigned Bits); /// Checks if Div/Rem operation on LHS and RHS is valid. template <typename T> -bool CheckDivRem(InterpState &S, CodePtr OpPC, const T &LHS, const T &RHS) { - if (RHS.isZero()) { - const SourceInfo &Loc = S.Current->getSource(OpPC); - S.FFDiag(Loc, diag::note_expr_divide_by_zero); - return false; - } - - if (LHS.isSigned() && LHS.isMin() && RHS.isNegative() && RHS.isMinusOne()) { - APSInt LHSInt = LHS.toAPSInt(); - SmallString<32> Trunc; - (-LHSInt.extend(LHSInt.getBitWidth() + 1)).toString(Trunc, 10); - const SourceInfo &Loc = S.Current->getSource(OpPC); - const Expr *E = S.Current->getExpr(OpPC); - S.CCEDiag(Loc, diag::note_constexpr_overflow) << Trunc << E->getType(); - return false; - } - return true; -} +bool CheckDivRem(InterpState &S, CodePtr OpPC, const T &LHS, const T &RHS); /// Interpreter entry point. bool Interpret(InterpState &S, APValue &Result); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits