File: optnone-and-attributes.cpp

package info (click to toggle)
llvm-toolchain-15 1%3A15.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,554,644 kB
  • sloc: cpp: 5,922,452; ansic: 1,012,136; asm: 674,362; python: 191,568; objc: 73,855; f90: 42,327; lisp: 31,913; pascal: 11,973; javascript: 10,144; sh: 9,421; perl: 7,447; ml: 5,527; awk: 3,523; makefile: 2,520; xml: 885; cs: 573; fortran: 567
file content (82 lines) | stat: -rw-r--r-- 2,250 bytes parent folder | download | duplicates (19)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// RUN: %clang_cc1 < %s -triple i386-mingw32 -fms-extensions -emit-llvm -x c++ | FileCheck %s

// optnone wins over inlinehint.
// Test that both func1 and func2 are marked optnone and noinline.

// Definition with both optnone and inlinehint.
__attribute__((optnone))
inline int func1(int a) {
  return a + a + a + a;
}
// CHECK: @_Z5func1i({{.*}}) [[OPTNONE:#[0-9]+]]

// optnone declaration, inlinehint definition.
__attribute__((optnone))
int func2(int a);

inline int func2(int a) {
  return a + a + a + a;
}
// CHECK: @_Z5func2i({{.*}}) [[OPTNONE]]

// Keep alive the definitions of func1 and func2.
int foo() {
  int val = func1(1);
  return val + func2(2);
}

// optnone wins over minsize.
__attribute__((optnone))
int func3(int a);

__attribute__((minsize))
int func3(int a) {
  return a + a + a + a;
}
// Same attribute set as everything else, therefore no 'minsize'.
// CHECK: @_Z5func3i({{.*}}) [[OPTNONE]]


// Verify that noreturn is compatible with optnone.
__attribute__((noreturn))
extern void exit_from_function();

__attribute__((noreturn)) __attribute((optnone))
extern void noreturn_function(int a) { exit_from_function(); }
// CHECK: @_Z17noreturn_functioni({{.*}}) [[NORETURN:#[0-9]+]]


// Verify that __declspec(noinline) is compatible with optnone.
__declspec(noinline) __attribute__((optnone))
void func4() { return; }
// CHECK: @_Z5func4v() [[OPTNONE]]

__declspec(noinline)
extern void func5();

__attribute__((optnone))
void func5() { return; }
// CHECK: @_Z5func5v() [[OPTNONE]]


// Verify also that optnone can be used on dllexport functions.
// Adding attribute optnone on a dllimport function has no effect.

__attribute__((dllimport))
__attribute__((optnone))
int imported_optnone_func(int a);

__attribute__((dllexport))
__attribute__((optnone))
int exported_optnone_func(int a) {
  return imported_optnone_func(a); // use of imported func
}
// CHECK: @_Z21exported_optnone_funci({{.*}}) [[OPTNONE]]
// CHECK: declare dllimport {{.*}} @_Z21imported_optnone_funci({{.*}}) [[DLLIMPORT:#[0-9]+]]


// CHECK: attributes [[OPTNONE]] = { mustprogress noinline {{.*}} optnone
// CHECK: attributes [[NORETURN]] = { mustprogress noinline noreturn {{.*}} optnone

// CHECK: attributes [[DLLIMPORT]] =
// CHECK-NOT: optnone