[clang] a9006bf - [clang][bytecode] Fix zero-init of first union member (#106962)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 2 04:51:04 PDT 2024
Author: Timm Baeder
Date: 2024-09-02T13:51:01+02:00
New Revision: a9006bffa994d5afe9ad0b661b69d655658ab5e8
URL: https://github.com/llvm/llvm-project/commit/a9006bffa994d5afe9ad0b661b69d655658ab5e8
DIFF: https://github.com/llvm/llvm-project/commit/a9006bffa994d5afe9ad0b661b69d655658ab5e8.diff
LOG: [clang][bytecode] Fix zero-init of first union member (#106962)
... if done via a ImplicitValueInitExpr.
We were already doing this later in visitZeroRecordInitializer().
Added:
Modified:
clang/lib/AST/ByteCode/Compiler.cpp
clang/test/SemaObjC/non-trivial-c-union.m
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 1ddaa5bd41df75..554e23e272e41c 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