[clang] 68360dc - [clang][Interp] Don't abort on float div-by-zero
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 14 08:25:44 PDT 2024
Author: Timm Bäder
Date: 2024-03-14T16:25:23+01:00
New Revision: 68360dc85507350c9d38bcc6916debe29fd58fee
URL: https://github.com/llvm/llvm-project/commit/68360dc85507350c9d38bcc6916debe29fd58fee
DIFF: https://github.com/llvm/llvm-project/commit/68360dc85507350c9d38bcc6916debe29fd58fee.diff
LOG: [clang][Interp] Don't abort on float div-by-zero
The result in that case can still be computed, and it's inf.
Added:
clang/test/AST/Interp/c23.c
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 336cf2a1103395..08e272cbc005bd 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -168,7 +168,8 @@ bool CheckDivRem(InterpState &S, CodePtr OpPC, const T &LHS, const T &RHS) {
const auto *Op = cast<BinaryOperator>(S.Current->getExpr(OpPC));
S.FFDiag(Op, diag::note_expr_divide_by_zero)
<< Op->getRHS()->getSourceRange();
- return false;
+ if constexpr (!std::is_same_v<T, Floating>)
+ return false;
}
if (LHS.isSigned() && LHS.isMin() && RHS.isNegative() && RHS.isMinusOne()) {
diff --git a/clang/test/AST/Interp/c23.c b/clang/test/AST/Interp/c23.c
new file mode 100644
index 00000000000000..cf1bf4d4e7d905
--- /dev/null
+++ b/clang/test/AST/Interp/c23.c
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -std=c23 -fexperimental-new-constant-interpreter -verify=expected,both %s
+// RUN: %clang_cc1 -std=c23 -verify=ref,both %s
+
+
+
+const _Bool inf1 = (1.0/0.0 == __builtin_inf());
+constexpr _Bool inf2 = (1.0/0.0 == __builtin_inf()); // both-error {{must be initialized by a constant expression}} \
+ // both-note {{division by zero}}
+constexpr _Bool inf3 = __builtin_inf() == __builtin_inf();
+
+
More information about the cfe-commits
mailing list