Skip to content

Commit a3c0c9a

Browse files
author
Erich Keane
committed
Add lit tests forgotten for R332470
I forgot to svn-add the lit tests for R332470. Added here! llvm-svn: 332492
1 parent c39e85d commit a3c0c9a

File tree

6 files changed

+593
-0
lines changed

6 files changed

+593
-0
lines changed

clang/test/CodeGenCXX/code_seg1.cpp

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
// RUN: %clang_cc1 -emit-llvm -triple i686-pc-win32 -fms-extensions -verify -o - %s | FileCheck %s
2+
// expected-no-diagnostics
3+
4+
// Simple case
5+
6+
int __declspec(code_seg("foo_one")) bar_one() { return 1; }
7+
//CHECK: define {{.*}}bar_one{{.*}} section "foo_one"
8+
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"
13+
14+
// Check that attribute on one function doesn't affect another
15+
int another1() { return 1001; }
16+
//CHECK: define {{.*}}another1{{.*}} section "foo_two"
17+
18+
// Member functions
19+
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; }
29+
};
30+
31+
struct __declspec(code_seg("foo_four")) FooTwo : Foo {
32+
int baz1() { return 20; }
33+
};
34+
35+
int caller1() {
36+
Foo f; return f.bar3();
37+
}
38+
39+
//CHECK: define {{.*}}bar3@Foo{{.*}} section "foo_four"
40+
int Foo::bar4() { return 4; }
41+
//CHECK: define {{.*}}bar4@Foo{{.*}} section "foo_four"
42+
43+
#pragma code_seg("someother")
44+
45+
int caller2() {
46+
Foo f;
47+
Foo *fp = new FooTwo;
48+
return f.z.bar5() + f.bar6() + f.bar7() + fp->baz1();
49+
}
50+
// TBD: 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+
//CHECK: define {{.*}}bar6@Foo{{.*}} section "foo_six"
54+
//CHECK: define {{.*}}bar7@Foo{{.*}} section "foo_four"
55+
// Check that code_seg active at class declaration is not used on member
56+
// declared outside class when it is not active.
57+
58+
#pragma code_seg(push,"AnotherSeg")
59+
60+
struct FooThree {
61+
int bar8();
62+
int bar9() { return 9; }
63+
};
64+
65+
#pragma code_seg(pop)
66+
67+
68+
int FooThree::bar8() {return 0;}
69+
70+
int caller3()
71+
{
72+
FooThree f;
73+
return f.bar8() + f.bar9();
74+
}
75+
76+
//CHECK: define {{.*}}bar8@FooThree{{.*}} section "someother"
77+
//CHECK: define {{.*}}bar9@FooThree{{.*}} section "AnotherSeg"
78+
79+
struct NonTrivialCopy {
80+
NonTrivialCopy();
81+
NonTrivialCopy(const NonTrivialCopy&);
82+
~NonTrivialCopy();
83+
};
84+
85+
// check the section for compiler-generated function with declspec.
86+
87+
struct __declspec(code_seg("foo_seven")) FooFour {
88+
FooFour() {}
89+
int __declspec(code_seg("foo_eight")) bar10(int t) { return t; }
90+
NonTrivialCopy f;
91+
};
92+
93+
//CHECK: define {{.*}}0FooFour@@QAE@ABU0@@Z{{.*}} section "foo_seven"
94+
// check the section for compiler-generated function with no declspec.
95+
96+
struct FooFive {
97+
FooFive() {}
98+
int __declspec(code_seg("foo_nine")) bar11(int t) { return t; }
99+
NonTrivialCopy f;
100+
};
101+
102+
//CHECK: define {{.*}}0FooFive@@QAE@ABU0@@Z{{.*}} section "someother"
103+
104+
#pragma code_seg("YetAnother")
105+
int caller4()
106+
{
107+
FooFour z1;
108+
FooFour z2 = z1;
109+
FooFive y1;
110+
FooFive y2 = y1;
111+
return z2.bar10(0) + y2.bar11(1);
112+
}
113+
114+
//CHECK: define {{.*}}bar10@FooFour{{.*}} section "foo_eight"
115+
//CHECK: define {{.*}}bar11@FooFive{{.*}} section "foo_nine"
116+
117+
struct FooSix {
118+
#pragma code_seg("foo_ten")
119+
int bar12() { return 12; }
120+
#pragma code_seg("foo_eleven")
121+
int bar13() { return 13; }
122+
};
123+
124+
int bar14() { return 14; }
125+
//CHECK: define {{.*}}bar14{{.*}} section "foo_eleven"
126+
127+
int caller5()
128+
{
129+
FooSix fsix;
130+
return fsix.bar12() + fsix.bar13();
131+
}
132+
133+
//CHECK: define {{.*}}bar12@FooSix{{.*}} section "foo_ten"
134+
//CHECK: define {{.*}}bar13@FooSix{{.*}} section "foo_eleven"
135+
//CHECK: define {{.*}}baz1@FooTwo{{.*}} section "foo_four"

