From 01b47eb86c991f88d3117f494ebd1826fd3ab41e Mon Sep 17 00:00:00 2001 From: Timm Baeder Date: Wed, 23 Jul 2025 05:28:37 +0200 Subject: [clang][bytecode] Only implicitly start lifetime of trivially-default-constructible union members (#149835) See https://github.com/llvm/llvm-project/commit/faee39baa87e43f4b746dd77e479268391163658 --- clang/lib/AST/ByteCode/Compiler.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'clang/lib/AST/ByteCode/Compiler.cpp') diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index 07efd6f8..e760055 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -25,11 +25,18 @@ using APSInt = llvm::APSInt; namespace clang { namespace interp { +static bool hasTrivialDefaultCtorParent(const FieldDecl *FD) { + assert(FD); + assert(FD->getParent()->isUnion()); + const auto *CXXRD = dyn_cast(FD->getParent()); + return !CXXRD || CXXRD->hasTrivialDefaultConstructor(); +} + static bool refersToUnion(const Expr *E) { for (;;) { if (const auto *ME = dyn_cast(E)) { if (const auto *FD = dyn_cast(ME->getMemberDecl()); - FD && FD->getParent()->isUnion()) + FD && FD->getParent()->isUnion() && hasTrivialDefaultCtorParent(FD)) return true; E = ME->getBase(); continue; -- cgit v1.1