-
-
Notifications
You must be signed in to change notification settings - Fork 594
/
cppb.cpp
726 lines (576 loc) · 12.2 KB
/
cppb.cpp
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
#include <stdio.h>
#include <assert.h>
#include <exception>
/**************************************/
int foo(int i, int j, int k);
int foob(int i, int j, int k)
{
printf("i = %d\n", i);
printf("j = %d\n", j);
printf("k = %d\n", k);
assert(i == 1);
assert(j == 2);
assert(k == 3);
foo(i, j, k);
return 7;
}
/**************************************/
class D *dthis;
class D
{
public:
virtual int bar(int i, int j, int k)
{
printf("this = %p\n", this);
assert(this == dthis);
printf("D.bar: i = %d\n", i);
printf("D.bar: j = %d\n", j);
printf("D.bar: k = %d\n", k);
assert(i == 9);
assert(j == 10);
assert(k == 11);
return 8;
}
};
D* getD()
{
D *d = new D();
dthis = d;
return d;
}
/**************************************/
class E
{
public:
virtual int bar(int i, int j, int k);
};
int callE(E *e)
{
return e->bar(11,12,13);
}
/**************************************/
void foo4(char *p)
{
}
/**************************************/
struct foo5 { int i; int j; void *p; };
class bar5
{
public:
virtual foo5 getFoo(int i){
printf("This = %p\n", this);
foo5 f;
f.i = 1;
f.j = 2 + i;
f.p = (void*)this;
return f;
}
};
bar5* newBar()
{
bar5* b = new bar5();
printf("bar = %p\n", b);
return b;
}
/**************************************/
struct A11802;
struct B11802;
class C11802
{
public:
virtual void fun(A11802 *);
virtual void fun(B11802 *);
};
class D11802 : public C11802
{
public:
void fun(A11802 *);
void fun(B11802 *);
};
void test11802x(D11802 *c)
{
c->fun((A11802 *)0);
c->fun((B11802 *)0);
}
/**************************************/
typedef struct
{
int i;
double d;
} S6;
union S6_2
{
int i;
double d;
};
enum S6_3
{
A, B
};
S6 foo6(void)
{
S6 s;
s.i = 42;
s.d = 2.5;
return s;
}
S6_2 foo6_2(void)
{
S6_2 s;
s.i = 42;
return s;
}
S6_3 foo6_3(void)
{
S6_3 s = A;
return s;
}
extern "C" { int foosize6()
{
return sizeof(S6);
}
}
/**************************************/
typedef struct
{
int i;
long long d;
} S7;
extern "C" { int foo7()
{
return sizeof(S7);
}
}
/**************************************/
struct S13955a
{
float a;
double b;
};
struct S13955b
{
double a;
float b;
};
struct S13955c
{
float a;
float b;
};
struct S13955d
{
double a;
double b;
};
void check13955(S13955a a, S13955b b, S13955c c, S13955d d);
void func13955(S13955a a, S13955b b, S13955c c, S13955d d)
{
check13955(a, b, c, d);
}
/**************************************/
struct Struct10071
{
void *p;
long double r;
};
size_t offset10071()
{
Struct10071 s;
return (char *)&s.r - (char *)&s;
}
/**************************************/
void foo8(const char *p)
{
}
/**************************************/
// 4059
struct elem9 { };
void foobar9(elem9*, elem9*) { }
/**************************************/
// 5148
void foo10(const char*, const char*) { }
void foo10(const int, const int) { }
void foo10(const char, const char) { }
void foo10(bool, bool) { }
struct MyStructType { };
void foo10(const MyStructType s, const MyStructType t) { }
enum MyEnumType { onemember };
void foo10(const MyEnumType s, const MyEnumType t) { }
/**************************************/
namespace N11 { namespace M { void bar11() { } } }
namespace A11 { namespace B { namespace C { void bar() { } } } }
/**************************************/
void myvprintfx(const char* format, va_list);
void myvprintf(const char* format, va_list va)
{
myvprintfx(format, va);
}
/**************************************/
class C13161
{
public:
virtual void dummyfunc() {}
long long val_5;
unsigned val_9;
};
class Test : public C13161
{
public:
unsigned val_0;
long long val_1;
};
size_t getoffset13161()
{
Test s;
return (char *)&s.val_0 - (char *)&s;
}
class C13161a
{
public:
virtual void dummyfunc() {}
long double val_5;
unsigned val_9;
};
class Testa : public C13161a
{
public:
bool val_0;
};
size_t getoffset13161a()
{
Testa s;
return (char *)&s.val_0 - (char *)&s;
}
/****************************************************/
#if __linux__ || __APPLE__ || __FreeBSD__
#include <memory>
#include <vector>
#include <string>
#if __linux__
template struct std::allocator<int>;
template struct std::vector<int>;
void foo15()
{
std::allocator<int>* p;
p->deallocate(0, 0);
}
#endif
// _Z5foo14PSt6vectorIiSaIiEE
void foo14(std::vector<int, std::allocator<int> > *p) { }
void foo14a(std::basic_string<char> *p) { }
void foo14b(std::basic_string<int> *p) { }
void foo14c(std::basic_istream<char> *p) { }
void foo14d(std::basic_ostream<char> *p) { }
void foo14e(std::basic_iostream<char> *p) { }
void foo14f(std::char_traits<char>* x, std::basic_string<char> *p, std::basic_string<char> *q) { }
#endif
/**************************************/
struct S13956
{
};
void check13956(S13956 arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6);
void func13956(S13956 arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6)
{
check13956(arg0, arg1, arg2, arg3, arg4, arg5, arg6);
}
/**************************************/
wchar_t f13289_cpp_wchar_t(wchar_t ch)
{
if (ch <= L'z' && ch >= L'a')
{
return ch - (L'a' - L'A');
}
else
{
return ch;
}
}
#if __linux__ || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun
unsigned short f13289_d_wchar(unsigned short ch);
wchar_t f13289_d_dchar(wchar_t ch);
#elif _WIN32
wchar_t f13289_d_wchar(wchar_t ch);
unsigned int f13289_d_dchar(unsigned int ch);
#endif
bool f13289_cpp_test()
{
#if __linux__ || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun
if (!(f13289_d_wchar((unsigned short)'c') == (unsigned short)'C')) return false;
if (!(f13289_d_wchar((unsigned short)'D') == (unsigned short)'D')) return false;
if (!(f13289_d_dchar(L'e') == L'E')) return false;
if (!(f13289_d_dchar(L'F') == L'F')) return false;
return true;
#elif _WIN32
if (!(f13289_d_wchar(L'c') == L'C')) return false;
if (!(f13289_d_wchar(L'D') == L'D')) return false;
if (!(f13289_d_dchar((unsigned int)'e') == (unsigned int)'E')) return false;
if (!(f13289_d_dchar((unsigned int)'F') == (unsigned int)'F')) return false;
return true;
#else
return false;
#endif
}
/******************************************/
long double testld(long double ld)
{
assert(ld == 5);
return ld + 1;
}
long testl(long lng)
{
assert(lng == 5);
return lng + sizeof(long);
}
unsigned long testul(unsigned long ul)
{
assert(ul == 5);
return ul + sizeof(unsigned long);
}
/******************************************/
struct S13707
{
void* a;
void* b;
S13707(void *a, void* b)
{
this->a = a;
this->b = b;
}
};
S13707 func13707()
{
S13707 pt(NULL, NULL);
return pt;
}
/******************************************/
template <int x> struct S13932
{
int member;
};
void func13932(S13932<-1> s) {}
/******************************************/
namespace N13337 {
namespace M13337 {
struct S13337 { };
void foo13337(S13337 s) { }
}
}
/****************************************/
// 14195
template <typename T>
struct Delegate1 {};
template <typename R1>
struct Delegate1 < R1() > {};
template <typename T1, typename T2>
struct Delegate2 {};
template < typename R1, typename T1, typename T2, typename R2, typename T3, typename T4 >
struct Delegate2<R1(T1, T2), R2(T3, T4)> {};
void test14195a(Delegate1<void()> func) {}
void test14195b(Delegate2<int(float, double), int(float, double)> func) {}
/******************************************/
// 14200
void test14200a(int a) {};
void test14200b(float a, int b, double c) {};
/******************************************/
// 14956
namespace std {
namespace N14956 {
struct S14956 { };
}
}
void test14956(std::N14956::S14956 s) { }
/******************************************/
// check order of overloads in vtable
class Statement;
class ErrorStatement;
class PeelStatement;
class ExpStatement;
class DtorExpStatement;
class Visitor
{
public:
virtual int visit(Statement*) { return 1; }
virtual int visit(ErrorStatement*) { return 2; }
virtual int visit(PeelStatement*) { return 3; }
};
class Visitor2 : public Visitor
{
public:
virtual int visit2(ExpStatement*) { return 4; }
virtual int visit2(DtorExpStatement*) { return 5; }
};
bool testVtableCpp(Visitor2* sv)
{
if (sv->visit((Statement*)0) != 1) return false;
if (sv->visit((ErrorStatement*)0) != 2) return false;
if (sv->visit((PeelStatement*)0) != 3) return false;
if (sv->visit2((ExpStatement*)0) != 4) return false;
if (sv->visit2((DtorExpStatement*)0) != 5) return false;
return true;
}
Visitor2 inst;
Visitor2* getVisitor2()
{
return &inst;
}
/******************************************/
// issues detected by fuzzer
#if _LP64
#define longlong long
#else
#define longlong long long
#endif
void fuzz1_checkValues(longlong arg10, longlong arg11, bool arg12);
void fuzz1_cppvararg(longlong arg10, longlong arg11, bool arg12)
{
fuzz1_checkValues(arg10, arg11, arg12);
}
void fuzz2_checkValues(unsigned longlong arg10, unsigned longlong arg11, bool arg12);
void fuzz2_cppvararg(unsigned longlong arg10, unsigned longlong arg11, bool arg12)
{
fuzz2_checkValues(arg10, arg11, arg12);
}
#if __linux__ || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun
#define wchar unsigned short
#elif _WIN32
#define wchar wchar_t
#endif
void fuzz3_checkValues(wchar arg10, wchar arg11, bool arg12);
void fuzz3_cppvararg(wchar arg10, wchar arg11, bool arg12)
{
fuzz3_checkValues(arg10, arg11, arg12);
}
/******************************************/
void throwit()
{
#if _WIN32
#else
std::exception se;
throw se;
#endif
}
/******************************************/
#if linux
#include <stdexcept>
void throwle()
{
std::logic_error le("test");
throw le;
}
#endif
/******************************************/
// 15579
/******************************************/
// 15579
class Base
{
public:
//virtual ~Base() {}
virtual void base();
unsigned char x;
};
class Interface
{
public:
virtual int MethodCPP() = 0;
virtual int MethodD() = 0;
};
class Derived : public Base, public Interface
{
public:
Derived();
short y;
int MethodCPP();
#if _WIN32 || _WIN64
int MethodD();
virtual int Method();
#else
int MethodD() { return 3; } // need def or vtbl[] is not generated
virtual int Method() { return 6; } // need def or vtbl[] is not generated
#endif
};
void Base::base() { }
int Derived::MethodCPP() {
printf("Derived::MethodCPP() this = %p, x = %d, y = %d\n", this, x, y);
assert(x == 4 || x == 7);
assert(y == 5 || y == 8);
return 30;
}
Derived::Derived() { }
Derived *cppfoo(Derived *d)
{
printf("cppfoo(): d = %p\n", d);
assert(d->x == 4);
assert(d->y == 5);
assert(d->MethodD() == 3);
assert(d->MethodCPP() == 30);
assert(d->Method() == 6);
d = new Derived();
d->x = 7;
d->y = 8;
assert(d->MethodD() == 3);
assert(d->MethodCPP() == 30);
assert(d->Method() == 6);
printf("d1 = %p\n", d);
return d;
}
Interface *cppfooi(Interface *i)
{
printf("cppfooi(): i = %p\n", i);
assert(i->MethodD() == 3);
assert(i->MethodCPP() == 30);
Derived *d = new Derived();
d->x = 7;
d->y = 8;
printf("d = %p, i = %p\n", d, (Interface *)d);
return d;
}
/******************************************/
// 15610
class Base2
{
public:
int i;
virtual void baser() { }
};
class Interface2
{
public:
virtual void f() = 0;
};
class Derived2 : public Base2, public Interface2
{
public:
void f();
};
void Derived2::f()
{
printf("Derived2::f() this = %p i = %d\n", this, i);
assert(i == 3);
}
/******************************************/
// 15372
template <typename T>
int foo15372(int value)
{
return value;
}
void test15372b()
{
int t = foo15372<int>(1);
}
/****************************************/
// 15802
template <typename T>
class Foo15802
{
public:
static int boo(int value)
{
return value;
}
};
void test15802b()
{
int t = Foo15802<int>::boo(1);
}