[clang] [clang][bytecode] Handle DiscardResult for fixed-point literals (PR #110475)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 30 02:16:08 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/110475.diff
3 Files Affected:
- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+3)
- (modified) clang/test/AST/ByteCode/fixed-point.cpp (+2)
- (modified) clang/test/Frontend/fixed_point_crash.c (+1)
``````````diff
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index c24c4b6db2a5bf..0399f1fcbc7a93 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -763,6 +763,9 @@ bool Compiler<Emitter>::VisitFixedPointLiteral(const FixedPointLiteral *E) {
assert(E->getType()->isFixedPointType());
assert(classifyPrim(E) == PT_FixedPoint);
+ if (DiscardResult)
+ return true;
+
auto Sem = Ctx.getASTContext().getFixedPointSemantics(E->getType());
APInt Value = E->getValue();
return this->emitConstFixedPoint(FixedPoint(Value, Sem), E);
diff --git a/clang/test/AST/ByteCode/fixed-point.cpp b/clang/test/AST/ByteCode/fixed-point.cpp
index 48673d8be6f601..4bf80ba7c58f02 100644
--- a/clang/test/AST/ByteCode/fixed-point.cpp
+++ b/clang/test/AST/ByteCode/fixed-point.cpp
@@ -11,6 +11,8 @@ static_assert(1.0k != 1.0k); // both-error {{failed due to requirement '1.0k !=
static_assert(1.0k != 1); // both-error {{failed due to requirement '1.0k != 1'}}
static_assert(-12.0k == -(-(-12.0k)));
+constexpr _Accum acc = (0.5r, 6.9k);
+
/// Zero-init.
constexpr _Accum A{};
static_assert(A == 0.0k);
diff --git a/clang/test/Frontend/fixed_point_crash.c b/clang/test/Frontend/fixed_point_crash.c
index 3b3911117400ca..9cfe6ba64c519d 100644
--- a/clang/test/Frontend/fixed_point_crash.c
+++ b/clang/test/Frontend/fixed_point_crash.c
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -verify -ffixed-point %s
+// RUN: %clang_cc1 -verify -ffixed-point %s -fexperimental-new-constant-interpreter
union a {
_Accum x;
``````````
</details>
https://github.com/llvm/llvm-project/pull/110475
More information about the cfe-commits
mailing list