Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGenCXX / code-seg.cpp
blob7dad9274208ab2287be5b7c0407e38edfe2b64b1
1 // RUN: %clang_cc1 -emit-llvm -triple i686-pc-win32 -fms-extensions -verify -o - %s | FileCheck %s
2 // expected-no-diagnostics
4 // Simple case
6 int __declspec(code_seg("foo_one")) bar_one() { return 1; }
7 //CHECK: define {{.*}}bar_one{{.*}} section "foo_one"
9 // Simple case - explicit attribute used over pragma
10 #pragma code_seg("foo_two")
11 int __declspec(code_seg("foo_three")) bar2() { return 2; }
12 //CHECK: define {{.*}}bar2{{.*}} section "foo_three"
14 // Check that attribute on one function doesn't affect another
15 int another1() { return 1001; }
16 //CHECK: define {{.*}}another1{{.*}} section "foo_two"
18 // Member functions
20 struct __declspec(code_seg("foo_four")) Foo {
21 int bar3() {return 0;}
22 int bar4();
23 int __declspec(code_seg("foo_six")) bar6() { return 6; }
24 int bar7() { return 7; }
25 struct Inner {
26 int bar5() { return 5; }
27 } z;
28 virtual int baz1() { return 1; }
31 struct __declspec(code_seg("foo_four")) FooTwo : Foo {
32 int baz1() { return 20; }
35 int caller1() {
36 Foo f; return f.bar3();
39 //CHECK: define {{.*}}bar3@Foo{{.*}} section "foo_four"
40 int Foo::bar4() { return 4; }
41 //CHECK: define {{.*}}bar4@Foo{{.*}} section "foo_four"
43 #pragma code_seg("someother")
45 int caller2() {
46 Foo f;
47 Foo *fp = new FooTwo;
48 return f.z.bar5() + f.bar6() + f.bar7() + fp->baz1();
50 // MS Compiler and Docs do not match for nested routines
51 // Doc says: define {{.*}}bar5@Inner@Foo{{.*}} section "foo_four"
52 // Compiler says: define {{.*}}bar5@Inner@Foo{{.*}} section "foo_two"
53 // A bug has been reported: see https://reviews.llvm.org/D22931, the
54 // Microsoft feedback page is no longer available.
55 //CHECK: define {{.*}}bar5@Inner@Foo{{.*}} section "foo_two"
56 //CHECK: define {{.*}}bar6@Foo{{.*}} section "foo_six"
57 //CHECK: define {{.*}}bar7@Foo{{.*}} section "foo_four"
58 // Check that code_seg active at class declaration is not used on member
59 // declared outside class when it is not active.
61 #pragma code_seg(push,"AnotherSeg")
63 struct FooThree {
64 int bar8();
65 int bar9() { return 9; }
68 #pragma code_seg(pop)
71 int FooThree::bar8() {return 0;}
73 int caller3()
75 FooThree f;
76 return f.bar8() + f.bar9();
79 //CHECK: define {{.*}}bar8@FooThree{{.*}} section "someother"
80 //CHECK: define {{.*}}bar9@FooThree{{.*}} section "AnotherSeg"
82 struct NonTrivialCopy {
83 NonTrivialCopy();
84 NonTrivialCopy(const NonTrivialCopy&);
85 ~NonTrivialCopy();
88 // check the section for compiler-generated function with declspec.
90 struct __declspec(code_seg("foo_seven")) FooFour {
91 FooFour() {}
92 int __declspec(code_seg("foo_eight")) bar10(int t) { return t; }
93 NonTrivialCopy f;
96 //CHECK: define {{.*}}0FooFour@@QAE@ABU0@@Z{{.*}} section "foo_seven"
97 // check the section for compiler-generated function with no declspec.
99 struct FooFive {
100 FooFive() {}
101 int __declspec(code_seg("foo_nine")) bar11(int t) { return t; }
102 NonTrivialCopy f;
105 //CHECK: define {{.*}}0FooFive@@QAE@ABU0@@Z{{.*}} section "someother"
107 #pragma code_seg("YetAnother")
108 int caller4()
110 FooFour z1;
111 FooFour z2 = z1;
112 FooFive y1;
113 FooFive y2 = y1;
114 return z2.bar10(0) + y2.bar11(1);
117 //CHECK: define {{.*}}bar10@FooFour{{.*}} section "foo_eight"
118 //CHECK: define {{.*}}bar11@FooFive{{.*}} section "foo_nine"
120 struct FooSix {
121 #pragma code_seg("foo_ten")
122 int bar12() { return 12; }
123 #pragma code_seg("foo_eleven")
124 int bar13() { return 13; }
127 int bar14() { return 14; }
128 //CHECK: define {{.*}}bar14{{.*}} section "foo_eleven"
130 int caller5()
132 FooSix fsix;
133 return fsix.bar12() + fsix.bar13();
136 //CHECK: define {{.*}}bar12@FooSix{{.*}} section "foo_ten"
137 //CHECK: define {{.*}}bar13@FooSix{{.*}} section "foo_eleven"
138 //CHECK: define {{.*}}baz1@FooTwo{{.*}} section "foo_four"