[clang] [clang][bytecode] Remove superfluous check from fixed-point div (PR #110478)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 30 02:41:54 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
We shouldn't do this check for fixed-point values, at least the current interpreter doesn't do it.
---
Full diff: https://github.com/llvm/llvm-project/pull/110478.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Interp.h (+10-8)
- (modified) clang/test/Frontend/fixed_point_div_const.c (+3)
``````````diff
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 different fixed point types
short _Accum sa_const = 1.0hk / 2.0hk;
// CHECK-DAG: @sa_const = {{.*}}global i16 64, align 2
``````````
</details>
https://github.com/llvm/llvm-project/pull/110478
More information about the cfe-commits
mailing list