xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/optnone-def-decl.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 %s -triple %itanium_abi_triple -fms-extensions -emit-llvm -o - | FileCheck %s
2*0a6a1f1dSLionel Sambuc 
3*0a6a1f1dSLionel Sambuc // Test optnone on both function declarations and function definitions.
4*0a6a1f1dSLionel Sambuc // Verify also that we don't generate invalid IR functions with
5*0a6a1f1dSLionel Sambuc // both alwaysinline and noinline. (optnone implies noinline and wins
6*0a6a1f1dSLionel Sambuc // over alwaysinline, in all cases.)
7*0a6a1f1dSLionel Sambuc 
8*0a6a1f1dSLionel Sambuc // Test optnone on extern declaration only.
9*0a6a1f1dSLionel Sambuc extern int decl_only(int a) __attribute__((optnone));
10*0a6a1f1dSLionel Sambuc 
11*0a6a1f1dSLionel Sambuc // This function should be marked 'optnone'.
decl_only(int a)12*0a6a1f1dSLionel Sambuc int decl_only(int a) {
13*0a6a1f1dSLionel Sambuc   return a + a + a + a;
14*0a6a1f1dSLionel Sambuc }
15*0a6a1f1dSLionel Sambuc 
16*0a6a1f1dSLionel Sambuc // CHECK: define {{.*}} @_Z9decl_onlyi({{.*}}) [[OPTNONE:#[0-9]+]]
17*0a6a1f1dSLionel Sambuc 
18*0a6a1f1dSLionel Sambuc // Test optnone on definition but not extern declaration.
19*0a6a1f1dSLionel Sambuc extern int def_only(int a);
20*0a6a1f1dSLionel Sambuc 
21*0a6a1f1dSLionel Sambuc __attribute__((optnone))
def_only(int a)22*0a6a1f1dSLionel Sambuc int def_only(int a) {
23*0a6a1f1dSLionel Sambuc   return a + a + a + a;
24*0a6a1f1dSLionel Sambuc }
25*0a6a1f1dSLionel Sambuc 
26*0a6a1f1dSLionel Sambuc // Function def_only is a optnone function and therefore it should not be
27*0a6a1f1dSLionel Sambuc // inlined inside 'user_of_def_only'.
user_of_def_only()28*0a6a1f1dSLionel Sambuc int user_of_def_only() {
29*0a6a1f1dSLionel Sambuc   return def_only(5);
30*0a6a1f1dSLionel Sambuc }
31*0a6a1f1dSLionel Sambuc 
32*0a6a1f1dSLionel Sambuc // CHECK: define {{.*}} @_Z8def_onlyi({{.*}}) [[OPTNONE]]
33*0a6a1f1dSLionel Sambuc // CHECK: define {{.*}} @_Z16user_of_def_onlyv() [[NORMAL:#[0-9]+]]
34*0a6a1f1dSLionel Sambuc 
35*0a6a1f1dSLionel Sambuc // Test optnone on both definition and declaration.
36*0a6a1f1dSLionel Sambuc extern int def_and_decl(int a) __attribute__((optnone));
37*0a6a1f1dSLionel Sambuc 
38*0a6a1f1dSLionel Sambuc __attribute__((optnone))
def_and_decl(int a)39*0a6a1f1dSLionel Sambuc int def_and_decl(int a) {
40*0a6a1f1dSLionel Sambuc   return a + a + a + a;
41*0a6a1f1dSLionel Sambuc }
42*0a6a1f1dSLionel Sambuc 
43*0a6a1f1dSLionel Sambuc // CHECK: define {{.*}} @_Z12def_and_decli({{.*}}) [[OPTNONE]]
44*0a6a1f1dSLionel Sambuc 
45*0a6a1f1dSLionel Sambuc // Check that optnone wins over always_inline.
46*0a6a1f1dSLionel Sambuc 
47*0a6a1f1dSLionel Sambuc // Test optnone on definition and always_inline on declaration.
48*0a6a1f1dSLionel Sambuc extern int always_inline_function(int a) __attribute__((always_inline));
49*0a6a1f1dSLionel Sambuc 
50*0a6a1f1dSLionel Sambuc __attribute__((optnone))
always_inline_function(int a)51*0a6a1f1dSLionel Sambuc extern int always_inline_function(int a) {
52*0a6a1f1dSLionel Sambuc   return a + a + a + a;
53*0a6a1f1dSLionel Sambuc }
54*0a6a1f1dSLionel Sambuc // CHECK: define {{.*}} @_Z22always_inline_functioni({{.*}}) [[OPTNONE]]
55*0a6a1f1dSLionel Sambuc 
user_of_always_inline_function()56*0a6a1f1dSLionel Sambuc int user_of_always_inline_function() {
57*0a6a1f1dSLionel Sambuc   return always_inline_function(4);
58*0a6a1f1dSLionel Sambuc }
59*0a6a1f1dSLionel Sambuc 
60*0a6a1f1dSLionel Sambuc // CHECK: define {{.*}} @_Z30user_of_always_inline_functionv() [[NORMAL]]
61*0a6a1f1dSLionel Sambuc 
62*0a6a1f1dSLionel Sambuc // Test optnone on declaration and always_inline on definition.
63*0a6a1f1dSLionel Sambuc extern int optnone_function(int a) __attribute__((optnone));
64*0a6a1f1dSLionel Sambuc 
65*0a6a1f1dSLionel Sambuc __attribute__((always_inline))
optnone_function(int a)66*0a6a1f1dSLionel Sambuc int optnone_function(int a) {
67*0a6a1f1dSLionel Sambuc   return a + a + a + a;
68*0a6a1f1dSLionel Sambuc }
69*0a6a1f1dSLionel Sambuc // CHECK: define {{.*}} @_Z16optnone_functioni({{.*}}) [[OPTNONE]]
70*0a6a1f1dSLionel Sambuc 
user_of_optnone_function()71*0a6a1f1dSLionel Sambuc int user_of_optnone_function() {
72*0a6a1f1dSLionel Sambuc   return optnone_function(4);
73*0a6a1f1dSLionel Sambuc }
74*0a6a1f1dSLionel Sambuc 
75*0a6a1f1dSLionel Sambuc // CHECK: define {{.*}} @_Z24user_of_optnone_functionv() [[NORMAL]]
76*0a6a1f1dSLionel Sambuc 
77*0a6a1f1dSLionel Sambuc // Test the combination of optnone with forceinline (optnone wins).
78*0a6a1f1dSLionel Sambuc extern __forceinline int forceinline_optnone_function(int a, int b);
79*0a6a1f1dSLionel Sambuc 
80*0a6a1f1dSLionel Sambuc __attribute__((optnone))
forceinline_optnone_function(int a,int b)81*0a6a1f1dSLionel Sambuc extern int forceinline_optnone_function(int a, int b) {
82*0a6a1f1dSLionel Sambuc     return a + b;
83*0a6a1f1dSLionel Sambuc }
84*0a6a1f1dSLionel Sambuc 
user_of_forceinline_optnone_function()85*0a6a1f1dSLionel Sambuc int user_of_forceinline_optnone_function() {
86*0a6a1f1dSLionel Sambuc     return forceinline_optnone_function(4,5);
87*0a6a1f1dSLionel Sambuc }
88*0a6a1f1dSLionel Sambuc 
89*0a6a1f1dSLionel Sambuc // CHECK: @_Z36user_of_forceinline_optnone_functionv() [[NORMAL]]
90*0a6a1f1dSLionel Sambuc // CHECK: @_Z28forceinline_optnone_functionii({{.*}}) [[OPTNONE]]
91*0a6a1f1dSLionel Sambuc 
92*0a6a1f1dSLionel Sambuc // CHECK: attributes [[OPTNONE]] = { noinline nounwind optnone {{.*}} }
93*0a6a1f1dSLionel Sambuc // CHECK: attributes [[NORMAL]] = { nounwind {{.*}} }
94*0a6a1f1dSLionel Sambuc 
95