Clang Project

clang_source_code/test/CodeGenCXX/optnone-and-attributes.cpp
1// RUN: %clang_cc1 < %s -triple i386-mingw32 -fms-extensions -emit-llvm -x c++ | FileCheck %s
2
3// optnone wins over inlinehint.
4// Test that both func1 and func2 are marked optnone and noinline.
5
6// Definition with both optnone and inlinehint.
7__attribute__((optnone))
8inline int func1(int a) {
9  return a + a + a + a;
10}
11// CHECK: @_Z5func1i({{.*}}) [[OPTNONE:#[0-9]+]]
12
13// optnone declaration, inlinehint definition.
14__attribute__((optnone))
15int func2(int a);
16
17inline int func2(int a) {
18  return a + a + a + a;
19}
20// CHECK: @_Z5func2i({{.*}}) [[OPTNONE]]
21
22// Keep alive the definitions of func1 and func2.
23int foo() {
24  int val = func1(1);
25  return val + func2(2);
26}
27
28// optnone wins over minsize.
29__attribute__((optnone))
30int func3(int a);
31
32__attribute__((minsize))
33int func3(int a) {
34  return a + a + a + a;
35}
36// Same attribute set as everything else, therefore no 'minsize'.
37// CHECK: @_Z5func3i({{.*}}) [[OPTNONE]]
38
39
40// Verify that noreturn is compatible with optnone.
41__attribute__((noreturn))
42extern void exit_from_function();
43
44__attribute__((noreturn)) __attribute((optnone))
45extern void noreturn_function(int a) { exit_from_function(); }
46// CHECK: @_Z17noreturn_functioni({{.*}}) [[NORETURN:#[0-9]+]]
47
48
49// Verify that __declspec(noinline) is compatible with optnone.
50__declspec(noinline) __attribute__((optnone))
51void func4() { return; }
52// CHECK: @_Z5func4v() [[OPTNONE]]
53
54__declspec(noinline)
55extern void func5();
56
57__attribute__((optnone))
58void func5() { return; }
59// CHECK: @_Z5func5v() [[OPTNONE]]
60
61
62// Verify also that optnone can be used on dllexport functions.
63// Adding attribute optnone on a dllimport function has no effect.
64
65__attribute__((dllimport))
66__attribute__((optnone))
67int imported_optnone_func(int a);
68
69__attribute__((dllexport))
70__attribute__((optnone))
71int exported_optnone_func(int a) {
72  return imported_optnone_func(a); // use of imported func
73}
74// CHECK: @_Z21exported_optnone_funci({{.*}}) [[OPTNONE]]
75// CHECK: declare dllimport {{.*}} @_Z21imported_optnone_funci({{.*}}) [[DLLIMPORT:#[0-9]+]]
76
77
78// CHECK: attributes [[OPTNONE]] = { noinline {{.*}} optnone
79// CHECK: attributes [[NORETURN]] = { noinline noreturn {{.*}} optnone
80
81// CHECK: attributes [[DLLIMPORT]] =
82// CHECK-NOT: optnone
83