File: assume_attr.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 (120 lines) | stat: -rw-r--r-- 4,000 bytes parent folder | download | duplicates (12)
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// RUN: %clang_cc1 -emit-llvm -triple i386-linux-gnu %s -o - | FileCheck %s
// RUN: %clang_cc1 -x c++ -emit-pch -triple i386-linux-gnu -o %t %s
// RUN: %clang_cc1 -include-pch %t %s -triple i386-linux-gnu -emit-llvm -o - | FileCheck %s
// expected-no-diagnostics

#ifndef HEADER
#define HEADER

/// foo: declarations only

__attribute__((assume("foo:before1"))) void foo();

__attribute__((assume("foo:before2")))
__attribute__((assume("foo:before3"))) void
foo();

/// baz: static function declarations and a definition

__attribute__((assume("baz:before1"))) static void baz();

__attribute__((assume("baz:before2")))
__attribute__((assume("baz:before3"))) static void
baz();

// Definition
__attribute__((assume("baz:def1,baz:def2"))) static void baz() { foo(); }

__attribute__((assume("baz:after"))) static void baz();

/// bar: external function declarations and a definition

__attribute__((assume("bar:before1"))) void bar();

__attribute__((assume("bar:before2")))
__attribute__((assume("bar:before3"))) void
bar();

// Definition
__attribute__((assume("bar:def1,bar:def2"))) void bar() { baz(); }

__attribute__((assume("bar:after"))) void bar();

/// back to foo

__attribute__((assume("foo:after"))) void foo();

/// class tests
class C {
  __attribute__((assume("C:private_method"))) void private_method();
  __attribute__((assume("C:private_static"))) static void private_static();

public:
  __attribute__((assume("C:public_method1"))) void public_method();
  __attribute__((assume("C:public_static1"))) static void public_static();
};

__attribute__((assume("C:public_method2"))) void C::public_method() {
  private_method();
}

__attribute__((assume("C:public_static2"))) void C::public_static() {
  private_static();
}

/// template tests
template <typename T>
__attribute__((assume("template_func<T>"))) void template_func() {}

template <>
__attribute__((assume("template_func<float>"))) void template_func<float>() {}

template <>
void template_func<int>() {}

template <typename T>
struct S {
  __attribute__((assume("S<T>::method"))) void method();
};

template <>
__attribute__((assume("S<float>::method"))) void S<float>::method() {}

template <>
void S<int>::method() {}

// CHECK:         define{{.*}} void @_Z3barv() #0
// CHECK:         define{{.*}} void @_ZL3bazv() #1
// CHECK:         define{{.*}} void @_ZN1C13public_methodEv({{.*}}) #2
// CHECK:         declare{{.*}} void @_ZN1C14private_methodEv({{.*}}) #3
// CHECK:         define{{.*}} void @_ZN1C13public_staticEv() #4
// CHECK:         declare{{.*}} void @_ZN1C14private_staticEv() #5
// CHECK:         define{{.*}} void @_Z13template_funcIfEvv() #6
// CHECK:         define{{.*}} void @_Z13template_funcIiEvv() #7
// CHECK:         define{{.*}} void @_ZN1SIfE6methodEv({{.*}}) #8
// CHECK:         define{{.*}} void @_ZN1SIiE6methodEv({{.*}}) #9
// CHECK:         declare{{.*}} void @_Z3foov() #10
// CHECK:         attributes #0
// CHECK-SAME:      "llvm.assume"="bar:before1,bar:before2,bar:before3,bar:def1,bar:def2"
// CHECK:         attributes #1
// CHECK-SAME:      "llvm.assume"="baz:before1,baz:before2,baz:before3,baz:def1,baz:def2,baz:after"
// CHECK:         attributes #2
// CHECK-SAME:      "llvm.assume"="C:public_method1,C:public_method2"
// CHECK:         attributes #3
// CHECK-SAME:      "llvm.assume"="C:private_method"
// CHECK:         attributes #4
// CHECK-SAME:      "llvm.assume"="C:public_static1,C:public_static2"
// CHECK:         attributes #5
// CHECK-SAME:      "llvm.assume"="C:private_static"
// CHECK:         attributes #6
// CHECK-SAME:      "llvm.assume"="template_func<T>,template_func<float>"
// CHECK:         attributes #7
// CHECK-SAME:      "llvm.assume"="template_func<T>"
// CHECK:         attributes #8
// CHECK-SAME:      "llvm.assume"="S<T>::method,S<float>::method"
// CHECK:         attributes #9
// CHECK-SAME:      "llvm.assume"="S<T>::method"
// CHECK:         attributes #10
// CHECK-SAME:      "llvm.assume"="foo:before1,foo:before2,foo:before3"

#endif