clang/test/CodeGenCXX/code_seg2.cpp

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
// RUN: %clang_cc1 -emit-llvm -triple i686-pc-win32 -std=c++11 -fms-extensions -verify -o - %s | FileCheck %s
2+
// expected-no-diagnostics
3+
4+
// Class member templates
5+
6+
#pragma code_seg(push, "something")
7+
8+
template <typename T>
9+
struct __declspec(code_seg("foo_one")) ClassOne {
10+
int bar1(T t) { return int(t); }
11+
int bar2(T t);
12+
int bar3(T t);
13+
};
14+
15+
template <typename T>
16+
int ClassOne<T>::bar2(T t) {
17+
return int(t);
18+
}
19+
20+
int caller1() {
21+
ClassOne<int> coi;
22+
return coi.bar1(6) + coi.bar2(3);
23+
}
24+
25+
//CHECK: define {{.*}}bar1@?$ClassOne{{.*}} section "foo_one"
26+
//CHECK: define {{.*}}bar2@?$ClassOne{{.*}} section "foo_one"
27+
28+
29+
template <typename T>
30+
struct ClassTwo {
31+
int bar11(T t) { return int(t); }
32+
int bar22(T t);
33+
int bar33(T t);
34+
};
35+
36+
#pragma code_seg("newone")
37+
38+
template <typename T>
39+
int ClassTwo<T>::bar22(T t) {
40+
return int(t);
41+
}
42+
43+
#pragma code_seg("someother")
44+
45+
template <typename T>
46+
int ClassTwo<T>::bar33(T t) {
47+
return int(t);
48+
}
49+
50+
#pragma code_seg("yetanother")
51+
52+
int caller2() {
53+
ClassTwo<int> coi;
54+
return coi.bar11(6) + coi.bar22(3) + coi.bar33(44);
55+
}
56+
57+
//CHECK: define {{.*}}bar11@?$ClassTwo{{.*}} section "something"
58+
//CHECK: define {{.*}}bar22@?$ClassTwo{{.*}} section "newone"
59+
//CHECK: define {{.*}}bar33@?$ClassTwo{{.*}} section "someother"
60+
61+
template<>
62+
struct ClassOne<double>
63+
{
64+
int bar44(double d) { return 1; }
65+
};
66+
template<>
67+
struct __declspec(code_seg("foo_three")) ClassOne<long>
68+
{
69+
int bar55(long d) { return 1; }
70+
};
71+
72+
#pragma code_seg("onemore")
73+
int caller3() {
74+
ClassOne<double> d;
75+
ClassOne<long> l;
76+
return d.bar44(1.0)+l.bar55(1);
77+
}
78+
79+
//CHECK: define {{.*}}bar44{{.*}} section "yetanother"
80+
//CHECK: define {{.*}}bar55{{.*}} section "foo_three"
81+
82+
83+
// Function templates
84+
template <typename T>
85+
int __declspec(code_seg("foo_four")) bar66(T t) { return int(t); }
86+
87+
// specializations do not take the segment from primary
88+
template<>
89+
int bar66(int i) { return 0; }
90+
91+
#pragma code_seg(pop)
92+
93+
template<>
94+
int bar66(char c) { return 0; }
95+
96+
struct A1 {int i;};
97+
template<>
98+
int __declspec(code_seg("foo_five")) bar66(A1 a) { return a.i; }
99+
100+
int caller4()
101+
{
102+
// but instantiations do use the section from the primary
103+
return bar66(0) + bar66(1.0) + bar66('c');
104+
}
105+
//CHECK: define {{.*}}bar66@H{{.*}} section "onemore"
106+
//CHECK-NOT: define {{.*}}bar66@D{{.*}} section
107+
//CHECK: define {{.*}}bar66@UA1{{.*}} section "foo_five"
108+
//CHECK: define {{.*}}bar66@N{{.*}} section "foo_four"
109+
110+
111+
#pragma code_seg("another")
112+
// Member functions
113+
struct __declspec(code_seg("foo_four")) Foo {
114+
int bar3() {return 0;}
115+
__declspec(code_seg("foo_lala")) int bar4() {return 0;} }; int caller() {Foo f; return f.bar3() + f.bar4(); }
116+
117+
//CHECK: define {{.*}}bar3@Foo{{.*}} section "foo_four"
118+
//CHECK: define {{.*}}bar4@Foo{{.*}} section "foo_lala"
119+
120+
// Lambdas
121+
#pragma code_seg("something")
122+
123+
int __declspec(code_seg("foo")) bar1()
124+
{
125+
int lala = 4;
126+
auto l = [=](int i) { return i+4; };
127+
return l(-4);
128+
}
129+
130+
//CHECK: define {{.*}}bar1{{.*}} section "foo"
131+
//CHECK: define {{.*}}lambda{{.*}}bar1{{.*}} section "something"
132+
133+
double __declspec(code_seg("foo")) bar2()
134+
{
135+
double lala = 4.0;
136+
auto l = [=](double d) __declspec(code_seg("another")) { return d+4.0; };
137+
return l(4.0);
138+
}
139+
140+
//CHECK: define {{.*}}bar2{{.*}} section "foo"
141+
//CHECK: define {{.*}}lambda{{.*}}bar2{{.*}} section "another"

