Skip to content

Commit 79382eb

Browse files
authored
[clang][bytecode] Remove superfluous check from fixed-point div (llvm#110478)
We shouldn't do this check for fixed-point values, at least the current interpreter doesn't do it.
1 parent dc6e480 commit 79382eb

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

clang/lib/AST/ByteCode/Interp.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,16 @@ bool CheckDivRem(InterpState &S, CodePtr OpPC, const T &LHS, const T &RHS) {
235235
return false;
236236
}
237237

238-
if (LHS.isSigned() && LHS.isMin() && RHS.isNegative() && RHS.isMinusOne()) {
239-
APSInt LHSInt = LHS.toAPSInt();
240-
SmallString<32> Trunc;
241-
(-LHSInt.extend(LHSInt.getBitWidth() + 1)).toString(Trunc, 10);
242-
const SourceInfo &Loc = S.Current->getSource(OpPC);
243-
const Expr *E = S.Current->getExpr(OpPC);
244-
S.CCEDiag(Loc, diag::note_constexpr_overflow) << Trunc << E->getType();
245-
return false;
238+
if constexpr (!std::is_same_v<T, FixedPoint>) {
239+
if (LHS.isSigned() && LHS.isMin() && RHS.isNegative() && RHS.isMinusOne()) {
240+
APSInt LHSInt = LHS.toAPSInt();
241+
SmallString<32> Trunc;
242+
(-LHSInt.extend(LHSInt.getBitWidth() + 1)).toString(Trunc, 10);
243+
const SourceInfo &Loc = S.Current->getSource(OpPC);
244+
const Expr *E = S.Current->getExpr(OpPC);
245+
S.CCEDiag(Loc, diag::note_constexpr_overflow) << Trunc << E->getType();
246+
return false;
247+
}
246248
}
247249
return true;
248250
}

clang/test/Frontend/fixed_point_div_const.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,SIGNED
22
// RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu -fpadding-on-unsigned-fixed-point -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,UNSIGNED
33

4+
// RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - -fexperimental-new-constant-interpreter | FileCheck %s --check-prefixes=CHECK,SIGNED
5+
// RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu -fpadding-on-unsigned-fixed-point -emit-llvm %s -o - -fexperimental-new-constant-interpreter | FileCheck %s --check-prefixes=CHECK,UNSIGNED
6+
47
// Division between different fixed point types
58
short _Accum sa_const = 1.0hk / 2.0hk;
69
// CHECK-DAG: @sa_const = {{.*}}global i16 64, align 2

0 commit comments

Comments
 (0)