[clang] [clang][bytecode] Fix zero-init of first union member (PR #106962)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 2 03:04:21 PDT 2024
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/106962
... if done via a ImplicitValueInitExpr.
We were already doing this later in visitZeroRecordInitializer().
>From 3ca8c6c3408d78163c01d5ff95796fdc310b9b63 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Mon, 2 Sep 2024 11:48:49 +0200
Subject: [PATCH] [clang][bytecode] Fix zero-init of first union member
... if done via a ImplicitValueInitExpr.
We were already doing this later in visitZeroRecordInitializer().
---
clang/lib/AST/ByteCode/Compiler.cpp | 8 ++------
clang/test/SemaObjC/non-trivial-c-union.m | 1 +
2 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index dced9ea3493732..d8b4a554574e0a 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -1235,12 +1235,6 @@ bool Compiler<Emitter>::VisitImplicitValueInitExpr(
assert(RD);
if (RD->isInvalidDecl())
return false;
- if (RD->isUnion()) {
- // C++11 [dcl.init]p5: If T is a (possibly cv-qualified) union type, the
- // object's first non-static named data member is zero-initialized
- // FIXME
- return false;
- }
if (const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD);
CXXRD && CXXRD->getNumVBases() > 0) {
@@ -3434,6 +3428,8 @@ bool Compiler<Emitter>::visitZeroRecordInitializer(const Record *R,
if (!this->emitFinishInitPop(E))
return false;
+ // C++11 [dcl.init]p5: If T is a (possibly cv-qualified) union type, the
+ // object's first non-static named data member is zero-initialized
if (R->isUnion())
break;
}
diff --git a/clang/test/SemaObjC/non-trivial-c-union.m b/clang/test/SemaObjC/non-trivial-c-union.m
index 4c294764c430d8..34f1caad59df70 100644
--- a/clang/test/SemaObjC/non-trivial-c-union.m
+++ b/clang/test/SemaObjC/non-trivial-c-union.m
@@ -1,4 +1,5 @@
// RUN: %clang_cc1 -fsyntax-only -fblocks -fobjc-arc -fobjc-runtime-has-weak -I %S/Inputs -verify %s
+// RUN: %clang_cc1 -fsyntax-only -fblocks -fobjc-arc -fobjc-runtime-has-weak -I %S/Inputs -verify -fexperimental-new-constant-interpreter %s
#include "non-trivial-c-union.h"
More information about the cfe-commits
mailing list