Skip to content

Commit 68360dc

Browse files
committed
[clang][Interp] Don't abort on float div-by-zero
The result in that case can still be computed, and it's inf.
1 parent d836608 commit 68360dc

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

clang/lib/AST/Interp/Interp.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ bool CheckDivRem(InterpState &S, CodePtr OpPC, const T &LHS, const T &RHS) {
168168
const auto *Op = cast<BinaryOperator>(S.Current->getExpr(OpPC));
169169
S.FFDiag(Op, diag::note_expr_divide_by_zero)
170170
<< Op->getRHS()->getSourceRange();
171-
return false;
171+
if constexpr (!std::is_same_v<T, Floating>)
172+
return false;
172173
}
173174

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

clang/test/AST/Interp/c23.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %clang_cc1 -std=c23 -fexperimental-new-constant-interpreter -verify=expected,both %s
2+
// RUN: %clang_cc1 -std=c23 -verify=ref,both %s
3+
4+
5+
6+
const _Bool inf1 = (1.0/0.0 == __builtin_inf());
7+
constexpr _Bool inf2 = (1.0/0.0 == __builtin_inf()); // both-error {{must be initialized by a constant expression}} \
8+
// both-note {{division by zero}}
9+
constexpr _Bool inf3 = __builtin_inf() == __builtin_inf();
10+
11+

0 commit comments

Comments
 (0)