Skip to content

[clang][bytecode] Remove superfluous check from fixed-point div #110478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading