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

via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 5 17:59:06 PST 2024


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

None

>From 916a10f1cebbb339dec98bd18c945b63991190f1 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/CodeGenCXX/fixed-point-zero-init.cpp | 9 +++++++++
 2 files changed, 13 insertions(+)
 create mode 100644 clang/test/CodeGenCXX/fixed-point-zero-init.cpp

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 63453890d9879..089bc2094567f 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/CodeGenCXX/fixed-point-zero-init.cpp b/clang/test/CodeGenCXX/fixed-point-zero-init.cpp
new file mode 100644
index 0000000000000..9a7a6600fe556
--- /dev/null
+++ b/clang/test/CodeGenCXX/fixed-point-zero-init.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -ffixed-point -S -emit-llvm %s -o - | FileCheck %s
+
+// CHECK: @_ZL1a = internal constant [2 x i32] zeroinitializer
+constexpr _Accum a[2] = {};
+
+void func2(const _Accum *);
+void func() {
+  func2(a);
+}



More information about the cfe-commits mailing list