[clang] [clang] Add zero-initialization for fixed point types (PR #80781)

via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 6 15:42:34 PST 2024


https://github.com/PiJoules updated https://github.com/llvm/llvm-project/pull/80781

>From 3b267b1aeb49aa5ab54920da5f6a1fa7492ae88c Mon Sep 17 00:00:00 2001
From: Leonard Chan <leonardchan at google.com>
Date: Mon, 5 Feb 2024 17:58:08 -0800
Subject: [PATCH] [clang] Add zero-initialization for fixed point types

---
 clang/lib/AST/ExprConstant.cpp           | 4 ++++
 clang/test/AST/fixed-point-zero-init.cpp | 5 +++++
 2 files changed, 9 insertions(+)
 create mode 100644 clang/test/AST/fixed-point-zero-init.cpp

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 63453890d98798..089bc2094567f7 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11427,6 +11427,10 @@ class FixedPointExprEvaluator
     return true;
   }
 
+  bool ZeroInitialization(const Expr *E) {
+    return Success(0, E);
+  }
+
   //===--------------------------------------------------------------------===//
   //                            Visitor Methods
   //===--------------------------------------------------------------------===//
diff --git a/clang/test/AST/fixed-point-zero-init.cpp b/clang/test/AST/fixed-point-zero-init.cpp
new file mode 100644
index 00000000000000..abe8aa8c396a85
--- /dev/null
+++ b/clang/test/AST/fixed-point-zero-init.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -ffixed-point %s -verify
+// expected-no-diagnostics
+
+constexpr _Accum a[2] = {};
+static_assert(a[0] == 0 && a[0] != 1);



More information about the cfe-commits mailing list