From 3c85102756ca0737e2282794451889cac502389f Mon Sep 17 00:00:00 2001 From: Timm Baeder Date: Mon, 30 Sep 2024 12:42:18 +0200 Subject: [PATCH] [clang][bytecode] Handle DiscardResult for fixed-point literals (#110475) --- 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 5ad5899739909f..680be736aa6471 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -763,6 +763,9 @@ bool Compiler::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;