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

via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 30 03:42:23 PDT 2024


Author: Timm Baeder
Date: 2024-09-30T12:42:18+02:00
New Revision: 3c85102756ca0737e2282794451889cac502389f

URL: https://github.com/llvm/llvm-project/commit/3c85102756ca0737e2282794451889cac502389f
DIFF: https://github.com/llvm/llvm-project/commit/3c85102756ca0737e2282794451889cac502389f.diff

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

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Compiler.cpp
    clang/test/AST/ByteCode/fixed-point.cpp
    clang/test/Frontend/fixed_point_crash.c

Removed: 
    


################################################################################
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<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