Skip to content

Commit 70d6a0a

Browse files
tbaederryuxuanchen1997
authored andcommitted
[clang][Interp][NFC] Diagnose div by 0 more like the current interpreter
Summary: CCEDiag when it's a floating point operation, FFDiag otherwise. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251091
1 parent 6946ef5 commit 70d6a0a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

clang/lib/AST/Interp/Interp.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,15 @@ template <typename T>
187187
bool CheckDivRem(InterpState &S, CodePtr OpPC, const T &LHS, const T &RHS) {
188188
if (RHS.isZero()) {
189189
const auto *Op = cast<BinaryOperator>(S.Current->getExpr(OpPC));
190+
if constexpr (std::is_same_v<T, Floating>) {
191+
S.CCEDiag(Op, diag::note_expr_divide_by_zero)
192+
<< Op->getRHS()->getSourceRange();
193+
return true;
194+
}
195+
190196
S.FFDiag(Op, diag::note_expr_divide_by_zero)
191197
<< Op->getRHS()->getSourceRange();
192-
if constexpr (!std::is_same_v<T, Floating>)
193-
return false;
198+
return false;
194199
}
195200

196201
if (LHS.isSigned() && LHS.isMin() && RHS.isNegative() && RHS.isMinusOne()) {

0 commit comments

Comments
 (0)