Skip to content

Commit

Permalink
[clang][bytecode] Remove superfluous check from fixed-point div (llvm…
Browse files Browse the repository at this point in the history
…#110478)

We shouldn't do this check for fixed-point values, at least the current
interpreter doesn't do it.
  • Loading branch information
tbaederr authored Sep 30, 2024
1 parent dc6e480 commit 79382eb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
18 changes: 10 additions & 8 deletions clang/lib/AST/ByteCode/Interp.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,16 @@ bool CheckDivRem(InterpState &S, CodePtr OpPC, const T &LHS, const T &RHS) {
return false;
}

if (LHS.isSigned() && LHS.isMin() && RHS.isNegative() && RHS.isMinusOne()) {
APSInt LHSInt = LHS.toAPSInt();
SmallString<32> Trunc;
(-LHSInt.extend(LHSInt.getBitWidth() + 1)).toString(Trunc, 10);
const SourceInfo &Loc = S.Current->getSource(OpPC);
const Expr *E = S.Current->getExpr(OpPC);
S.CCEDiag(Loc, diag::note_constexpr_overflow) << Trunc << E->getType();
return false;
if constexpr (!std::is_same_v<T, FixedPoint>) {
if (LHS.isSigned() && LHS.isMin() && RHS.isNegative() && RHS.isMinusOne()) {
APSInt LHSInt = LHS.toAPSInt();
SmallString<32> Trunc;
(-LHSInt.extend(LHSInt.getBitWidth() + 1)).toString(Trunc, 10);
const SourceInfo &Loc = S.Current->getSource(OpPC);
const Expr *E = S.Current->getExpr(OpPC);
S.CCEDiag(Loc, diag::note_constexpr_overflow) << Trunc << E->getType();
return false;
}
}
return true;
}
Expand Down
3 changes: 3 additions & 0 deletions clang/test/Frontend/fixed_point_div_const.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefixes=CHECK,SIGNED
// 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

// 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
// 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

// Division between different fixed point types
short _Accum sa_const = 1.0hk / 2.0hk;
// CHECK-DAG: @sa_const = {{.*}}global i16 64, align 2
Expand Down

0 comments on commit 79382eb

Please sign in to comment.