[clang][Interp][NFC] Move CheckDivRem() implementation into Interp.cpp
authorTimm Bäder <tbaeder@redhat.com>
Sun, 30 Oct 2022 09:21:58 +0000 (10:21 +0100)
committerTimm Bäder <tbaeder@redhat.com>
Thu, 19 Jan 2023 11:18:34 +0000 (12:18 +0100)
Just like we do with all the other Check* functions.

clang/lib/AST/Interp/Interp.cpp
clang/lib/AST/Interp/Interp.h

index 76ade44..d719514 100644 (file)
@@ -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) {
index 903c68f..3fa977d 100644 (file)
@@ -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);