47 lines · cpp
1// Check that initialization of the only one memcpy-able struct member will not2// be performed twice after successful non-trivial initializtion of the second3// member.4//5// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fexceptions -fcxx-exceptions -O0 -fno-elide-constructors -emit-llvm %s -o - | FileCheck %s6 7int globId = 0;8 9struct ImplicitCopy {10 int id;11 12 ImplicitCopy() { id = 10; }13 ~ImplicitCopy() { id = 20; }14};15 16struct ExplicitCopy {17 int id;18 19 ExplicitCopy() { id = 15; }20 ExplicitCopy(const ExplicitCopy &x) { id = 25; }21 ~ExplicitCopy() { id = 35; }22};23 24struct Container {25 ImplicitCopy o1; // memcpy-able member.26 ExplicitCopy o2; // non-trivial initialization.27 28 Container() { globId = 1000; }29 ~Container() { globId = 2000; }30};31 32int main() {33 try {34 Container c1;35 // CHECK-DAG: call void @llvm.memcpy36 // CHECK-DAG: declare void @llvm.memcpy37 // CHECK-NOT: @llvm.memcpy38 Container c2(c1);39 40 return 2;41 }42 catch (...) {43 return 1;44 }45 return 0;46}47