xref: /aosp_15_r20/external/clang/test/CodeGenCXX/key-function-vtable.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -triple x86_64-none-linux-gnu %s -emit-llvm -o - | FileCheck %s
2*67e74705SXin Li // RUN: %clang_cc1 -triple arm-apple-darwin %s -emit-llvm -o - | FileCheck %s
3*67e74705SXin Li 
4*67e74705SXin Li // Simple key function test
5*67e74705SXin Li struct testa { virtual void a(); };
a()6*67e74705SXin Li void testa::a() {}
7*67e74705SXin Li 
8*67e74705SXin Li // Simple key function test
atestb9*67e74705SXin Li struct testb { virtual void a() {} };
10*67e74705SXin Li testb *testbvar = new testb;
11*67e74705SXin Li 
12*67e74705SXin Li // Key function with out-of-line inline definition
13*67e74705SXin Li struct testc { virtual void a(); };
a()14*67e74705SXin Li inline void testc::a() {}
15*67e74705SXin Li 
16*67e74705SXin Li // Functions with inline specifier are not key functions (PR5705)
17*67e74705SXin Li struct testd { inline virtual void a(); };
a()18*67e74705SXin Li void testd::a() {}
19*67e74705SXin Li 
20*67e74705SXin Li // Functions with inline specifier are not key functions (PR5705)
21*67e74705SXin Li struct teste { inline virtual void a(); };
22*67e74705SXin Li teste *testevar = new teste;
23*67e74705SXin Li 
24*67e74705SXin Li // Key functions with namespace (PR5711)
25*67e74705SXin Li namespace {
26*67e74705SXin Li   struct testf { virtual void a(); };
27*67e74705SXin Li }
a()28*67e74705SXin Li void testf::a() {}
29*67e74705SXin Li 
30*67e74705SXin Li // Key functions with namespace (PR5711)
31*67e74705SXin Li namespace {
32*67e74705SXin Li   struct testg { virtual void a(); };
33*67e74705SXin Li }
a()34*67e74705SXin Li void testg::a() {}
35*67e74705SXin Li testg *testgvar = new testg;
36*67e74705SXin Li 
37*67e74705SXin Li struct X0 { virtual ~X0(); };
38*67e74705SXin Li struct X1 : X0 {
39*67e74705SXin Li   virtual void f();
40*67e74705SXin Li };
41*67e74705SXin Li 
f()42*67e74705SXin Li inline void X1::f() { }
43*67e74705SXin Li 
use_X1()44*67e74705SXin Li void use_X1() { X1 x1; }
45*67e74705SXin Li 
46*67e74705SXin Li // CHECK-DAG: @_ZTV2X1 = linkonce_odr unnamed_addr constant
47*67e74705SXin Li // CHECK-DAG: @_ZTV5testa = unnamed_addr constant [3 x i8*] [i8* null
48*67e74705SXin Li // CHECK-DAG: @_ZTV5testc = linkonce_odr unnamed_addr constant [3 x i8*] [i8* null
49*67e74705SXin Li // CHECK-DAG: @_ZTV5testb = linkonce_odr unnamed_addr constant [3 x i8*] [i8* null
50*67e74705SXin Li // CHECK-DAG: @_ZTV5teste = linkonce_odr unnamed_addr constant [3 x i8*] [i8* null
51*67e74705SXin Li // CHECK-DAG: @_ZTVN12_GLOBAL__N_15testgE = internal unnamed_addr constant [3 x i8*] [i8* null
52