xref: /aosp_15_r20/external/clang/test/CodeGenCXX/attr-used.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple -o - %s | FileCheck %s
2*67e74705SXin Li 
3*67e74705SXin Li // <rdar://problem/8684363>: clang++ not respecting __attribute__((used)) on destructors
4*67e74705SXin Li struct X0 {
5*67e74705SXin Li   // CHECK-DAG: define linkonce_odr {{.*}} @_ZN2X0C1Ev
X0X06*67e74705SXin Li   __attribute__((used)) X0() {}
7*67e74705SXin Li   // CHECK-DAG: define linkonce_odr {{.*}} @_ZN2X0D1Ev
~X0X08*67e74705SXin Li   __attribute__((used)) ~X0() {}
9*67e74705SXin Li };
10*67e74705SXin Li 
11*67e74705SXin Li // PR19743: not emitting __attribute__((used)) inline methods in nested classes.
12*67e74705SXin Li struct X1 {
13*67e74705SXin Li   struct Nested {
14*67e74705SXin Li     // CHECK-DAG: define linkonce_odr {{.*}} @_ZN2X16Nested1fEv
fX1::Nested15*67e74705SXin Li     void __attribute__((used)) f() {}
16*67e74705SXin Li   };
17*67e74705SXin Li };
18*67e74705SXin Li 
19*67e74705SXin Li struct X2 {
20*67e74705SXin Li   // We must delay emission of bar() until foo() has had its body parsed,
21*67e74705SXin Li   // otherwise foo() would not be emitted.
barX222*67e74705SXin Li   void __attribute__((used)) bar() { foo(); }
fooX223*67e74705SXin Li   void foo() { }
24*67e74705SXin Li 
25*67e74705SXin Li   // CHECK-DAG: define linkonce_odr {{.*}} @_ZN2X23barEv
26*67e74705SXin Li   // CHECK-DAG: define linkonce_odr {{.*}} @_ZN2X23fooEv
27*67e74705SXin Li };
28