authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-22 15:09:29-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-22 15:09:29-04:00
log23c263776c448a7ffc7e03d1b8528a4b5761f289
treeae5e59800427ce54ba36f0ef1ece96d36131eaf9
parent53b5aa812bd9c0229054121a1c196c9b18994d64
parenta8fa1ecd89eebd444736d73da4ebf24af74daea8
signature Commit is signed but in an unrecognized format.

Merge remote-tracking branch 'origin/master' into llvm10


29 files changed, 459 insertions(+), 93 deletions(-)

CMakeLists.txt-1
......@@ -430,7 +430,6 @@ set(BUILD_LIBSTAGE2_ARGS "build-lib"
430430 --cache on
431431 --output-dir "${CMAKE_BINARY_DIR}"
432432 ${LIBSTAGE2_RELEASE_ARG}
433 --disable-gen-h
434433 --bundle-compiler-rt
435434 -fPIC
436435 -lc
build.zig+2-1
......@@ -135,7 +135,8 @@ pub fn build(b: *Builder) !void {
135135 test_step.dependOn(tests.addRuntimeSafetyTests(b, test_filter, modes));
136136 test_step.dependOn(tests.addTranslateCTests(b, test_filter));
137137 test_step.dependOn(tests.addRunTranslatedCTests(b, test_filter));
138 test_step.dependOn(tests.addGenHTests(b, test_filter));
138 // tests for this feature are disabled until we have the self-hosted compiler available
139 //test_step.dependOn(tests.addGenHTests(b, test_filter));
139140 test_step.dependOn(tests.addCompileErrorTests(b, test_filter, modes));
140141 test_step.dependOn(docs_step);
141142}
ci/drone/linux_script+2-1
......@@ -26,7 +26,8 @@ make -j$(nproc) install
2626# TODO test-cli is hitting https://github.com/ziglang/zig/issues/3526
2727./zig build test-asm-link test-runtime-safety
2828# TODO test-translate-c is hitting https://github.com/ziglang/zig/issues/3526
29./zig build test-gen-h
29# TODO disabled until we are shipping self-hosted
30#./zig build test-gen-h
3031# TODO test-compile-errors is hitting https://github.com/ziglang/zig/issues/3526
3132# TODO building docs is hitting https://github.com/ziglang/zig/issues/3526
3233
ci/srht/freebsd_script+2-1
......@@ -42,7 +42,8 @@ release/bin/zig build test-asm-link
4242release/bin/zig build test-runtime-safety
4343release/bin/zig build test-translate-c
4444release/bin/zig build test-run-translated-c
45release/bin/zig build test-gen-h
45# TODO disabled until we are shipping self-hosted
46#release/bin/zig build test-gen-h
4647release/bin/zig build test-compile-errors
4748release/bin/zig build docs
4849
lib/libc/glibc/abi.txt+135
......@@ -193,6 +193,7 @@ aarch64-linux-gnu aarch64_be-linux-gnu
193193
194194
19519529
196
19619729
197198
19819929
......@@ -514,6 +515,7 @@ aarch64-linux-gnu aarch64_be-linux-gnu
51451529
51551629
51651729
51829
517519
51852029
519521
......@@ -697,6 +699,7 @@ aarch64-linux-gnu aarch64_be-linux-gnu
69769929
69870029
69970129
702
70070329
70170429
70270529
......@@ -819,6 +822,7 @@ aarch64-linux-gnu aarch64_be-linux-gnu
81982229
82082329
82182429
82529
822826
82382729
82482829
......@@ -904,6 +908,9 @@ aarch64-linux-gnu aarch64_be-linux-gnu
90490829
90590929
90691029
91129
912
913
90791429
90891529
90991629
......@@ -1004,6 +1011,7 @@ aarch64-linux-gnu aarch64_be-linux-gnu
1004101129
1005101229
1006101329
101429
10071015
1008101629
1009101729
......@@ -1033,6 +1041,7 @@ aarch64-linux-gnu aarch64_be-linux-gnu
1033104129
1034104229
1035104329
104429
10361045
1037104629
1038104729
......@@ -3920,6 +3929,7 @@ s390x-linux-gnu
39203929
39213930
392239315
3932
3923393327
39243934
3925393527
......@@ -4241,6 +4251,7 @@ s390x-linux-gnu
424142515
424242525
424342535
42545
4244425511
4245425627
42464257
......@@ -4424,6 +4435,7 @@ s390x-linux-gnu
4424443519
4425443619
442644375
4438
442744395
442844405
4429444128
......@@ -4543,6 +4555,7 @@ s390x-linux-gnu
4543455527
45444556
4545455716
4558
454645595
454745605
4548456115
......@@ -4631,6 +4644,9 @@ s390x-linux-gnu
4631464416
463246455
463346465
4647
4648
464912
463446505
463546515
463646525
......@@ -4731,6 +4747,7 @@ s390x-linux-gnu
473147475
473247485
473347495
47505
47344751
473547525
473647535
......@@ -4756,6 +4773,7 @@ s390x-linux-gnu
475647735
475747745
475847755
47765
4759477731 5
4760477824 5 12 16
4761477924 5 12 16
......@@ -7645,6 +7663,7 @@ arm-linux-gnueabi armeb-linux-gnueabi arm-linux-gnueabihf armeb-linux-gnueabihf
76457663
76467664
76477665
7666
76487667
76497668
7650766927
......@@ -7968,6 +7987,7 @@ arm-linux-gnueabi armeb-linux-gnueabi arm-linux-gnueabihf armeb-linux-gnueabihf
7968798716
7969798816
7970798916
799016
79717991
7972799227
79737993
......@@ -8151,6 +8171,7 @@ arm-linux-gnueabi armeb-linux-gnueabi arm-linux-gnueabihf armeb-linux-gnueabihf
8151817119
8152817219
8153817316
8174
8154817516
8155817616
8156817728
......@@ -8273,6 +8294,7 @@ arm-linux-gnueabi armeb-linux-gnueabi arm-linux-gnueabihf armeb-linux-gnueabihf
8273829416
8274829516
8275829616
829716
82768298
8277829916
8278830016
......@@ -8358,6 +8380,9 @@ arm-linux-gnueabi armeb-linux-gnueabi arm-linux-gnueabihf armeb-linux-gnueabihf
8358838016
8359838116
8360838216
838316
8384
8385
8361838616
8362838716
8363838816
......@@ -8458,6 +8483,7 @@ arm-linux-gnueabi armeb-linux-gnueabi arm-linux-gnueabihf armeb-linux-gnueabihf
8458848316
8459848416
8460848516
848616
84618487
8462848816
8463848916
......@@ -8484,6 +8510,7 @@ arm-linux-gnueabi armeb-linux-gnueabi arm-linux-gnueabihf armeb-linux-gnueabihf
8484851016
8485851116
8486851216
851316
8487851424 16
8488851524 16
8489851616
......@@ -11374,6 +11401,7 @@ sparc-linux-gnu sparcel-linux-gnu
1137411401
1137511402
11376114030
11404
113771140527
1137811406
113791140727
......@@ -11693,6 +11721,7 @@ sparc-linux-gnu sparcel-linux-gnu
11693117210
11694117220
11695117231
117241
11696117250
11697117260
11698117273 11
......@@ -11878,6 +11907,7 @@ sparc-linux-gnu sparcel-linux-gnu
118781190719
118791190819
11880119090
11910
11881119110
11882119121
118831191328
......@@ -11997,6 +12027,7 @@ sparc-linux-gnu sparcel-linux-gnu
119971202733
1199812028
119991202916
12030
12000120315
12001120320
120021203315
......@@ -12085,6 +12116,9 @@ sparc-linux-gnu sparcel-linux-gnu
120851211616
12086121170
12087121180
1211912
12120
12121
12088121221
12089121231
12090121241
......@@ -12183,6 +12217,7 @@ sparc-linux-gnu sparcel-linux-gnu
12183122171
12184122181
12185122191
122201
12186122210
12187122220
1218812223
......@@ -12207,6 +12242,7 @@ sparc-linux-gnu sparcel-linux-gnu
12207122420
12208122430
12209122440
122450
12210122465
12211122470
12212122480
......@@ -15101,6 +15137,7 @@ sparcv9-linux-gnu
15101151375
15102151385
1510315139
15140
151041514127
1510515142
151061514327
......@@ -15422,6 +15459,7 @@ sparcv9-linux-gnu
15422154595
15423154605
15424154615
154625
154251546311
154261546427
1542715465
......@@ -15605,6 +15643,7 @@ sparcv9-linux-gnu
156051564319
156061564419
15607156455
15646
15608156475
15609156485
156101564928
......@@ -15724,6 +15763,7 @@ sparcv9-linux-gnu
157241576327
1572515764
157261576516
15766
15727157675
15728157685
157291576915
......@@ -15812,6 +15852,9 @@ sparcv9-linux-gnu
158121585216
15813158535
15814158545
1585512
15856
15857
15815158585
15816158595
15817158605
......@@ -15912,6 +15955,7 @@ sparcv9-linux-gnu
15912159555
15913159565
15914159575
159585
1591515959
15916159605
15917159615
......@@ -15938,6 +15982,7 @@ sparcv9-linux-gnu
15938159825
15939159835
15940159845
159855
159411598624 28 5 12 16
159421598724 28 5 12 16
15943159885 14
......@@ -18828,6 +18873,7 @@ mips64el-linux-gnuabi64 mips64-linux-gnuabi64
1882818873
1882918874
18830188750
18876
188311887727
1883218878
188331887927
......@@ -19147,6 +19193,7 @@ mips64el-linux-gnuabi64 mips64-linux-gnuabi64
19147191930
19148191940
19149191955
191965
19150191970
19151191980
191521919911
......@@ -19332,6 +19379,7 @@ mips64el-linux-gnuabi64 mips64-linux-gnuabi64
193321937919
193331938019
19334193810
19382
19335193830
19336193845
193371938528
......@@ -19450,6 +19498,7 @@ mips64el-linux-gnuabi64 mips64-linux-gnuabi64
194501949827
194511949927
1945219500
1950116
194531950216
19454195035
19455195040
......@@ -19539,6 +19588,9 @@ mips64el-linux-gnuabi64 mips64-linux-gnuabi64
195391958816
19540195890
19541195900
1959112
19592
19593
19542195945
19543195955
19544195965
......@@ -19637,6 +19689,7 @@ mips64el-linux-gnuabi64 mips64-linux-gnuabi64
19637196895
19638196905
19639196915
196925
19640196930
19641196940
19642196950
......@@ -19661,6 +19714,7 @@ mips64el-linux-gnuabi64 mips64-linux-gnuabi64
19661197140
19662197150
19663197160
197170
19664197185
19665197190
19666197200
......@@ -22555,6 +22609,7 @@ mips64el-linux-gnuabin32 mips64-linux-gnuabin32
2255522609
2255622610
22557226110
22612
225582261327
2255922614
225602261527
......@@ -22874,6 +22929,7 @@ mips64el-linux-gnuabin32 mips64-linux-gnuabin32
22874229290
22875229300
22876229315
229325
22877229330
22878229340
228792293511
......@@ -23059,6 +23115,7 @@ mips64el-linux-gnuabin32 mips64-linux-gnuabin32
230592311519
230602311619
23061231170
23118
23062231190
23063231205
230642312128
......@@ -23177,6 +23234,7 @@ mips64el-linux-gnuabin32 mips64-linux-gnuabin32
231772323427
231782323527
2317923236
2323716
231802323816
23181232395
23182232400
......@@ -23266,6 +23324,9 @@ mips64el-linux-gnuabin32 mips64-linux-gnuabin32
232662332416
23267233250
23268233260
2332712
23328
23329
23269233305
23270233315
23271233325
......@@ -23364,6 +23425,7 @@ mips64el-linux-gnuabin32 mips64-linux-gnuabin32
23364234255
23365234265
23366234275
234285
23367234290
23368234300
23369234310
......@@ -23388,6 +23450,7 @@ mips64el-linux-gnuabin32 mips64-linux-gnuabin32
23388234500
23389234510
23390234520
234530
23391234545
23392234550
23393234560
......@@ -26282,6 +26345,7 @@ mipsel-linux-gnueabihf mips-linux-gnueabihf
2628226345
2628326346
26284263470
26348
262852634927
2628626350
262872635127
......@@ -26601,6 +26665,7 @@ mipsel-linux-gnueabihf mips-linux-gnueabihf
26601266650
26602266660
26603266675
266685
26604266690
26605266700
266062667111
......@@ -26786,6 +26851,7 @@ mipsel-linux-gnueabihf mips-linux-gnueabihf
267862685119
267872685219
26788268530
26854
26789268550
26790268565
267912685728
......@@ -26904,6 +26970,7 @@ mipsel-linux-gnueabihf mips-linux-gnueabihf
269042697027
2690526971
2690626972
2697316
269072697416
26908269755
26909269760
......@@ -26993,6 +27060,9 @@ mipsel-linux-gnueabihf mips-linux-gnueabihf
269932706016
26994270610
26995270620
2706312
27064
27065
26996270665
26997270675
26998270685
......@@ -27091,6 +27161,7 @@ mipsel-linux-gnueabihf mips-linux-gnueabihf
27091271615
27092271625
27093271635
271645
27094271650
27095271660
27096271670
......@@ -27115,6 +27186,7 @@ mipsel-linux-gnueabihf mips-linux-gnueabihf
27115271860
27116271870
27117271880
271890
27118271905
27119271910
27120271920
......@@ -30009,6 +30081,7 @@ mipsel-linux-gnueabi mips-linux-gnueabi
3000930081
3001030082
30011300830
30084
300123008527
3001330086
300143008727
......@@ -30328,6 +30401,7 @@ mipsel-linux-gnueabi mips-linux-gnueabi
30328304010
30329304020
30330304035
304045
30331304050
30332304060
303333040711
......@@ -30513,6 +30587,7 @@ mipsel-linux-gnueabi mips-linux-gnueabi
305133058719
305143058819
30515305890
30590
30516305910
30517305925
305183059328
......@@ -30631,6 +30706,7 @@ mipsel-linux-gnueabi mips-linux-gnueabi
306313070627
3063230707
3063330708
3070916
306343071016
30635307115
30636307120
......@@ -30720,6 +30796,9 @@ mipsel-linux-gnueabi mips-linux-gnueabi
307203079616
30721307970
30722307980
3079912
30800
30801
30723308025
30724308035
30725308045
......@@ -30818,6 +30897,7 @@ mipsel-linux-gnueabi mips-linux-gnueabi
30818308975
30819308985
30820308995
309005
30821309010
30822309020
30823309030
......@@ -30842,6 +30922,7 @@ mipsel-linux-gnueabi mips-linux-gnueabi
30842309220
30843309230
30844309240
309250
30845309265
30846309270
30847309280
......@@ -33734,6 +33815,7 @@ x86_64-linux-gnu
3373433815
3373533816
3373633817
33818
3373733819
3373833820
337393382127
......@@ -34057,6 +34139,7 @@ x86_64-linux-gnu
340573413910
340583414010
340593414110
3414210
340603414311
340613414427
340623414536
......@@ -34240,6 +34323,7 @@ x86_64-linux-gnu
342403432319
342413432419
342423432510
34326
342433432710
342443432810
342453432928
......@@ -34359,6 +34443,7 @@ x86_64-linux-gnu
343593444327
3436034444
343613444516
34446
343623444710
343633444810
343643444915
......@@ -34447,6 +34532,9 @@ x86_64-linux-gnu
344473453216
344483453310
344493453410
3453512
34536
34537
344503453810
344513453910
344523454010
......@@ -34547,6 +34635,7 @@ x86_64-linux-gnu
345473463510
345483463610
345493463710
3463810
3455034639
345513464010
345523464110
......@@ -34573,6 +34662,7 @@ x86_64-linux-gnu
345733466210
345743466310
345753466410
3466510
345763466624 10 12 16
345773466724 10 12 16
345783466810 14
......@@ -37461,6 +37551,7 @@ x86_64-linux-gnux32
3746137551
3746237552
3746337553
37554
3746437555
3746537556
374663755728
......@@ -37784,6 +37875,7 @@ x86_64-linux-gnux32
377843787528
377853787628
377863787728
3787828
3778737879
377883788028
377893788136
......@@ -37967,6 +38059,7 @@ x86_64-linux-gnux32
379673805928
379683806028
379693806128
38062
379703806328
379713806428
379723806528
......@@ -38086,6 +38179,7 @@ x86_64-linux-gnux32
380863817928
3808738180
380883818128
38182
380893818328
380903818428
380913818528
......@@ -38174,6 +38268,9 @@ x86_64-linux-gnux32
381743826828
381753826928
381763827028
3827128
38272
38273
381773827428
381783827528
381793827628
......@@ -38274,6 +38371,7 @@ x86_64-linux-gnux32
382743837128
382753837228
382763837328
3837428
3827738375
382783837628
382793837728
......@@ -38303,6 +38401,7 @@ x86_64-linux-gnux32
383033840128
383043840228
383053840328
3840428
3830638405
383073840628
383083840728
......@@ -41190,6 +41289,7 @@ i386-linux-gnu
4119041289
4119141290
41192412910
4129212
411934129327
411944129436
411954129527
......@@ -41509,6 +41609,7 @@ i386-linux-gnu
41509416090
41510416100
41511416111
416121
41512416130
41513416140
41514416153 11
......@@ -41694,6 +41795,7 @@ i386-linux-gnu
416944179519
416954179619
41696417970
41798
41697417990
41698418001
416994180128
......@@ -41813,6 +41915,7 @@ i386-linux-gnu
418134191527
4181441916
418154191716
41918
41816419195
41817419200
418184192115
......@@ -41901,6 +42004,9 @@ i386-linux-gnu
419014200416
41902420050
41903420060
4200712
42008
42009
41904420101
41905420111
41906420121
......@@ -41999,6 +42105,7 @@ i386-linux-gnu
41999421051
42000421061
42001421071
421081
42002421090
42003421100
4200442111
......@@ -42023,6 +42130,7 @@ i386-linux-gnu
42023421300
42024421310
42025421320
421330
42026421345
42027421350
42028421360
......@@ -44915,6 +45023,7 @@ powerpc64le-linux-gnu
4491545023
4491645024
4491745025
45026
4491845027
4491945028
449204502929
......@@ -45238,6 +45347,7 @@ powerpc64le-linux-gnu
452384534729
452394534829
452404534929
4535029
4524145351
452424535229
452434535336
......@@ -45421,6 +45531,7 @@ powerpc64le-linux-gnu
454214553129
454224553229
454234553329
4553433
454244553529
454254553629
454264553729
......@@ -45540,6 +45651,7 @@ powerpc64le-linux-gnu
455404565129
4554145652
455424565329
45654
455434565529
455444565629
455454565729
......@@ -45628,6 +45740,9 @@ powerpc64le-linux-gnu
456284574029
456294574129
456304574229
4574329
4574432
45745
456314574629
456324574729
456334574829
......@@ -45728,6 +45843,7 @@ powerpc64le-linux-gnu
457284584329
457294584429
457304584529
4584629
4573145847
457324584829
457334584929
......@@ -45757,6 +45873,7 @@ powerpc64le-linux-gnu
457574587329
457584587429
457594587529
4587629
4576045877
457614587829
457624587929
......@@ -48642,6 +48759,7 @@ powerpc64-linux-gnu
4864248759
4864348760
4864448761
48762
4864548763
4864648764
486474876527
......@@ -48965,6 +49083,7 @@ powerpc64-linux-gnu
489654908312
489664908412
489674908512
4908612
4896849087
489694908827
4897049089
......@@ -49148,6 +49267,7 @@ powerpc64-linux-gnu
491484926719
491494926819
491504926912
4927033
491514927112
491524927212
491534927328
......@@ -49267,6 +49387,7 @@ powerpc64-linux-gnu
492674938727
4926849388
492694938916
49390
492704939112
492714939212
492724939315
......@@ -49355,6 +49476,9 @@ powerpc64-linux-gnu
493554947616
493564947712
493574947812
4947912
4948032
49481
493584948212
493594948312
493604948412
......@@ -49455,6 +49579,7 @@ powerpc64-linux-gnu
494554957912
494564958012
494574958112
4958212
4945849583
494594958412
494604958512
......@@ -49480,6 +49605,7 @@ powerpc64-linux-gnu
494804960512
494814960612
494824960712
4960812
494834960912 15
494844961024 12 16
494854961124 12 16
......@@ -52369,6 +52495,7 @@ powerpc-linux-gnueabi powerpc-linux-gnueabihf
5236952495
5237052496
5237152497
52498
5237252499
5237352500
523745250127
......@@ -52690,6 +52817,7 @@ powerpc-linux-gnueabi powerpc-linux-gnueabihf
52690528170
52691528180
52692528191
528201
52693528210
52694528220
52695528233 11
......@@ -52875,6 +53003,7 @@ powerpc-linux-gnueabi powerpc-linux-gnueabihf
528755300319
528765300419
52877530050
5300633
52878530070
52879530081
528805300928
......@@ -52994,6 +53123,7 @@ powerpc-linux-gnueabi powerpc-linux-gnueabihf
529945312327
529955312413
529965312516
53126
52997531275
52998531280
529995312915
......@@ -53082,6 +53212,9 @@ powerpc-linux-gnueabi powerpc-linux-gnueabihf
530825321216
53083532130
53084532140
5321512
5321632
53217
53085532181
53086532191
53087532201
......@@ -53180,6 +53313,7 @@ powerpc-linux-gnueabi powerpc-linux-gnueabihf
53180533131
53181533141
53182533151
533161
53183533170
53184533180
5318553319
......@@ -53204,6 +53338,7 @@ powerpc-linux-gnueabi powerpc-linux-gnueabihf
53204533380
53205533390
53206533400
533410
53207533425
53208533430
53209533440
lib/libc/glibc/fns.txt+9
......@@ -192,6 +192,7 @@ _Qp_uitoq c
192192_Qp_uxtoq c
193193_Qp_xtoq c
194194___brk_addr c
195___tls_get_addr ld
195196__acos_finite m
196197__acosf128_finite m
197198__acosf_finite m
......@@ -511,6 +512,7 @@ __libc_memalign c
511512__libc_pvalloc c
512513__libc_realloc c
513514__libc_sa_len c
515__libc_stack_end ld
514516__libc_start_main c
515517__libc_valloc c
516518__libpthread_version_placeholder pthread
......@@ -696,6 +698,7 @@ __open_2 c
696698__openat64_2 c
697699__openat_2 c
698700__overflow c
701__parse_hwcap_and_convert_at_platform ld
699702__pipe c
700703__poll c
701704__poll_chk c
......@@ -815,6 +818,7 @@ __sqrtf_finite m
815818__sqrtl_finite m
816819__sqrtsf2 c
817820__stack_chk_fail c
821__stack_chk_guard ld
818822__statfs c
819823__stpcpy c
820824__stpcpy_chk c
......@@ -903,6 +907,9 @@ __sysctl c
903907__syslog_chk c
904908__sysv_signal c
905909__timezone c
910__tls_get_addr ld
911__tls_get_addr_opt ld
912__tls_get_offset ld
906913__toascii_l c
907914__tolower_l c
908915__toupper_l c
......@@ -999,6 +1006,7 @@ __ynf128_finite m
9991006__ynf_finite m
10001007__ynl_finite m
10011008_authenticate c
1009_dl_mcount ld
10021010_dl_mcount_wrapper c
10031011_dl_mcount_wrapper_check c
10041012_environ c
......@@ -1024,6 +1032,7 @@ _pthread_cleanup_pop pthread
10241032_pthread_cleanup_pop_restore pthread
10251033_pthread_cleanup_push pthread
10261034_pthread_cleanup_push_defer pthread
1035_r_debug ld
10271036_res c
10281037_res_hconf c
10291038_rpc_dtablesize c
lib/std/build.zig+9-11
......@@ -1121,7 +1121,7 @@ pub const LibExeObjStep = struct {
11211121 emit_llvm_ir: bool = false,
11221122 emit_asm: bool = false,
11231123 emit_bin: bool = true,
1124 disable_gen_h: bool,
1124 emit_h: bool = false,
11251125 bundle_compiler_rt: bool,
11261126 disable_stack_probing: bool,
11271127 disable_sanitize_c: bool,
......@@ -1281,7 +1281,6 @@ pub const LibExeObjStep = struct {
12811281 .exec_cmd_args = null,
12821282 .name_prefix = "",
12831283 .filter = null,
1284 .disable_gen_h = false,
12851284 .bundle_compiler_rt = false,
12861285 .disable_stack_probing = false,
12871286 .disable_sanitize_c = false,
......@@ -1600,8 +1599,9 @@ pub const LibExeObjStep = struct {
16001599 self.main_pkg_path = dir_path;
16011600 }
16021601
1603 pub fn setDisableGenH(self: *LibExeObjStep, value: bool) void {
1604 self.disable_gen_h = value;
1602 /// Deprecated; just set the field directly.
1603 pub fn setDisableGenH(self: *LibExeObjStep, is_disabled: bool) void {
1604 self.emit_h = !is_disabled;
16051605 }
16061606
16071607 pub fn setLibCFile(self: *LibExeObjStep, libc_file: ?[]const u8) void {
......@@ -1632,7 +1632,7 @@ pub const LibExeObjStep = struct {
16321632 /// the make step, from a step that has declared a dependency on this one.
16331633 pub fn getOutputHPath(self: *LibExeObjStep) []const u8 {
16341634 assert(self.kind != Kind.Exe);
1635 assert(!self.disable_gen_h);
1635 assert(self.emit_h);
16361636 return fs.path.join(
16371637 self.builder.allocator,
16381638 &[_][]const u8{ self.output_dir.?, self.out_h_filename },
......@@ -1679,7 +1679,7 @@ pub const LibExeObjStep = struct {
16791679 }
16801680
16811681 pub fn addBuildOption(self: *LibExeObjStep, comptime T: type, name: []const u8, value: T) void {
1682 const out = &std.io.BufferOutStream.init(&self.build_options_contents).stream;
1682 const out = self.build_options_contents.outStream();
16831683 out.print("pub const {} = {};\n", .{ name, value }) catch unreachable;
16841684 }
16851685
......@@ -1884,6 +1884,7 @@ pub const LibExeObjStep = struct {
18841884 if (self.emit_llvm_ir) try zig_args.append("-femit-llvm-ir");
18851885 if (self.emit_asm) try zig_args.append("-femit-asm");
18861886 if (!self.emit_bin) try zig_args.append("-fno-emit-bin");
1887 if (self.emit_h) try zig_args.append("-femit-h");
18871888
18881889 if (self.strip) {
18891890 try zig_args.append("--strip");
......@@ -1929,9 +1930,6 @@ pub const LibExeObjStep = struct {
19291930 if (self.is_dynamic) {
19301931 try zig_args.append("-dynamic");
19311932 }
1932 if (self.disable_gen_h) {
1933 try zig_args.append("--disable-gen-h");
1934 }
19351933 if (self.bundle_compiler_rt) {
19361934 try zig_args.append("--bundle-compiler-rt");
19371935 }
......@@ -2069,7 +2067,7 @@ pub const LibExeObjStep = struct {
20692067 try zig_args.append("-isystem");
20702068 try zig_args.append(self.builder.pathFromRoot(include_path));
20712069 },
2072 .OtherStep => |other| if (!other.disable_gen_h) {
2070 .OtherStep => |other| if (other.emit_h) {
20732071 const h_path = other.getOutputHPath();
20742072 try zig_args.append("-isystem");
20752073 try zig_args.append(fs.path.dirname(h_path).?);
......@@ -2209,7 +2207,7 @@ const InstallArtifactStep = struct {
22092207 break :blk InstallDir.Lib;
22102208 }
22112209 } else null,
2212 .h_dir = if (artifact.kind == .Lib and !artifact.disable_gen_h) .Header else null,
2210 .h_dir = if (artifact.kind == .Lib and artifact.emit_h) .Header else null,
22132211 };
22142212 self.step.dependOn(&artifact.step);
22152213 artifact.install_step = self;
lib/std/debug.zig+44-11
......@@ -235,9 +235,17 @@ pub fn panic(comptime format: []const u8, args: var) noreturn {
235235 panicExtra(null, first_trace_addr, format, args);
236236}
237237
238/// TODO multithreaded awareness
238/// Non-zero whenever the program triggered a panic.
239/// The counter is incremented/decremented atomically.
239240var panicking: u8 = 0;
240241
242// Locked to avoid interleaving panic messages from multiple threads.
243var panic_mutex = std.Mutex.init();
244
245/// Counts how many times the panic handler is invoked by this thread.
246/// This is used to catch and handle panics triggered by the panic handler.
247threadlocal var panic_stage: usize = 0;
248
241249pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, comptime format: []const u8, args: var) noreturn {
242250 @setCold(true);
243251
......@@ -247,25 +255,50 @@ pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, c
247255 resetSegfaultHandler();
248256 }
249257
250 switch (@atomicRmw(u8, &panicking, .Add, 1, .SeqCst)) {
258 switch (panic_stage) {
251259 0 => {
252 const stderr = getStderrStream();
253 noasync stderr.print(format ++ "\n", args) catch os.abort();
254 if (trace) |t| {
255 dumpStackTrace(t.*);
260 panic_stage = 1;
261
262 _ = @atomicRmw(u8, &panicking, .Add, 1, .SeqCst);
263
264 // Make sure to release the mutex when done
265 {
266 const held = panic_mutex.acquire();
267 defer held.release();
268
269 const stderr = getStderrStream();
270 noasync stderr.print(format ++ "\n", args) catch os.abort();
271 if (trace) |t| {
272 dumpStackTrace(t.*);
273 }
274 dumpCurrentStackTrace(first_trace_addr);
275 }
276
277 if (@atomicRmw(u8, &panicking, .Sub, 1, .SeqCst) != 1) {
278 // Another thread is panicking, wait for the last one to finish
279 // and call abort()
280
281 // Sleep forever without hammering the CPU
282 var event = std.ResetEvent.init();
283 event.wait();
284
285 unreachable;
256286 }
257 dumpCurrentStackTrace(first_trace_addr);
258287 },
259288 1 => {
260 // TODO detect if a different thread caused the panic, because in that case
261 // we would want to return here instead of calling abort, so that the thread
262 // which first called panic can finish printing a stack trace.
263 warn("Panicked during a panic. Aborting.\n", .{});
289 panic_stage = 2;
290
291 // A panic happened while trying to print a previous panic message,
292 // we're still holding the mutex but that's fine as we're going to
293 // call abort()
294 const stderr = getStderrStream();
295 noasync stderr.print("Panicked during a panic. Aborting.\n", .{}) catch os.abort();
264296 },
265297 else => {
266298 // Panicked while printing "Panicked during a panic."
267299 },
268300 }
301
269302 os.abort();
270303}
271304
lib/std/net.zig+2-2
......@@ -820,7 +820,7 @@ fn linuxLookupNameFromHosts(
820820 // Skip to the delimiter in the stream, to fix parsing
821821 try stream.skipUntilDelimiterOrEof('\n');
822822 // Use the truncated line. A truncated comment or hostname will be handled correctly.
823 break :blk @as([]u8, &line_buf); // TODO the cast should not be necessary
823 break :blk &line_buf;
824824 },
825825 else => |e| return e,
826826 }) |line| {
......@@ -1017,7 +1017,7 @@ fn getResolvConf(allocator: *mem.Allocator, rc: *ResolvConf) !void {
10171017 // Skip to the delimiter in the stream, to fix parsing
10181018 try stream.skipUntilDelimiterOrEof('\n');
10191019 // Give an empty line to the while loop, which will be skipped.
1020 break :blk @as([]u8, line_buf[0..0]); // TODO the cast should not be necessary
1020 break :blk line_buf[0..0];
10211021 },
10221022 else => |e| return e,
10231023 }) |line| {
lib/std/start.zig+4
......@@ -41,6 +41,10 @@ fn _DllMainCRTStartup(
4141 fdwReason: std.os.windows.DWORD,
4242 lpReserved: std.os.windows.LPVOID,
4343) callconv(.Stdcall) std.os.windows.BOOL {
44 if (!builtin.single_threaded) {
45 _ = @import("start_windows_tls.zig");
46 }
47
4448 if (@hasDecl(root, "DllMain")) {
4549 return root.DllMain(hinstDLL, fdwReason, lpReserved);
4650 }
lib/std/zig/ast.zig+3-4
......@@ -1035,6 +1035,7 @@ pub const Node = struct {
10351035 pub const Defer = struct {
10361036 base: Node = Node{ .id = .Defer },
10371037 defer_token: TokenIndex,
1038 payload: ?*Node,
10381039 expr: *Node,
10391040
10401041 pub fn iterate(self: *Defer, index: usize) ?*Node {
......@@ -1836,8 +1837,7 @@ pub const Node = struct {
18361837 var i = index;
18371838
18381839 switch (self.kind) {
1839 .Break,
1840 .Continue => |maybe_label| {
1840 .Break, .Continue => |maybe_label| {
18411841 if (maybe_label) |label| {
18421842 if (i < 1) return label;
18431843 i -= 1;
......@@ -1864,8 +1864,7 @@ pub const Node = struct {
18641864 }
18651865
18661866 switch (self.kind) {
1867 .Break,
1868 .Continue => |maybe_label| {
1867 .Break, .Continue => |maybe_label| {
18691868 if (maybe_label) |label| {
18701869 return label.lastToken();
18711870 }
lib/std/zig/parse.zig+6-1
......@@ -465,7 +465,7 @@ fn parseContainerField(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*No
465465/// / KEYWORD_noasync BlockExprStatement
466466/// / KEYWORD_suspend (SEMICOLON / BlockExprStatement)
467467/// / KEYWORD_defer BlockExprStatement
468/// / KEYWORD_errdefer BlockExprStatement
468/// / KEYWORD_errdefer Payload? BlockExprStatement
469469/// / IfStatement
470470/// / LabeledStatement
471471/// / SwitchExpr
......@@ -526,6 +526,10 @@ fn parseStatement(arena: *Allocator, it: *TokenIterator, tree: *Tree) Error!?*No
526526
527527 const defer_token = eatToken(it, .Keyword_defer) orelse eatToken(it, .Keyword_errdefer);
528528 if (defer_token) |token| {
529 const payload = if (tree.tokens.at(token).id == .Keyword_errdefer)
530 try parsePayload(arena, it, tree)
531 else
532 null;
529533 const expr_node = try expectNode(arena, it, tree, parseBlockExprStatement, .{
530534 .ExpectedBlockOrExpression = .{ .token = it.index },
531535 });
......@@ -533,6 +537,7 @@ fn parseStatement(arena: *Allocator, it: *TokenIterator, tree: *Tree) Error!?*No
533537 node.* = .{
534538 .defer_token = token,
535539 .expr = expr_node,
540 .payload = payload,
536541 };
537542 return &node.base;
538543 }
lib/std/zig/parser_test.zig+13
......@@ -1,3 +1,16 @@
1test "zig fmt: errdefer with payload" {
2 try testCanonical(
3 \\pub fn main() anyerror!void {
4 \\ errdefer |a| x += 1;
5 \\ errdefer |a| {}
6 \\ errdefer |a| {
7 \\ x += 1;
8 \\ }
9 \\}
10 \\
11 );
12}
13
114test "zig fmt: noasync block" {
215 try testCanonical(
316 \\pub fn main() anyerror!void {
lib/std/zig/render.zig+3
......@@ -376,6 +376,9 @@ fn renderExpression(
376376 const defer_node = @fieldParentPtr(ast.Node.Defer, "base", base);
377377
378378 try renderToken(tree, stream, defer_node.defer_token, indent, start_col, Space.Space);
379 if (defer_node.payload) |payload| {
380 try renderExpression(allocator, stream, tree, indent, start_col, payload, Space.Space);
381 }
379382 return renderExpression(allocator, stream, tree, indent, start_col, defer_node.expr, space);
380383 },
381384 .Comptime => {
src-self-hosted/stage2.zig+8
......@@ -909,6 +909,7 @@ const Stage2Target = extern struct {
909909 os_builtin_str: ?[*:0]const u8,
910910
911911 dynamic_linker: ?[*:0]const u8,
912 standard_dynamic_linker_path: ?[*:0]const u8,
912913
913914 fn fromTarget(self: *Stage2Target, cross_target: CrossTarget) !void {
914915 const allocator = std.heap.c_allocator;
......@@ -1119,6 +1120,12 @@ const Stage2Target = extern struct {
11191120 }
11201121 };
11211122
1123 const std_dl = target.standardDynamicLinkerPath();
1124 const std_dl_z = if (std_dl.get()) |dl|
1125 (try mem.dupeZ(std.heap.c_allocator, u8, dl)).ptr
1126 else
1127 null;
1128
11221129 const cache_hash_slice = cache_hash.toOwnedSlice();
11231130 self.* = .{
11241131 .arch = @enumToInt(target.cpu.arch) + 1, // skip over ZigLLVM_UnknownArch
......@@ -1134,6 +1141,7 @@ const Stage2Target = extern struct {
11341141 .is_native = cross_target.isNative(),
11351142 .glibc_or_darwin_version = glibc_or_darwin_version,
11361143 .dynamic_linker = dynamic_linker,
1144 .standard_dynamic_linker_path = std_dl_z,
11371145 };
11381146 }
11391147};
src/all_types.hpp+2
......@@ -744,6 +744,7 @@ struct AstNodeReturnExpr {
744744
745745struct AstNodeDefer {
746746 ReturnKind kind;
747 AstNode *err_payload;
747748 AstNode *expr;
748749
749750 // temporary data used in IR generation
......@@ -2266,6 +2267,7 @@ struct CodeGen {
22662267 Buf *zig_lib_dir;
22672268 Buf *zig_std_dir;
22682269 Buf *version_script_path;
2270 Buf *override_soname;
22692271
22702272 const char **llvm_argv;
22712273 size_t llvm_argv_len;
src/codegen.cpp+1
......@@ -10504,6 +10504,7 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
1050410504 cache_str(ch, g->libc->kernel32_lib_dir);
1050510505 }
1050610506 cache_buf_opt(ch, g->version_script_path);
10507 cache_buf_opt(ch, g->override_soname);
1050710508
1050810509 // gen_c_objects appends objects to g->link_objects which we want to include in the hash
1050910510 gen_c_objects(g);
src/glibc.cpp+10
......@@ -16,6 +16,7 @@ static const ZigGLibCLib glibc_libs[] = {
1616 {"pthread", 0},
1717 {"dl", 2},
1818 {"rt", 1},
19 {"ld", 2},
1920};
2021
2122Error glibc_load_metadata(ZigGLibCAbi **out_result, Buf *zig_lib_dir, bool verbose) {
......@@ -330,6 +331,8 @@ Error glibc_build_dummies_and_maps(CodeGen *g, const ZigGLibCAbi *glibc_abi, con
330331 return err;
331332 }
332333
334 bool is_ld = (strcmp(lib->name, "ld") == 0);
335
333336 CodeGen *child_gen = create_child_codegen(g, zig_file_path, OutTypeLib, nullptr, lib->name, progress_node);
334337 codegen_set_lib_version(child_gen, lib->sover, 0, 0);
335338 child_gen->is_dynamic = true;
......@@ -337,6 +340,13 @@ Error glibc_build_dummies_and_maps(CodeGen *g, const ZigGLibCAbi *glibc_abi, con
337340 child_gen->version_script_path = map_file_path;
338341 child_gen->enable_cache = false;
339342 child_gen->output_dir = dummy_dir;
343 if (is_ld) {
344 assert(g->zig_target->standard_dynamic_linker_path != nullptr);
345 Buf *ld_basename = buf_alloc();
346 os_path_split(buf_create_from_str(g->zig_target->standard_dynamic_linker_path),
347 nullptr, ld_basename);
348 child_gen->override_soname = ld_basename;
349 }
340350 codegen_build_and_link(child_gen);
341351 }
342352
src/ir.cpp+101-30
......@@ -272,6 +272,10 @@ static ResultLoc *no_result_loc(void);
272272static IrInstGen *ir_analyze_test_non_null(IrAnalyze *ira, IrInst *source_inst, IrInstGen *value);
273273static IrInstGen *ir_error_dependency_loop(IrAnalyze *ira, IrInst *source_instr);
274274static IrInstGen *ir_const_undef(IrAnalyze *ira, IrInst *source_instruction, ZigType *ty);
275static ZigVar *ir_create_var(IrBuilderSrc *irb, AstNode *node, Scope *scope, Buf *name,
276 bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstSrc *is_comptime);
277static void build_decl_var_and_init(IrBuilderSrc *irb, Scope *scope, AstNode *source_node, ZigVar *var,
278 IrInstSrc *init, const char *name_hint, IrInstSrc *is_comptime);
275279
276280static void destroy_instruction_src(IrInstSrc *inst) {
277281 switch (inst->id) {
......@@ -5011,39 +5015,73 @@ static IrInstSrc *ir_mark_gen(IrInstSrc *instruction) {
50115015 return instruction;
50125016}
50135017
5014static bool ir_gen_defers_for_block(IrBuilderSrc *irb, Scope *inner_scope, Scope *outer_scope, bool gen_error_defers) {
5018static bool ir_gen_defers_for_block(IrBuilderSrc *irb, Scope *inner_scope, Scope *outer_scope, bool *is_noreturn, IrInstSrc *err_value) {
50155019 Scope *scope = inner_scope;
5016 bool is_noreturn = false;
5020 if (is_noreturn != nullptr) *is_noreturn = false;
50175021 while (scope != outer_scope) {
50185022 if (!scope)
5019 return is_noreturn;
5023 return true;
50205024
50215025 switch (scope->id) {
50225026 case ScopeIdDefer: {
50235027 AstNode *defer_node = scope->source_node;
50245028 assert(defer_node->type == NodeTypeDefer);
50255029 ReturnKind defer_kind = defer_node->data.defer.kind;
5026 if (defer_kind == ReturnKindUnconditional ||
5027 (gen_error_defers && defer_kind == ReturnKindError))
5028 {
5029 AstNode *defer_expr_node = defer_node->data.defer.expr;
5030 Scope *defer_expr_scope = defer_node->data.defer.expr_scope;
5031 IrInstSrc *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope);
5032 if (defer_expr_value != irb->codegen->invalid_inst_src) {
5033 if (defer_expr_value->is_noreturn) {
5034 is_noreturn = true;
5035 } else {
5036 ir_mark_gen(ir_build_check_statement_is_void(irb, defer_expr_scope, defer_expr_node,
5037 defer_expr_value));
5038 }
5030 AstNode *defer_expr_node = defer_node->data.defer.expr;
5031 AstNode *defer_var_node = defer_node->data.defer.err_payload;
5032
5033 if (defer_kind == ReturnKindError && err_value == nullptr) {
5034 // This is an `errdefer` but we're generating code for a
5035 // `return` that doesn't return an error, skip it
5036 scope = scope->parent;
5037 continue;
5038 }
5039
5040 Scope *defer_expr_scope = defer_node->data.defer.expr_scope;
5041 if (defer_var_node != nullptr) {
5042 assert(defer_kind == ReturnKindError);
5043 assert(defer_var_node->type == NodeTypeSymbol);
5044 Buf *var_name = defer_var_node->data.symbol_expr.symbol;
5045
5046 if (defer_expr_node->type == NodeTypeUnreachable) {
5047 add_node_error(irb->codegen, defer_var_node,
5048 buf_sprintf("unused variable: '%s'", buf_ptr(var_name)));
5049 return false;
5050 }
5051
5052 IrInstSrc *is_comptime;
5053 if (ir_should_inline(irb->exec, defer_expr_scope)) {
5054 is_comptime = ir_build_const_bool(irb, defer_expr_scope,
5055 defer_expr_node, true);
5056 } else {
5057 is_comptime = ir_build_test_comptime(irb, defer_expr_scope,
5058 defer_expr_node, err_value);
50395059 }
5060
5061 ZigVar *err_var = ir_create_var(irb, defer_var_node, defer_expr_scope,
5062 var_name, true, true, false, is_comptime);
5063 build_decl_var_and_init(irb, defer_expr_scope, defer_var_node, err_var, err_value,
5064 buf_ptr(var_name), is_comptime);
5065
5066 defer_expr_scope = err_var->child_scope;
5067 }
5068
5069 IrInstSrc *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope);
5070 if (defer_expr_value == irb->codegen->invalid_inst_src)
5071 return irb->codegen->invalid_inst_src;
5072
5073 if (defer_expr_value->is_noreturn) {
5074 if (is_noreturn != nullptr) *is_noreturn = true;
5075 } else {
5076 ir_mark_gen(ir_build_check_statement_is_void(irb, defer_expr_scope, defer_expr_node,
5077 defer_expr_value));
50405078 }
50415079 scope = scope->parent;
50425080 continue;
50435081 }
50445082 case ScopeIdDecls:
50455083 case ScopeIdFnDef:
5046 return is_noreturn;
5084 return true;
50475085 case ScopeIdBlock:
50485086 case ScopeIdVarDecl:
50495087 case ScopeIdLoop:
......@@ -5060,7 +5098,7 @@ static bool ir_gen_defers_for_block(IrBuilderSrc *irb, Scope *inner_scope, Scope
50605098 zig_unreachable();
50615099 }
50625100 }
5063 return is_noreturn;
5101 return true;
50645102}
50655103
50665104static void ir_set_cursor_at_end_gen(IrBuilderGen *irb, IrBasicBlockGen *basic_block) {
......@@ -5146,7 +5184,8 @@ static IrInstSrc *ir_gen_return(IrBuilderSrc *irb, Scope *scope, AstNode *node,
51465184 bool have_err_defers = defer_counts[ReturnKindError] > 0;
51475185 if (!have_err_defers && !irb->codegen->have_err_ret_tracing) {
51485186 // only generate unconditional defers
5149 ir_gen_defers_for_block(irb, scope, outer_scope, false);
5187 if (!ir_gen_defers_for_block(irb, scope, outer_scope, nullptr, nullptr))
5188 return irb->codegen->invalid_inst_src;
51505189 IrInstSrc *result = ir_build_return_src(irb, scope, node, nullptr);
51515190 result_loc_ret->base.source_instruction = result;
51525191 return result;
......@@ -5169,14 +5208,16 @@ static IrInstSrc *ir_gen_return(IrBuilderSrc *irb, Scope *scope, AstNode *node,
51695208 IrBasicBlockSrc *ret_stmt_block = ir_create_basic_block(irb, scope, "RetStmt");
51705209
51715210 ir_set_cursor_at_end_and_append_block(irb, err_block);
5172 ir_gen_defers_for_block(irb, scope, outer_scope, true);
5211 if (!ir_gen_defers_for_block(irb, scope, outer_scope, nullptr, return_value))
5212 return irb->codegen->invalid_inst_src;
51735213 if (irb->codegen->have_err_ret_tracing && !should_inline) {
51745214 ir_build_save_err_ret_addr_src(irb, scope, node);
51755215 }
51765216 ir_build_br(irb, scope, node, ret_stmt_block, is_comptime);
51775217
51785218 ir_set_cursor_at_end_and_append_block(irb, ok_block);
5179 ir_gen_defers_for_block(irb, scope, outer_scope, false);
5219 if (!ir_gen_defers_for_block(irb, scope, outer_scope, nullptr, nullptr))
5220 return irb->codegen->invalid_inst_src;
51805221 ir_build_br(irb, scope, node, ret_stmt_block, is_comptime);
51815222
51825223 ir_set_cursor_at_end_and_append_block(irb, ret_stmt_block);
......@@ -5213,7 +5254,12 @@ static IrInstSrc *ir_gen_return(IrBuilderSrc *irb, Scope *scope, AstNode *node,
52135254 result_loc_ret->base.id = ResultLocIdReturn;
52145255 ir_build_reset_result(irb, scope, node, &result_loc_ret->base);
52155256 ir_build_end_expr(irb, scope, node, err_val, &result_loc_ret->base);
5216 if (!ir_gen_defers_for_block(irb, scope, outer_scope, true)) {
5257
5258 bool is_noreturn = false;
5259 if (!ir_gen_defers_for_block(irb, scope, outer_scope, &is_noreturn, err_val)) {
5260 return irb->codegen->invalid_inst_src;
5261 }
5262 if (!is_noreturn) {
52175263 if (irb->codegen->have_err_ret_tracing && !should_inline) {
52185264 ir_build_save_err_ret_addr_src(irb, scope, node);
52195265 }
......@@ -5415,7 +5461,8 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode *
54155461
54165462 bool is_return_from_fn = block_node == irb->main_block_node;
54175463 if (!is_return_from_fn) {
5418 ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false);
5464 if (!ir_gen_defers_for_block(irb, child_scope, outer_block_scope, nullptr, nullptr))
5465 return irb->codegen->invalid_inst_src;
54195466 }
54205467
54215468 IrInstSrc *result;
......@@ -5440,7 +5487,8 @@ static IrInstSrc *ir_gen_block(IrBuilderSrc *irb, Scope *parent_scope, AstNode *
54405487 result_loc_ret->base.id = ResultLocIdReturn;
54415488 ir_build_reset_result(irb, parent_scope, block_node, &result_loc_ret->base);
54425489 ir_mark_gen(ir_build_end_expr(irb, parent_scope, block_node, result, &result_loc_ret->base));
5443 ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false);
5490 if (!ir_gen_defers_for_block(irb, child_scope, outer_block_scope, nullptr, nullptr))
5491 return irb->codegen->invalid_inst_src;
54445492 return ir_mark_gen(ir_build_return_src(irb, child_scope, result->base.source_node, result));
54455493}
54465494
......@@ -9207,7 +9255,8 @@ static IrInstSrc *ir_gen_return_from_block(IrBuilderSrc *irb, Scope *break_scope
92079255 }
92089256
92099257 IrBasicBlockSrc *dest_block = block_scope->end_block;
9210 ir_gen_defers_for_block(irb, break_scope, dest_block->scope, false);
9258 if (!ir_gen_defers_for_block(irb, break_scope, dest_block->scope, nullptr, nullptr))
9259 return irb->codegen->invalid_inst_src;
92119260
92129261 block_scope->incoming_blocks->append(irb->current_basic_block);
92139262 block_scope->incoming_values->append(result_value);
......@@ -9281,7 +9330,8 @@ static IrInstSrc *ir_gen_break(IrBuilderSrc *irb, Scope *break_scope, AstNode *n
92819330 }
92829331
92839332 IrBasicBlockSrc *dest_block = loop_scope->break_block;
9284 ir_gen_defers_for_block(irb, break_scope, dest_block->scope, false);
9333 if (!ir_gen_defers_for_block(irb, break_scope, dest_block->scope, nullptr, nullptr))
9334 return irb->codegen->invalid_inst_src;
92859335
92869336 loop_scope->incoming_blocks->append(irb->current_basic_block);
92879337 loop_scope->incoming_values->append(result_value);
......@@ -9340,7 +9390,8 @@ static IrInstSrc *ir_gen_continue(IrBuilderSrc *irb, Scope *continue_scope, AstN
93409390 }
93419391
93429392 IrBasicBlockSrc *dest_block = loop_scope->continue_block;
9343 ir_gen_defers_for_block(irb, continue_scope, dest_block->scope, false);
9393 if (!ir_gen_defers_for_block(irb, continue_scope, dest_block->scope, nullptr, nullptr))
9394 return irb->codegen->invalid_inst_src;
93449395 return ir_mark_gen(ir_build_br(irb, continue_scope, node, dest_block, is_comptime));
93459396}
93469397
......@@ -12317,11 +12368,22 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT
1231712368 prev_type->data.pointer.child_type->id == ZigTypeIdArray &&
1231812369 prev_type->data.pointer.ptr_len == PtrLenSingle &&
1231912370 ((cur_type->id == ZigTypeIdErrorUnion && is_slice(cur_type->data.error_union.payload_type)) ||
12320 is_slice(cur_type)))
12371 (cur_type->id == ZigTypeIdOptional && is_slice(cur_type->data.maybe.child_type)) ||
12372 is_slice(cur_type)))
1232112373 {
1232212374 ZigType *array_type = prev_type->data.pointer.child_type;
12323 ZigType *slice_type = (cur_type->id == ZigTypeIdErrorUnion) ?
12324 cur_type->data.error_union.payload_type : cur_type;
12375 ZigType *slice_type;
12376 switch (cur_type->id) {
12377 case ZigTypeIdErrorUnion:
12378 slice_type = cur_type->data.error_union.payload_type;
12379 break;
12380 case ZigTypeIdOptional:
12381 slice_type = cur_type->data.maybe.child_type;
12382 break;
12383 default:
12384 slice_type = cur_type;
12385 break;
12386 }
1232512387 ZigType *slice_ptr_type = slice_type->data.structure.fields[slice_ptr_index]->type_entry;
1232612388 if ((slice_ptr_type->data.pointer.is_const || array_type->data.array.len == 0 ||
1232712389 !prev_type->data.pointer.is_const) &&
......@@ -16191,6 +16253,15 @@ static IrInstGen *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstSrcBinOp *bin_op_i
1619116253 IrInstGen *union_val = op1->value->type->id == ZigTypeIdUnion ? op1 : op2;
1619216254 IrInstGen *enum_val = op1->value->type->id == ZigTypeIdUnion ? op2 : op1;
1619316255
16256 if (!is_tagged_union(union_val->value->type)) {
16257 ErrorMsg *msg = ir_add_error_node(ira, source_node,
16258 buf_sprintf("comparison of union and enum literal is only valid for tagged union types"));
16259 add_error_note(ira->codegen, msg, union_val->value->type->data.unionation.decl_node,
16260 buf_sprintf("type %s is not a tagged union",
16261 buf_ptr(&union_val->value->type->name)));
16262 return ira->codegen->invalid_inst_gen;
16263 }
16264
1619416265 ZigType *tag_type = union_val->value->type->data.unionation.tag_type;
1619516266 assert(tag_type != nullptr);
1619616267
src/link.cpp+4-4
......@@ -1651,7 +1651,6 @@ static void construct_linker_job_elf(LinkJob *lj) {
16511651
16521652 bool is_lib = g->out_type == OutTypeLib;
16531653 bool is_dyn_lib = g->is_dynamic && is_lib;
1654 Buf *soname = nullptr;
16551654 if (!g->have_dynamic_link) {
16561655 if (g->zig_target->arch == ZigLLVM_arm || g->zig_target->arch == ZigLLVM_armeb ||
16571656 g->zig_target->arch == ZigLLVM_thumb || g->zig_target->arch == ZigLLVM_thumbeb)
......@@ -1662,15 +1661,13 @@ static void construct_linker_job_elf(LinkJob *lj) {
16621661 }
16631662 } else if (is_dyn_lib) {
16641663 lj->args.append("-shared");
1665
1666 assert(buf_len(&g->bin_file_output_path) != 0);
1667 soname = buf_sprintf("lib%s.so.%" ZIG_PRI_usize, buf_ptr(g->root_out_name), g->version_major);
16681664 }
16691665
16701666 if (target_requires_pie(g->zig_target) && g->out_type == OutTypeExe) {
16711667 lj->args.append("-pie");
16721668 }
16731669
1670 assert(buf_len(&g->bin_file_output_path) != 0);
16741671 lj->args.append("-o");
16751672 lj->args.append(buf_ptr(&g->bin_file_output_path));
16761673
......@@ -1740,6 +1737,9 @@ static void construct_linker_job_elf(LinkJob *lj) {
17401737 }
17411738
17421739 if (is_dyn_lib) {
1740 Buf *soname = (g->override_soname == nullptr) ?
1741 buf_sprintf("lib%s.so.%" ZIG_PRI_usize, buf_ptr(g->root_out_name), g->version_major) :
1742 g->override_soname;
17431743 lj->args.append("-soname");
17441744 lj->args.append(buf_ptr(soname));
17451745
src/main.cpp+10-6
......@@ -54,7 +54,6 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) {
5454 " --cache-dir [path] override the local cache directory\n"
5555 " --cache [auto|off|on] build in cache, print output path to stdout\n"
5656 " --color [auto|off|on] enable or disable colored error messages\n"
57 " --disable-gen-h do not generate a C header file (.h)\n"
5857 " --disable-valgrind omit valgrind client requests in debug builds\n"
5958 " --eh-frame-hdr enable C++ exception handling by passing --eh-frame-hdr to linker\n"
6059 " --enable-valgrind include valgrind client requests release builds\n"
......@@ -77,6 +76,8 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) {
7776 " -fno-emit-asm (default) do not output .s (assembly code)\n"
7877 " -femit-llvm-ir produce a .ll file with LLVM IR\n"
7978 " -fno-emit-llvm-ir (default) do not produce a .ll file with LLVM IR\n"
79 " -femit-h generate a C header file (.h)\n"
80 " -fno-emit-h (default) do not generate a C header file (.h)\n"
8081 " --libc [file] Provide a file which specifies libc paths\n"
8182 " --name [name] override output name\n"
8283 " --output-dir [dir] override output directory (defaults to cwd)\n"
......@@ -432,6 +433,7 @@ static int main0(int argc, char **argv) {
432433 bool emit_bin = true;
433434 bool emit_asm = false;
434435 bool emit_llvm_ir = false;
436 bool emit_h = false;
435437 const char *cache_dir = nullptr;
436438 CliPkg *cur_pkg = heap::c_allocator.create<CliPkg>();
437439 BuildMode build_mode = BuildModeDebug;
......@@ -440,7 +442,6 @@ static int main0(int argc, char **argv) {
440442 bool system_linker_hack = false;
441443 TargetSubsystem subsystem = TargetSubsystemAuto;
442444 bool want_single_threaded = false;
443 bool disable_gen_h = false;
444445 bool bundle_compiler_rt = false;
445446 Buf *override_lib_dir = nullptr;
446447 Buf *main_pkg_path = nullptr;
......@@ -661,9 +662,7 @@ static int main0(int argc, char **argv) {
661662 } else if (strcmp(arg, "--system-linker-hack") == 0) {
662663 system_linker_hack = true;
663664 } else if (strcmp(arg, "--single-threaded") == 0) {
664 want_single_threaded = true;
665 } else if (strcmp(arg, "--disable-gen-h") == 0) {
666 disable_gen_h = true;
665 want_single_threaded = true;;
667666 } else if (strcmp(arg, "--bundle-compiler-rt") == 0) {
668667 bundle_compiler_rt = true;
669668 } else if (strcmp(arg, "--test-cmd-bin") == 0) {
......@@ -720,6 +719,11 @@ static int main0(int argc, char **argv) {
720719 emit_llvm_ir = true;
721720 } else if (strcmp(arg, "-fno-emit-llvm-ir") == 0) {
722721 emit_llvm_ir = false;
722 } else if (strcmp(arg, "-femit-h") == 0) {
723 emit_h = true;
724 } else if (strcmp(arg, "-fno-emit-h") == 0 || strcmp(arg, "--disable-gen-h") == 0) {
725 // the --disable-gen-h is there to support godbolt. once they upgrade to -fno-emit-h then we can remove this
726 emit_h = false;
723727 } else if (str_starts_with(arg, "-mcpu=")) {
724728 mcpu = arg + strlen("-mcpu=");
725729 } else if (i + 1 >= argc) {
......@@ -1203,7 +1207,7 @@ static int main0(int argc, char **argv) {
12031207 g->verbose_cc = verbose_cc;
12041208 g->verbose_llvm_cpu_features = verbose_llvm_cpu_features;
12051209 g->output_dir = output_dir;
1206 g->disable_gen_h = disable_gen_h;
1210 g->disable_gen_h = !emit_h;
12071211 g->bundle_compiler_rt = bundle_compiler_rt;
12081212 codegen_set_errmsg_color(g, color);
12091213 g->system_linker_hack = system_linker_hack;
src/parser.cpp+9-2
......@@ -879,7 +879,7 @@ static AstNode *ast_parse_container_field(ParseContext *pc) {
879879// / KEYWORD_noasync BlockExprStatement
880880// / KEYWORD_suspend (SEMICOLON / BlockExprStatement)
881881// / KEYWORD_defer BlockExprStatement
882// / KEYWORD_errdefer BlockExprStatement
882// / KEYWORD_errdefer Payload? BlockExprStatement
883883// / IfStatement
884884// / LabeledStatement
885885// / SwitchExpr
......@@ -923,12 +923,18 @@ static AstNode *ast_parse_statement(ParseContext *pc) {
923923 if (defer == nullptr)
924924 defer = eat_token_if(pc, TokenIdKeywordErrdefer);
925925 if (defer != nullptr) {
926 Token *payload = (defer->id == TokenIdKeywordErrdefer) ?
927 ast_parse_payload(pc) : nullptr;
926928 AstNode *statement = ast_expect(pc, ast_parse_block_expr_statement);
927929 AstNode *res = ast_create_node(pc, NodeTypeDefer, defer);
930
928931 res->data.defer.kind = ReturnKindUnconditional;
929932 res->data.defer.expr = statement;
930 if (defer->id == TokenIdKeywordErrdefer)
933 if (defer->id == TokenIdKeywordErrdefer) {
931934 res->data.defer.kind = ReturnKindError;
935 if (payload != nullptr)
936 res->data.defer.err_payload = token_symbol(pc, payload);
937 }
932938 return res;
933939 }
934940
......@@ -3032,6 +3038,7 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont
30323038 break;
30333039 case NodeTypeDefer:
30343040 visit_field(&node->data.defer.expr, visit, context);
3041 visit_field(&node->data.defer.err_payload, visit, context);
30353042 break;
30363043 case NodeTypeVariableDeclaration:
30373044 visit_field(&node->data.variable_declaration.type, visit, context);
src/stage2.h+1
......@@ -291,6 +291,7 @@ struct ZigTarget {
291291 size_t cache_hash_len;
292292 const char *os_builtin_str;
293293 const char *dynamic_linker;
294 const char *standard_dynamic_linker_path;
294295};
295296
296297// ABI warning
test/compile_errors.zig+23
......@@ -2,6 +2,29 @@ const tests = @import("tests.zig");
22const std = @import("std");
33
44pub fn addCases(cases: *tests.CompileErrorContext) void {
5 cases.addTest("unused variable error on errdefer",
6 \\fn foo() !void {
7 \\ errdefer |a| unreachable;
8 \\ return error.A;
9 \\}
10 \\export fn entry() void {
11 \\ foo() catch unreachable;
12 \\}
13 , &[_][]const u8{
14 "tmp.zig:2:15: error: unused variable: 'a'",
15 });
16
17 cases.addTest("comparison of non-tagged union and enum literal",
18 \\export fn entry() void {
19 \\ const U = union { A: u32, B: u64 };
20 \\ var u = U{ .A = 42 };
21 \\ var ok = u == .A;
22 \\}
23 , &[_][]const u8{
24 "tmp.zig:4:16: error: comparison of union and enum literal is only valid for tagged union types",
25 "tmp.zig:2:15: note: type U is not a tagged union",
26 });
27
528 cases.addTest("shift on type with non-power-of-two size",
629 \\export fn entry() void {
730 \\ const S = struct {
test/stage1/behavior/defer.zig+20-1
......@@ -1,4 +1,7 @@
1const expect = @import("std").testing.expect;
1const std = @import("std");
2const expect = std.testing.expect;
3const expectEqual = std.testing.expectEqual;
4const expectError = std.testing.expectError;
25
36var result: [3]u8 = undefined;
47var index: usize = undefined;
......@@ -93,3 +96,19 @@ test "return variable while defer expression in scope to modify it" {
9396 S.doTheTest();
9497 comptime S.doTheTest();
9598}
99
100test "errdefer with payload" {
101 const S = struct {
102 fn foo() !i32 {
103 errdefer |a| {
104 expectEqual(error.One, a);
105 }
106 return error.One;
107 }
108 fn doTheTest() void {
109 expectError(error.One, foo());
110 }
111 };
112 S.doTheTest();
113 comptime S.doTheTest();
114}
test/stage1/behavior/slice.zig+8
......@@ -159,6 +159,7 @@ test "slice syntax resulting in pointer-to-array" {
159159 testSlice();
160160 testSliceZ();
161161 testSlice0();
162 testSliceOpt();
162163 testSliceAlign();
163164 }
164165
......@@ -249,6 +250,13 @@ test "slice syntax resulting in pointer-to-array" {
249250 comptime expect(@TypeOf(slice[1..3 :4]) == *[2:4]u8);
250251 }
251252
253 fn testSliceOpt() void {
254 var array: [2]u8 = [2]u8{ 1, 2 };
255 var slice: ?[]u8 = &array;
256 comptime expect(@TypeOf(&array, slice) == ?[]u8);
257 comptime expect(@TypeOf(slice.?[0..2]) == *[2]u8);
258 }
259
252260 fn testSlice0() void {
253261 {
254262 var array = [0]u8{};
test/standalone/mix_o_files/test.c+5-3
......@@ -1,10 +1,12 @@
1// This header is generated by zig from base64.zig
2#include "base64.h"
3
41#include <assert.h>
52#include <string.h>
63#include <stdint.h>
74
5// TODO we would like to #include "base64.h" here but this feature has been disabled in
6// the stage1 compiler. Users will have to wait until self-hosted is available for
7// the "generate .h file" feature.
8size_t decode_base_64(uint8_t *dest_ptr, size_t dest_len, const uint8_t *source_ptr, size_t source_len);
9
810extern int *x_ptr;
911
1012int main(int argc, char **argv) {
test/standalone/shared_library/test.c+7-1
......@@ -1,6 +1,12 @@
1#include "mathtest.h"
21#include <assert.h>
32
3// TODO we would like to #include "mathtest.h" here but this feature has been disabled in
4// the stage1 compiler. Users will have to wait until self-hosted is available for
5// the "generate .h file" feature.
6
7#include <stdint.h>
8int32_t add(int32_t a, int32_t b);
9
410int main(int argc, char **argv) {
511 assert(add(42, 1337) == 1379);
612 return 0;
tools/update_glibc.zig+16-13
......@@ -20,6 +20,7 @@ const lib_names = [_][]const u8{
2020 "m",
2121 "pthread",
2222 "rt",
23 "ld",
2324};
2425
2526// fpu/nofpu are hardcoded elsewhere, based on .gnueabi/.gnueabihf with an exception for .arm
......@@ -154,22 +155,24 @@ pub fn main() !void {
154155 const fn_set = &target_funcs_gop.kv.value.list;
155156
156157 for (lib_names) |lib_name, lib_name_index| {
157 const basename = try fmt.allocPrint(allocator, "lib{}.abilist", .{lib_name});
158 const lib_prefix = if (std.mem.eql(u8, lib_name, "ld")) "" else "lib";
159 const basename = try fmt.allocPrint(allocator, "{}{}.abilist", .{ lib_prefix, lib_name });
158160 const abi_list_filename = blk: {
159 if (abi_list.targets[0].abi == .gnuabi64 and std.mem.eql(u8, lib_name, "c")) {
161 const is_c = std.mem.eql(u8, lib_name, "c");
162 const is_m = std.mem.eql(u8, lib_name, "m");
163 const is_ld = std.mem.eql(u8, lib_name, "ld");
164 if (abi_list.targets[0].abi == .gnuabi64 and (is_c or is_ld)) {
160165 break :blk try fs.path.join(allocator, &[_][]const u8{ prefix, abi_list.path, "n64", basename });
161 } else if (abi_list.targets[0].abi == .gnuabin32 and std.mem.eql(u8, lib_name, "c")) {
166 } else if (abi_list.targets[0].abi == .gnuabin32 and (is_c or is_ld)) {
162167 break :blk try fs.path.join(allocator, &[_][]const u8{ prefix, abi_list.path, "n32", basename });
163168 } else if (abi_list.targets[0].arch != .arm and
164169 abi_list.targets[0].abi == .gnueabihf and
165 (std.mem.eql(u8, lib_name, "c") or
166 (std.mem.eql(u8, lib_name, "m") and abi_list.targets[0].arch == .powerpc)))
170 (is_c or (is_m and abi_list.targets[0].arch == .powerpc)))
167171 {
168172 break :blk try fs.path.join(allocator, &[_][]const u8{ prefix, abi_list.path, "fpu", basename });
169173 } else if (abi_list.targets[0].arch != .arm and
170174 abi_list.targets[0].abi == .gnueabi and
171 (std.mem.eql(u8, lib_name, "c") or
172 (std.mem.eql(u8, lib_name, "m") and abi_list.targets[0].arch == .powerpc)))
175 (is_c or (is_m and abi_list.targets[0].arch == .powerpc)))
173176 {
174177 break :blk try fs.path.join(allocator, &[_][]const u8{ prefix, abi_list.path, "nofpu", basename });
175178 } else if (abi_list.targets[0].arch == .arm) {
......@@ -234,8 +237,8 @@ pub fn main() !void {
234237 const vers_txt_path = try fs.path.join(allocator, &[_][]const u8{ glibc_out_dir, "vers.txt" });
235238 const vers_txt_file = try fs.cwd().createFile(vers_txt_path, .{});
236239 defer vers_txt_file.close();
237 var buffered = std.io.BufferedOutStream(fs.File.WriteError).init(&vers_txt_file.outStream().stream);
238 const vers_txt = &buffered.stream;
240 var buffered = std.io.bufferedOutStream(vers_txt_file.outStream());
241 const vers_txt = buffered.outStream();
239242 for (global_ver_list) |name, i| {
240243 _ = global_ver_set.put(name, i) catch unreachable;
241244 try vers_txt.print("{}\n", .{name});
......@@ -246,8 +249,8 @@ pub fn main() !void {
246249 const fns_txt_path = try fs.path.join(allocator, &[_][]const u8{ glibc_out_dir, "fns.txt" });
247250 const fns_txt_file = try fs.cwd().createFile(fns_txt_path, .{});
248251 defer fns_txt_file.close();
249 var buffered = std.io.BufferedOutStream(fs.File.WriteError).init(&fns_txt_file.outStream().stream);
250 const fns_txt = &buffered.stream;
252 var buffered = std.io.bufferedOutStream(fns_txt_file.outStream());
253 const fns_txt = buffered.outStream();
251254 for (global_fn_list) |name, i| {
252255 const kv = global_fn_set.get(name).?;
253256 kv.value.index = i;
......@@ -277,8 +280,8 @@ pub fn main() !void {
277280 const abilist_txt_path = try fs.path.join(allocator, &[_][]const u8{ glibc_out_dir, "abi.txt" });
278281 const abilist_txt_file = try fs.cwd().createFile(abilist_txt_path, .{});
279282 defer abilist_txt_file.close();
280 var buffered = std.io.BufferedOutStream(fs.File.WriteError).init(&abilist_txt_file.outStream().stream);
281 const abilist_txt = &buffered.stream;
283 var buffered = std.io.bufferedOutStream(abilist_txt_file.outStream());
284 const abilist_txt = buffered.outStream();
282285
283286 // first iterate over the abi lists
284287 for (abi_lists) |*abi_list, abi_index| {