-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][bytecode] Cast fixed-point cmp result to int if necessary #110469
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
Conversation
This is the case in C.
@llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) ChangesThis is the case in C. Full diff: https://github.com/llvm/llvm-project/pull/110469.diff 2 Files Affected:
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index c24c4b6db2a5bf..5ad5899739909f 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -1542,19 +1542,30 @@ bool Compiler<Emitter>::VisitFixedPointBinOp(const BinaryOperator *E) {
return true;
};
+ auto MaybeCastToBool = [&](bool Result) {
+ if (!Result)
+ return false;
+ PrimType T = classifyPrim(E);
+ if (DiscardResult)
+ return this->emitPop(T, E);
+ if (T != PT_Bool)
+ return this->emitCast(PT_Bool, T, E);
+ return true;
+ };
+
switch (E->getOpcode()) {
case BO_EQ:
- return this->emitEQFixedPoint(E);
+ return MaybeCastToBool(this->emitEQFixedPoint(E));
case BO_NE:
- return this->emitNEFixedPoint(E);
+ return MaybeCastToBool(this->emitNEFixedPoint(E));
case BO_LT:
- return this->emitLTFixedPoint(E);
+ return MaybeCastToBool(this->emitLTFixedPoint(E));
case BO_LE:
- return this->emitLEFixedPoint(E);
+ return MaybeCastToBool(this->emitLEFixedPoint(E));
case BO_GT:
- return this->emitGTFixedPoint(E);
+ return MaybeCastToBool(this->emitGTFixedPoint(E));
case BO_GE:
- return this->emitGEFixedPoint(E);
+ return MaybeCastToBool(this->emitGEFixedPoint(E));
case BO_Add:
return ConvertResult(this->emitAddFixedPoint(E));
case BO_Sub:
diff --git a/clang/test/Frontend/fixed_point_comparisons.c b/clang/test/Frontend/fixed_point_comparisons.c
index 59c4405e41c031..39e62bce51e2b2 100644
--- a/clang/test/Frontend/fixed_point_comparisons.c
+++ b/clang/test/Frontend/fixed_point_comparisons.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,UNPADDED
// 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,PADDED
+// RUN: %clang_cc1 -ffixed-point -triple x86_64-unknown-linux-gnu -emit-llvm %s -o - -fexperimental-new-constant-interpreter | FileCheck %s --check-prefixes=CHECK,UNPADDED
+// 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,PADDED
+
// Fixed point against other fixed point
_Bool b_eq_true = 2.5hk == 2.5uhk; // CHECK-DAG: @b_eq_true = {{.*}}global i8 1, align 1
_Bool b_eq_false = 2.5hk == 2.4uhk; // CHECK-DAG: @b_eq_false = {{.*}}global i8 0, align 1
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/30/builds/7289 Here is the relevant piece of the build log for the reference
|
This is the case in C.