1 /*
2 REQUIRED_ARGS: -mcpu=native -preview=intpromote
3 PERMUTE_ARGS: -O -inline -release
4 */
5 
6 import core.stdc.stdio;
7 
tuple(A...)8 template tuple(A...) { alias tuple = A; }
9 
10 ///////////////////////
11 
12 // https://github.com/dlang/dmd/pull/11441
13 
sdiv1(long l)14 long sdiv1(long l)
15 {
16   return l / 2;
17 }
18 
sdiv2(int i)19 int sdiv2(int i)
20 {
21   return i / 2;
22 }
23 
testsdiv2()24 void testsdiv2()
25 {
26     assert(sdiv1(10) == 5);
27     assert(sdiv1(-10) == -5);
28     assert(sdiv2(10) == 5);
29     assert(sdiv2(-10) == -5);
30 }
31 
32 ///////////////////////
33 
testulldiv()34 void testulldiv()
35 {
36     __gshared ulong[4][] vectors =
37     [
38         [10,3,3,1],
39         [10,1,10,0],
40         [3,10,0,3],
41         [10,10,1,0],
42         [10_000_000_000L, 11_000_000_000L, 0, 10_000_000_000L],
43         [11_000_000_000L, 10_000_000_000L, 1, 1_000_000_000L],
44         [11_000_000_000L, 11_000_000_000L, 1, 0],
45         [10_000_000_000L, 10, 1_000_000_000L, 0],
46         [0x8000_0000_0000_0000, 0x8000_0000_0000_0000, 1, 0],
47         [0x8000_0000_0000_0001, 0x8000_0000_0000_0001, 1, 0],
48         [0x8000_0001_0000_0000, 0x8000_0001_0000_0000, 1, 0],
49         [0x8000_0001_0000_0000, 0x8000_0000_0000_0000, 1, 0x1_0000_0000],
50         [0x8000_0001_0000_0000, 0x8000_0000_8000_0000, 1, 0x8000_0000],
51         [0x8000_0000_0000_0000, 0x7FFF_FFFF_FFFF_FFFF, 1, 1],
52         [0x8000_0000_0000_0000, 0x8000_0000_0000_0001, 0, 0x8000_0000_0000_0000],
53         [0x8000_0000_0000_0000, 0x8000_0001_0000_0000, 0, 0x8000_0000_0000_0000],
54     ];
55 
56     for (size_t i = 0; i < vectors.length; i++)
57     {
58         ulong q = vectors[i][0] / vectors[i][1];
59         if (q != vectors[i][2])
60             printf("[%zd] %lld / %lld = %lld, should be %lld\n",
61                 i, vectors[i][0], vectors[i][1], q, vectors[i][2]);
62 
63         ulong r = vectors[i][0] % vectors[i][1];
64         if (r != vectors[i][3])
65             printf("[%zd] %lld %% %lld = %lld, should be %lld\n",
66                 i, vectors[i][0], vectors[i][1], r, vectors[i][3]);
67     }
68 }
69 
70 ////////////////////////////////////////////////////////////////////////
71 
udiv10(uint x)72 uint udiv10(uint x)
73 {
74     return x / 10;
75 }
76 
udiv14(uint x)77 uint udiv14(uint x)
78 {
79     return x / 14;
80 }
81 
udiv14007(uint x)82 uint udiv14007(uint x)
83 {
84     return x / 14007;
85 }
86 
umod10(uint x)87 uint umod10(uint x)
88 {
89     return x % 10;
90 }
91 
umod14(uint x)92 uint umod14(uint x)
93 {
94     return x % 14;
95 }
96 
umod14007(uint x)97 uint umod14007(uint x)
98 {
99     return x % 14007;
100 }
101 
uremquo10(uint x)102 uint uremquo10(uint x)
103 {
104     return (x / 10) | (x % 10);
105 }
106 
uremquo14(uint x)107 uint uremquo14(uint x)
108 {
109     return (x / 14) | (x % 14);
110 }
111 
uremquo14007(uint x)112 uint uremquo14007(uint x)
113 {
114     return (x / 14007) | (x % 14007);
115 }
116 
117 
118 
uldiv10(ulong x)119 ulong uldiv10(ulong x)
120 {
121     return x / 10;
122 }
123 
uldiv14(ulong x)124 ulong uldiv14(ulong x)
125 {
126     return x / 14;
127 }
128 
uldiv14007(ulong x)129 ulong uldiv14007(ulong x)
130 {
131     return x / 14007;
132 }
133 
ulmod10(ulong x)134 ulong ulmod10(ulong x)
135 {
136     return x % 10;
137 }
138 
ulmod14(ulong x)139 ulong ulmod14(ulong x)
140 {
141     return x % 14;
142 }
143 
ulmod14007(ulong x)144 ulong ulmod14007(ulong x)
145 {
146     return x % 14007;
147 }
148 
ulremquo10(ulong x)149 ulong ulremquo10(ulong x)
150 {
151     return (x / 10) | (x % 10);
152 }
153 
ulremquo14(ulong x)154 ulong ulremquo14(ulong x)
155 {
156     return (x / 14) | (x % 14);
157 }
158 
ulremquo14007(ulong x)159 ulong ulremquo14007(ulong x)
160 {
161     return (x / 14007) | (x % 14007);
162 }
163 
164 
testfastudiv()165 void testfastudiv()
166 {
167   {
168     static uint x10 = 10;
169     static uint x14 = 14;
170     static uint x14007 = 14007;
171 
172     uint u = 10000;
173     uint r;
174     r = udiv10(u);  assert(r == u/x10);
175     r = udiv14(u);  assert(r == u/x14);
176     r = udiv14007(u);  assert(r == u/x14007);
177     r = umod10(u);  assert(r == u%x10);
178     r = umod14(u);  assert(r == u%x14);
179     r = umod14007(u);  assert(r == u%x14007);
180     r = uremquo10(u);  assert(r == ((u/10)|(u%x10)));
181     r = uremquo14(u);  assert(r == ((u/14)|(u%x14)));
182     r = uremquo14007(u);  assert(r == ((u/14007)|(u%x14007)));
183   }
184   {
185     static ulong y10 = 10;
186     static ulong y14 = 14;
187     static ulong y14007 = 14007;
188 
189     ulong u = 10000;
190     ulong r;
191     r = uldiv10(u);  assert(r == u/y10);
192     r = uldiv14(u);  assert(r == u/y14);
193     r = uldiv14007(u);  assert(r == u/y14007);
194     r = ulmod10(u);  assert(r == u%y10);
195     r = ulmod14(u);  assert(r == u%y14);
196     r = ulmod14007(u);  assert(r == u%y14007);
197     r = ulremquo10(u);  assert(r == ((u/10)|(u%y10)));
198     r = ulremquo14(u);  assert(r == ((u/14)|(u%y14)));
199     r = ulremquo14007(u);  assert(r == ((u/14007)|(u%y14007)));
200   }
201 }
202 
203 
204 ////////////////////////////////////////////////////////////////////////
205 
206 // https://issues.dlang.org/show_bug.cgi?id=14936
207 
sldiv1(long x)208 long sldiv1 (long x) { return x / (1L << 1); }
sldiv2(long x)209 long sldiv2 (long x) { return x / (1L << 2); }
sldiv3(long x)210 long sldiv3 (long x) { return x / (1L << 3); }
sldiv7(long x)211 long sldiv7 (long x) { return x / (1L << 7); }
sldiv8(long x)212 long sldiv8 (long x) { return x / (1L << 8); }
sldiv9(long x)213 long sldiv9 (long x) { return x / (1L << 9); }
sldiv30(long x)214 long sldiv30(long x) { return x / (1L << 30); }
sldiv31(long x)215 long sldiv31(long x) { return x / (1L << 31); }
sldiv32(long x)216 long sldiv32(long x) { return x / (1L << 32); }
sldiv33(long x)217 long sldiv33(long x) { return x / (1L << 33); }
sldiv34(long x)218 long sldiv34(long x) { return x / (1L << 34); }
sldiv62(long x)219 long sldiv62(long x) { return x / (1L << 62); }
sldiv63(long x)220 long sldiv63(long x) { return x / (1L << 63); }
221 
testsldiv()222 void testsldiv()
223 {
224     /* Test special div code for signed long divide
225      * by power of 2 for 32 bit targets.
226      */
227 
228     // printf("63 = %llx\n", sldiv63(-0x7FFF_F8FF_FF3F_2FFFL));
229 
230     static foreach (C; tuple!(
231                 1,2,3,10,300,1000,
232                 4_1001_2030_0030,
233                 0x7FFF_F8FF_FF3F_2FFFL))
234     {
235         /* Check if runtime computation matches compile time
236          */
237         assert(sldiv1 ( C) ==  C / (1L << 1));
238         assert(sldiv1 (-C) == -C / (1L << 1));
239         assert(sldiv2 ( C) ==  C / (1L << 2));
240         assert(sldiv2 (-C) == -C / (1L << 2));
241         assert(sldiv3 ( C) ==  C / (1L << 3));
242         assert(sldiv3 (-C) == -C / (1L << 3));
243         assert(sldiv7 ( C) ==  C / (1L << 7));
244         assert(sldiv7 (-C) == -C / (1L << 7));
245         assert(sldiv8 ( C) ==  C / (1L << 8));
246         assert(sldiv8 (-C) == -C / (1L << 8));
247         assert(sldiv9 ( C) ==  C / (1L << 9));
248         assert(sldiv9 (-C) == -C / (1L << 9));
249 
250         assert(sldiv30( C) ==  C / (1L << 30));
251         assert(sldiv30(-C) == -C / (1L << 30));
252         assert(sldiv31( C) ==  C / (1L << 31));
253         assert(sldiv31(-C) == -C / (1L << 31));
254         assert(sldiv32( C) ==  C / (1L << 32));
255         assert(sldiv32(-C) == -C / (1L << 32));
256         assert(sldiv33( C) ==  C / (1L << 33));
257         assert(sldiv33(-C) == -C / (1L << 33));
258         assert(sldiv34( C) ==  C / (1L << 34));
259         assert(sldiv34(-C) == -C / (1L << 34));
260         assert(sldiv62( C) ==  C / (1L << 62));
261         assert(sldiv62(-C) == -C / (1L << 62));
262         assert(sldiv63( C) ==  C / (1L << 63));
263         assert(sldiv63(-C) == -C / (1L << 63));
264     }
265 }
266 
267 ////////////////////////////////////////////////////////////////////////
268 
269 // https://issues.dlang.org/show_bug.cgi?id=14936
270 
slmod1(long x)271 long slmod1 (long x) { return x % (1L << 1); }
slmod2(long x)272 long slmod2 (long x) { return x % (1L << 2); }
slmod3(long x)273 long slmod3 (long x) { return x % (1L << 3); }
slmod7(long x)274 long slmod7 (long x) { return x % (1L << 7); }
slmod8(long x)275 long slmod8 (long x) { return x % (1L << 8); }
slmod9(long x)276 long slmod9 (long x) { return x % (1L << 9); }
slmod30(long x)277 long slmod30(long x) { return x % (1L << 30); }
slmod31(long x)278 long slmod31(long x) { return x % (1L << 31); }
slmod32(long x)279 long slmod32(long x) { return x % (1L << 32); }
slmod33(long x)280 long slmod33(long x) { return x % (1L << 33); }
slmod34(long x)281 long slmod34(long x) { return x % (1L << 34); }
slmod62(long x)282 long slmod62(long x) { return x % (1L << 62); }
slmod63(long x)283 long slmod63(long x) { return x % (1L << 63); }
284 
testslmod()285 void testslmod()
286 {
287     static foreach (C; tuple!(
288                 1,2,3,10,300,1000,
289                 4_1001_2030_0030,
290                 0x7FFF_F8FF_FF3F_2FFFL))
291     {
292         /* Check if runtime computation matches compile time
293          */
294         assert(slmod1 ( C) ==  C % (1L << 1));
295         assert(slmod1 (-C) == -C % (1L << 1));
296         assert(slmod2 ( C) ==  C % (1L << 2));
297         assert(slmod2 (-C) == -C % (1L << 2));
298         assert(slmod3 ( C) ==  C % (1L << 3));
299         assert(slmod3 (-C) == -C % (1L << 3));
300         assert(slmod7 ( C) ==  C % (1L << 7));
301         assert(slmod7 (-C) == -C % (1L << 7));
302         assert(slmod8 ( C) ==  C % (1L << 8));
303         assert(slmod8 (-C) == -C % (1L << 8));
304         assert(slmod9 ( C) ==  C % (1L << 9));
305         assert(slmod9 (-C) == -C % (1L << 9));
306 
307         assert(slmod30( C) ==  C % (1L << 30));
308         assert(slmod30(-C) == -C % (1L << 30));
309         assert(slmod31( C) ==  C % (1L << 31));
310         assert(slmod31(-C) == -C % (1L << 31));
311         assert(slmod32( C) ==  C % (1L << 32));
312         assert(slmod32(-C) == -C % (1L << 32));
313         assert(slmod33( C) ==  C % (1L << 33));
314         assert(slmod33(-C) == -C % (1L << 33));
315         assert(slmod34( C) ==  C % (1L << 34));
316         assert(slmod34(-C) == -C % (1L << 34));
317         assert(slmod62( C) ==  C % (1L << 62));
318         assert(slmod62(-C) == -C % (1L << 62));
319         assert(slmod63( C) ==  C % (1L << 63));
320         assert(slmod63(-C) == -C % (1L << 63));
321     }
322 }
323 
324 ////////////////////////////////////////////////////////////////////////
325 
divC(int C,T)326 T divC(int C, T)(T x)
327 {
328     T y = x;
329     y /= C;
330     assert(y == x / C);
331     y = x;
332     y /= -C;
333     assert(y == x / -C);
334     return x / C;
335 }
336 
modC(int C,T)337 T modC(int C, T)(T x)
338 {
339     T y = x;
340     y %= C;
341     assert(y == x % C);
342     y = x;
343     y %= -C;
344     assert(y == x % -C);
345     return x % C;
346 }
347 
remquoC(int C,T)348 T remquoC(int C, T)(T x)
349 {
350     return (x / C) | (x % C);
351 }
352 
testfastdiv()353 void testfastdiv()
354 {
355     static int z = 0; // prevent constant folding by optimizer
356 
357     static foreach (T; tuple!(int, long, uint, ulong))
358     {{
359         T u = 10000;
360         T r;
361         static foreach (C; tuple!(10, 14, 14007, -10, -14, -14007))
362         {
363             r = divC!C(u);     assert(r == u / (z + C));
364             r = modC!C(u);     assert(r == u % (z + C));
365             r = remquoC!C(u);  assert(r == ((u / (z + C) | (u % (z + C)))));
366         }
367     }}
368 }
369 
370 ////////////////////////////////////////////////////////////////////////
371 
372 
373 /* Test the pattern:
374  *   replace ((i / C1) / C2) with (i / (C1 * C2))
375  * when e1 is 0 or 1 and (i2-i1) is a power of 2.
376  */
377 
divdiv(T,T C1,T C2)378 void divdiv(T, T C1, T C2)(T i)
379 {
380     auto a = (i / C1) / C2;
381     auto b = i / (C1 * C2);
382     if (a != b) assert(0);
383 }
384 
testdivdiv()385 void testdivdiv()
386 {
387     divdiv!(int,10,20)(30);
388     divdiv!(uint,10,20)(30);
389     divdiv!(long,10,20)(30);
390     divdiv!(ulong,10,20)(30);
391 
392     divdiv!(int,-10,20)(30);
393     divdiv!(long,-10,20)(30);
394 
395     divdiv!(int,-10,-20)(-30);
396     divdiv!(long,-10,-20)(-30);
397 }
398 
399 ////////////////////////////////////////////////////////////////////////
400 
testdivcmp()401 void testdivcmp()
402 {
403     // https://github.com/dlang/dmd/pull/7128
404     static bool foo(uint a, uint b)
405     {
406         return cast(bool)(a / b); // convert / to >=
407     }
408 
409     assert(!foo(3, 4));
410     assert(foo(4, 4));
411     assert(foo(5, 4));
412 }
413 
414 /////////////////////////////////////////////////////
415 
testgoto()416 void testgoto()
417 {
418     int i;
419 
420     i = 3;
421     goto L4;
422 L3: i++;
423     goto L5;
424 L4: goto L3;
425 L5: assert(i == 4);
426 }
427 
testswitch()428 int testswitch()
429 {
430     int i;
431 
432     i = 3;
433     switch (i)
434     {
435         case 0:
436         case 1:
437         default:
438             assert(0);
439         case 3:
440             break;
441     }
442     return 0;
443 }
444 
testdo()445 void testdo()
446 {
447     int x = 0;
448 
449     do
450     {
451         x++;
452     } while (x < 10);
453     printf("x == %d\n", x);
454     assert(x == 10);
455 }
456 
457 
testbreak()458 void testbreak()
459 {   int i, j;
460 
461   Louter:
462     for (i = 0; i < 10; i++)
463     {
464         for (j = 0; j < 10; j++)
465         {
466             if (j == 3)
467                 break Louter;
468         }
469     }
470 
471     printf("i = %d, j = %d\n", i, j);
472     assert(i == 0);
473     assert(j == 3);
474 }
475 
476 ///////////////////////
477 
foo(string s)478 int foo(string s)
479 {
480     int i;
481 
482     i = 0;
483     switch (s)
484     {
485         case "hello":
486             i = 1;
487             break;
488         case "goodbye":
489             i = 2;
490             break;
491         case "goodb":
492             i = 3;
493             break;
494         default:
495             i = 10;
496             break;
497     }
498     return i;
499 }
500 
501 
teststringswitch()502 void teststringswitch()
503 {   int i;
504 
505     i = foo("hello");
506     printf("i = %d\n", i);
507     assert(i == 1);
508 
509     i = foo("goodbye");
510     printf("i = %d\n", i);
511     assert(i == 2);
512 
513     i = foo("goodb");
514     printf("i = %d\n", i);
515     assert(i == 3);
516 
517     i = foo("huzzah");
518     printf("i = %d\n", i);
519     assert(i == 10);
520 }
521 
522 
523 ///////////////////////
524 
525 struct Foo
526 {
527     int a;
528     char b;
529     long c;
530 }
531 
test(Foo f)532 Foo test(Foo f)
533 {
534     f.a += 1;
535     f.b += 3;
536     f.c += 4;
537     return f;
538 }
539 
540 
teststrarg()541 void teststrarg()
542 {
543     Foo g;
544     g.a = 1;
545     g.b = 2;
546     g.c = 3;
547 
548     Foo q;
549     q = test(g);
550     assert(q.a == 2);
551     assert(q.b == 5);
552     assert(q.c == 7);
553 }
554 
555 ///////////////////////
556 
557 align (1) struct Foo1
558 {
559   align (1):
560     int a;
561     char b;
562     long c;
563 }
564 
565 struct Foo2
566 {
567     int a;
568     char b;
569     long c;
570 }
571 
572 struct Foo3
573 {
574     int a;
575     align (1) char b;
576     long c;
577 }
578 
579 struct Foo4
580 {
581     int a;
582     struct { char b; }
583     long c;
584 }
585 
testsizes()586 void testsizes()
587 {
588     printf("%zd\n", Foo1.sizeof);
589     assert(Foo1.a.offsetof == 0);
590     assert(Foo1.b.offsetof == 4);
591     assert(Foo1.c.offsetof == 5);
592     assert(Foo1.sizeof == 13);
593 
594     assert(Foo2.a.offsetof == 0);
595     assert(Foo2.b.offsetof == 4);
596     assert(Foo2.c.offsetof == 8);
597     assert(Foo2.sizeof == 16);
598 
599     assert(Foo3.a.offsetof == 0);
600     assert(Foo3.b.offsetof == 4);
601     assert(Foo3.c.offsetof == 8);
602     assert(Foo3.b.sizeof == 1);
603     assert(Foo3.sizeof == 16);
604 
605     assert(Foo4.sizeof == 16);
606 }
607 
608 ///////////////////////
609 
cond11565(size_t val)610 size_t cond11565(size_t val)
611 {
612     return val ? size_t.max : 0;
613 }
614 
test11565()615 void test11565()
616 {
617     assert(cond11565(true) == size_t.max);
618 }
619 
620 ///////////////////////
621 
622 int[3] array1 = [1:1,2,0:3];
623 
testarrayinit()624 void testarrayinit()
625 {
626     assert(array1[0] == 3);
627     assert(array1[1] == 1);
628     assert(array1[2] == 2);
629 }
630 
631 ///////////////////////
632 
test13023(ulong n)633 void test13023(ulong n)
634 {
635     static void func(bool b) {}
636 
637     ulong k = 0;
638 
639     func(k >= n / 2);
640 
641     if (k >= n / 2)
642         assert(0);
643 }
644 
645 ///////////////////////
646 
647 struct U { int a; union { char c; int d; } long b; }
648 
649 U f = { b:3, d:0x22222222, a:1 };
650 
testU()651 void testU()
652 {
653     assert(f.b == 3);
654     assert(f.d == 0x22222222);
655     assert(f.c == 0x22);
656     assert(f.a == 1);
657     assert(f.sizeof == 16);
658     assert(U.sizeof == 16);
659 }
660 
661 
662 ////////////////////////////////////////////////////////////////////////
663 
vfunc()664 void vfunc() {}
665 
test12095(int k)666 void test12095(int k)
667 {
668     int e = 0;
669     e ? k || assert(0) : !e || vfunc();
670     e ? k || assert(0) : e && vfunc();
671     !e ? !e || vfunc() : k || assert(0);
672 }
673 
674 
675 ////////////////////////////////////////////////////////////////////////
676 
677 
test3918a(float t,real u)678 bool test3918a( float t, real u )
679 {
680         printf("%Lf\n", u );
681         return t && u;
682 }
683 
test3918b(real t,float u)684 bool test3918b( real t, float u )
685 {
686         printf("%Lf\n", t );
687         return t && u;
688 }
689 
test3918()690 void test3918()
691 {
692         assert(test3918a(float.nan, real.nan));
693         assert(test3918b(real.nan, float.nan));
694 }
695 
696 ////////////////////////////////////////////////////////////////////////
697 
docond1(T)698 T docond1(T)(T l, ubyte thresh, ubyte val) {
699     l += (thresh < val);
700     return l;
701 }
702 
docond2(T)703 T docond2(T)(T l, ubyte thresh, ubyte val) {
704     l -= (thresh >= val);
705     return l;
706 }
707 
docond3(T)708 T docond3(T)(T l, ubyte thresh, ubyte val) {
709     l += (thresh >= val);
710     return l;
711 }
712 
docond4(T)713 T docond4(T)(T l, ubyte thresh, ubyte val) {
714     l -= (thresh < val);
715     return l;
716 }
717 
testdocond()718 void testdocond()
719 {
720     assert(docond1!ubyte(10,3,5)  == 11);
721     assert(docond1!ushort(10,3,5) == 11);
722     assert(docond1!uint(10,3,5)   == 11);
723     assert(docond1!ulong(10,3,5)  == 11);
724 
725     assert(docond2!ubyte(10,3,5)  == 10);
726     assert(docond2!ushort(10,3,5) == 10);
727     assert(docond2!uint(10,3,5)   == 10);
728     assert(docond2!ulong(10,3,5)  == 10);
729 
730     assert(docond3!ubyte(10,3,5)  == 10);
731     assert(docond3!ushort(10,3,5) == 10);
732     assert(docond3!uint(10,3,5)   == 10);
733     assert(docond3!ulong(10,3,5)  == 10);
734 
735     assert(docond4!ubyte(10,3,5)  == 9);
736     assert(docond4!ushort(10,3,5) == 9);
737     assert(docond4!uint(10,3,5)   == 9);
738     assert(docond4!ulong(10,3,5)  == 9);
739 
740 
741     assert(docond1!ubyte(10,5,3)  == 10);
742     assert(docond1!ushort(10,5,3) == 10);
743     assert(docond1!uint(10,5,3)   == 10);
744     assert(docond1!ulong(10,5,3)  == 10);
745 
746     assert(docond2!ubyte(10,5,3)  == 9);
747     assert(docond2!ushort(10,5,3) == 9);
748     assert(docond2!uint(10,5,3)   == 9);
749     assert(docond2!ulong(10,5,3)  == 9);
750 
751     assert(docond3!ubyte(10,5,3)  == 11);
752     assert(docond3!ushort(10,5,3) == 11);
753     assert(docond3!uint(10,5,3)   == 11);
754     assert(docond3!ulong(10,5,3)  == 11);
755 
756     assert(docond4!ubyte(10,5,3)  == 10);
757     assert(docond4!ushort(10,5,3) == 10);
758     assert(docond4!uint(10,5,3)   == 10);
759     assert(docond4!ulong(10,5,3)  == 10);
760 }
761 
762 ////////////////////////////////////////////////////////////////////////
763 
764 struct S8658
765 {
766     int[16385] a;
767 }
768 
foo8658(S8658 s)769 void foo8658(S8658 s)
770 {
771     int x;
772 }
773 
test8658()774 void test8658()
775 {
776     S8658 s;
777     for(int i = 0; i < 1000; i++)
778         foo8658(s);
779 }
780 
781 ////////////////////////////////////////////////////////////////////////
782 
neg(uint i)783 uint neg(uint i)
784 {
785     return ~i + 1;
786 }
787 
com(uint i)788 uint com(uint i)
789 {
790     return -i - 1;
791 }
792 
com(float i)793 float com(float i)
794 {
795     return -i - 1;
796 }
797 
com2(uint i)798 uint com2(uint i)
799 {
800     return -(i + 1);
801 }
802 
testnegcom()803 void testnegcom()
804 {
805     assert(neg(3) == -3);
806     assert(com(3) == -4);
807     assert(com(3.0f) == -4.0f);
808     assert(com2(3) == -4);
809 }
810 
811 ////////////////////////////////////////////////////////////////////////
812 
oror1(char c)813 int oror1(char c)
814 {
815     return ((((((((((cast(int) c <= 32 || cast(int) c == 46) || cast(int) c == 44)
816                  || cast(int) c == 58) || cast(int) c == 59) || cast(int) c == 60)
817               || cast(int) c == 62) || cast(int) c == 34) || cast(int) c == 92)
818            || cast(int) c == 39) != 0);
819 }
820 
oror2(char c)821 int oror2(char c)
822 {
823     return ((((((((((c <= 32 || c == 46) || c == 44)
824                  || c == 58) || c == 59) || c == 60)
825                  || c == 62) || c == 34) || c == 92)
826                  || c == 39) != 0);
827 }
828 
testoror()829 void testoror()
830 {
831     assert(oror1(0) == 1);
832     assert(oror1(32) == 1);
833     assert(oror1(46) == 1);
834     assert(oror1(44) == 1);
835     assert(oror1(58) == 1);
836     assert(oror1(59) == 1);
837     assert(oror1(60) == 1);
838     assert(oror1(62) == 1);
839     assert(oror1(34) == 1);
840     assert(oror1(92) == 1);
841     assert(oror1(39) == 1);
842     assert(oror1(33) == 0);
843     assert(oror1(61) == 0);
844     assert(oror1(93) == 0);
845     assert(oror1(255) == 0);
846 
847     assert(oror2(0) == 1);
848     assert(oror2(32) == 1);
849     assert(oror2(46) == 1);
850     assert(oror2(44) == 1);
851     assert(oror2(58) == 1);
852     assert(oror2(59) == 1);
853     assert(oror2(60) == 1);
854     assert(oror2(62) == 1);
855     assert(oror2(34) == 1);
856     assert(oror2(92) == 1);
857     assert(oror2(39) == 1);
858     assert(oror2(33) == 0);
859     assert(oror2(61) == 0);
860     assert(oror2(93) == 0);
861     assert(oror2(255) == 0);
862 }
863 
864 ////////////////////////////////////////////////////////////////////////
865 
bt1(int p,int a,int b)866 bool bt1(int p, int a, int b)
867 {
868     return p && ((1 << b) & a);
869 }
870 
bt2(int p,long a,long b)871 bool bt2(int p, long a, long b)
872 {
873     return p && ((1L << b) & a);
874 }
875 
testbt()876 void testbt()
877 {
878     assert(bt1(1,7,2) == 1);
879     assert(bt1(1,7,3) == 0);
880 
881     assert(bt2(1,0x7_0000_0000,2+32) == 1);
882     assert(bt2(1,0x7_0000_0000,3+32) == 0);
883 }
884 
885 ////////////////////////////////////////////////////////////////////////
886 
test13383()887 void test13383()
888 {
889     foreach (k; 32..33)
890     {
891         if (1L & (1L << k))
892         {
893             assert(0);
894         }
895     }
896 }
897 
898 ////////////////////////////////////////////////////////////////////////
899 
andand1(int c)900 int andand1(int c)
901 {
902     return (c > 32 && c != 46 && c != 44
903                    && c != 58 && c != 59
904                    && c != 60 && c != 62
905                    && c != 34 && c != 92
906                    && c != 39) != 0;
907 }
908 
andand2(long c)909 bool andand2(long c)
910 {
911     return (c > 32 && c != 46 && c != 44
912                    && c != 58 && c != 59
913                    && c != 60 && c != 62
914                    && c != 34 && c != 92
915                    && c != 39) != 0;
916 }
917 
foox3()918 int foox3() { return 1; }
919 
andand3(uint op)920 int andand3(uint op)
921 {
922     if (foox3() &&
923         op != 7 &&
924         op != 3 &&
925         op != 18 &&
926         op != 30 &&
927         foox3())
928         return 3;
929     return 4;
930 }
931 
932 
testandand()933 void testandand()
934 {
935     assert(andand1(0) == 0);
936     assert(andand1(32) == 0);
937     assert(andand1(46) == 0);
938     assert(andand1(44) == 0);
939     assert(andand1(58) == 0);
940     assert(andand1(59) == 0);
941     assert(andand1(60) == 0);
942     assert(andand1(62) == 0);
943     assert(andand1(34) == 0);
944     assert(andand1(92) == 0);
945     assert(andand1(39) == 0);
946     assert(andand1(33) == 1);
947     assert(andand1(61) == 1);
948     assert(andand1(93) == 1);
949     assert(andand1(255) == 1);
950 
951     assert(andand2(0) == false);
952     assert(andand2(32) == false);
953     assert(andand2(46) == false);
954     assert(andand2(44) == false);
955     assert(andand2(58) == false);
956     assert(andand2(59) == false);
957     assert(andand2(60) == false);
958     assert(andand2(62) == false);
959     assert(andand2(34) == false);
960     assert(andand2(92) == false);
961     assert(andand2(39) == false);
962     assert(andand2(33) == true);
963     assert(andand2(61) == true);
964     assert(andand2(93) == true);
965     assert(andand2(255) == true);
966 
967     assert(andand3(6) == 3);
968     assert(andand3(30) == 4);
969 }
970 
971 ////////////////////////////////////////////////////////////////////////
972 
bittest11508(char c)973 bool bittest11508(char c)
974 {
975     return c=='_' || c=='-' || c=='+' || c=='.';
976 }
977 
testbittest()978 void testbittest()
979 {
980     assert(bittest11508('_'));
981 }
982 
983 ////////////////////////////////////////////////////////////////////////
984 
or1(ubyte x)985 uint or1(ubyte x)
986 {
987     return x | (x<<8) | (x<<16) | (x<<24) | (x * 3);
988 }
989 
testor_combine()990 void testor_combine()
991 {
992     printf("%x\n", or1(1));
993     assert(or1(5) == 5 * (0x1010101 | 3));
994 }
995 
996 ////////////////////////////////////////////////////////////////////////
997 
998 
shrshl(int i)999 int shrshl(int i) {
1000   return ((i+1)>>1)<<1;
1001 }
1002 
testshrshl()1003 void testshrshl()
1004 {
1005     assert(shrshl(6) == 6);
1006     assert(shrshl(7) == 8);
1007 }
1008 
1009 ////////////////////////////////////////////////////////////////////////
1010 
bt10715(in uint[]ary,size_t bitnum)1011 bool bt10715(in uint[] ary, size_t bitnum)
1012 {
1013     return !!(ary[bitnum >> 5] & 1 << (bitnum & 31)); // uses bt
1014 }
1015 
neg_bt10715(in uint[]ary,size_t bitnum)1016 bool neg_bt10715(in uint[] ary, size_t bitnum)
1017 {
1018     return !(ary[bitnum >> 5] & 1 << (bitnum & 31)); // does not use bt
1019 }
1020 
test10715()1021 void test10715()
1022 {
1023     static uint[2]  a1 = [0x1001_1100, 0x0220_0012];
1024 
1025     if ( bt10715(a1,30)) assert(0);
1026     if (!bt10715(a1,8))  assert(0);
1027     if ( bt10715(a1,30+32)) assert(0);
1028     if (!bt10715(a1,1+32))  assert(0);
1029 
1030     if (!neg_bt10715(a1,30)) assert(0);
1031     if ( neg_bt10715(a1,8))  assert(0);
1032     if (!neg_bt10715(a1,30+32)) assert(0);
1033     if ( neg_bt10715(a1,1+32))  assert(0);
1034 }
1035 
1036 ////////////////////////////////////////////////////////////////////////
1037 
compare12164(A12164 * rhsPA,A12164 * zis)1038 ptrdiff_t compare12164(A12164* rhsPA, A12164* zis)
1039 {
1040     if (*rhsPA == *zis)
1041         return 0;
1042     return ptrdiff_t.min;
1043 }
1044 
1045 struct A12164
1046 {
1047     int a;
1048 }
1049 
test12164()1050 void test12164()
1051 {
1052     auto a = A12164(3);
1053     auto b = A12164(2);
1054     assert(compare12164(&a, &b));
1055 }
1056 
1057 ////////////////////////////////////////////////////////////////////////
1058 
foo10678(char[5]txt)1059 int foo10678(char[5] txt)
1060 {
1061     return txt[0] + txt[1] + txt[4];
1062 }
1063 
test10678()1064 void test10678()
1065 {
1066     char[5] hello = void;
1067     hello[0] = 8;
1068     hello[1] = 9;
1069     hello[4] = 10;
1070     int i = foo10678(hello);
1071     assert(i == 27);
1072 }
1073 
1074 ////////////////////////////////////////////////////////////////////////
1075 
1076 struct S12051
1077 {
thisS120511078     this(char c)
1079     {
1080         assert(c == 'P' || c == 'M');
1081     }
1082 }
1083 
test12051()1084 void test12051()
1085 {
1086     auto ip = ["abc"];
1087     foreach (i, s; ip)
1088     {
1089         S12051(i < ip.length ? 'P' : 'M');
1090     }
1091 }
1092 
1093 ////////////////////////////////////////////////////////////////////////
1094 
bug7565(double x)1095 void bug7565( double x) { assert(x == 3); }
1096 
test7565()1097 void test7565()
1098 {
1099    double y = 3;
1100    bug7565( y++ );
1101    assert(y == 4);
1102 }
1103 
1104 ////////////////////////////////////////////////////////////////////////
1105 
bug8525(int[]devt)1106 int bug8525(int[] devt)
1107 {
1108     return devt[$ - 1];
1109 }
1110 
1111 ////////////////////////////////////////////////////////////////////////
1112 
func13190(int)1113 void func13190(int) {}
1114 
1115 struct Struct13190
1116 {
1117     ulong a;
1118     uint b;
1119 };
1120 
1121 __gshared Struct13190* table13190 =
1122 [
1123     Struct13190(1, 1),
1124     Struct13190(0, 2)
1125 ];
1126 
test13190()1127 void test13190()
1128 {
1129     for (int i = 0; table13190[i].a; i++)
1130     {
1131         ulong tbl = table13190[i].a;
1132         func13190(i);
1133         if (1 + tbl)
1134         {
1135             if (tbl == 0x80000)
1136                 return;
1137         }
1138     }
1139 }
1140 
1141 ////////////////////////////////////////////////////////////////////////
1142 
foo13485(double c,double d)1143 double foo13485(double c, double d)
1144 {
1145     // This must not be optimized to c += (d + d)
1146     c += d;
1147     c += d;
1148     return c;
1149 }
1150 
test13485()1151 void test13485()
1152 {
1153     enum double d = 0X1P+1023;
1154     assert(foo13485(-d, d) == d);
1155 }
1156 
1157 ////////////////////////////////////////////////////////////////////////
1158 
test12833a(int a)1159 void test12833a(int a)
1160 {
1161     long x = cast(long)a;
1162 
1163     switch (cast(int)(cast(ushort)(x >> 16 & 65535L)))
1164     {
1165         case 1:
1166         {
1167             break;
1168         }
1169         default:
1170         {
1171             assert(0);
1172         }
1173     }
1174 }
1175 
test12833()1176 void test12833()
1177 {
1178     test12833a(0x1_0000);
1179 }
1180 
1181 /***********************************************/
1182 
1183 struct Point9449
1184 {
1185     double f = 3.0;
1186     double g = 4.0;
1187 }
1188 
test9449()1189 void test9449()
1190 {
1191     Point9449[1] arr;
1192     if (arr[0].f != 3.0) assert(0);
1193     if (arr[0].g != 4.0) assert(0);
1194 }
1195 
1196 struct Point9449x
1197 {
1198     float  f = 0.0;
1199     double g = 0.0;
1200 }
1201 
test9449x()1202 void test9449x()
1203 {
1204     Point9449x[1] arr;
1205     if (arr[0].f != 0.0) assert(0);
1206     if (arr[0].g != 0.0) assert(0);
1207 }
1208 
1209 ////////////////////////////////////////////////////////////////////////
1210 // https://issues.dlang.org/show_bug.cgi?id=12057
1211 
prop12057(real x)1212 bool prop12057(real x) { return false; }
f12057(real)1213 double f12057(real) { return double.init; }
test12057()1214 void test12057()
1215 {
1216     real fc = f12057(real.init);
1217     if (fc == 0 || fc.prop12057) {}
1218 }
1219 
1220 
1221 ////////////////////////////////////////////////////////////////////////
1222 
modulo24(long ticks)1223 long modulo24 (long ticks)
1224 {
1225     ticks %= 864000000000;
1226     if (ticks < 0)
1227         ticks += 864000000000;
1228     return ticks;
1229 }
1230 
test13784()1231 void test13784()
1232 {
1233     assert (modulo24(-141600000000) == 722400000000);
1234 }
1235 
1236 
1237 ////////////////////////////////////////////////////////////////////////
1238 
1239 struct S13969 {
1240     int x, y;
1241 }
1242 
test13969(const S13969 * f)1243 int test13969(const S13969* f) {
1244     return 0 % ((f.y > 0) ? f.x / f.y : f.x / -f.y);
1245 }
1246 
1247 ////////////////////////////////////////////////////////////////////////
1248 
1249 int[] arr14436;
test14436()1250 void test14436()
1251 {
1252     assert(arr14436 == null);
1253     arr14436 = [1, 2, 3];
1254     assert(arr14436 != null);
1255 }
1256 
1257 ////////////////////////////////////////////////////////////////////////
1258 
test14220()1259 void test14220()
1260 {
1261     auto a = toString(14);
1262 
1263     printf("a.ptr = %p, a.length = %d\n", a.ptr, cast(int)a.length);
1264     return;
1265 }
1266 
toString(int value)1267 auto toString(int value)
1268 {
1269     uint mValue = value;
1270 
1271     char[int.sizeof * 3] buffer = void;
1272     size_t index = buffer.length;
1273 
1274     do
1275     {
1276         uint div = cast(int)(mValue / 10);
1277         char mod = mValue % 10 + '0';
1278         buffer[--index] = mod;        // Line 22
1279         mValue = div;
1280     } while (mValue);
1281 
1282     //printf("buffer.ptr = %p, index = %d\n", buffer.ptr, cast(int)index);
1283     return dup(buffer[index .. $]);
1284 }
1285 
dup(char[]a)1286 char[] dup(char[] a)
1287 {
1288     //printf("a.ptr = %p, a.length = %d\n", a.ptr, cast(int)a.length);
1289     a[0] = 1;       // segfault
1290     return a;
1291 }
1292 
1293 ////////////////////////////////////////////////////////////////////////
1294 
stripLeft(int str,int dc)1295 int stripLeft(int str, int dc)
1296 {
1297     while (true)
1298     {
1299         int a = str;
1300         int s = a;
1301         str += 1;
1302         if (dc) return s;
1303     }
1304 }
1305 
test14829()1306 void test14829()
1307 {
1308     if (stripLeft(3, 1) != 3) // fails with -O
1309         assert(0);
1310 }
1311 
1312 
1313 ////////////////////////////////////////////////////////////////////////
1314 
test3()1315 void test3()
1316 {
1317     int[6] a;
1318     int[] b;
1319     b = a;
1320     b = (b.ptr + b.length - 5)[0 .. b.ptr + b.length - 1 - a.ptr];
1321     assert(b.ptr == a.ptr + 1);
1322     assert(b.length == 5);
1323 }
1324 
1325 ////////////////////////////////////////////////////////////////////////
1326 // https://issues.dlang.org/show_bug.cgi?id=14782
1327 
1328 
test14782()1329 void test14782()
1330 {
1331     static struct Foo
1332     {
1333         long a = 8;
1334         int b = 7;
1335     }
1336 
1337     static Foo[1] fun() { Foo[1] a; return a; }
1338 
1339     auto result = fun();
1340     assert(result[0].a == 8);
1341     assert(result[0].b == 7);
1342 }
1343 
1344 ////////////////////////////////////////////////////////////////////////
1345 
test14987()1346 void test14987()
1347 {
1348     static struct Foo
1349     {
1350         int b = 7;
1351     }
1352     static assert((Foo[4]).sizeof == 16);
1353 
1354     static Foo[4] fun() { Foo[4] a; return a; }
1355 
1356     auto result = fun();
1357     assert(result[0].b == 7);
1358     assert(result[1].b == 7);
1359     assert(result[2].b == 7);
1360     assert(result[3].b == 7);
1361 }
1362 
1363 ////////////////////////////////////////////////////////////////////////
1364 
calloc15272(size_t bc)1365 void[] calloc15272(size_t bc) nothrow pure
1366 {
1367     assert(bc == 1);
1368     return new void[1];
1369 }
1370 
test15272()1371 void test15272()
1372 {
1373     void[] scache = cast(void[])"abc";
1374     size_t count = 1;
1375     void[]* buckets = &scache;
1376     *buckets = calloc15272(count)[0 .. count];
1377 }
1378 
1379 /*****************************************
1380  * https://issues.dlang.org/show_bug.cgi?id=15861
1381  */
1382 
test15861()1383 void test15861()
1384 {
1385     double val = 4286853117.;
1386 
1387     (){
1388         assert(val == 4286853117.);
1389     }();
1390 }
1391 
1392 ////////////////////////////////////////////////////////////////////////
1393 
1394 // https://issues.dlang.org/show_bug.cgi?id=15629 comment 3
1395 // -O
1396 
test15629()1397 void test15629()
1398 {
1399     int[] a = [3];
1400     int value = a[0] >= 0 ? a[0] : -a[0];
1401     assert(a[0] == 3);
1402     writeln(value, a);
1403 }
1404 
writeln(int v,int[]a)1405 void writeln(int v, int[] a)
1406 {
1407 }
1408 
1409 ////////////////////////////////////////////////////////////////////////
1410 
binPosPow2()1411 real binPosPow2() { return 1.0L; }
1412 
binPow2()1413 real binPow2()
1414 {
1415     return 1.0L/binPosPow2();
1416 }
1417 
test4()1418 void test4()
1419 {
1420     assert(binPow2() == 1.0L);
1421 }
1422 
1423 ////////////////////////////////////////////////////////////////////////
1424 // https://issues.dlang.org/show_bug.cgi?id=13474
1425 
1426 
1427 double sumKBN(double s = 0.0)
1428 {
1429     import core.math : fabs;
1430     double c = 0.0;
foreach(double x;[1,1e100,1,-1e100])1431         foreach(double x; [1, 1e100, 1, -1e100])
1432         {
1433             x = multiply(x);
1434             double t = s + x;
1435             if(s.fabs >= x.fabs)
1436             {
1437                 double y = s-t;
1438                 c += y+x;
1439             }
1440             else
1441             {
1442                 double y = x-t;
1443                 c += y+s;
1444             }
1445             s = t;
1446         }
1447     return s + c;
1448 }
1449 
multiply(double a)1450 double multiply(double a) { return a * 10000; }
1451 
test13474()1452 void test13474()
1453 {
1454     double r = 20000;
1455     assert(r == sumKBN());
1456 }
1457 
1458 ////////////////////////////////////////////////////////////////////////
1459 // https://issues.dlang.org/show_bug.cgi?id=16699
1460 
parseDateRange()1461 ulong[1] parseDateRange()
1462 {
1463     try
1464     {
1465         ulong[1] result;
1466         result[0] = 6;
1467         return result;
1468     }
1469     finally
1470     {
1471     }
1472 }
1473 
test16699()1474 void test16699()
1475 {
1476     ulong[1] range = parseDateRange();
1477     assert(range[0] == 6);
1478 }
1479 
1480 ////////////////////////////////////////////////////////////////////////
1481 
1482 // https://issues.dlang.org/show_bug.cgi?id=16102
1483 
~thisS161021484 struct S16102 { ~this() { } }
1485 
f16102()1486 long[1] f16102()
1487 {
1488     S16102 a;
1489     return [1];
1490 }
1491 
test16102()1492 void test16102()
1493 {
1494     assert( f16102() == [1] );
1495 }
1496 
1497 ////////////////////////////////////////////////////////////////////////
1498 
test5a(ulong x,ulong y)1499 void test5a(ulong x, ulong y)
1500 {
1501     int a;
1502     if (x >> 32)
1503         a = 1;
1504     else
1505         a = 2;
1506     assert(a == 1);
1507 
1508     if (y >> 32)
1509         a = 1;
1510     else
1511         a = 2;
1512     assert(a == 2);
1513 }
1514 
test5()1515 void test5()
1516 {
1517     test5a(uint.max + 1L, uint.max);
1518 }
1519 
1520 ////////////////////////////////////////////////////////////////////////
1521 
1522 /* Test the pattern:
1523  *   replace (e ? i1 : i2) with (i1 + e * (i2 - i1))
1524  * when e1 is 0 or 1 and (i2-i1) is a power of 2.
1525  */
1526 
foo61(int i)1527 int foo61(int i)
1528 {
1529     return (i % 2 != 0) ? 4 : 2;
1530 }
1531 
foo62(int i)1532 int foo62(int i)
1533 {
1534     return (i % 2 != 0) ? 2 : 4;
1535 }
1536 
bar6(bool b)1537 bool bar6(bool b) { return b; }
1538 
foo63(bool b)1539 int foo63(bool b)
1540 {
1541     return bar6(b) ? 16 : 8;
1542 }
1543 
foo64(bool b)1544 int foo64(bool b)
1545 {
1546     return bar6(b) ? 8 : 16;
1547 }
1548 
test6()1549 void test6()
1550 {
1551     if (foo61(0) != 2) assert(0);
1552     if (foo61(1) != 4) assert(0);
1553     if (foo62(0) != 4) assert(0);
1554     if (foo62(1) != 2) assert(0);
1555     if (foo63(0) != 8) assert(0);
1556     if (foo63(1) != 16) assert(0);
1557     if (foo64(0) != 16) assert(0);
1558     if (foo64(1) != 8) assert(0);
1559 }
1560 
1561 ////////////////////////////////////////////////////////////////////////
1562 
dataflow(int b)1563 int dataflow(int b) {
1564   int ret;
1565 
1566   if (b==4)
1567     ret = 3;
1568   else
1569     ret = 5;
1570 
1571   if (ret == 4)
1572     return 0;
1573   else
1574     return 1;
1575 }
1576 
testeqeqranges()1577 void testeqeqranges()
1578 {
1579     int i = dataflow(4);
1580     if (i != 1)
1581         assert(0);
1582 }
1583 
1584 ////////////////////////////////////////////////////////////////////////
1585 
1586 // https://issues.dlang.org/show_bug.cgi?id=16189
1587 
test16189()1588 void test16189()
1589 {
1590     ubyte[9][1] data;
1591     uint a = 0;
1592   loop:
1593     data[0] = data[a];
1594     a--;
1595     bool b = false;
1596     if (b) goto loop;
1597     assert(a == -1); // was failing with -O
1598 }
1599 
1600 
1601 ////////////////////////////////////////////////////////////////////////
1602 
1603 // https://issues.dlang.org/show_bug.cgi?id=16997
1604 
test16997()1605 void test16997()
1606 {
1607     /* Exhaustively test all signed and unsigned byte promotions for
1608      * - + and ~
1609      */
1610     for (int i = 0; i < 256; ++i)
1611     {
1612         ubyte c = cast(ubyte)i;
1613 
1614         int i1 = cast(int)(~c);
1615         int i2 = cast(int)(~cast(int)c);
1616 
1617         //printf("%d, %d\n", i1, i2);
1618         assert(i1 == i2);
1619 
1620         i1 = cast(int)(+c);
1621         i2 = cast(int)(+cast(int)c);
1622         assert(i1 == i2);
1623 
1624         i1 = cast(int)(-c);
1625         i2 = cast(int)(-cast(int)c);
1626         assert(i1 == i2);
1627     }
1628 
1629     for (int i = 0; i < 256; ++i)
1630     {
1631         byte c = cast(byte)i;
1632 
1633         int i1 = cast(int)(~c);
1634         int i2 = cast(int)(~cast(int)c);
1635 
1636         //printf("%d, %d\n", i1, i2);
1637         assert(i1 == i2);
1638 
1639         i1 = cast(int)(+c);
1640         i2 = cast(int)(+cast(int)c);
1641         assert(i1 == i2);
1642 
1643         i1 = cast(int)(-c);
1644         i2 = cast(int)(-cast(int)c);
1645         assert(i1 == i2);
1646     }
1647 }
1648 
1649 ////////////////////////////////////////////////////////////////////////
1650 
test18315()1651 void test18315() // https://issues.dlang.org/show_bug.cgi?id=18315
1652 {
1653     int i = int.min;
1654     bool b = i > 0;
1655     assert(!b);
1656     b = 0 < i;
1657     assert(!b);
1658 }
1659 
1660 ////////////////////////////////////////////////////////////////////////
1661 
1662 // https://issues.dlang.org/show_bug.cgi?id=18461
1663 
test18461()1664 void test18461()
1665 {
1666     import core.bitop;
1667 
1668     size_t test_val = 0b0001_0000;
1669 
1670     if (bt(&test_val, 4) == 0)
1671         assert(false);
1672 }
1673 
1674 ////////////////////////////////////////////////////////////////////////
1675 
test18730()1676 void test18730() // https://issues.dlang.org/show_bug.cgi?id=18730
1677 {
1678     static if (size_t.sizeof == 8)
1679     {
1680         static int bt18730_64_64(in ulong* p, ulong bitnum) pure @system
1681         {
1682             return ((p[bitnum >> 6] & (1L << (bitnum & 63)))) != 0;
1683         }
1684         static int bt18730_64_32(in ulong* p, uint bitnum) pure @system
1685         {
1686             return ((p[bitnum >> 6] & (1L << (bitnum & 63)))) != 0;
1687         }
1688         static int bt18730_32_64(in uint* p, ulong bitnum) pure @system
1689         {
1690             return ((p[bitnum >> 5] & (1 << (bitnum & 31)))) != 0;
1691         }
1692 
1693         // Check that bt_64_64 uses a 64-bit register for the offset.
1694         {
1695             enum bitIndex = int.max + 1L;
1696             auto a = new ulong[](bitIndex / 64 + 1);
1697             a[bitIndex / 64] = 1;
1698             assert(bt18730_64_64(a.ptr, bitIndex));
1699             assert(!bt18730_64_64(a.ptr, bitIndex + 1));
1700             assert(!bt18730_64_64(a.ptr, bitIndex - 1));
1701         }
1702         // Check that bt_64_32 uses a 32-bit register for the offset.
1703         {
1704             static int f(ulong* p, ulong bitnum)
1705             {
1706                 return bt18730_64_32(p, cast(uint) bitnum);
1707             }
1708             enum bitIndex = uint.max + 1L;
1709             assert(cast(uint) bitIndex == 0);
1710             ulong s = 1;
1711             assert(f(&s, bitIndex));
1712         }
1713         /* Check that bt_32_64 does not become a 64-bit bt instruction. Would lead
1714         to a segfault when trying to load 8 bytes while only 4 are accessible. */
1715         version (Posix)
1716         {{
1717             import core.sys.posix.sys.mman;
1718             import core.sys.posix.unistd;
1719             // Allocate two pages.
1720             immutable sz = 2 * sysconf(_SC_PAGESIZE);
1721             auto m = mmap(null, sz, PROT_READ, MAP_PRIVATE | MAP_ANON, -1, 0);
1722             // Discard the higher page. It becomes unreadable.
1723             munmap(m + sz / 2, sz / 2);
1724             // Try looking at the last 4 bytes of the readable page.
1725             uint* p = cast(uint*) (m + sz / 2 - uint.sizeof);
1726             bt18730_32_64(p, 0);
1727             munmap(m, sz / 2); // Free the readable page.
1728         }}
1729     }
1730 }
1731 
1732 ////////////////////////////////////////////////////////////////////////
1733 
test19497()1734 void test19497() // https://issues.dlang.org/show_bug.cgi?id=19497
1735 {
1736     {
1737         ubyte[1024] data;
1738         ushort* ushortPtr = cast(ushort*) data.ptr;
1739         *ushortPtr++ = 0xfe00;
1740         printf("ushortPtr(%p)\n", ushortPtr);
1741         fflush(stdout);
1742     }
1743 
1744     alias Seq(stuff ...) = stuff;
1745     static foreach (T; Seq!(ubyte, ushort, uint, ulong, byte, short, int, long))
1746     {{
1747         T[2] data = 0x2A;
1748         T* q = &data[0];
1749         *q++ = cast(T) 0x1122334455667788;
1750         if (*q != 0x2A) assert(false);
1751     }}
1752 
1753     {
1754         static int toStringz(string s) { return s.length > 0 ? s[0] : 0; }
1755         static void toAStringz(in string[] a, int* az)
1756         {
1757             foreach (string s; a)
1758             {
1759                 *az++ = toStringz(s);
1760             }
1761         }
1762         string[1] sa = ["abc"];
1763         int[2] tgt = 0x2a;
1764         toAStringz(sa[], tgt.ptr);
1765         if (tgt[0] != 'a') assert(false);
1766         if (tgt[1] != 0x2a) assert(false);
1767     }
1768 }
1769 
1770 ////////////////////////////////////////////////////////////////////////
1771 
1772 // https://issues.dlang.org/show_bug.cgi?id=18794
1773 
method18794(size_t * p)1774 bool method18794(size_t* p)
1775 {
1776     int bitIdx = 0;
1777     func18794();
1778     return (*p & (1UL << bitIdx)) != 0;
1779 }
1780 
func18794()1781 void func18794() {}
1782 
prep18794()1783 void prep18794()
1784 {
1785     asm {}
1786     ulong[2] x = -1;
1787 }
1788 
test18794()1789 void test18794()
1790 {
1791     prep18794();
1792     size_t s;
1793     method18794(&s);
1794 }
1795 
1796 ////////////////////////////////////////////////////////////////////////
1797 
1798 /* Test the optimization
1799  *  (e1+c)-e2 => (e1-e2)+c
1800  */
1801 
testelmin()1802 void testelmin()
1803 {
1804     static void foo(int i)
1805     {
1806         static ubyte[4] bar()
1807         {
1808             ubyte[4] array;
1809             foreach (i, ref a; array)
1810                 a = cast(ubyte)(i + 1);
1811             return array;
1812         }
1813 
1814         static void test(int i, ubyte* p)
1815         {
1816             foreach (j; 0 .. 4)
1817                 assert(p[i * 4 + j] == j + 1);
1818         }
1819 
1820         ubyte[32] data;
1821         data[i*4..(i+1)*4] = bar(); // optimize to single MOV
1822 
1823         test(i, data.ptr);
1824     }
1825 
1826     foo(4);
1827 }
1828 
1829 ////////////////////////////////////////////////////////////////////////
1830 
fastpar(string s)1831 const(char)* fastpar(string s)
1832 {
1833     return s.ptr + s.length;
1834 }
1835 
testfastpar()1836 void testfastpar()
1837 {
1838     string s = "abcde";
1839     auto p = fastpar(s);
1840     assert(*p == 0);
1841 }
1842 
1843 ////////////////////////////////////////////////////////////////////////
1844 // https://issues.dlang.org/show_bug.cgi?id=20363
1845 
foo20363(double d)1846 ulong foo20363(double d)
1847 {
1848     ulong u = * cast(ulong*) &d;
1849     return (u >> 1) & 1;
1850 }
1851 
test20363()1852 void test20363()
1853 {
1854     ulong u = 0b10;
1855     if (foo20363(*cast(double*) &u) == 0)
1856         assert(false);
1857 }
1858 
1859 ////////////////////////////////////////////////////////////////////////
1860 
1861 
testfooa(T)1862 T testfooa(T)(T value)
1863 {
1864     return 10 - (value * 57); // gets rewritten into (value*-57)+10
1865 }
1866 
testfoob(T)1867 T testfoob(T)(T value)
1868 {
1869     return (value * -57) + 10;
1870 }
1871 
testNegConst()1872 void testNegConst()
1873 {
1874     assert(testfooa(1) == -47);
1875     assert(testfoob(1) == -47);
1876     assert(testfooa(1.0) == -47);
1877     assert(testfoob(1.0) == -47);
1878 }
1879 
1880 ////////////////////////////////////////////////////////////////////////
1881 
1882 // https://issues.dlang.org/show_bug.cgi?id=16317
1883 
add8ret3(ref int s)1884 int add8ret3(ref int s)
1885 {
1886     s += 8;
1887     return 3;
1888 }
1889 
binAdd(int val)1890 int binAdd(int val)
1891 {
1892     val = val + add8ret3(val);
1893     return val;
1894 }
1895 
test16317()1896 void test16317()
1897 {
1898     assert(binAdd(1) == (1 + 3));
1899     static assert(binAdd(1) == (1 + 3));
1900 }
1901 
1902 ////////////////////////////////////////////////////////////////////////
1903 
1904 // https://issues.dlang.org/show_bug.cgi?id=20050
1905 
1906 int test20050_g = 0;
test20050_impure_function_1()1907 void test20050_impure_function_1() { ++test20050_g; }
function()1908 void function() test20050_get_impure_function() pure
1909 {
1910     static void impure_function_2()
1911     {
1912         ++test20050_g;
1913         test20050_impure_function_1();
1914     }
1915     return &impure_function_2;
1916 }
test20050()1917 void test20050()
1918 {
1919     auto f = test20050_get_impure_function();
1920     f();
1921     assert(test20050_g == 2);
1922 }
1923 
1924 ////////////////////////////////////////////////////////////////////////
1925 
1926 // http://github.com/dlang/dmd/pull/11238
1927 
testCpStatic1(int y)1928 int testCpStatic1(int y)
1929 {
1930     __gshared int yyy = 7;
1931     auto x = yyy; // no copy-propagation
1932     if (y)
1933         return x;
1934     return x + 3;
1935 }
1936 
testCpStatic()1937 void testCpStatic()
1938 {
1939     assert(testCpStatic1(1) == 7);
1940     assert(testCpStatic1(0) == 10);
1941 }
1942 
1943 ////////////////////////////////////////////////////////////////////////
1944 // https://issues.dlang.org/show_bug.cgi?id=20991
1945 
1946 int x7;
1947 
bar7(int i)1948 void bar7(int i)
1949 {
1950     assert(i == x7);
1951     ++x7;
1952 }
1953 
test7()1954 void test7()
1955 {
1956     for (int i = 0; i <= 1; ++i)
1957         bar7(i);
1958     assert(x7 == 2);
1959 }
1960 
1961 ////////////////////////////////////////////////////////////////////////
1962 
1963 // http://github.com/dlang/dmd/pull/11388
1964 
byteswap(ushort x)1965 ushort byteswap(ushort x) pure
1966 {
1967     // Should be detected and XCHG instruction generated
1968     return cast(ushort) (((x >> 8) & 0xFF) | ((x << 8) & 0xFF00u));
1969 }
1970 
testbyteswap()1971 void testbyteswap()
1972 {
1973     assert(byteswap(0xF234) == 0x34F2);
1974     static ushort xx = 0xF234;
1975     assert(byteswap(xx) == 0x34F2);
1976 }
1977 
1978 ////////////////////////////////////////////////////////////////////////
1979 
1980 // These should all be recognized by the compiler and generate ROL or ROR
1981 // instructions.
1982 
rol32(uint x,uint n)1983 uint rol32(uint x, uint n)
1984 {
1985     return (x << n) | (x >> (32 - n));
1986 }
1987 
ror32(uint x,uint n)1988 uint ror32(uint x, uint n)
1989 {
1990     return (x >> n) | (x << (32 - n));
1991 }
1992 
rol64(ulong x,uint n)1993 ulong rol64(ulong x, uint n)
1994 {
1995     return (x << n) | (x >> (64 - n));
1996 }
1997 
ror64(ulong x,uint n)1998 ulong ror64(ulong x, uint n)
1999 {
2000     return (x >> n) | (x << (64 - n));
2001 }
2002 
testrolror()2003 void testrolror()
2004 {
2005     assert(ror32(0x0123_4567u, 4) == 0x7012_3456);
2006     assert(rol32(0x7012_3456u, 4) == 0x0123_4567);
2007 
2008     assert(ror64(0x0123_4567_89AB_CDEFuL, 4) == 0xF012_3456_789A_BCDE);
2009     assert(rol64(0xF012_3456_789A_BCDEuL, 4) == 0x0123_4567_89AB_CDEF);
2010 }
2011 
2012 ////////////////////////////////////////////////////////////////////////
2013 
2014 // https://issues.dlang.org/show_bug.cgi?id=20162
2015 
test20162()2016 void test20162()
2017 {
2018     static long f(long a)
2019     {
2020          assert(a == -1L);
2021          return a;
2022     }
2023 
2024     foreach (i; 1 .. 2)
2025     {
2026         foreach (j; 0 .. 2)
2027         {
2028             printf("%d %d %llx\n", i,
2029               ((i != 0) ? -1 : +1),
2030               f((i != 0) ? -1 : +1));
2031         }
2032     }
2033 }
2034 
2035 ////////////////////////////////////////////////////////////////////////
2036 // https://issues.dlang.org/show_bug.cgi?id=3713
2037 
star1(int i)2038 int star1(int i)
2039 {
2040     return i ? star1(i - 1) : 0;
2041 }
2042 
star2(int i)2043 int star2(int i)
2044 {
2045     return i == 0 ? 0 : star2(i - 1);
2046 }
2047 
star3(int i)2048 int star3(int i)
2049 {
2050     if (i == 0)
2051         return 0;
2052     return i == 2 ? star3(i - 2) : star3(i - 1);
2053 }
2054 
star4(int i)2055 int star4(int i)
2056 {
2057     return (i == 0) ? 0
2058           : i != 2  ? star4(i - 1)
2059           : star4(i - 2);
2060 }
2061 
test3713()2062 void test3713()
2063 {
2064     assert(star1(10) == 0);
2065     assert(star2(10) == 0);
2066     assert(star3(10) == 0);
2067     assert(star4(10) == 0);
2068 }
2069 
2070 ////////////////////////////////////////////////////////////////////////
2071 
testsbbrex()2072 void testsbbrex()
2073 {
2074     // special code is generated for these two cases
2075     static long foolt(dchar c)
2076     {
2077         return c < 0x10000 ? 1 : 2;
2078     }
2079 
2080     static long fooge(uint c)
2081     {
2082         return c >= 0x10000 ? 1L : 2L;
2083     }
2084 
2085     assert(foolt(0) == 1);
2086     assert(foolt(0x10000) == 2);
2087     assert(fooge(0) == 2);
2088     assert(fooge(0x10000) == 1);
2089 }
2090 
2091 
2092 ////////////////////////////////////////////////////////////////////////
2093 
2094 // https://issues.dlang.org/show_bug.cgi?id=19846
2095 
2096 alias Void = byte[0];
2097 static immutable Void VOID; // = [];
2098 
2099 __gshared int x19846;
2100 
print19846()2101 Void print19846()
2102 {
2103     //printf("This should print\n");
2104     x19846 = 3;
2105     return VOID;
2106 }
2107 
identity19846(Void value,out int i)2108 Void identity19846(Void value, out int i)
2109 {
2110     i = 7;
2111     return value;
2112 }
2113 
test19846()2114 void test19846()
2115 {
2116     int i;
2117     identity19846(print19846(), i);
2118     //printf("i = %d\n", i);
2119     assert(x19846 == 3);
2120     assert(i == 7);
2121 }
2122 
2123 ////////////////////////////////////////////////////////////////////////
2124 
2125 // Some tests for OPmemcpy
2126 
2127 enum N = 128;
2128 
def()2129 ubyte[N] def()
2130 {
2131     ubyte[N] array;
2132     foreach (i, ref a; array)
2133         a = cast(ubyte)(i + 1);
2134     return array;
2135 }
2136 
2137 
ghi(ubyte * p)2138 void ghi(ubyte* p)
2139 {
2140     foreach (i; 0 .. N)
2141         assert(p[i] == i + 1);
2142 }
2143 
testmemcpy()2144 void testmemcpy()
2145 {
2146     ubyte[N] bits;
2147     ubyte[N] bits2;
2148     bits2[0..N] = bits[0..N] = def();
2149     ghi(bits.ptr);
2150     ghi(bits2.ptr);
2151 
2152     __gshared size_t n = N;
2153     ubyte[N] bits3;
2154     ubyte[N] bits4;
2155     bits4[0..n] = bits3[0..n] = def();
2156     ghi(bits3.ptr);
2157     ghi(bits4.ptr);
2158 }
2159 
2160 ////////////////////////////////////////////////////////////////////////
2161 
2162 
2163 /* Test all the cases of uses of LEA for multiplication by a constant
2164  */
2165 
testlea(uint C,T)2166 T testlea(uint C, T)(T x, T y)
2167 {
2168     y = y * C;          // cdmul()
2169     x *= C;             // cdmulass()
2170     return x + y;
2171 }
2172 
testleax(uint C)2173 void testleax(uint C)(uint X, uint Y)
2174 {
2175     assert(testlea!C(X,Y) == C * (X + Y));
2176     assert(testlea!C(cast(long)X,cast(long)Y) == cast(long)C*X + cast(long)C*Y);
2177 }
2178 
testMulLea()2179 void testMulLea()
2180 {
2181     testleax!3(10,11);
2182     testleax!5(10,11);
2183     testleax!6(10,11);
2184     testleax!9(10,11);
2185 
2186     testleax!10(10,11);
2187     testleax!12(10,11);
2188     testleax!18(10,11);
2189     testleax!20(10,11);
2190     testleax!24(10,11);
2191     testleax!36(10,11);
2192     testleax!40(10,11);
2193     testleax!72(10,11);
2194 
2195     testleax!37(10,11);
2196     testleax!74(10,11);
2197     testleax!13(10,11);
2198     testleax!26(10,11);
2199 }
2200 
2201 ////////////////////////////////////////////////////////////////////////
2202 
2203 /* Test *= of register pair
2204  */
2205 
testMulAssPair()2206 void testMulAssPair()
2207 {
2208     static ulong pow(ulong x, int m)
2209     {
2210         ulong v = x;
2211         ulong p = 1;
2212         while (1)
2213         {
2214             if (m & 1)
2215                 p *= v;
2216             m >>= 1;
2217             if (!m)
2218                 break;
2219             v *= v;
2220         }
2221         return p;
2222     }
2223 
2224     enum ulong e_10_pow_19 = 10uL^^19;
2225     assert(e_10_pow_19 == pow(10uL, 19));
2226 }
2227 
2228 ////////////////////////////////////////////////////////////////////////
2229 // https://issues.dlang.org/show_bug.cgi?id=21038
2230 
2231 const(wchar)* x21038 = "xz";
2232 const(dchar)* name21038 = "abcd";
2233 
test21038()2234 void test21038()
2235 {
2236     assert((cast(size_t)    x21038) % wchar.sizeof == 0);
2237     assert((cast(size_t) name21038) % dchar.sizeof == 0);
2238 }
2239 
2240 ////////////////////////////////////////////////////////////////////////
2241 // https://issues.dlang.org/show_bug.cgi?id=21325
2242 
f21325(const real x)2243 real f21325(const real x) pure @safe nothrow @nogc
2244 {
2245     return (x != 0.0L) ? x : real.nan;
2246 }
2247 
test21325()2248 void test21325() @safe
2249 {
2250     ulong x = 0uL;
2251     while(true)
2252     {
2253         const y = f21325(x); // should set y to real.nan
2254 
2255         assert(y != y);
2256 
2257         if (++x)
2258             return; // good
2259     }
2260 }
2261 
2262 ////////////////////////////////////////////////////////////////////////
2263 // https://issues.dlang.org/show_bug.cgi?id=16274
2264 
2265 extern(C) int pair(short a, ushort b, byte c, ubyte d);
2266 
2267 struct S
2268 {
2269     // provide alternate implementation of .pair()
2270     pragma(mangle, "pair")
pairS2271     extern(C) static void pair(int a, int b, int c, int d)
2272     {
2273         //printf("%d %d %d %d\n", a, b, c, d);
2274         assert(a == -1);
2275         assert(b == 2);
2276         assert(c == -3);
2277         assert(d == 4);
2278     }
2279 }
2280 
test16274()2281 void test16274()
2282 {
2283     version (X86_64)
2284         pair(-1, 2, -3, 4);
2285     version (X86)
2286         pair(-1, 2, -3, 4);
2287 }
2288 
2289 ////////////////////////////////////////////////////////////////////////
2290 // https://issues.dlang.org/show_bug.cgi?id=16268
2291 
test16268()2292 void test16268()
2293 {
2294     static void f(byte x)
2295     {
2296         for (byte i = 0; i <= x && i >= 0; ++i)
2297         {
2298             assert(i >= 0);
2299             assert(i != -1);
2300             //printf("%d\n", i);
2301         }
2302     }
2303 
2304     f(byte.max);
2305 }
2306 
2307 ////////////////////////////////////////////////////////////////////////
2308 // https://issues.dlang.org/show_bug.cgi?id=11435
2309 
test11435a()2310 void test11435a()
2311 {
2312     alias T = byte;
2313 
2314     static void fun(T c, T b, int v)
2315     {
2316     }
2317 
2318     static void abc(T[] b)
2319     {
2320         fun(b[0], b[1], 0);
2321     }
2322 
2323     version(Windows)
2324     {
2325         import core.sys.windows.windows;
2326         auto p = VirtualAlloc(null, 4096, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
2327     }
2328     else
2329     {
2330         import core.sys.posix.sys.mman;
2331         auto p = mmap(null, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0L);
2332     }
2333     assert(p);
2334     auto px = (cast(T*)(p + 4096 - 2 * T.sizeof));
2335     abc(px[0..2]);
2336 }
2337 
test11435b()2338 void test11435b()
2339 {
2340     import core.sys.windows.windows;
2341     alias T = short;
2342 
2343     static void fun(T c, T b, int v)
2344     {
2345     }
2346 
2347     static void abc(T[] b)
2348     {
2349         fun(b[0], b[1], 0);
2350     }
2351 
2352     version(Windows)
2353     {
2354         import core.sys.windows.windows;
2355         auto p = VirtualAlloc(null, 4096, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
2356     }
2357     else
2358     {
2359         import core.sys.posix.sys.mman;
2360         auto p = mmap(null, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0L);
2361     }
2362     assert(p);
2363     auto px = (cast(T*)(p + 4096 - 2 * T.sizeof));
2364     abc(px[0..2]);
2365 }
2366 
2367 ////////////////////////////////////////////////////////////////////////
2368 // https://issues.dlang.org/show_bug.cgi?id=21513
2369 
2370 struct Stuff
2371 {
2372     size_t c;         // declare after items and not crash !
2373     ubyte[1] items;
2374 }
2375 
grow(ref Stuff stuff)2376 void grow(ref Stuff stuff)
2377 {
2378     with (stuff)
2379     {
2380         const oldCapacity = c;
2381         items.ptr[0..oldCapacity] = items.ptr[0..0]; // use literal 0 instead of
2382         items.ptr[0] = 0;                            // oldcapacity and no crash !
2383     }
2384 }
2385 
test21513()2386 void test21513()
2387 {
2388     Stuff stuff;
2389     grow(stuff);
2390 }
2391 
2392 ////////////////////////////////////////////////////////////////////////
2393 // https://issues.dlang.org/show_bug.cgi?id=21526
2394 
f21256(double a,double b)2395 double f21256(double a, double b) {
2396     double c = a + b;
2397     return c;
2398 }
2399 
test21256()2400 void test21256()
2401 {
2402     union DX
2403     {
2404         double d;
2405         ulong l;
2406     }
2407 
2408     DX a, b;
2409     a.l = 0x4341c37937e08000;
2410     b.l = 0x4007ffcb923a29c7;
2411 
2412     DX r;
2413     r.d = f21256(a.d, b.d);
2414     //if (r.d != 0x1.1c37937e08001p+53)
2415         //printf("r = %A should be 0x1.1c37937e08001p+53 %A\n", r.d, 0x1.1c37937e08001p+53);
2416     //assert(r == 0x1.1c37937e08001p+53);
2417 
2418     // cannot seem to get the two to produce the same value
2419     assert(r.l == 0x4341c37937e08001 || // value using XMM
2420            r.l == 0x4341c37937e08002);  // value using x87
2421 }
2422 
2423 ////////////////////////////////////////////////////////////////////////
2424 // https://issues.dlang.org/show_bug.cgi?id=21816
2425 
test21816a(float t)2426 bool test21816a(float t)
2427 {
2428     return cast(bool)t;
2429 }
2430 
test21816()2431 void test21816()
2432 {
2433     assert(test21816a(float.nan));
2434 }
2435 
2436 ////////////////////////////////////////////////////////////////////////
2437 // https://issues.dlang.org/show_bug.cgi?id=21835
2438 
2439 struct Point21835
2440 {
2441     float  f = 3.0;
2442     double d = 4.0;
2443     real   r = 5.0;
2444 }
2445 
test21835y()2446 void test21835y()
2447 {
2448     Point21835[1] arr;
2449     if (arr[0].f != 3.0) assert(0);
2450     if (arr[0].d != 4.0) assert(0);
2451     if (arr[0].r != 5.0) assert(0);
2452 }
2453 
2454 struct Point21835x
2455 {
2456     float  f = 0.0;
2457     double d = 0.0;
2458     real   r = 0.0;
2459 }
2460 
test21835()2461 void test21835()
2462 {
2463     test21835y();
2464     Point21835x[1] arr;
2465     if (arr[0].f != 0.0) assert(0);
2466     if (arr[0].d != 0.0) assert(0);
2467     if (arr[0].r != 0.0) assert(0);
2468 }
2469 
2470 ////////////////////////////////////////////////////////////////////////
2471 
main()2472 int main()
2473 {
2474     // All the various integer divide tests
2475     testsdiv2();
2476     testulldiv();
2477     testfastudiv();
2478     testsldiv();
2479     testslmod();
2480     testfastdiv();
2481     testdivdiv();
2482     testdivcmp();
2483 
2484     testgoto();
2485     testswitch();
2486     testdo();
2487     testbreak();
2488     teststringswitch();
2489     teststrarg();
2490     test12164();
2491     testsizes();
2492     testarrayinit();
2493     testU();
2494     testbittest();
2495     test8658();
2496     test3918();
2497     test12051();
2498     testdocond();
2499     testnegcom();
2500     test11565();
2501     testoror();
2502     testbt();
2503     test12095(0);
2504     testandand();
2505     testor_combine();
2506     testshrshl();
2507     test13383();
2508     test13190();
2509     test13485();
2510     test14436();
2511     test10715();
2512     test10678();
2513     test7565();
2514     test13023(0x10_0000_0000);
2515     test12833();
2516     test9449();
2517     test9449x();
2518     test12057();
2519     test13784();
2520     test14220();
2521     test14829();
2522     test3();
2523     test14782();
2524     test14987();
2525     test15272();
2526     test15861();
2527     test15629();
2528     test4();
2529     test13474();
2530     test16699();
2531     test16102();
2532     test5();
2533     test6();
2534     testeqeqranges();
2535     test16189();
2536     test16997();
2537     test18315();
2538     test18461();
2539     test18730();
2540     test19497();
2541     test18794();
2542     testelmin();
2543     testfastpar();
2544     test20363();
2545     testNegConst();
2546     test16317();
2547     test20050();
2548     testCpStatic();
2549     test7();
2550     testbyteswap();
2551     testrolror();
2552     test20162();
2553     test3713();
2554     testsbbrex();
2555     test19846();
2556     testmemcpy();
2557     testMulLea();
2558     testMulAssPair();
2559     test21038();
2560     test21325();
2561     test16274();
2562     test16268();
2563     test11435a();
2564     test11435b();
2565     test21513();
2566     test21256();
2567     test21816();
2568     test21835();
2569 
2570     printf("Success\n");
2571     return 0;
2572 }
2573