-
-
Notifications
You must be signed in to change notification settings - Fork 594
/
testcstuff2.c
544 lines (419 loc) · 11 KB
/
testcstuff2.c
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
// check bugs in the expression parser
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=21931
typedef long int T21931a;
typedef T21931a T21931b;
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=21933
struct S21933 { void *opaque; };
int test21933(struct S21933 *);
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=21934
typedef int T21934 asm("realtype");
int init21934 asm("realsym") = 1;
int var21934 asm("realvsym");
int fun21934() asm("realfun");
void test21934()
{
typedef int asmreg;
register asmreg r1 asm("r1");
// asm ignored by C compiler, should be disallowed?
asmreg r2 asm("r2");
register asmreg r3 asm("r3") = 3;
// asm ignored by C compiler, should be disallowed?
asmreg r4 asm("r4") = 4;
}
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=21937
__attribute__(()) int test21937a();
int test21937b() __attribute__(( , nothrow, hot, aligned(2), ));
int test21937c() __attribute__((nothrow , leaf)) __attribute__((noreturn));
__attribute__((noinline))
void test21937d()
{
typedef int attr_var_t;
attr_var_t attr_local __attribute__((unused));
}
__attribute__((aligned)) int test21937e;
int test21937f __attribute__((aligned));
struct __attribute__((packed)) S21937a
{
__attribute__((deprecated("msg"))) char c;
int i __attribute__((deprecated));
};
struct S21937b
{
__attribute__((deprecated("msg"))) char c;
int i __attribute__((deprecated));
} __attribute__((packed));
enum __attribute__((aligned)) E21937a
{
E21937a_A,
};
enum E21937b
{
E21937b_A,
} __attribute__((aligned));
typedef int T21937a __attribute__((unused));
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=21945
typedef struct {
long var;
} S21945;
S21945 test21945a;
typedef enum {
E21945_member,
} E21945;
E21945 test21945b;
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=21948
void test21948()
{
typedef int myint;
typedef struct { int f; } mystruct;
myint var1;
myint var2 = 12;
mystruct var3;
// Uncomment when bug fixed https://issues.dlang.org/show_bug.cgi?id=21979
//mystruct var4 = { 34 };
}
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=21963
union U21963
{
int iv;
float fv;
};
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=21965
struct { int var; };
typedef struct { int var; };
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=21967
const int test21967a(void);
const int *test21967b(void);
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=21968
struct S21968
{
struct inner *data[16];
};
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=21970
extern int test21970a;
extern char *test21970b;
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=21973
struct S21973
{
int field;
struct
{
int nested;
};
};
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=21977
int test21977a;
_Thread_local int test21977b;
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=21982
struct S21982 { int field; };
struct S21982 test21982;
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=21992
void test21992(int var)
{
var = (var) & 1234;
var = (var) * 1234;
var = (var) + 1234;
var = (var) - 1234;
}
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22028
struct S22028
{
struct nested
{
int field;
};
const int cfield;
_Static_assert(1 == 1, "ok");
};
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22060
struct S22060;
typedef struct S22060 T22060a;
struct S22060;
typedef struct S22060 T22060b;
struct S22060;
struct S22060
{
int _flags;
};
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22061
union S22061
{
int field;
};
typedef union S22061 S22061;
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22063
typedef struct S22063_t
{
int field;
} S22063;
void test22063()
{
// BUG: no definition of struct
//struct S22063_t v1 = { 0 };
// BUG: cannot implicitly cast from integer to pointer.
struct S22063_t *v2 = (struct S22063_t *)0;
S22063 v3 = { 0 };
S22063 *v4 = (S22063 *)0;
}
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22066
void test22066()
{
int var = 0;
(var)++;
}
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22067
void test22067()
{
union U {
int value;
char *ptr;
char array[4];
} var;
union U *pvar = &var;
var.value = 0xabcdef;
var.array[0]++;
(*var.ptr)--;
++(*pvar).value;
--(*pvar).array[3];
}
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22073
struct S22073a { int field; };
struct S22073b { const char *field; };
_Static_assert((struct S22073a){6789}.field == 6789, "ok");
_Static_assert((struct S22073b){"zxcv"}.field[2] == 'c', "ok");
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22079
struct S22079
{
int a, b, c;
};
_Static_assert(sizeof(struct S22079){1,2,3} == sizeof(int)*3, "ok");
_Static_assert(sizeof(struct S22079){1,2,3}.a == sizeof(int), "ok");
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22080
int F22080(const char *);
int test22080()
{
int (*fun)(const char *) = &F22080;
}
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22086
typedef union U22086 U22086;
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22088
void test22088()
{
int *p;
int i;
p = i;
i = p;
void *pv;
p = pv;
pv = p;
long long ll;
ll = i;
i = ll;
char c;
c = i;
i = c;
float f;
f = i;
i = f;
double d;
d = i;
i = d;
long double ld;
ld = i;
i = ld;
c = ld;
}
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22102
void fun22102(int var);
typedef int int22102;
void test22102()
{
int22102(var);
fun22102(var);
}
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22103
void test22103a(char *const argv[restrict]);
void test22103b(char *const argv[restrict 4]);
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22106
typedef struct S22106
{
int field;
} S22106_t;
struct T22106
{
struct S22106 f1;
S22106_t f2;
};
void testS22106()
{
struct S22106 v1;
S22106_t v2;
}
int S22106; // not a redeclaration of 'struct S22106'
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22160
typedef struct testcstuff2 testcstuff2;
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22182
int test22182a(int x)
{
return (int)(x);
}
typedef struct S22182 { int x; } S22182;
int test22182b(S22182* b)
{
return ((S22182*)(b))->x;
}
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22196
__attribute__((static, unsigned, long, const, extern, register, typedef, short,
inline, _Noreturn, volatile, signed, auto, restrict, _Complex,
_Thread_local, int, char, float, double, void, _Bool, _Atomic))
int test22196();
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22245
struct S22245 { int i; };
int test22245()
{
struct S22245 s;
return sizeof(s.i);
}
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22262
void test22262(unsigned char *buf)
{
if (buf == 0)
return;
if (0 == buf)
return;
if (buf == 1)
return;
if (2 == buf)
return;
}
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22264
typedef int T22264;
unsigned long test22264(crc, buf, len)
unsigned long crc;
const T22264 *buf;
T22264 len;
{
return len;
}
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22274
void test22274(compr, comprLen, uncompr, uncomprLen)
unsigned *compr, *uncompr;
signed comprLen, uncomprLen;
{
}
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22375
typedef struct S22375S
{
unsigned short a, b, c, d;
} S22375;
static const S22375 s22375[10] =
{
{0, 0, 0, 0},
{4, 4, 8, 4},
{4, 5, 16, 8},
{4, 6, 32, 32},
{4, 4, 16, 16},
{8, 16, 32, 32},
{8, 16, 128, 128},
{8, 32, 128, 256},
{32, 128, 258, 1024},
{32, 258, 258, 4096}
};
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22399
struct S22399a
{
unsigned short f1;
};
struct S22399b
{
const struct S22399a *f1;
};
const struct S22399a C22399[1] = { {12} };
const struct S22399b C22399b = {C22399};
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22400
typedef struct S22400
{
unsigned short f1;
} S22400_t;
struct S22400b
{
const S22400_t *f1;
};
const S22400_t C22400[1] = { {12} };
const struct S22400b C22400b = {C22400};
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22406
int test22406(int a)
{
switch (a)
{
case 1: return -1;
case 2: return -2;
case 3: return -3;
}
return 0;
}
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22407
typedef int (*T22407) (int a);
int test22407(int a);
T22407 table22407[1] = { test22407 };
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22409
struct S22409;
typedef struct S22409
{
int f1;
} S22409_t;
/***************************************************/
// https://issues.dlang.org/show_bug.cgi?id=22413
int test22413(void)
{
char msg[] = "ok";
return msg[0] | msg[1];
}
/***************************************************/
int test(char *dest)
{
int x;
return dest == x;
}
/***************************************************/