Skip to content

Commit 1f16d28

Browse files
committed
fbc: add tests for "this" member procedure parameter
- test "__thiscall" calling convention - test "cdecl" calling convetion - test "stdcall" calling convetion
1 parent ada09f5 commit 1f16d28

File tree

3 files changed

+429
-0
lines changed

3 files changed

+429
-0
lines changed

tests/cpp/this-cpp.cpp

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
static void * ptr1 = 0;
2+
static void * ptr2 = 0;
3+
static void * ptr3 = 0;
4+
5+
6+
// global getters:
7+
// we can retrieve argument information passed
8+
// by calling the getters
9+
10+
void resetChecks() {
11+
ptr1 = ptr2 = ptr3 = 0;
12+
}
13+
14+
void* getPtr1() {
15+
return ptr1;
16+
}
17+
18+
void* getPtr2() {
19+
return ptr2;
20+
}
21+
22+
void* getPtr3() {
23+
return ptr3;
24+
}
25+
26+
// Default calling convention in c++
27+
28+
class UDT_DEFAULT {
29+
public:
30+
int value;
31+
UDT_DEFAULT();
32+
~UDT_DEFAULT();
33+
void loadpointer1 ( void );
34+
void loadpointer2 ( void* arg );
35+
void loadpointer3 ( void* arg1, void* arg2 );
36+
};
37+
38+
UDT_DEFAULT::UDT_DEFAULT() {
39+
ptr1 = this;
40+
ptr2 = 0;
41+
ptr3 = 0;
42+
}
43+
44+
UDT_DEFAULT::~UDT_DEFAULT() {
45+
ptr1 = this;
46+
ptr2 = 0;
47+
ptr3 = 0;
48+
}
49+
50+
void UDT_DEFAULT::loadpointer1( void ) {
51+
ptr1 = this;
52+
ptr2 = 0;
53+
ptr3 = 0;
54+
}
55+
56+
void UDT_DEFAULT::loadpointer2( void* arg ) {
57+
ptr1 = this;
58+
ptr2 = arg;
59+
ptr3 = 0;
60+
}
61+
62+
void UDT_DEFAULT::loadpointer3( void* arg1, void* arg2 ) {
63+
ptr1 = this;
64+
ptr2 = arg1;
65+
ptr3 = arg2;
66+
}
67+
68+
69+
// thiscall calling convention in c++
70+
// Normally, __attribute__((thiscall)) will generate warnings on
71+
// linux x86_64 so we should pass '-Wno-attributes' to gcc/g++
72+
73+
class UDT_THISCALL {
74+
public:
75+
int value;
76+
UDT_THISCALL() __attribute__((thiscall));
77+
~UDT_THISCALL() __attribute__((thiscall));
78+
void loadpointer1 ( void ) __attribute__((thiscall));
79+
void loadpointer2 ( void* arg ) __attribute__((thiscall));
80+
void loadpointer3 ( void* arg1, void* arg2 ) __attribute__((thiscall));
81+
};
82+
83+
UDT_THISCALL::UDT_THISCALL() {
84+
ptr1 = this;
85+
ptr2 = 0;
86+
ptr3 = 0;
87+
}
88+
89+
UDT_THISCALL::~UDT_THISCALL() {
90+
ptr1 = this;
91+
ptr2 = 0;
92+
ptr3 = 0;
93+
}
94+
95+
void UDT_THISCALL::loadpointer1( void ) {
96+
ptr1 = this;
97+
ptr2 = 0;
98+
ptr3 = 0;
99+
}
100+
101+
void UDT_THISCALL::loadpointer2( void* arg ) {
102+
ptr1 = this;
103+
ptr2 = arg;
104+
ptr3 = 0;
105+
}
106+
107+
void UDT_THISCALL::loadpointer3( void* arg1, void* arg2 ) {
108+
ptr1 = this;
109+
ptr2 = arg1;
110+
ptr3 = arg2;
111+
}
112+
113+
// cdecl calling convention in c++
114+
115+
class UDT_CDECL {
116+
public:
117+
int value;
118+
UDT_CDECL() __attribute__((cdecl));
119+
~UDT_CDECL() __attribute__((cdecl));
120+
void loadpointer1 ( void ) __attribute__((cdecl));
121+
void loadpointer2 ( void* arg ) __attribute__((cdecl));
122+
void loadpointer3 ( void* arg1, void* arg2 ) __attribute__((cdecl));
123+
};
124+
125+
UDT_CDECL::UDT_CDECL() {
126+
ptr1 = this;
127+
ptr2 = 0;
128+
ptr3 = 0;
129+
}
130+
131+
UDT_CDECL::~UDT_CDECL() {
132+
ptr1 = this;
133+
ptr2 = 0;
134+
ptr3 = 0;
135+
}
136+
137+
void UDT_CDECL::loadpointer1( void ) {
138+
ptr1 = this;
139+
ptr2 = 0;
140+
ptr3 = 0;
141+
}
142+
143+
void UDT_CDECL::loadpointer2( void* arg ) {
144+
ptr1 = this;
145+
ptr2 = arg;
146+
ptr3 = 0;
147+
}
148+
149+
void UDT_CDECL::loadpointer3( void* arg1, void* arg2 ) {
150+
ptr1 = this;
151+
ptr2 = arg1;
152+
ptr3 = arg2;
153+
}
154+
155+
// stdcall calling convention in c++
156+
157+
class UDT_STDCALL {
158+
public:
159+
int value;
160+
UDT_STDCALL() __attribute__((stdcall));
161+
162+
// mingw/gcc appears to have a bug that generates wrong
163+
// mangling "__ZN11UDT_STDCALLD1Ev@8" so just use cdecl
164+
// here instead
165+
~UDT_STDCALL() __attribute__((cdecl));
166+
167+
void loadpointer1 ( void ) __attribute__((stdcall));
168+
void loadpointer2 ( void* arg ) __attribute__((stdcall));
169+
void loadpointer3 ( void* arg1, void* arg2 ) __attribute__((stdcall));
170+
};
171+
172+
UDT_STDCALL::UDT_STDCALL() {
173+
ptr1 = this;
174+
ptr2 = 0;
175+
ptr3 = 0;
176+
}
177+
178+
UDT_STDCALL::~UDT_STDCALL() {
179+
ptr1 = this;
180+
ptr2 = 0;
181+
ptr3 = 0;
182+
}
183+
184+
void UDT_STDCALL::loadpointer1( void ) {
185+
ptr1 = this;
186+
ptr2 = 0;
187+
ptr3 = 0;
188+
}
189+
190+
void UDT_STDCALL::loadpointer2( void* arg ) {
191+
ptr1 = this;
192+
ptr2 = arg;
193+
ptr3 = 0;
194+
}
195+
196+
void UDT_STDCALL::loadpointer3( void* arg1, void* arg2 ) {
197+
ptr1 = this;
198+
ptr2 = arg1;
199+
ptr3 = arg2;
200+
}

0 commit comments

Comments
 (0)