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 &Dest = S.Stk.peek(); - 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];