Skip to content

Commit 40db261

Browse files
authored
[clang][bytecode] Fix #55390 here as well (#106395)
Ignore the multiplication overflow but report the 0 denominator.
1 parent be7014e commit 40db261

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

clang/lib/AST/ByteCode/Interp.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,12 +517,19 @@ inline bool Divc(InterpState &S, CodePtr OpPC) {
517517

518518
// Den = real(RHS)² + imag(RHS)²
519519
T A, B;
520-
if (T::mul(RHSR, RHSR, Bits, &A) || T::mul(RHSI, RHSI, Bits, &B))
521-
return false;
520+
if (T::mul(RHSR, RHSR, Bits, &A) || T::mul(RHSI, RHSI, Bits, &B)) {
521+
// Ignore overflow here, because that's what the current interpeter does.
522+
}
522523
T Den;
523524
if (T::add(A, B, Bits, &Den))
524525
return false;
525526

527+
if (Compare(Den, Zero) == ComparisonCategoryResult::Equal) {
528+
const SourceInfo &E = S.Current->getSource(OpPC);
529+
S.FFDiag(E, diag::note_expr_divide_by_zero);
530+
return false;
531+
}
532+
526533
// real(Result) = ((real(LHS) * real(RHS)) + (imag(LHS) * imag(RHS))) / Den
527534
T &ResultR = Result.atIndex(0).deref<T>();
528535
T &ResultI = Result.atIndex(1).deref<T>();

clang/test/AST/ByteCode/complex.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ constexpr _Complex float getComplexFloat() {
181181
static_assert(__real(getComplexFloat()) == 1, "");
182182
static_assert(__imag(getComplexFloat()) == 2, "");
183183

184+
constexpr auto GH55390 = 1 / 65536j; // both-note {{division by zero}} \
185+
// both-error {{constexpr variable 'GH55390' must be initialized by a constant expression}}
186+
184187
namespace CastToBool {
185188
constexpr _Complex int F = {0, 1};
186189
static_assert(F, "");

0 commit comments

Comments
 (0)