[clang] 14f2556 - [clang][bytecode] Don't check anonymous union in memcpy op (#191783)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 13 06:05:32 PDT 2026
Author: Timm Baeder
Date: 2026-04-13T15:05:28+02:00
New Revision: 14f2556639be002af1e614ddcb6bff496ca32fc3
URL: https://github.com/llvm/llvm-project/commit/14f2556639be002af1e614ddcb6bff496ca32fc3
DIFF: https://github.com/llvm/llvm-project/commit/14f2556639be002af1e614ddcb6bff496ca32fc3.diff
LOG: [clang][bytecode] Don't check anonymous union in memcpy op (#191783)
It's fine if they are uninitialized.
Added:
Modified:
clang/lib/AST/ByteCode/Interp.h
clang/test/AST/ByteCode/cxx11.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Interp.h b/clang/lib/AST/ByteCode/Interp.h
index 2ba223010d4ad..99651ca98ea6d 100644
--- a/clang/lib/AST/ByteCode/Interp.h
+++ b/clang/lib/AST/ByteCode/Interp.h
@@ -2428,8 +2428,10 @@ inline bool Memcpy(InterpState &S, CodePtr OpPC) {
const Pointer &Src = S.Stk.pop<Pointer>();
Pointer &Dest = S.Stk.peek<Pointer>();
- if (!CheckLoad(S, OpPC, Src))
- return false;
+ if (!Src.getRecord() || !Src.getRecord()->isAnonymousUnion()) {
+ if (!CheckLoad(S, OpPC, Src))
+ return false;
+ }
return DoMemcpy(S, OpPC, Src, Dest);
}
diff --git a/clang/test/AST/ByteCode/cxx11.cpp b/clang/test/AST/ByteCode/cxx11.cpp
index 91c828abd87a9..668228e2dc166 100644
--- a/clang/test/AST/ByteCode/cxx11.cpp
+++ b/clang/test/AST/ByteCode/cxx11.cpp
@@ -345,6 +345,16 @@ namespace ReadMutableInCopyCtor {
// both-note {{in call to 'G(g1)'}}
}
+namespace ReadAnonUnionInCopyCtor {
+ struct G {
+ struct X {};
+ union U { X a; };
+ union {X a; };
+ };
+ constexpr G g1 = {};
+ constexpr G g2 = g1;
+}
+
namespace GH150709 {
struct C { };
struct D : C {
@@ -353,7 +363,7 @@ namespace GH150709 {
struct E : C { };
struct F : D { };
struct G : E { };
-
+
constexpr C c1, c2[2];
constexpr D d1, d2[2];
constexpr E e1, e2[2];
More information about the cfe-commits
mailing list