-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mkt-int.sh
1518 lines (1398 loc) · 38.4 KB
/
mkt-int.sh
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
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
rcsid='$MirOS: int/mkt-int.sh,v 1.47 2024/04/02 09:04:32 tg Exp $'
#-
# © mirabilos Ⓕ MirBSD
# Warning: stress test, creates multiple multi-MiB .c files, .o about half each
set -e
BC_ENV_ARGS=-qs LC_ALL=C LANGUAGE=C
unset LANGUAGE
export BC_ENV_ARGS LC_ALL
nl='
'
ht=' '
rcsid="$rcsid ($*|$LDFLAGS)"
die() {
w=false
if test x"$1" = x"-w"; then
w=true
shift
fi
echo >&2 "E: mkt-int.sh: $*"
if $w; then
echo >&2 'N: press Return to continue'
read dummy
fi
exit 1
}
v() { (
set -x
exec "$@"
); }
if test x"$1" = x"-cxx"; then
shift
usecxx=true
else
usecxx=false
fi
if test x"$1" = x"-x"; then
shift
cross=true
else
cross=false
fi
if test -z "$1"; then cat >&2 <<\EOF
E: usage: LDFLAGS=$LDFLAGS sh mkt-int.sh [-cxx] [-x] \
$CC $CPPFLAGS $CFLAGS [-Dextra...]
N: -cxx = build as CFrustFrust
N: -x = cross-compile
N: extra definitions can be:
N: -DMBSDINT_H_SMALL_SYSTEM=1/2/3
N: -DMBSDINT_H_MBIPTR_IS_SIZET=0 (if sizet_mbiPTRU fails)
N: -DMBSDINT_H_MBIPTR_IN_LARGE=0 (+ mbiPTRU_inlarge, do report!)
N: -DMBSDINT_H_WANT_LONG_IN_SIZET=0 (for 16-bit size_t from int)
N: -DMBSDINT_H_WANT_PTR_IN_SIZET (extra check, see below)
N: -DMBSDINT_H_WANT_SIZET_IN_LONG (extra check, !Win64)
N: -DMBSDINT_H_WANT_INT32 (extra check, POSIX guaranteed)
N: -DMBSDINT_H_WANT_LRG64 (ensure a 64-bit type exists)
N: -DMBSDINT_H_WANT_SAFEC (test safe twos complement)
EOF
exit 3
fi
test "$(bc <<\EOF
define f(x) {
return (-(256 - x))
}
for (v = 4; v <= 5; ++v) {
v
f(v)
}
EOF
)" = "4${nl}-252${nl}5${nl}-251" || die 'bc(1) inoperable'
cd "$(dirname "$0")" || die cannot change to script directory
rm -f mkt-int-t* || die cannot delete old files
test -n "$DEBUG" || trap 'rm -f mkt-int-t*' EXIT
srcext=c
case " $* " in
*\ do-cl.bat\ *)
Fe=/Fe
objext=obj
$usecxx && srcext=cxx || :
;;
*\ wcl\ *|*\ wcl386\ *)
Fe=-fe=
objext=obj
set -- "$@" "-fo=.$objext"
$usecxx && srcext=cc || :
;;
*)
Fe='-o '
objext=o
$usecxx && srcext=cc || :
;;
esac
echo >&2 'I: testing whether we can detect configure failures...'
canfail=false
cat >mkt-int-t-in.$srcext <<EOF
extern int thiswillneverbedefinedIhope(void);
int main(void) { return (thiswillneverbedefinedIhope()); }
EOF
v "$@" $LDFLAGS ${Fe}mkt-int-t-t.exe mkt-int-t-in.$srcext || canfail=true
$canfail || die cannot fail
echo >&2 'I: checking if we can build at all'
cat >mkt-int-t-in.$srcext <<EOF
#ifndef __STDC_WANT_LIB_EXT1__
#define __STDC_WANT_LIB_EXT1__ 1
#endif
#include <limits.h>
#include <stdio.h>
#include <time.h>
#include "mbsdcc.h"
typedef unsigned char but;
typedef signed char bst;
typedef unsigned short hut;
typedef signed short hst;
mbCTA_BEG(check);
/* it can easily be ported to allow CHAR_BIT ≠ 8, if needed */
mbCTA(testsuite_assumes_char_has_8_bits, (CHAR_BIT) == 8);
mbCTA_END(check);
int main(void) {
return (printf("Hi!"));
}
EOF
v "$@" $LDFLAGS ${Fe}mkt-int-t-t.exe mkt-int-t-in.$srcext || die cannot build
$cross || test "$(set +e; ./mkt-int-t-t.exe; echo $?)" = "Hi!3" || die fails to run
rm -f mkt-int-t-t.exe
echo >&2 'I: checking if we can compile and link separately'
v "$@" -c mkt-int-t-in.$srcext || die cannot compile
v "$@" $LDFLAGS ${Fe}mkt-int-t-t.exe mkt-int-t-*.$objext || die cannot link
$cross || test "$(set +e; ./mkt-int-t-t.exe; echo $?)" = "Hi!3" || die fails to run
test -n "$TARGET_OS" || TARGET_OS=$(uname -s 2>/dev/null || uname)
flagstotest=-Werror
case $TARGET_OS in
MirBSD)
;;
*)
flagstotest="$flagstotest -fno-lto -qnoipa -xipo=0"
;;
esac
case " $* " in
*\ do-cl.bat\ *)
flagstotest='/WX' ;;
*\ owcc\ *|*\ wcl\ *|*\ wcl386\ *)
flagstotest= ;;
esac
for flagtotest in $flagstotest; do
varname=$(echo "X$flagtotest" | sed \
-e 's!^X[/-]*!HAVE_CAN_!' | tr \
qwertyuiopasdfghjklzxcvbnm/=- \
QWERTYUIOPASDFGHJKLZXCVBNM___)
eval "varvalue=\${$varname-x}"
case $varvalue in
0)
echo >&2 "I: skipping trying to add $flagtotest"
continue
;;
1)
echo >&2 "I: forcing to add $flagtotest"
set -- "$@" $flagtotest
continue
;;
esac
echo >&2 "I: checking if we can add $flagtotest"
if v "$@" $LDFLAGS $flagtotest ${Fe}mkt-int-t-t.exe mkt-int-t-in.$srcext; then
set -- "$@" $flagtotest
fi
done
use_systypes='#include <sys/types.h>'
use_stdint='#include <stdint.h>'
use_inttypes='#include <inttypes.h>'
use_basetsd='#include <basetsd.h>'
use_icexp_rsmax=-DHAVE_INTCONSTEXPR_RSIZE_MAX
have_offt=1
echo >&2 'I: checking if we have <sys/types.h>'
cat >mkt-int-t-in.$srcext <<EOF
#ifndef __STDC_WANT_LIB_EXT1__
#define __STDC_WANT_LIB_EXT1__ 1
#endif
$use_systypes
#include <limits.h>
#include <stddef.h>
#include <stdio.h>
typedef unsigned char but;
typedef signed char bst;
typedef unsigned short hut;
typedef signed short hst;
int main(void) { return (printf("Hi!\\n")); }
EOF
v "$@" $LDFLAGS ${Fe}mkt-int-t-t.exe mkt-int-t-in.$srcext || use_systypes=
echo >&2 'I: checking if we have <inttypes.h>'
cat >mkt-int-t-in.$srcext <<EOF
#ifndef __STDC_WANT_LIB_EXT1__
#define __STDC_WANT_LIB_EXT1__ 1
#endif
$use_systypes
$use_inttypes
#include <limits.h>
#include <stddef.h>
#include <stdio.h>
typedef unsigned char but;
typedef signed char bst;
typedef unsigned short hut;
typedef signed short hst;
int main(void) { return (printf("Hi!\\n")); }
EOF
v "$@" $LDFLAGS ${Fe}mkt-int-t-t.exe mkt-int-t-in.$srcext || use_inttypes=
echo >&2 'I: checking if we have <stdint.h>'
cat >mkt-int-t-in.$srcext <<EOF
#ifndef __STDC_WANT_LIB_EXT1__
#define __STDC_WANT_LIB_EXT1__ 1
#endif
$use_systypes
$use_inttypes
$use_stdint
#include <limits.h>
#include <stddef.h>
#include <stdio.h>
typedef unsigned char but;
typedef signed char bst;
typedef unsigned short hut;
typedef signed short hst;
int main(void) { return (printf("Hi!\\n")); }
EOF
v "$@" $LDFLAGS ${Fe}mkt-int-t-t.exe mkt-int-t-in.$srcext || use_stdint=
echo >&2 'I: checking if we have <basetsd.h>'
cat >mkt-int-t-in.$srcext <<EOF
#ifndef __STDC_WANT_LIB_EXT1__
#define __STDC_WANT_LIB_EXT1__ 1
#endif
$use_systypes
$use_inttypes
$use_stdint
$use_basetsd
#include <limits.h>
#include <stddef.h>
#include <stdio.h>
typedef unsigned char but;
typedef signed char bst;
typedef unsigned short hut;
typedef signed short hst;
int main(void) { return (printf("Hi!\\n")); }
EOF
v "$@" $LDFLAGS ${Fe}mkt-int-t-t.exe mkt-int-t-in.$srcext || use_basetsd=
echo >&2 'I: checking whether RSIZE_MAX is an integer constant expression'
cat >mkt-int-t-in.$srcext <<EOF
#ifndef __STDC_WANT_LIB_EXT1__
#define __STDC_WANT_LIB_EXT1__ 1
#endif
$use_systypes
$use_inttypes
$use_stdint
$use_basetsd
#include <limits.h>
#include <stdio.h>
#include "mbsdcc.h"
typedef unsigned char but;
typedef signed char bst;
typedef unsigned short hut;
typedef signed short hst;
#ifdef _MSC_VER
#pragma warning(disable:4310)
#endif
int tstarr[((int)mbccCEX(RSIZE_MAX) & 1) + 1] = {0};
#if defined(INTMAX_MIN)
#define mbiHUGE_U uintmax_t
#elif defined(LLONG_MIN)
#define mbiHUGE_U unsigned long long
#elif defined(_UI64_MAX)
#define mbiHUGE_U unsigned __int64
#elif defined(QUAD_MIN)
#define mbiHUGE_U u_quad_t
#else
#define mbiHUGE_U unsigned long
#endif
mbCTA_BEG(check);
mbCTA(fits_sizet, (mbiHUGE_U)(RSIZE_MAX) == (mbiHUGE_U)(size_t)(RSIZE_MAX));
mbCTA_END(check);
int main(void) { return (printf("Hi! %d\\n", tstarr[0])); }
EOF
v "$@" $LDFLAGS $use_icexp_rsmax ${Fe}mkt-int-t-t.exe mkt-int-t-in.$srcext || use_icexp_rsmax=
set -- "$@" $use_icexp_rsmax
echo >&2 'I: checking for off_t'
cat >mkt-int-t-in.$srcext <<EOF
#ifndef __STDC_WANT_LIB_EXT1__
#define __STDC_WANT_LIB_EXT1__ 1
#endif
$use_systypes
$use_inttypes
$use_stdint
$use_basetsd
#include <limits.h>
#include <stddef.h>
#include <stdio.h>
typedef unsigned char but;
typedef signed char bst;
typedef unsigned short hut;
typedef signed short hst;
int main(void) { return ((int)sizeof(off_t)); }
EOF
v "$@" $LDFLAGS ${Fe}mkt-int-t-t.exe mkt-int-t-in.$srcext || have_offt=0
set -- "$@" -DHAVE_OFF_T=$have_offt
xset() {
v=have
test -n "$1" || v=lack
}
echo >&2 'I: results so far:'
xset "$use_systypes"
echo >&2 "N: you $v <sys/types.h>"
xset "$use_basetsd"
echo >&2 "N: you $v <basetsd.h>"
xset "$use_inttypes"
echo >&2 "N: you $v <inttypes.h>"
xset "$use_stdint"
echo >&2 "N: you $v <stdint.h>"
xset "$use_icexp_rsmax"
echo >&2 "N: you $v an integer constant expression RSIZE_MAX"
echo >&2 'I: checking if compile-time checks pass'
cat >mkt-int-t-in.$srcext <<EOF
#ifndef __STDC_WANT_LIB_EXT1__
#define __STDC_WANT_LIB_EXT1__ 1
#endif
$use_systypes
$use_inttypes
$use_stdint
$use_basetsd
#undef MBSDINT_H_SKIP_CTAS
#include "mbsdcc.h"
#include "mbsdint.h"
#include <stdio.h>
int main(void) { return (printf("Hi!\\n")); }
EOF
v "$@" $LDFLAGS ${Fe}mkt-int-t-t.exe mkt-int-t-in.$srcext || die compile-time checks fail
use_float='#include <float.h>'
echo >&2 'I: checking if we have <float.h>'
cat >mkt-int-t-in.$srcext <<EOF
#ifndef __STDC_WANT_LIB_EXT1__
#define __STDC_WANT_LIB_EXT1__ 1
#endif
$use_systypes
$use_inttypes
$use_stdint
$use_basetsd
$use_float
#include <limits.h>
#include <stddef.h>
#include <stdio.h>
int main(void) { return (printf("Hi!\\n")); }
EOF
v "$@" $LDFLAGS ${Fe}mkt-int-t-t.exe mkt-int-t-in.$srcext || die use_float=
echo >&2 'I: creating tests... (can take very long)'
cat - xxt-int.c >mkt-int-t-xx.$srcext <<EOF
#ifndef __STDC_WANT_LIB_EXT1__
#define __STDC_WANT_LIB_EXT1__ 1
#endif
$use_systypes
$use_inttypes
$use_stdint
$use_basetsd
#undef MBSDINT_H_SKIP_CTAS
#include "mbsdcc.h"
#include "mbsdint.h"
#include "xxt-int.h"
#include <string.h>
EOF
for x in 0 1 2; do
cat >mkt-int-t-f$x.$srcext <<EOF
#ifndef __STDC_WANT_LIB_EXT1__
#define __STDC_WANT_LIB_EXT1__ 1
#endif
$use_systypes
$use_inttypes
$use_stdint
$use_basetsd
#define MBSDINT_H_SKIP_CTAS 1
#include "mbsdcc.h"
#include "mbsdint.h"
#include <stdio.h>
#include "xxt-int.h"
#include "mkt-int-t-ff.h"
EOF
done
cat >mkt-int-t-in.$srcext <<EOF
#define S(x) #x
#define s(x) S(x)
#ifdef MBSDINT_H_MBIPTR_IS_SIZET
static const char oMBSDINT_H_MBIPTR_IS_SIZET[] = "passed '" s(MBSDINT_H_MBIPTR_IS_SIZET) "'";
#else
static const char oMBSDINT_H_MBIPTR_IS_SIZET[] = "not passed";
#endif
#ifdef MBSDINT_H_MBIPTR_IN_LARGE
static const char oMBSDINT_H_MBIPTR_IN_LARGE[] = "passed '" s(MBSDINT_H_MBIPTR_IN_LARGE) "'";
#else
static const char oMBSDINT_H_MBIPTR_IN_LARGE[] = "not passed";
#endif
#ifdef MBSDINT_H_WANT_LONG_IN_SIZET
static const char oMBSDINT_H_WANT_LONG_IN_SIZET[] = "passed '" s(MBSDINT_H_WANT_LONG_IN_SIZET) "'";
#else
static const char oMBSDINT_H_WANT_LONG_IN_SIZET[] = "not passed";
#endif
#ifdef MBSDINT_H_WANT_PTR_IN_SIZET
static const char oMBSDINT_H_WANT_PTR_IN_SIZET[] = "passed '" s(MBSDINT_H_WANT_PTR_IN_SIZET) "'";
#else
static const char oMBSDINT_H_WANT_PTR_IN_SIZET[] = "not passed";
#endif
#ifdef MBSDINT_H_WANT_SIZET_IN_LONG
static const char oMBSDINT_H_WANT_SIZET_IN_LONG[] = "passed '" s(MBSDINT_H_WANT_SIZET_IN_LONG) "'";
#else
static const char oMBSDINT_H_WANT_SIZET_IN_LONG[] = "not passed";
#endif
#ifdef MBSDINT_H_WANT_INT32
static const char oMBSDINT_H_WANT_INT32[] = "passed '" s(MBSDINT_H_WANT_INT32) "'";
#else
static const char oMBSDINT_H_WANT_INT32[] = "not passed";
#endif
#ifdef MBSDINT_H_WANT_LRG64
static const char oMBSDINT_H_WANT_LRG64[] = "passed '" s(MBSDINT_H_WANT_LRG64) "'";
#else
static const char oMBSDINT_H_WANT_LRG64[] = "not passed";
#endif
#ifdef MBSDINT_H_WANT_SAFEC
static const char oMBSDINT_H_WANT_SAFEC[] = "passed '" s(MBSDINT_H_WANT_SAFEC) "'";
#else
static const char oMBSDINT_H_WANT_SAFEC[] = "not passed";
#endif
#undef s
#undef S
#ifndef __STDC_WANT_LIB_EXT1__
#define __STDC_WANT_LIB_EXT1__ 1
#endif
$use_systypes
$use_inttypes
$use_stdint
$use_basetsd
#define MBSDINT_H_SKIP_CTAS 1
#include "mbsdcc.h"
#include "mbsdint.h"
$use_float
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define XXT_DO_STDIO_IMPLS
#include "xxt-int.h"
#include "mkt-int-t-ff.h"
static const char use_systypes[] = "$use_systypes";
static const char use_inttypes[] = "$use_inttypes";
static const char use_stdint[] = "$use_stdint";
static const char use_basetsd[] = "$use_basetsd";
static const char test_rcsid[] = "$rcsid";
extern const char xxtc_rcsid[];
EOF
cat >>mkt-int-t-in.$srcext <<\EOF
int rv = 0;
but bin1u, bin2u, boutu;
bst bin1s, bin2s, bouts;
hut hin1u, hin2u, houtu;
hst hin1s, hin2s, houts;
int iouts;
const char *fstr;
static void c2_(const char *where) {
fprintf(stderr, "E: %s(%02X, %u) failed, got %02X want %02X\n",
where, (unsigned)hin1u, (unsigned)hin2u,
(unsigned)boutu, (unsigned)iouts);
rv = 1;
}
static void cs_(const char *where) {
fprintf(stderr, "E: %s(%d, %d) failed, got %d want %d\n",
where, (signed)hin1s, (signed)hin2s,
(signed)bouts, (signed)iouts);
rv = 1;
}
static void cf_(const char *where) {
fprintf(stderr, "E: %s(%02X, %u) overflow: want %d got %d\n",
where, (unsigned)hin1u, (unsigned)hin2u, houts, hin1s);
rv = 1;
}
#define c2(where) do { \
if (boutu != (unsigned)iouts) \
c2_(where); \
} while (/* CONSTCOND */ 0)
#define C2u(where) do { \
if (hin1s != houts) \
cf_(where); \
else if (!hin1s && \
(boutu != (unsigned)iouts)) \
c2_(where); \
} while (/* CONSTCOND */ 0)
#define C2s(where) do { \
if (hin1u != houtu) \
cf_(where); \
else if (!hin1u && \
(bouts != iouts)) \
cs_(where); \
} while (/* CONSTCOND */ 0)
typedef long larr[3];
typedef larr *larrp;
static const int xMBSDINT_H_MBIPTR_IS_SIZET =
#if defined(UINTPTR_MAX) && !defined(__CHERI__)
sizeof(size_t) == sizeof(uintptr_t) &&
#endif
sizeof(mbiPTR_U) == sizeof(size_t) &&
mbiTYPE_UBITS(mbiPTR_U) == mbiTYPE_UBITS(size_t);
static const int xMBSDINT_H_MBIPTR_IN_LARGE =
sizeof(mbiPTR_U) <= sizeof(mbiLARGE_U) &&
mbiTYPE_UBITS(mbiPTR_U) <= mbiMASK_BITS(mbiLARGE_U_MAX);
static const int xMBSDINT_H_WANT_LONG_IN_SIZET =
sizeof(size_t) >= sizeof(long);
static const int xMBSDINT_H_WANT_PTR_IN_SIZET =
sizeof(void *) == sizeof(size_t) &&
sizeof(char *) == sizeof(size_t) &&
sizeof(int *) == sizeof(size_t) &&
sizeof(larrp) == sizeof(size_t) &&
sizeof(void (*)(void)) == sizeof(size_t);
static const int xMBSDINT_H_WANT_SIZET_IN_LONG =
sizeof(size_t) <= sizeof(long);
static const int xMBSDINT_H_WANT_INT32 =
mbiTYPE_UBITS(unsigned int) >= 32;
static const int xMBSDINT_H_WANT_LRG64 =
mbiTYPE_UBITS(mbiLARGE_U) >= 64;
static const int xMBSDINT_H_WANT_SAFEC =
mbiSAFECOMPLEMENT == 1;
#define s(x) "'" mbccS(x) "'"
#ifdef MBSDINT_H_MBIPTR_IS_SIZET
static const char dMBSDINT_H_MBIPTR_IS_SIZET[] = s(MBSDINT_H_MBIPTR_IS_SIZET);
#else
static const char dMBSDINT_H_MBIPTR_IS_SIZET[] = "undef";
#endif
#ifdef MBSDINT_H_MBIPTR_IN_LARGE
static const char dMBSDINT_H_MBIPTR_IN_LARGE[] = s(MBSDINT_H_MBIPTR_IN_LARGE);
#else
static const char dMBSDINT_H_MBIPTR_IN_LARGE[] = "undef";
#endif
#ifdef MBSDINT_H_WANT_LONG_IN_SIZET
static const char dMBSDINT_H_WANT_LONG_IN_SIZET[] = s(MBSDINT_H_WANT_LONG_IN_SIZET);
#else
static const char dMBSDINT_H_WANT_LONG_IN_SIZET[] = "undef";
#endif
#ifdef MBSDINT_H_WANT_PTR_IN_SIZET
static const char dMBSDINT_H_WANT_PTR_IN_SIZET[] = s(MBSDINT_H_WANT_PTR_IN_SIZET);
#else
static const char dMBSDINT_H_WANT_PTR_IN_SIZET[] = "undef";
#endif
#ifdef MBSDINT_H_WANT_SIZET_IN_LONG
static const char dMBSDINT_H_WANT_SIZET_IN_LONG[] = s(MBSDINT_H_WANT_SIZET_IN_LONG);
#else
static const char dMBSDINT_H_WANT_SIZET_IN_LONG[] = "undef";
#endif
#ifdef MBSDINT_H_WANT_INT32
static const char dMBSDINT_H_WANT_INT32[] = s(MBSDINT_H_WANT_INT32);
#else
static const char dMBSDINT_H_WANT_INT32[] = "undef";
#endif
#ifdef MBSDINT_H_WANT_LRG64
static const char dMBSDINT_H_WANT_LRG64[] = s(MBSDINT_H_WANT_LRG64);
#else
static const char dMBSDINT_H_WANT_LRG64[] = "undef";
#endif
#ifdef MBSDINT_H_WANT_SAFEC
static const char dMBSDINT_H_WANT_SAFEC[] = s(MBSDINT_H_WANT_SAFEC);
#else
static const char dMBSDINT_H_WANT_SAFEC[] = "undef";
#endif
#undef s
struct ChkTest {
char expr1[mbccChkExpr(3*3) + 1];
mbmscWs(4820) /* padding warning */
unsigned int expr2 : mbccCEX(3*3);
};
/* ensure flexible array members can be used */
struct want_fam {
int blahfoo;
char moo;
mbccFAMslot(char, label);
};
union pre1_fam {
struct want_fam s;
char storage[mbccFAMSZ(struct want_fam, label, 1)];
};
union pre5_fam {
struct want_fam s;
char storage[mbccFAMSZ(struct want_fam, label, 5)];
};
struct fam_t {
int count;
mbccFAMslot(time_t, value);
};
mbCTA_BEG(fieldsizeof);
mbCTA(o0, offsetof(struct want_fam, blahfoo) == 0);
mbCTA(s0, mbccFSZ(struct want_fam, blahfoo) == sizeof(int));
mbCTA(o1, offsetof(struct want_fam, moo) >= sizeof(int));
mbCTA(s1, mbccFSZ(struct want_fam, moo) == sizeof(char));
mbCTA(o2, offsetof(struct want_fam, label) >=
(offsetof(struct want_fam, moo) + sizeof(char)));
mbCTA(e1, mbccFSZ(struct ChkTest, expr1) == 1);
mbCTA_END(fieldsizeof);
static const char faml[] = "FAM label";
void dfam(const char *what, const char *exp, struct want_fam *fam);
void dfam(const char *what, const char *exp, struct want_fam *fam) {
fprintf(stderr, "I: %s: the following text should read '%s':\n", what, exp);
fflush(stderr);
fprintf(stderr, "N: '%s'\n", fam->label);
}
volatile int zero = 0;
volatile mbiHUGE_U uzero = 0;
static void
ti_f(const char *t, size_t sz, const char *Min, const char *Max)
{
fprintf(stderr, "N: %18s: floatish, %u chars, min(%s) max(%s)\n",
t, 0U+(unsigned)sz, Min, Max);
}
static void
tin_u(const char *t, size_t sz,
unsigned Bits, const char *Max, unsigned Mb)
{
fprintf(stderr, "N: %18s: unsigned, %u chars, %u bits, max(%s) w=%u\n",
t, 0U+(unsigned)sz, Bits, Max, Mb);
}
static void
tif_u(const char *t, size_t sz, int TbOK, int MaxOK,
mbiHUGE_U Tb, const char *Max, mbiHUGE_U uMax)
{
fprintf(stderr, "N: %18s: unsigned, %u chars, ", t, 0U+(unsigned)sz);
if (TbOK == 1)
fprintf(stderr, "%u", mbiMASK_BITS(Tb));
else
fprintf(stderr, "more than %u", mbiTYPE_UBITS(mbiHUGE_U));
fprintf(stderr, " bits, max(%s) w", Max);
if (MaxOK == 0)
fprintf(stderr, "=0\n");
else if (MaxOK == 1)
fprintf(stderr, "=%u\n", mbiMASK_BITS(uMax));
else
fprintf(stderr, " > %u\n", mbiTYPE_UBITS(mbiHUGE_U));
}
static void
tin_s(const char *t, size_t sz, const char *Min, const char *Max, unsigned Bits)
{
fprintf(stderr, "N: %18s: signed, %u chars, min(%s), max(%s) w=%u\n",
t, 0U+(unsigned)sz, Min, Max, Bits);
}
static void
tif_s(const char *t, size_t sz, const char *Min, const char *Max,
int MaxOK, mbiHUGE_U uMax)
{
fprintf(stderr, "N: %18s: signed, %u chars, min(%s), max(%s) w",
t, 0U+(unsigned)sz, Min, Max);
if (MaxOK == 0)
fprintf(stderr, "=0\n");
else if (MaxOK == 1)
fprintf(stderr, "=%u\n", mbiMASK_BITS(uMax) + 1U);
else
fprintf(stderr, " > %u\n", mbiTYPE_UBITS(mbiHUGE_U));
}
int main(void) {
unsigned int b_rsz = 0, b_sz = 0, b_ptr = 0, b_mbi = 0, f_mbi;
const char *whichrepr;
const char *mbiPTR_casttgt;
struct want_fam *fam;
struct fam_t *fam2;
struct ChkTest ct = { { 0 }, 1 };
--ct.expr2;
--ct.expr2;
/* check FAMs don’t warn */
fam = (struct want_fam *)malloc(mbccFAMSZ(struct want_fam, label, sizeof(faml)));
if (!fam) {
fprintf(stderr, "E: malloc failed\n");
return (1);
}
memcpy(&fam->label, faml, sizeof(faml));
dfam("faml", faml, fam);
free(fam);
fam2 = (struct fam_t *)malloc(mbccFAMSZ(struct fam_t, value, sizeof(time_t[5])));
fam2->count = 5;
free(fam2);
(void)mbccFAMsz(struct fam_t, value, sizeof(time_t[5]));
#undef mbccABEND
#define mbccABEND(reasonstr) (fprintf(stderr, "E: mbccABEND: %s\n", (reasonstr)), abort())
fam2 = (struct fam_t *)malloc(mbccFAMsz(struct fam_t, value, sizeof(time_t[5])));
free(fam2);
/* CFrustFrust has no support for FAMs, so omit triggering -Warray-bounds */
#if !defined(__cplusplus) || defined(__cpp_flexible_array_members) || defined(_MSC_VER)
{
union pre1_fam p1fam;
union pre5_fam p5fam;
p1fam.s.label[0] = '\0';
p5fam.s.label[0] = 'm';
p5fam.s.label[1] = 'i';
p5fam.s.label[2] = 'a';
p5fam.s.label[3] = 'u';
p5fam.s.label[4] = '\0';
dfam("p1", "", (struct want_fam *)&p1fam);
dfam("p5", "miau", (struct want_fam *)&p5fam);
}
#endif
fprintf(stderr, "I: initial tests...\n");
mbmscWd(4127);
EOF
echo "/* NeXTstep bug workaround */" >mkt-int-t-ff.h
numf=0
t1() { cat >>mkt-int-t-in.$srcext <<EOF
if (($1) != ($2)) {
fprintf(stderr, "E: (%s) failed, got %lu want %lu (%s)\\n",
"$1", (unsigned long)($1), (unsigned long)($2), "$2");
rv = 1;
}
EOF
}
mbc1() {
:>mkt-int-t-bc
mbc1a "$@"
}
mbc1a() {
want=$(( ($1) * 2))
bc >mkt-int-t-bc2 <<EOF
define f(x) {
${4#$nl}
}
for (v = $2; v <= $3; ++v) {
v
f(v)
}
EOF
got=$(wc -l <mkt-int-t-bc2)
test $got -eq $want || \
die got $got lines, not "$want", from bc "'$4'"
cat mkt-int-t-bc2 >>mkt-int-t-bc
}
mbc2() {
:>mkt-int-t-bc
mbc2a "$@"
}
mbc2a() {
want=$(( ($1) * 3))
bc >mkt-int-t-bc2 <<EOF
define f(x,y) {
${6#$nl}
}
for (v = $2; v <= $3; ++v) {
for (w = $4; w <= $5; ++w) {
v
w
f(v,w)
}
}
EOF
got=$(wc -l <mkt-int-t-bc2)
test $got -eq $want || \
die got $got lines, not "$want", from bc "'$6'"
cat mkt-int-t-bc2 >>mkt-int-t-bc
}
mba() {
printf '%s\n' "$@" >>mkt-int-t-bc
}
gett() {
case $1 in
iouts) echo int; return ;;
bin?s|bouts) echo bst; return ;;
hin?s|houts) echo hst; return ;;
bin?u|boutu) echo but; return ;;
hin?u|houtu) echo hut; return ;;
*) echo "unknown type for argument <$1>" ;;
esac
}
ubc1() {
fn=f$numf
numf=$(($numf + 1))
ti=$(gett $2)
to=$(gett $3)
echo " $fn();" >>mkt-int-t-in.$srcext
echo "extern void $fn(void);" >>mkt-int-t-ff.h
{
echo >&4 "extern const $ti ${fn}_i[];"
echo >&4 "const $ti ${fn}_i[] = {"
echo "extern const $ti ${fn}_i[];"
echo "static const $to ${fn}_o[] = {"
os=$ht
while read in; do
read out
echo >&4 "$os$in"
echo "$os$out"
os=,$ht
done <mkt-int-t-bc
echo >&4 "};"
echo "};"
echo "void $fn(void) {"
echo " size_t cnt = sizeof(${fn}_o) / sizeof(${fn}_o[0]);"
echo " fstr = \"$1\";"
echo " while (cnt--)"
echo " tm1($2, $3, $1, ${fn}_i[cnt], ${fn}_o[cnt]);"
echo '}'
} >>mkt-int-t-f0.$srcext 4>>mkt-int-t-f1.$srcext
}
ubc2() {
fn=f$numf
numf=$(($numf + 1))
ta=$(gett $2)
tb=$(gett $3)
ty=$(gett $4)
echo " $fn();" >>mkt-int-t-in.$srcext
echo "extern void $fn(void);" >>mkt-int-t-ff.h
{
echo >&4 "extern const $ta ${fn}_a[];"
echo >&4 "const $ta ${fn}_a[] = {"
echo "extern const $ta ${fn}_a[];"
echo >&5 "extern const $tb ${fn}_b[];"
echo >&5 "const $tb ${fn}_b[] = {"
echo "extern const $tb ${fn}_b[];"
echo "static const $ty ${fn}_y[] = {"
os=$ht
while read in; do
read in2
read out
echo >&4 "$os$in"
echo >&5 "$os$in2"
echo "$os$out"
os=,$ht
done <mkt-int-t-bc
echo >&4 "};"
echo >&5 "};"
echo "};"
echo "void $fn(void) {"
echo " size_t cnt = sizeof(${fn}_y) / sizeof(${fn}_y[0]);"
echo " fstr = \"$1\";"
echo " while (cnt--)"
echo " tm2($2, $3, $4, $1, ${fn}_a[cnt], ${fn}_b[cnt], ${fn}_y[cnt]);"
echo '}'
} >>mkt-int-t-f0.$srcext 4>>mkt-int-t-f1.$srcext 5>>mkt-int-t-f2.$srcext
}
t1 'mbiCOS(bst, -1, <, 2)' 1
t1 'mbiMOT(hut, hfm, 1, 0x1234, 0x5678)' 0x0234
t1 'mbiUP(but, bfm)' '0xFFU'
t1 'mbiUP(but, bhm)' '0x7FU'
t1 'mbiUP(hut, hfm)' '0x3FFU'
t1 'mbiUP(hut, hhm)' '0x1FFU'
t1 'mbiMM(hut, hfm, (hut)0xFFFFUL)' hfm
t1 'mbiMM(hut, hhm, (hut)0xFFFFUL)' hhm
cat >>mkt-int-t-in.$srcext <<\EOF
mbmscWpop;
fprintf(stderr, "I: manual two’s complement in unsigned...\n");
EOF
mbc1 255 -127 127 '
t=0
if (x < 0) t=1
return (t)'
ubc1 b_mbiA_S2VZ bin1s iouts
mbc1 256 0 255 '
if (x > 127) return (1)
return (0)'
ubc1 b_mbiA_U2VZ bin1u iouts
mbc1 1024 0 1023 '
if (x > 511) return (1)
return (0)'
mba 1024 0 \
1534 0 \
1535 0 \
1536 1 \
2047 1 \
2048 0
ubc1 h_mbiMA_U2VZ hin1u iouts
mbc1 128 0 127 'return (x)'
mbc1a 127 129 255 'return (-(256 - x))'
ubc1 b_mbiA_U2S bin1u bouts
mbc1 512 0 511 'return (x)'
mbc1a 512 512 1023 'return (-(1024 - x))'
mba 1024 0 \
1535 511 \
1536 -512 \
2047 -1 \
2048 0
ubc1 h_mbiMA_U2S hin1u houts
mbc1 255 -127 127 '
if (x >= 0) return (x)
return (256 + x)'
ubc1 b_mbiA_S2U bin1s boutu
mbc1 1024 -512 511 '
if (x >= 0) return (x)
return (1024 + x)'
ubc1 b_mbiMA_S2U hin1s houtu
mbc1 127 -127 -1 'return (-x)'
mbc1a 128 0 127 'return (x)'
ubc1 b_mbiA_S2M bin1s boutu
mbc1 512 -512 -1 'return (-x)'
mbc1a 512 0 511 'return (x)'
ubc1 h_mbiMA_S2M hin1s houtu
mbc1 128 0 127 'return (x)'
mbc1a 128 128 255 'return (256 - x)'
ubc1 b_mbiA_U2M bin1u boutu
mbc1 512 0 511 'return (x)'
mbc1a 512 512 1023 'return (1024 - x)'
mba 1024 0 \
1534 510 \
1535 511 \
1536 512 \
1537 511 \
1538 510 \
2046 2 \
2047 1 \
2048 0
ubc1 h_mbiMA_U2M hin1u houtu
mbc2 256 0 1 0 127 '
if (y == 0) return (0)
if (x == 0) return (y)
return (-y)'
ubc2 b_mbiA_VZM2S bin1u bin2u bouts
mbc2 4096 0 0 0 4095 'return (y % 512)'
mbc2a 4096 1 1 0 4095 '
if ((y % 1024) == 0) return (0)
return (-((y - 1) % 512) - 1)'
ubc2 h_mbiMA_VZM2S hin1u hin2u houts
mbc2 512 0 1 0 255 '
if (y == 0) return (0)
if (x == 0) return (y % 128)
a = (-((y - 1) % 128) - 1)
while (a < 0) a += 256
return (a)'
ubc2 b_mbiA_VZM2U bin1u bin2u boutu
mbc2 8192 0 1 0 4095 '
if ((y % 1024) == 0) return (0)
if (x == 0) return (y % 512)
a = (-((y - 1) % 512) - 1)
while (a < 0) a += 1024
return (a)'