[clang] 79382eb - [clang][bytecode] Remove superfluous check from fixed-point div (#110478)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 30 03:13:25 PDT 2024
Author: Timm Baeder
Date: 2024-09-30T12:13:21+02:00
New Revision: 79382eb97adff71dbc9d4969431dd4a0967ee7ad
URL: https://github.com/llvm/llvm-project/commit/79382eb97adff71dbc9d4969431dd4a0967ee7ad
DIFF: https://github.com/llvm/llvm-project/commit/79382eb97adff71dbc9d4969431dd4a0967ee7ad.diff
LOG: [clang][bytecode] Remove superfluous check from fixed-point div (#110478)
We shouldn't do this check for fixed-point values, at least the current
interpreter doesn't do it.
Added:
Modified:
clang/lib/AST/ByteCode/Interp.h
clang/test/Frontend/fixed_point_div_const.c
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 68c04587a4919e..8a3c6810e0e11b 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -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;
}
diff --git a/clang/test/Frontend/fixed_point_div_const.c b/clang/test/Frontend/fixed_point_div_const.c
index 46935207d186a8..66c028e608db60 100644
--- a/clang/test/Frontend/fixed_point_div_const.c
+++ b/clang/test/Frontend/fixed_point_div_const.c
@@ -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
diff erent fixed point types
short _Accum sa_const = 1.0hk / 2.0hk;
// CHECK-DAG: @sa_const = {{.*}}global i16 64, align 2
More information about the cfe-commits
mailing list