[clang] [clang][Interp] Fix scalar inits of void type (PR #69868)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Sat Oct 21 21:58:06 PDT 2023


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

None

>From 537c917cab1fe8bd8dc7dfd849bff9cd5be5efc2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Sun, 22 Oct 2023 06:56:46 +0200
Subject: [PATCH] [clang][Interp] Fix scalar inits of void type

---
 clang/lib/AST/Interp/ByteCodeExprGen.cpp | 8 ++++++--
 clang/test/AST/Interp/literals.cpp       | 9 +++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index ed971fe0f650f22..d7c370cb3efa45c 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -1571,8 +1571,12 @@ bool ByteCodeExprGen<Emitter>::VisitOffsetOfExpr(const OffsetOfExpr *E) {
 template <class Emitter>
 bool ByteCodeExprGen<Emitter>::VisitCXXScalarValueInitExpr(
     const CXXScalarValueInitExpr *E) {
-  return this->visitZeroInitializer(classifyPrim(E->getType()), E->getType(),
-                                    E);
+  QualType Ty = E->getType();
+
+  if (Ty->isVoidType())
+    return true;
+
+  return this->visitZeroInitializer(classifyPrim(Ty), Ty, E);
 }
 
 template <class Emitter> bool ByteCodeExprGen<Emitter>::discard(const Expr *E) {
diff --git a/clang/test/AST/Interp/literals.cpp b/clang/test/AST/Interp/literals.cpp
index a83dcd234111587..fd0123e2ef55115 100644
--- a/clang/test/AST/Interp/literals.cpp
+++ b/clang/test/AST/Interp/literals.cpp
@@ -56,6 +56,15 @@ namespace ScalarTypes {
   };
   static_assert(getScalar<E>() == First, "");
   /// FIXME: Member pointers.
+
+#if __cplusplus >= 201402L
+  constexpr void Void(int n) {
+    void(n + 1);
+    void();
+  }
+  constexpr int void_test = (Void(0), 1);
+  static_assert(void_test == 1, "");
+#endif
 }
 
 namespace IntegralCasts {



More information about the cfe-commits mailing list