clang/test/CodeGenCXX/code_seg3.cpp

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// RUN: %clang_cc1 -emit-llvm -triple i686-pc-win32 -fms-extensions -verify -o - %s | FileCheck %s
2+
// expected-no-diagnostics
3+
// The Microsoft document says: "When this attribute is applied to a class,
4+
// all member functions of the class and nested classes - this includes
5+
// compiler-generated special member functions - are put in the specified segment."
6+
// But the MS compiler does not always follow that. A bug has been reported:
7+
// see https://reviews.llvm.org/D22931, the Microsoft feedback page is no
8+
// longer available.
9+
// The MS compiler will apply a declspec from the parent class if there is no
10+
// #pragma code_seg active at the class definition. If there is an active
11+
// code_seg that is used instead.
12+
13+
// No active code_seg
14+
15+
struct __declspec(code_seg("foo_outer")) Foo1 {
16+
struct Inner {
17+
void bar1();
18+
static void bar2();
19+
};
20+
};
21+
void Foo1::Inner::bar1() {}
22+
void Foo1::Inner::bar2() {}
23+
24+
//CHECK: define {{.*}}bar1@Inner@Foo1{{.*}} section "foo_outer"
25+
//CHECK: define {{.*}}bar2@Inner@Foo1{{.*}} section "foo_outer"
26+
27+
struct __declspec(code_seg("foo_outer")) Foo2 {
28+
struct __declspec(code_seg("foo_inner")) Inner {
29+
void bar1();
30+
static void bar2();
31+
};
32+
};
33+
void Foo2::Inner::bar1() {}
34+
void Foo2::Inner::bar2() {}
35+
36+
//CHECK: define {{.*}}bar1@Inner@Foo2{{.*}} section "foo_inner"
37+
//CHECK: define {{.*}}bar2@Inner@Foo2{{.*}} section "foo_inner"
38+
39+
#pragma code_seg(push, "otherseg")
40+
struct __declspec(code_seg("foo_outer")) Foo3 {
41+
struct Inner {
42+
void bar1();
43+
static void bar2();
44+
};
45+
};
46+
void Foo3::Inner::bar1() {}
47+
void Foo3::Inner::bar2() {}
48+
49+
//CHECK: define {{.*}}bar1@Inner@Foo3{{.*}} section "otherseg"
50+
//CHECK: define {{.*}}bar2@Inner@Foo3{{.*}} section "otherseg"
51+
52+
struct __declspec(code_seg("foo_outer")) Foo4 {
53+
struct __declspec(code_seg("foo_inner")) Inner {
54+
void bar1();
55+
static void bar2();
56+
};
57+
};
58+
void Foo4::Inner::bar1() {}
59+
void Foo4::Inner::bar2() {}
60+
61+
//CHECK: define {{.*}}bar1@Inner@Foo4{{.*}} section "foo_inner"
62+
//CHECK: define {{.*}}bar2@Inner@Foo4{{.*}} section "foo_inner"
63+
64+
#pragma code_seg(pop)
65+
// Back to no active pragma
66+
struct __declspec(code_seg("foo_outer")) Foo5 {
67+
struct Inner {
68+
void bar1();
69+
static void bar2();
70+
struct __declspec(code_seg("inner1_seg")) Inner1 {
71+
struct Inner2 {
72+
void bar1();
73+
static void bar2();
74+
};
75+
};
76+
};
77+
};
78+
void Foo5::Inner::bar1() {}
79+
void Foo5::Inner::bar2() {}
80+
void Foo5::Inner::Inner1::Inner2::bar1() {}
81+
void Foo5::Inner::Inner1::Inner2::bar2() {}
82+
83+
//CHECK: define {{.*}}bar1@Inner@Foo5{{.*}} section "foo_outer"
84+
//CHECK: define {{.*}}bar2@Inner@Foo5{{.*}} section "foo_outer"
85+
//CHECK: define {{.*}}bar1@Inner2@Inner1@Inner@Foo5{{.*}} section "inner1_seg"
86+
//CHECK: define {{.*}}bar2@Inner2@Inner1@Inner@Foo5{{.*}} section "inner1_seg"

