1 // Check that initialization of the only one memcpy-able struct member will not
2 // be performed twice after successful non-trivial initializtion of the second
3 // member.
4 //
5 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -O0 -fno-elide-constructors -emit-llvm %s -o - | FileCheck %s
6 
7 int globId = 0;
8 
9 struct ImplicitCopy {
10   int id;
11 
ImplicitCopyImplicitCopy12   ImplicitCopy() { id = 10; }
~ImplicitCopyImplicitCopy13   ~ImplicitCopy() { id = 20; }
14 };
15 
16 struct ExplicitCopy {
17   int id;
18 
ExplicitCopyExplicitCopy19   ExplicitCopy() { id = 15; }
ExplicitCopyExplicitCopy20   ExplicitCopy(const ExplicitCopy &x) { id = 25; }
~ExplicitCopyExplicitCopy21   ~ExplicitCopy() { id = 35; }
22 };
23 
24 struct Container {
25   ImplicitCopy o1; // memcpy-able member.
26   ExplicitCopy o2; // non-trivial initialization.
27 
ContainerContainer28   Container() { globId = 1000; }
~ContainerContainer29   ~Container() { globId = 2000; }
30 };
31 
main()32 int main() {
33   try {
34     Container c1;
35     // CHECK-DAG: call void @llvm.memcpy
36     // CHECK-DAG: declare void @llvm.memcpy
37     // CHECK-NOT: @llvm.memcpy
38     Container c2(c1);
39 
40     return 2;
41   }
42   catch (...) {
43     return 1;
44   }
45   return 0;
46 }
47