xref: /llvm-project/clang/test/CodeGenCXX/ctor-empty-nounique.cpp (revision d60c3d08e78dfbb4b180776b83e910d810e1f36a)
1 // RUN: %clang_cc1 -triple x86_64-windows-gnu -emit-llvm -o - %s | FileCheck %s
2 // RUN: %clang_cc1 -triple powerpc64le-windows-gnu -emit-llvm -o - %s | FileCheck %s
3 
4 // An empty struct is handled as a struct with a dummy i8, on all targets.
5 // Most targets treat an empty struct return value as essentially void - but
6 // some don't. (Currently, at least x86_64-windows-* and powerpc64le-* don't
7 // treat it as void.)
8 //
9 // When intializing a struct with such a no_unique_address member, make sure we
10 // don't write the dummy i8 into the struct where there's no space allocated for
11 // it.
12 //
13 // This can only be tested with targets that don't treat empty struct returns as
14 // void.
15 
16 struct S {};
17 S f();
18 struct Z {
19   int x;
20   [[no_unique_address]] S y;
21   Z();
22 };
Z()23 Z::Z() : x(111), y(f()) {}
24 
25 // CHECK: define {{.*}} @_ZN1ZC2Ev
26 // CHECK: %call = call i8 @_Z1fv()
27 // CHECK-NEXT: ret void
28 
29 
30 // Check that the constructor for an empty member gets called with the right
31 // 'this' pointer.
32 
33 struct S2 {
34   S2();
35 };
36 struct Z2 {
37   int x;
38   [[no_unique_address]] S2 y;
39   Z2();
40 };
Z2()41 Z2::Z2() : x(111) {}
42 
43 // CHECK: define {{.*}} @_ZN2Z2C2Ev(ptr {{.*}} %this)
44 // CHECK: %this.addr = alloca ptr
45 // CHECK: store ptr %this, ptr %this.addr
46 // CHECK: %this1 = load ptr, ptr %this.addr
47 // CHECK: call void @_ZN2S2C1Ev(ptr {{.*}} %this1)
48