clang/test/CodeGenCXX/code_seg4.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: %clang_cc1 -fsyntax-only -verify -fms-extensions %s -triple x86_64-pc-win32
2+
// expected-no-diagnostics
3+
4+
// Non-Member Function Overloading is involved
5+
6+
int __declspec(code_seg("foo_one")) bar_one(int) { return 1; }
7+
//CHECK: define {{.*}}bar_one{{.*}} section "foo_one"
8+
int __declspec(code_seg("foo_two")) bar_one(int,float) { return 11; }
9+
//CHECK: define {{.*}}bar_one{{.*}} section "foo_two"
10+
int __declspec(code_seg("foo_three")) bar_one(float) { return 12; }
11+
//CHECK: define {{.*}}bar_one{{.*}} section "foo_three"
12+
13+
// virtual function overloading is involved
14+
15+
struct __declspec(code_seg("my_one")) Base3 {
16+
virtual int barA(int) { return 1; }
17+
virtual int barA(int,float) { return 2; }
18+
virtual int barA(float) { return 3; }
19+
20+
virtual void __declspec(code_seg("my_two")) barB(int) { }
21+
virtual void __declspec(code_seg("my_three")) barB(float) { }
22+
virtual void __declspec(code_seg("my_four")) barB(int, float) { }
23+
24+
};
25+
26+
//CHECK: define {{.*}}barA@Base3{{.*}} section "my_one"
27+
//CHECK: define {{.*}}barA@Base3{{.*}} section "my_one"
28+
//CHECK: define {{.*}}barA@Base3{{.*}} section "my_one"
29+
//CHECK: define {{.*}}barB@Base3{{.*}} section "my_two"
30+
//CHECK: define {{.*}}barB@Base3{{.*}} section "my_three"
31+
//CHECK: define {{.*}}barB@Base3{{.*}} section "my_four"

0 commit comments

Comments
 (0)