[clang] [clang][bytecode] Handle DiscardResult for fixed-point literals (PR #110475)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 30 02:15:29 PDT 2024


https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/110475

None

>From b69e9bb4bca8710fae493086e4c4250a5ab1f249 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Mon, 30 Sep 2024 11:14:05 +0200
Subject: [PATCH] [clang][bytecode] Handle DiscardResult for fixed-point
 literals

---
 clang/lib/AST/ByteCode/Compiler.cpp     | 3 +++
 clang/test/AST/ByteCode/fixed-point.cpp | 2 ++
 clang/test/Frontend/fixed_point_crash.c | 1 +
 3 files changed, 6 insertions(+)

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;



More information about the cfe-commits mailing list