authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-09-10 13:00:35-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-09-10 13:00:35-04:00
log185cb1327806f073b91218ff2fd6f21d95060c00
tree2b1ad839768962626689df3abd1434b59f43d96f
parent058050f22c5c72507cae57f27e83b2ad2e9afec3
parentba4d83af3e58ce2a34ccb945a297211333fd904c
signaturelock-open Commit is signed but in an unrecognized format.

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


171 files changed, 6231 insertions(+), 2802 deletions(-)

CMakeLists.txt+21-7
......@@ -23,14 +23,18 @@ find_program(GIT_EXE NAMES git)
2323if(GIT_EXE)
2424 execute_process(
2525 COMMAND ${GIT_EXE} -C ${CMAKE_SOURCE_DIR} name-rev HEAD --tags --name-only --no-undefined --always
26 RESULT_VARIABLE EXIT_STATUS
2627 OUTPUT_VARIABLE ZIG_GIT_REV
27 OUTPUT_STRIP_TRAILING_WHITESPACE)
28 if(ZIG_GIT_REV MATCHES "\\^0$")
29 if(NOT("${ZIG_GIT_REV}" STREQUAL "${ZIG_VERSION}^0"))
30 message("WARNING: Tag does not match configured Zig version")
28 OUTPUT_STRIP_TRAILING_WHITESPACE
29 ERROR_QUIET)
30 if(EXIT_STATUS EQUAL "0")
31 if(ZIG_GIT_REV MATCHES "\\^0$")
32 if(NOT("${ZIG_GIT_REV}" STREQUAL "${ZIG_VERSION}^0"))
33 message("WARNING: Tag does not match configured Zig version")
34 endif()
35 else()
36 set(ZIG_VERSION "${ZIG_VERSION}+${ZIG_GIT_REV}")
3137 endif()
32 else()
33 set(ZIG_VERSION "${ZIG_VERSION}+${ZIG_GIT_REV}")
3438 endif()
3539endif()
3640message("Configuring zig version ${ZIG_VERSION}")
......@@ -448,6 +452,7 @@ set(ZIG_SOURCES
448452 "${CMAKE_SOURCE_DIR}/src/os.cpp"
449453 "${CMAKE_SOURCE_DIR}/src/parser.cpp"
450454 "${CMAKE_SOURCE_DIR}/src/range_set.cpp"
455 "${CMAKE_SOURCE_DIR}/src/stack_report.cpp"
451456 "${CMAKE_SOURCE_DIR}/src/target.cpp"
452457 "${CMAKE_SOURCE_DIR}/src/tokenizer.cpp"
453458 "${CMAKE_SOURCE_DIR}/src/translate_c.cpp"
......@@ -504,7 +509,7 @@ endif()
504509if(MSVC)
505510 set(EXE_CFLAGS "${EXE_CFLAGS}")
506511else()
507 set(EXE_CFLAGS "${EXE_CFLAGS} -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D_GNU_SOURCE -fvisibility-inlines-hidden -fno-exceptions -fno-rtti -Werror=strict-prototypes -Werror=old-style-definition -Werror=type-limits -Wno-missing-braces")
512 set(EXE_CFLAGS "${EXE_CFLAGS} -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D_GNU_SOURCE -fvisibility-inlines-hidden -fno-exceptions -fno-rtti -Werror=type-limits -Wno-missing-braces")
508513 if(MINGW)
509514 set(EXE_CFLAGS "${EXE_CFLAGS} -Wno-format")
510515 endif()
......@@ -515,6 +520,9 @@ set(OPTIMIZED_C_FLAGS "-std=c99 -O3")
515520set(EXE_LDFLAGS " ")
516521if(MSVC)
517522 set(EXE_LDFLAGS "${EXE_LDFLAGS} /STACK:16777216")
523 if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Release" AND NOT "${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel")
524 set(EXE_LDFLAGS "${EXE_LDFLAGS} /debug:fastlink")
525 endif()
518526elseif(MINGW)
519527 set(EXE_LDFLAGS "${EXE_LDFLAGS} -Wl,--stack,16777216")
520528endif()
......@@ -586,12 +594,18 @@ if(MSVC)
586594else()
587595 set(LIBUSERLAND "${CMAKE_BINARY_DIR}/libuserland.a")
588596endif()
597if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
598 set(LIBUSERLAND_RELEASE_MODE "false")
599else()
600 set(LIBUSERLAND_RELEASE_MODE "true")
601endif()
589602add_custom_target(zig_build_libuserland ALL
590603 COMMAND zig0 build
591604 --override-std-dir std
592605 --override-lib-dir "${CMAKE_SOURCE_DIR}"
593606 libuserland install
594607 "-Doutput-dir=${CMAKE_BINARY_DIR}"
608 "-Drelease=${LIBUSERLAND_RELEASE_MODE}"
595609 "-Dlib-files-only"
596610 --prefix "${CMAKE_INSTALL_PREFIX}"
597611 DEPENDS zig0
build.zig+8-3
......@@ -63,7 +63,7 @@ pub fn build(b: *Builder) !void {
6363 try configureStage2(b, test_stage2, ctx);
6464 try configureStage2(b, exe, ctx);
6565
66 addLibUserlandStep(b);
66 addLibUserlandStep(b, mode);
6767
6868 const skip_release = b.option(bool, "skip-release", "Main test suite skips release builds") orelse false;
6969 const skip_release_small = b.option(bool, "skip-release-small", "Main test suite skips release-small builds") orelse skip_release;
......@@ -138,12 +138,13 @@ pub fn build(b: *Builder) !void {
138138
139139 test_step.dependOn(tests.addCompareOutputTests(b, test_filter, modes));
140140 test_step.dependOn(tests.addStandaloneTests(b, test_filter, modes));
141 test_step.dependOn(tests.addStackTraceTests(b, test_filter, modes));
141142 test_step.dependOn(tests.addCliTests(b, test_filter, modes));
142 test_step.dependOn(tests.addCompileErrorTests(b, test_filter, modes));
143143 test_step.dependOn(tests.addAssembleAndLinkTests(b, test_filter, modes));
144144 test_step.dependOn(tests.addRuntimeSafetyTests(b, test_filter, modes));
145145 test_step.dependOn(tests.addTranslateCTests(b, test_filter));
146146 test_step.dependOn(tests.addGenHTests(b, test_filter));
147 test_step.dependOn(tests.addCompileErrorTests(b, test_filter, modes));
147148 test_step.dependOn(docs_step);
148149}
149150
......@@ -369,11 +370,15 @@ const Context = struct {
369370 llvm: LibraryDep,
370371};
371372
372fn addLibUserlandStep(b: *Builder) void {
373fn addLibUserlandStep(b: *Builder, mode: builtin.Mode) void {
373374 const artifact = b.addStaticLibrary("userland", "src-self-hosted/stage1.zig");
374375 artifact.disable_gen_h = true;
375376 artifact.bundle_compiler_rt = true;
376377 artifact.setTarget(builtin.arch, builtin.os, builtin.abi);
378 artifact.setBuildMode(mode);
379 if (mode != .Debug) {
380 artifact.strip = true;
381 }
377382 artifact.linkSystemLibrary("c");
378383 if (builtin.os == .windows) {
379384 artifact.linkSystemLibrary("ntdll");
doc/docgen.zig+28-4
......@@ -307,7 +307,7 @@ const Node = union(enum) {
307307const Toc = struct {
308308 nodes: []Node,
309309 toc: []u8,
310 urls: std.HashMap([]const u8, Token, mem.hash_slice_u8, mem.eql_slice_u8),
310 urls: std.StringHashMap(Token),
311311};
312312
313313const Action = enum {
......@@ -316,11 +316,12 @@ const Action = enum {
316316};
317317
318318fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
319 var urls = std.HashMap([]const u8, Token, mem.hash_slice_u8, mem.eql_slice_u8).init(allocator);
319 var urls = std.StringHashMap(Token).init(allocator);
320320 errdefer urls.deinit();
321321
322322 var header_stack_size: usize = 0;
323323 var last_action = Action.Open;
324 var last_columns: ?u8 = null;
324325
325326 var toc_buf = try std.Buffer.initSize(allocator, 0);
326327 defer toc_buf.deinit();
......@@ -361,7 +362,23 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
361362 _ = try eatToken(tokenizer, Token.Id.Separator);
362363 const content_token = try eatToken(tokenizer, Token.Id.TagContent);
363364 const content = tokenizer.buffer[content_token.start..content_token.end];
364 _ = try eatToken(tokenizer, Token.Id.BracketClose);
365 var columns: ?u8 = null;
366 while (true) {
367 const bracket_tok = tokenizer.next();
368 switch (bracket_tok.id) {
369 .BracketClose => break,
370 .Separator => continue,
371 .TagContent => {
372 const param = tokenizer.buffer[bracket_tok.start..bracket_tok.end];
373 if (mem.eql(u8, param, "3col")) {
374 columns = 3;
375 } else {
376 return parseError(tokenizer, bracket_tok, "unrecognized header_open param: {}", param);
377 }
378 },
379 else => return parseError(tokenizer, bracket_tok, "invalid header_open token"),
380 }
381 }
365382
366383 header_stack_size += 1;
367384
......@@ -381,10 +398,15 @@ fn genToc(allocator: *mem.Allocator, tokenizer: *Tokenizer) !Toc {
381398 if (last_action == Action.Open) {
382399 try toc.writeByte('\n');
383400 try toc.writeByteNTimes(' ', header_stack_size * 4);
384 try toc.write("<ul>\n");
401 if (last_columns) |n| {
402 try toc.print("<ul style=\"columns: {}\">\n", n);
403 } else {
404 try toc.write("<ul>\n");
405 }
385406 } else {
386407 last_action = Action.Open;
387408 }
409 last_columns = columns;
388410 try toc.writeByteNTimes(' ', 4 + header_stack_size * 4);
389411 try toc.print("<li><a id=\"toc-{}\" href=\"#{}\">{}</a>", urlized, urlized, content);
390412 } else if (mem.eql(u8, tag_name, "header_close")) {
......@@ -766,6 +788,8 @@ fn tokenizeAndPrintRaw(docgen_tokenizer: *Tokenizer, out: var, source_token: Tok
766788 .Keyword_inline,
767789 .Keyword_nakedcc,
768790 .Keyword_noalias,
791 .Keyword_noasync,
792 .Keyword_noinline,
769793 .Keyword_or,
770794 .Keyword_orelse,
771795 .Keyword_packed,
doc/langref.html.in+76-4
......@@ -6323,7 +6323,7 @@ fn readFile(allocator: *Allocator, filename: []const u8) ![]u8 {
63236323 {#header_close#}
63246324
63256325 {#header_close#}
6326 {#header_open|Builtin Functions#}
6326 {#header_open|Builtin Functions|3col#}
63276327 <p>
63286328 Builtin functions are provided by the compiler and are prefixed with <code>@</code>.
63296329 The {#syntax#}comptime{#endsyntax#} keyword on a parameter means that the parameter must be known
......@@ -6976,10 +6976,28 @@ export fn @"A function name that is a complete sentence."() void {}
69766976
69776977 {#header_open|@field#}
69786978 <pre>{#syntax#}@field(lhs: var, comptime field_name: []const u8) (field){#endsyntax#}</pre>
6979 <p>Preforms field access equivalent to {#syntax#}lhs.field_name{#endsyntax#}, except instead
6980 of the field {#syntax#}"field_name"{#endsyntax#}, it accesses the field named by the string
6981 value of {#syntax#}field_name{#endsyntax#}.
6979 <p>Performs field access by a compile-time string.
69826980 </p>
6981 {#code_begin|test#}
6982const std = @import("std");
6983
6984const Point = struct {
6985 x: u32,
6986 y: u32
6987};
6988
6989test "field access by string" {
6990 const assert = std.debug.assert;
6991 var p = Point {.x = 0, .y = 0};
6992
6993 @field(p, "x") = 4;
6994 @field(p, "y") = @field(p, "x") + 1;
6995
6996 assert(@field(p, "x") == 4);
6997 assert(@field(p, "y") == 5);
6998}
6999 {#code_end#}
7000
69837001 {#header_close#}
69847002
69857003 {#header_open|@fieldParentPtr#}
......@@ -7232,6 +7250,9 @@ fn add(a: i32, b: i32) i32 { return a + b; }
72327250 This function returns an integer type with the given signness and bit count. The maximum
72337251 bit count for an integer type is {#syntax#}65535{#endsyntax#}.
72347252 </p>
7253 <p>
7254 Deprecated. Use {#link|@Type#}.
7255 </p>
72357256 {#header_close#}
72367257
72377258 {#header_open|@memberCount#}
......@@ -7871,6 +7892,57 @@ test "integer truncation" {
78717892 </p>
78727893 {#header_close#}
78737894
7895 {#header_open|@Type#}
7896 <pre>{#syntax#}@Type(comptime info: @import("builtin").TypeInfo) type{#endsyntax#}</pre>
7897 <p>
7898 This function is the inverse of {#link|@typeInfo#}. It reifies type information
7899 into a {#syntax#}type{#endsyntax#}.
7900 </p>
7901 <p>
7902 It is available for the following types:
7903 </p>
7904 <ul>
7905 <li>{#syntax#}type{#endsyntax#}</li>
7906 <li>{#syntax#}noreturn{#endsyntax#}</li>
7907 <li>{#syntax#}void{#endsyntax#}</li>
7908 <li>{#syntax#}bool{#endsyntax#}</li>
7909 <li>{#link|Integers#}</li> - The maximum bit count for an integer type is {#syntax#}65535{#endsyntax#}.
7910 <li>{#link|Floats#}</li>
7911 <li>{#link|Pointers#}</li>
7912 <li>{#syntax#}comptime_int{#endsyntax#}</li>
7913 <li>{#syntax#}comptime_float{#endsyntax#}</li>
7914 <li>{#syntax#}@typeOf(undefined){#endsyntax#}</li>
7915 <li>{#syntax#}@typeOf(null){#endsyntax#}</li>
7916 </ul>
7917 <p>
7918 For these types it is a
7919 <a href="https://github.com/ziglang/zig/issues/2907">TODO in the compiler to implement</a>:
7920 </p>
7921 <ul>
7922 <li>Array</li>
7923 <li>Optional</li>
7924 <li>ErrorUnion</li>
7925 <li>ErrorSet</li>
7926 <li>Enum</li>
7927 <li>Opaque</li>
7928 <li>FnFrame</li>
7929 <li>AnyFrame</li>
7930 <li>Vector</li>
7931 <li>EnumLiteral</li>
7932 </ul>
7933 <p>
7934 For these types, {#syntax#}@Type{#endsyntax#} is not available.
7935 <a href="https://github.com/ziglang/zig/issues/383">There is an open proposal to allow unions and structs</a>.
7936 </p>
7937 <ul>
7938 <li>{#link|union#}</li>
7939 <li>{#link|Functions#}</li>
7940 <li>BoundFn</li>
7941 <li>ArgTuple</li>
7942 <li>{#link|struct#}</li>
7943 </ul>
7944 {#header_close#}
7945
78747946 {#header_open|@typeId#}
78757947 <pre>{#syntax#}@typeId(comptime T: type) @import("builtin").TypeId{#endsyntax#}</pre>
78767948 <p>
lib/libc/glibc/abi.txt+330
......@@ -514,6 +514,7 @@ aarch64-linux-gnu aarch64_be-linux-gnu
51451429
51551529
51651629
517
51751829
518519
51952029
......@@ -655,6 +656,18 @@ aarch64-linux-gnu aarch64_be-linux-gnu
655656
656657
657658
659
660
661
662
663
664
665
666
667
668
669
670
658671
659672
660673
......@@ -1928,6 +1941,7 @@ aarch64-linux-gnu aarch64_be-linux-gnu
1928194129
1929194229
1930194329
194440
1931194529
1932194629
1933194729
......@@ -2048,6 +2062,7 @@ aarch64-linux-gnu aarch64_be-linux-gnu
2048206229
2049206329
2050206429
206540
2051206629
2052206729
2053206829
......@@ -2721,6 +2736,7 @@ aarch64-linux-gnu aarch64_be-linux-gnu
2721273629
2722273729
2723273829
273940
2724274029
2725274129
2726274229
......@@ -2749,6 +2765,7 @@ aarch64-linux-gnu aarch64_be-linux-gnu
2749276529
2750276629
2751276729
276840
2752276929
2753277029
2754277129
......@@ -2776,6 +2793,8 @@ aarch64-linux-gnu aarch64_be-linux-gnu
2776279329
2777279429
2778279529
279640
279740
2779279829
2780279929
2781280029
......@@ -3002,6 +3021,7 @@ aarch64-linux-gnu aarch64_be-linux-gnu
3002302129
3003302229
3004302329
302440
3005302529
3006302629
3007302729
......@@ -3370,6 +3390,7 @@ aarch64-linux-gnu aarch64_be-linux-gnu
3370339037
3371339137
3372339229
339340
3373339438
3374339538
3375339638
......@@ -3443,6 +3464,7 @@ aarch64-linux-gnu aarch64_be-linux-gnu
3443346429
3444346529
3445346629
346740
3446346829
3447346929
3448347029
......@@ -4218,6 +4240,7 @@ s390x-linux-gnu
421842405
421942415
422042425
4243
4221424427
42224245
4223424627
......@@ -4330,12 +4353,18 @@ s390x-linux-gnu
4330435316
4331435416
4332435516
435640
435740
4333435816
4334435938
4335436038
4336436138
4337436216
4338436338
436440
436540
436640
436740
4339436816
4340436916
4341437016
......@@ -4356,6 +4385,8 @@ s390x-linux-gnu
4356438516
4357438616
4358438716
438840
438940
4359439016
4360439116
4361439216
......@@ -4368,8 +4399,12 @@ s390x-linux-gnu
4368439916
4369440016
4370440116
440240
440340
4371440416
4372440516
440640
440740
4373440816
4374440916
437544105
......@@ -5632,6 +5667,7 @@ s390x-linux-gnu
563256675
563356685
563456695
567040
563556715
563656725
563756735
......@@ -5752,6 +5788,7 @@ s390x-linux-gnu
575257885
575357895
575457905
579140
575557925
575657935
575757945
......@@ -6425,6 +6462,7 @@ s390x-linux-gnu
642564625
642664635
642764645 13
646540
642864665 13
642964675 13
643064685 13
......@@ -6453,6 +6491,7 @@ s390x-linux-gnu
645364915
645464925
645564935
649440
6456649524
6457649616
645864975
......@@ -6480,6 +6519,8 @@ s390x-linux-gnu
6480651916
648165205
648265215
652240
652340
648365245
648465255
648565265
......@@ -6706,6 +6747,7 @@ s390x-linux-gnu
670667475
670767485
670867495
675040
670967515
671067525
671167535
......@@ -7074,6 +7116,7 @@ s390x-linux-gnu
7074711637
7075711737
707671185 16
711940
7077712038
7078712138
7079712238
......@@ -7147,6 +7190,7 @@ s390x-linux-gnu
714771905
714871915
714971925
719340
715071945
715171955
715271965
......@@ -7922,6 +7966,7 @@ arm-linux-gnueabi armeb-linux-gnueabi arm-linux-gnueabihf armeb-linux-gnueabihf
7922796616
7923796716
7924796816
7969
7925797027
79267971
7927797227
......@@ -8063,6 +8108,18 @@ arm-linux-gnueabi armeb-linux-gnueabi arm-linux-gnueabihf armeb-linux-gnueabihf
80638108
80648109
80658110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
80668123
80678124
80688125
......@@ -9336,6 +9393,7 @@ arm-linux-gnueabi armeb-linux-gnueabi arm-linux-gnueabihf armeb-linux-gnueabihf
9336939316
9337939416
9338939516
939640
9339939716
9340939816
9341939916
......@@ -9456,6 +9514,7 @@ arm-linux-gnueabi armeb-linux-gnueabi arm-linux-gnueabihf armeb-linux-gnueabihf
9456951416
9457951516
9458951616
951740
9459951816
9460951916
9461952016
......@@ -10129,6 +10188,7 @@ arm-linux-gnueabi armeb-linux-gnueabi arm-linux-gnueabihf armeb-linux-gnueabihf
101291018816
101301018916
101311019016
1019140
101321019216
101331019316
101341019416
......@@ -10157,6 +10217,7 @@ arm-linux-gnueabi armeb-linux-gnueabi arm-linux-gnueabihf armeb-linux-gnueabihf
101571021716
101581021816
101591021916
1022040
101601022124
101611022216
101621022316
......@@ -10184,6 +10245,8 @@ arm-linux-gnueabi armeb-linux-gnueabi arm-linux-gnueabihf armeb-linux-gnueabihf
101841024516
101851024616
101861024716
1024840
1024940
101871025016
101881025116
101891025216
......@@ -10410,6 +10473,7 @@ arm-linux-gnueabi armeb-linux-gnueabi arm-linux-gnueabihf armeb-linux-gnueabihf
104101047316
104111047416
104121047516
1047640
104131047716
104141047816
104151047916
......@@ -10778,6 +10842,7 @@ arm-linux-gnueabi armeb-linux-gnueabi arm-linux-gnueabihf armeb-linux-gnueabihf
107781084237
1077910843
107801084416
1084540
107811084638
107821084738
107831084838
......@@ -10851,6 +10916,7 @@ arm-linux-gnueabi armeb-linux-gnueabi arm-linux-gnueabihf armeb-linux-gnueabihf
108511091616
108521091716
108531091816
1091940
108541092016
108551092116
108561092216
......@@ -11626,6 +11692,7 @@ sparc-linux-gnu sparcel-linux-gnu
11626116921
11627116930
11628116940
116953
116291169627
1163011697
116311169827
......@@ -11738,12 +11805,18 @@ sparc-linux-gnu sparcel-linux-gnu
117381180516
117391180616
117401180716
1180840
1180940
117411181016
117421181138
117431181238
117441181338
117451181416
117461181538
1181640
1181740
1181840
1181940
117471182016
117481182116
117491182216
......@@ -11764,6 +11837,8 @@ sparc-linux-gnu sparcel-linux-gnu
117641183716
117651183816
117661183916
1184040
1184140
117671184216
117681184316
117691184416
......@@ -11776,8 +11851,12 @@ sparc-linux-gnu sparcel-linux-gnu
117761185116
117771185216
117781185316
1185440
1185540
117791185616
117801185716
1185840
1185940
117811186016
117821186116
11783118620
......@@ -13040,6 +13119,7 @@ sparc-linux-gnu sparcel-linux-gnu
13040131191
13041131201
13042131210
1312240
13043131230
13044131245
13045131250
......@@ -13160,6 +13240,7 @@ sparc-linux-gnu sparcel-linux-gnu
13160132400 3
13161132410
13162132420
1324340
13163132440
13164132450
13165132460
......@@ -13833,6 +13914,7 @@ sparc-linux-gnu sparcel-linux-gnu
13833139145
13834139150
13835139160 13
1391740
13836139180 13
13837139190 13
13838139200 13
......@@ -13861,6 +13943,7 @@ sparc-linux-gnu sparcel-linux-gnu
13861139430
13862139440
13863139450
1394640
138641394724
138651394816
13866139490
......@@ -13888,6 +13971,8 @@ sparc-linux-gnu sparcel-linux-gnu
138881397116
13889139721
13890139730
1397440
1397540
13891139761
13892139771
13893139781
......@@ -14114,6 +14199,7 @@ sparc-linux-gnu sparcel-linux-gnu
14114141990
14115142000
14116142010
1420240
14117142032
14118142040 1
14119142050 1
......@@ -14482,6 +14568,7 @@ sparc-linux-gnu sparcel-linux-gnu
144821456837
144831456937
14484145701 16
1457140
144851457238
144861457338
144871457438
......@@ -14555,6 +14642,7 @@ sparc-linux-gnu sparcel-linux-gnu
14555146420
14556146430
14557146440
1464540
14558146460
14559146470
14560146480
......@@ -15330,6 +15418,7 @@ sparcv9-linux-gnu
15330154185
15331154195
15332154205
15421
153331542227
1533415423
153351542427
......@@ -15471,6 +15560,18 @@ sparcv9-linux-gnu
1547115560
1547215561
1547315562
15563
15564
15565
15566
15567
15568
15569
15570
15571
15572
15573
15574
1547415575
1547515576
1547615577
......@@ -16744,6 +16845,7 @@ sparcv9-linux-gnu
16744168455
16745168465
16746168475
1684840
16747168495
16748168505
16749168515
......@@ -16864,6 +16966,7 @@ sparcv9-linux-gnu
16864169665
16865169675
16866169685
1696940
16867169705
16868169715
16869169725
......@@ -17537,6 +17640,7 @@ sparcv9-linux-gnu
17537176405
17538176415
17539176425 13
1764340
17540176445 13
17541176455 13
17542176465 13
......@@ -17565,6 +17669,7 @@ sparcv9-linux-gnu
17565176695
17566176705
17567176715
1767240
175681767324
175691767416
17570176755
......@@ -17592,6 +17697,8 @@ sparcv9-linux-gnu
175921769716
17593176985
17594176995
1770040
1770140
17595177025
17596177035
17597177045
......@@ -17818,6 +17925,7 @@ sparcv9-linux-gnu
17818179255
17819179265
17820179275
1792840
17821179295
17822179305
17823179315
......@@ -18186,6 +18294,7 @@ sparcv9-linux-gnu
181861829437
181871829537
18188182965
1829740
181891829838
181901829938
181911830038
......@@ -18259,6 +18368,7 @@ sparcv9-linux-gnu
18259183685
18260183695
18261183705
1837140
18262183725
18263183735
18264183745
......@@ -19034,6 +19144,7 @@ mips64el-linux-gnuabi64 mips64-linux-gnuabi64
19034191445
19035191450
19036191460
19147
190371914827
1903819149
190391915027
......@@ -19175,6 +19286,18 @@ mips64el-linux-gnuabi64 mips64-linux-gnuabi64
1917519286
1917619287
1917719288
19289
19290
19291
19292
19293
19294
19295
19296
19297
19298
19299
19300
1917819301
1917919302
1918019303
......@@ -20448,6 +20571,7 @@ mips64el-linux-gnuabi64 mips64-linux-gnuabi64
20448205715
20449205725
20450205730
2057440
20451205750
20452205765
20453205770
......@@ -20568,6 +20692,7 @@ mips64el-linux-gnuabi64 mips64-linux-gnuabi64
20568206920 5
20569206930
20570206940
2069540
20571206960
20572206970
20573206980
......@@ -21241,6 +21366,7 @@ mips64el-linux-gnuabi64 mips64-linux-gnuabi64
21241213665
21242213670
21243213680 13
2136940
21244213700 13
21245213710 13
21246213720 13
......@@ -21269,6 +21395,7 @@ mips64el-linux-gnuabi64 mips64-linux-gnuabi64
21269213950
21270213960
21271213970
2139840
212722139924
212732140016
21274214010
......@@ -21296,6 +21423,8 @@ mips64el-linux-gnuabi64 mips64-linux-gnuabi64
212962142316
21297214245
21298214250
2142640
2142740
21299214285
21300214295
21301214305
......@@ -21522,6 +21651,7 @@ mips64el-linux-gnuabi64 mips64-linux-gnuabi64
21522216510
21523216520
21524216530
2165440
21525216555
21526216560 5
21527216570 5
......@@ -21890,6 +22020,7 @@ mips64el-linux-gnuabi64 mips64-linux-gnuabi64
218902202037
218912202137
21892220225
2202340
218932202438
218942202538
218952202638
......@@ -21963,6 +22094,7 @@ mips64el-linux-gnuabi64 mips64-linux-gnuabi64
21963220940
21964220950
21965220960
2209740
21966220980
21967220990
21968221000
......@@ -22738,6 +22870,7 @@ mips64el-linux-gnuabin32 mips64-linux-gnuabin32
22738228705
22739228710
22740228720
22873
227412287427
2274222875
227432287627
......@@ -22879,6 +23012,18 @@ mips64el-linux-gnuabin32 mips64-linux-gnuabin32
2287923012
2288023013
2288123014
23015
23016
23017
23018
23019
23020
23021
23022
23023
23024
23025
23026
2288223027
2288323028
2288423029
......@@ -24152,6 +24297,7 @@ mips64el-linux-gnuabin32 mips64-linux-gnuabin32
24152242975
24153242985
24154242990
2430040
24155243010
24156243025
24157243030
......@@ -24272,6 +24418,7 @@ mips64el-linux-gnuabin32 mips64-linux-gnuabin32
24272244180 5
24273244190
24274244200
2442140
24275244220
24276244230
24277244240
......@@ -24945,6 +25092,7 @@ mips64el-linux-gnuabin32 mips64-linux-gnuabin32
24945250925
24946250930
24947250940 13
2509540
24948250960 13
24949250970 13
24950250980 13
......@@ -24973,6 +25121,7 @@ mips64el-linux-gnuabin32 mips64-linux-gnuabin32
24973251210
24974251220
24975251230
2512440
249762512524
249772512616
24978251270
......@@ -25000,6 +25149,8 @@ mips64el-linux-gnuabin32 mips64-linux-gnuabin32
250002514916
25001251505
25002251510
2515240
2515340
25003251545
25004251555
25005251565
......@@ -25226,6 +25377,7 @@ mips64el-linux-gnuabin32 mips64-linux-gnuabin32
25226253770
25227253780
25228253790
2538040
25229253815
25230253820 5
25231253830 5
......@@ -25594,6 +25746,7 @@ mips64el-linux-gnuabin32 mips64-linux-gnuabin32
255942574637
255952574737
25596257485
2574940
255972575038
255982575138
255992575238
......@@ -25667,6 +25820,7 @@ mips64el-linux-gnuabin32 mips64-linux-gnuabin32
25667258200
25668258210
25669258220
2582340
25670258240
25671258250
25672258260
......@@ -26442,6 +26596,7 @@ mipsel-linux-gnueabihf mips-linux-gnueabihf
26442265965
26443265970
26444265980
26599
264452660027
2644626601
264472660227
......@@ -26583,6 +26738,18 @@ mipsel-linux-gnueabihf mips-linux-gnueabihf
2658326738
2658426739
2658526740
26741
26742
26743
26744
26745
26746
26747
26748
26749
26750
26751
26752
2658626753
2658726754
2658826755
......@@ -27856,6 +28023,7 @@ mipsel-linux-gnueabihf mips-linux-gnueabihf
27856280235
27857280245
27858280250
2802640
27859280270
27860280285
27861280290
......@@ -27976,6 +28144,7 @@ mipsel-linux-gnueabihf mips-linux-gnueabihf
27976281440 5
27977281450
27978281460
2814740
27979281480
27980281490
27981281500
......@@ -28649,6 +28818,7 @@ mipsel-linux-gnueabihf mips-linux-gnueabihf
28649288185
28650288190
28651288200 13
2882140
28652288220 13
28653288230 13
28654288240 13
......@@ -28677,6 +28847,7 @@ mipsel-linux-gnueabihf mips-linux-gnueabihf
28677288470
28678288480
28679288490
2885040
286802885124
286812885216
28682288530
......@@ -28704,6 +28875,8 @@ mipsel-linux-gnueabihf mips-linux-gnueabihf
287042887516
28705288765
28706288770
2887840
2887940
28707288805
28708288815
28709288825
......@@ -28930,6 +29103,7 @@ mipsel-linux-gnueabihf mips-linux-gnueabihf
28930291030
28931291040
28932291050
2910640
28933291075
28934291080 5
28935291090 5
......@@ -29298,6 +29472,7 @@ mipsel-linux-gnueabihf mips-linux-gnueabihf
292982947237
2929929473
29300294745
2947540
293012947638
293022947738
293032947838
......@@ -29371,6 +29546,7 @@ mipsel-linux-gnueabihf mips-linux-gnueabihf
29371295460
29372295470
29373295480
2954940
29374295500
29375295510
29376295520
......@@ -30146,6 +30322,7 @@ mipsel-linux-gnueabi mips-linux-gnueabi
30146303225
30147303230
30148303240
30325
301493032627
3015030327
301513032827
......@@ -30287,6 +30464,18 @@ mipsel-linux-gnueabi mips-linux-gnueabi
3028730464
3028830465
3028930466
30467
30468
30469
30470
30471
30472
30473
30474
30475
30476
30477
30478
3029030479
3029130480
3029230481
......@@ -31560,6 +31749,7 @@ mipsel-linux-gnueabi mips-linux-gnueabi
31560317495
31561317505
31562317510
3175240
31563317530
31564317545
31565317550
......@@ -31680,6 +31870,7 @@ mipsel-linux-gnueabi mips-linux-gnueabi
31680318700 5
31681318710
31682318720
3187340
31683318740
31684318750
31685318760
......@@ -32353,6 +32544,7 @@ mipsel-linux-gnueabi mips-linux-gnueabi
32353325445
32354325450
32355325460 13
3254740
32356325480 13
32357325490 13
32358325500 13
......@@ -32381,6 +32573,7 @@ mipsel-linux-gnueabi mips-linux-gnueabi
32381325730
32382325740
32383325750
3257640
323843257724
323853257816
32386325790
......@@ -32408,6 +32601,8 @@ mipsel-linux-gnueabi mips-linux-gnueabi
324083260116
32409326025
32410326030
3260440
3260540
32411326065
32412326075
32413326085
......@@ -32634,6 +32829,7 @@ mipsel-linux-gnueabi mips-linux-gnueabi
32634328290
32635328300
32636328310
3283240
32637328335
32638328340 5
32639328350 5
......@@ -33002,6 +33198,7 @@ mipsel-linux-gnueabi mips-linux-gnueabi
330023319837
3300333199
33004332005
3320140
330053320238
330063320338
330073320438
......@@ -33075,6 +33272,7 @@ mipsel-linux-gnueabi mips-linux-gnueabi
33075332720
33076332730
33077332740
3327540
33078332760
33079332770
33080332780
......@@ -33850,6 +34048,7 @@ x86_64-linux-gnu
338503404810
338513404910
338523405010
34051
338533405227
338543405336
338553405427
......@@ -33991,6 +34190,18 @@ x86_64-linux-gnu
3399134190
3399234191
3399334192
34193
34194
34195
34196
34197
34198
34199
34200
34201
34202
34203
34204
3399434205
3399534206
3399634207
......@@ -35264,6 +35475,7 @@ x86_64-linux-gnu
352643547510
352653547610
352663547710
3547840
352673547910
352683548010
352693548110
......@@ -35384,6 +35596,7 @@ x86_64-linux-gnu
353843559610
353853559710
353863559810
3559940
353873560010
353883560110
353893560210
......@@ -36057,6 +36270,7 @@ x86_64-linux-gnu
360573627010
360583627110
360593627210 13
3627340
360603627410 13
360613627510 13
360623627610 13
......@@ -36085,6 +36299,7 @@ x86_64-linux-gnu
360853629910
360863630010
360873630110
3630240
360883630324
360893630416
360903630510
......@@ -36112,6 +36327,8 @@ x86_64-linux-gnu
361123632716
361133632810
361143632910
3633040
3633140
361153633210
361163633310
361173633410
......@@ -36338,6 +36555,7 @@ x86_64-linux-gnu
363383655510
363393655610
363403655710
3655840
363413655910
363423656010
363433656110
......@@ -36706,6 +36924,7 @@ x86_64-linux-gnu
367063692437
367073692537
367083692610
3692740
367093692838
367103692938
367113693038
......@@ -36779,6 +36998,7 @@ x86_64-linux-gnu
367793699810
367803699910
367813700010
3700140
367823700210
367833700310
367843700410
......@@ -37554,6 +37774,7 @@ x86_64-linux-gnux32
375543777428
375553777528
375563777628
37777
375573777828
375583777936
375593778028
......@@ -37695,6 +37916,18 @@ x86_64-linux-gnux32
3769537916
3769637917
3769737918
37919
37920
37921
37922
37923
37924
37925
37926
37927
37928
37929
37930
3769837931
3769937932
3770037933
......@@ -38968,6 +39201,7 @@ x86_64-linux-gnux32
389683920128
389693920228
389703920328
3920440
389713920528
389723920628
389733920728
......@@ -39088,6 +39322,7 @@ x86_64-linux-gnux32
390883932228
390893932328
390903932428
3932540
390913932628
390923932728
390933932828
......@@ -39761,6 +39996,7 @@ x86_64-linux-gnux32
397613999628
397623999728
397633999828
3999940
397644000028
397654000128
397664000228
......@@ -39789,6 +40025,7 @@ x86_64-linux-gnux32
397894002528
397904002628
397914002728
4002840
397924002928
397934003028
397944003128
......@@ -39816,6 +40053,8 @@ x86_64-linux-gnux32
398164005328
398174005428
398184005528
4005640
4005740
398194005828
398204005928
398214006028
......@@ -40042,6 +40281,7 @@ x86_64-linux-gnux32
400424028128
400434028228
400444028328
4028440
400454028528
400464028628
400474028728
......@@ -40410,6 +40650,7 @@ x86_64-linux-gnux32
404104065037
404114065137
404124065228
4065340
404134065438
404144065538
404154065638
......@@ -40483,6 +40724,7 @@ x86_64-linux-gnux32
404834072428
404844072528
404854072628
4072740
404864072828
404874072928
404884073028
......@@ -41258,6 +41500,7 @@ i386-linux-gnu
41258415001
41259415010
41260415020
415033
412614150427
412624150536
412634150627
......@@ -41399,6 +41642,18 @@ i386-linux-gnu
4139941642
4140041643
4140141644
41645
41646
41647
41648
41649
41650
41651
41652
41653
41654
41655
41656
4140241657
4140341658
4140441659
......@@ -42672,6 +42927,7 @@ i386-linux-gnu
42672429271
42673429281
42674429290
4293040
42675429310
42676429325
42677429330
......@@ -42792,6 +43048,7 @@ i386-linux-gnu
42792430480 3
42793430490
42794430500
4305140
42795430520
42796430530
42797430540
......@@ -43465,6 +43722,7 @@ i386-linux-gnu
43465437225
43466437230
43467437240 13
4372540
43468437260 13
43469437270 13
43470437280 13
......@@ -43493,6 +43751,7 @@ i386-linux-gnu
43493437510
43494437520
43495437530
4375440
434964375524
434974375616
43498437570
......@@ -43520,6 +43779,8 @@ i386-linux-gnu
435204377916
43521437801
43522437810
4378240
4378340
43523437841
43524437851
43525437861
......@@ -43746,6 +44007,7 @@ i386-linux-gnu
43746440070
43747440080
43748440090
4401040
43749440112
43750440120 1
43751440130 1
......@@ -44114,6 +44376,7 @@ i386-linux-gnu
441144437637
441154437737
44116443781
4437940
441174438038
441184438138
441194438238
......@@ -44187,6 +44450,7 @@ i386-linux-gnu
44187444500
44188444510
44189444520
4445340
44190444540
44191444550
44192444560
......@@ -44962,6 +45226,7 @@ powerpc64le-linux-gnu
449624522629
449634522729
449644522829
45229
449654523029
449664523136
449674523229
......@@ -45074,12 +45339,18 @@ powerpc64le-linux-gnu
450744533929
450754534029
450764534129
4534240
4534340
450774534429
450784534538
450794534638
450804534738
450814534829
450824534938
4535040
4535140
4535240
4535340
450834535429
450844535529
450854535629
......@@ -45100,6 +45371,8 @@ powerpc64le-linux-gnu
451004537129
451014537229
451024537329
4537440
4537540
451034537629
451044537729
451054537829
......@@ -45112,8 +45385,12 @@ powerpc64le-linux-gnu
451124538529
451134538629
451144538729
4538840
4538940
451154539029
451164539129
4539240
4539340
451174539429
451184539529
451194539629
......@@ -46376,6 +46653,7 @@ powerpc64le-linux-gnu
463764665329
463774665429
463784665529
4665640
463794665729
463804665829
463814665929
......@@ -46496,6 +46774,7 @@ powerpc64le-linux-gnu
464964677429
464974677529
464984677629
4677740
464994677829
465004677929
465014678029
......@@ -47169,6 +47448,7 @@ powerpc64le-linux-gnu
471694744829
471704744929
471714745029
4745140
471724745229
471734745329
471744745429
......@@ -47197,6 +47477,7 @@ powerpc64le-linux-gnu
471974747729
471984747829
471994747929
4748040
472004748129
472014748229
472024748329
......@@ -47224,6 +47505,8 @@ powerpc64le-linux-gnu
472244750529
472254750629
472264750729
4750840
4750940
472274751029
472284751129
472294751229
......@@ -47450,6 +47733,7 @@ powerpc64le-linux-gnu
474504773329
474514773429
474524773529
4773640
474534773729
474544773829
474554773929
......@@ -47818,6 +48102,7 @@ powerpc64le-linux-gnu
478184810237
478194810337
478204810429
4810540
478214810638
478224810738
478234810838
......@@ -47891,6 +48176,7 @@ powerpc64le-linux-gnu
478914817629
478924817729
478934817829
4817940
478944818029
478954818129
478964818229
......@@ -48666,6 +48952,7 @@ powerpc64-linux-gnu
486664895212
486674895312
486684895412
48955
486694895627
4867048957
486714895827
......@@ -48778,12 +49065,18 @@ powerpc64-linux-gnu
487784906516
487794906616
487804906716
4906840
4906940
487814907016
487824907138
487834907238
487844907338
487854907416
487864907538
4907640
4907740
4907840
4907940
487874908016
487884908116
487894908216
......@@ -48804,6 +49097,8 @@ powerpc64-linux-gnu
488044909716
488054909816
488064909916
4910040
4910140
488074910216
488084910316
488094910416
......@@ -48816,8 +49111,12 @@ powerpc64-linux-gnu
488164911116
488174911216
488184911316
4911440
4911540
488194911616
488204911716
4911840
4911940
488214912016
488224912116
488234912212
......@@ -50080,6 +50379,7 @@ powerpc64-linux-gnu
500805037912
500815038012
500825038112
5038240
500835038312
500845038412
500855038512
......@@ -50200,6 +50500,7 @@ powerpc64-linux-gnu
502005050012
502015050112
502025050212
5050340
502035050412
502045050512
502055050612
......@@ -50873,6 +51174,7 @@ powerpc64-linux-gnu
508735117412
508745117512
508755117612 13
5117740
508765117812 13
508775117912 13
508785118012 13
......@@ -50901,6 +51203,7 @@ powerpc64-linux-gnu
509015120312
509025120412
509035120512
5120640
509045120724
509055120816
509065120912
......@@ -50928,6 +51231,8 @@ powerpc64-linux-gnu
509285123116
509295123212
509305123312
5123440
5123540
509315123612
509325123712
509335123812
......@@ -51154,6 +51459,7 @@ powerpc64-linux-gnu
511545145912
511555146012
511565146112
5146240
511575146312
511585146412
511595146512
......@@ -51522,6 +51828,7 @@ powerpc64-linux-gnu
515225182837
5152351829
515245183012 16
5183140
515255183238
515265183338
515275183438
......@@ -51595,6 +51902,7 @@ powerpc64-linux-gnu
515955190212
515965190312
515975190412
5190540
515985190612
515995190712
516005190812
......@@ -52370,6 +52678,7 @@ powerpc-linux-gnueabi powerpc-linux-gnueabihf
52370526781
52371526790
52372526800
526813
523735268227
5237452683
523755268427
......@@ -52482,12 +52791,18 @@ powerpc-linux-gnueabi powerpc-linux-gnueabihf
524825279116
524835279216
524845279316
5279440
5279540
524855279616
524865279738
524875279838
524885279938
524895280016
524905280138
5280240
5280340
5280440
5280540
524915280616
524925280716
524935280816
......@@ -52508,6 +52823,8 @@ powerpc-linux-gnueabi powerpc-linux-gnueabihf
525085282316
525095282416
525105282516
5282640
5282740
525115282816
525125282916
525135283016
......@@ -52520,8 +52837,12 @@ powerpc-linux-gnueabi powerpc-linux-gnueabihf
525205283716
525215283816
525225283916
5284040
5284140
525235284216
525245284316
5284440
5284540
525255284616
525265284716
52527528480
......@@ -53784,6 +54105,7 @@ powerpc-linux-gnueabi powerpc-linux-gnueabihf
53784541051
53785541061
53786541070
5410840
53787541090
53788541105
53789541110
......@@ -53904,6 +54226,7 @@ powerpc-linux-gnueabi powerpc-linux-gnueabihf
53904542260 3
53905542270
53906542280
5422940
53907542300
53908542310
53909542320
......@@ -54577,6 +54900,7 @@ powerpc-linux-gnueabi powerpc-linux-gnueabihf
54577549005
54578549010
54579549020 13
5490340
54580549040 13
54581549050 13
54582549060 13
......@@ -54605,6 +54929,7 @@ powerpc-linux-gnueabi powerpc-linux-gnueabihf
54605549290
54606549300
54607549310
5493240
546085493324
546095493416
54610549350
......@@ -54632,6 +54957,8 @@ powerpc-linux-gnueabi powerpc-linux-gnueabihf
546325495716
54633549581
54634549590
5496040
5496140
54635549621
54636549631
54637549641
......@@ -54858,6 +55185,7 @@ powerpc-linux-gnueabi powerpc-linux-gnueabihf
54858551850
54859551860
54860551870
5518840
54861551892
54862551900 1
54863551910 1
......@@ -55226,6 +55554,7 @@ powerpc-linux-gnueabi powerpc-linux-gnueabihf
552265555437
5522755555
55228555561 16
5555740
552295555838
552305555938
552315556038
......@@ -55299,6 +55628,7 @@ powerpc-linux-gnueabi powerpc-linux-gnueabihf
55299556280
55300556290
55301556300
5563140
55302556320
55303556330
55304556340
lib/libc/glibc/fns.txt+22
......@@ -513,6 +513,7 @@ __libc_realloc c
513513__libc_sa_len c
514514__libc_start_main c
515515__libc_valloc c
516__libpthread_version_placeholder pthread
516517__log10_finite m
517518__log10f128_finite m
518519__log10f_finite m
......@@ -625,12 +626,18 @@ __nldbl___vswprintf_chk c
625626__nldbl___vsyslog_chk c
626627__nldbl___vwprintf_chk c
627628__nldbl___wprintf_chk c
629__nldbl_argp_error c
630__nldbl_argp_failure c
628631__nldbl_asprintf c
629632__nldbl_daddl m
630633__nldbl_ddivl m
631634__nldbl_dmull m
632635__nldbl_dprintf c
633636__nldbl_dsubl m
637__nldbl_err c
638__nldbl_error c
639__nldbl_error_at_line c
640__nldbl_errx c
634641__nldbl_fprintf c
635642__nldbl_fscanf c
636643__nldbl_fwprintf c
......@@ -651,6 +658,8 @@ __nldbl_swscanf c
651658__nldbl_syslog c
652659__nldbl_vasprintf c
653660__nldbl_vdprintf c
661__nldbl_verr c
662__nldbl_verrx c
654663__nldbl_vfprintf c
655664__nldbl_vfscanf c
656665__nldbl_vfwprintf c
......@@ -663,8 +672,12 @@ __nldbl_vsscanf c
663672__nldbl_vswprintf c
664673__nldbl_vswscanf c
665674__nldbl_vsyslog c
675__nldbl_vwarn c
676__nldbl_vwarnx c
666677__nldbl_vwprintf c
667678__nldbl_vwscanf c
679__nldbl_warn c
680__nldbl_warnx c
668681__nldbl_wprintf c
669682__nldbl_wscanf c
670683__nss_configure_lookup c
......@@ -1927,6 +1940,7 @@ getdate c
19271940getdate_err c
19281941getdate_r c
19291942getdelim c
1943getdents64 c
19301944getdirentries c
19311945getdirentries64 c
19321946getdomainname c
......@@ -2047,6 +2061,7 @@ getspnam c
20472061getspnam_r c
20482062getsubopt c
20492063gettext c
2064gettid c
20502065gettimeofday c
20512066getttyent c
20522067getttynam c
......@@ -2720,6 +2735,7 @@ pthread_barrierattr_init pthread
27202735pthread_barrierattr_setpshared pthread
27212736pthread_cancel pthread
27222737pthread_cond_broadcast c
2738pthread_cond_clockwait pthread
27232739pthread_cond_destroy c
27242740pthread_cond_init c
27252741pthread_cond_signal c
......@@ -2748,6 +2764,7 @@ pthread_key_create pthread
27482764pthread_key_delete pthread
27492765pthread_kill pthread
27502766pthread_kill_other_threads_np pthread
2767pthread_mutex_clocklock pthread
27512768pthread_mutex_consistent pthread
27522769pthread_mutex_consistent_np pthread
27532770pthread_mutex_destroy c
......@@ -2775,6 +2792,8 @@ pthread_mutexattr_setrobust pthread
27752792pthread_mutexattr_setrobust_np pthread
27762793pthread_mutexattr_settype pthread
27772794pthread_once pthread
2795pthread_rwlock_clockrdlock pthread
2796pthread_rwlock_clockwrlock pthread
27782797pthread_rwlock_destroy pthread
27792798pthread_rwlock_init pthread
27802799pthread_rwlock_rdlock pthread
......@@ -3001,6 +3020,7 @@ seed48 c
30013020seed48_r c
30023021seekdir c
30033022select c
3023sem_clockwait pthread
30043024sem_close pthread
30053025sem_destroy pthread
30063026sem_getvalue pthread
......@@ -3369,6 +3389,7 @@ tgammaf32x m
33693389tgammaf64 m
33703390tgammaf64x m
33713391tgammal m
3392tgkill c
33723393thrd_create pthread
33733394thrd_current c
33743395thrd_detach pthread
......@@ -3442,6 +3463,7 @@ ttyname c
34423463ttyname_r c
34433464ttyslot c
34443465twalk c
3466twalk_r c
34453467tzname c
34463468tzset c
34473469ualarm c
lib/libc/glibc/vers.txt+1
......@@ -38,3 +38,4 @@ GLIBC_2.26
3838GLIBC_2.27
3939GLIBC_2.28
4040GLIBC_2.29
41GLIBC_2.30
lib/libc/include/aarch64-linux-gnu/bits/hwcap.h+4-1
......@@ -50,4 +50,7 @@
5050#define HWCAP_USCAT (1 << 25)
5151#define HWCAP_ILRCPC (1 << 26)
5252#define HWCAP_FLAGM (1 << 27)
53#define HWCAP_SSBS (1 << 28)
\ No newline at end of file
53#define HWCAP_SSBS (1 << 28)
54#define HWCAP_SB (1 << 29)
55#define HWCAP_PACA (1 << 30)
56#define HWCAP_PACG (1UL << 31)
\ No newline at end of file
lib/libc/include/aarch64-linux-gnu/gnu/stubs-lp64.h-6
......@@ -13,15 +13,9 @@
1313#define __stub___compat_query_module
1414#define __stub___compat_uselib
1515#define __stub_chflags
16#define __stub_fattach
1716#define __stub_fchflags
18#define __stub_fdetach
19#define __stub_getmsg
20#define __stub_getpmsg
2117#define __stub_gtty
2218#define __stub_lchmod
23#define __stub_putmsg
24#define __stub_putpmsg
2519#define __stub_revoke
2620#define __stub_setlogin
2721#define __stub_sigreturn
lib/libc/include/aarch64_be-linux-gnu/bits/hwcap.h+4-1
......@@ -50,4 +50,7 @@
5050#define HWCAP_USCAT (1 << 25)
5151#define HWCAP_ILRCPC (1 << 26)
5252#define HWCAP_FLAGM (1 << 27)
53#define HWCAP_SSBS (1 << 28)
\ No newline at end of file
53#define HWCAP_SSBS (1 << 28)
54#define HWCAP_SB (1 << 29)
55#define HWCAP_PACA (1 << 30)
56#define HWCAP_PACG (1UL << 31)
\ No newline at end of file
lib/libc/include/aarch64_be-linux-gnu/gnu/stubs-lp64_be.h-6
......@@ -13,15 +13,9 @@
1313#define __stub___compat_query_module
1414#define __stub___compat_uselib
1515#define __stub_chflags
16#define __stub_fattach
1716#define __stub_fchflags
18#define __stub_fdetach
19#define __stub_getmsg
20#define __stub_getpmsg
2117#define __stub_gtty
2218#define __stub_lchmod
23#define __stub_putmsg
24#define __stub_putpmsg
2519#define __stub_revoke
2620#define __stub_setlogin
2721#define __stub_sigreturn
lib/libc/include/generic-glibc/bits/dirent_ext.h created+33
......@@ -0,0 +1,33 @@
1/* System-specific extensions of <dirent.h>. Linux version.
2 Copyright (C) 2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#ifndef _DIRENT_H
20# error "Never include <bits/dirent_ext.h> directly; use <dirent.h> instead."
21#endif
22
23__BEGIN_DECLS
24
25#ifdef __USE_GNU
26/* Read from the directory descriptor FD into LENGTH bytes at BUFFER.
27 Return the number of bytes read on success (0 for end of
28 directory), and -1 for failure. */
29extern __ssize_t getdents64 (int __fd, void *__buffer, size_t __length)
30 __THROW __nonnull ((2));
31#endif
32
33__END_DECLS
\ No newline at end of file
lib/libc/include/generic-glibc/bits/fcntl-linux.h+2
......@@ -284,6 +284,8 @@ struct f_owner_ex
284284# define F_SEAL_SHRINK 0x0002 /* Prevent file from shrinking. */
285285# define F_SEAL_GROW 0x0004 /* Prevent file from growing. */
286286# define F_SEAL_WRITE 0x0008 /* Prevent writes. */
287# define F_SEAL_FUTURE_WRITE 0x0010 /* Prevent future writes while
288 mapped. */
287289#endif
288290
289291#ifdef __USE_GNU
lib/libc/include/generic-glibc/bits/in.h+1
......@@ -192,6 +192,7 @@ struct in_pktinfo
192192#define IPV6_JOIN_ANYCAST 27
193193#define IPV6_LEAVE_ANYCAST 28
194194#define IPV6_MULTICAST_ALL 29
195#define IPV6_ROUTER_ALERT_ISOLATE 30
195196#define IPV6_IPSEC_POLICY 34
196197#define IPV6_XFRM_POLICY 35
197198#define IPV6_HDRINCL 36
lib/libc/include/generic-glibc/bits/math-vector-fortran.h deleted-19
......@@ -1,19 +0,0 @@
1! Platform-specific declarations of SIMD math functions for Fortran. -*- f90 -*-
2! Copyright (C) 2019 Free Software Foundation, Inc.
3! This file is part of the GNU C Library.
4!
5! The GNU C Library is free software; you can redistribute it and/or
6! modify it under the terms of the GNU Lesser General Public
7! License as published by the Free Software Foundation; either
8! version 2.1 of the License, or (at your option) any later version.
9!
10! The GNU C Library is distributed in the hope that it will be useful,
11! but WITHOUT ANY WARRANTY; without even the implied warranty of
12! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13! Lesser General Public License for more details.
14!
15! You should have received a copy of the GNU Lesser General Public
16! License along with the GNU C Library; if not, see
17! <http://www.gnu.org/licenses/>.
18
19! No SIMD math functions are available for this platform.
\ No newline at end of file
lib/libc/include/generic-glibc/bits/signal_ext.h created+31
......@@ -0,0 +1,31 @@
1/* System-specific extensions of <signal.h>, Linux version.
2 Copyright (C) 2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#ifndef _SIGNAL_H
20# error "Never include <bits/signal_ext.h> directly; use <signal.h> instead."
21#endif
22
23#ifdef __USE_GNU
24
25/* Send SIGNAL to the thread TID in the thread group (process)
26 identified by TGID. This function behaves like kill, but also
27 fails with ESRCH if the specified TID does not belong to the
28 specified thread group. */
29extern int tgkill (__pid_t __tgid, __pid_t __tid, int __signal);
30
31#endif /* __USE_GNU */
\ No newline at end of file
lib/libc/include/generic-glibc/bits/socket-constants.h created+38
......@@ -0,0 +1,38 @@
1/* Socket constants which vary among Linux architectures.
2 Copyright (C) 2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#ifndef _SYS_SOCKET_H
20# error "Never include <bits/socket-constants.h> directly; use <sys/socket.h> instead."
21#endif
22
23#define SOL_SOCKET 1
24#define SO_ACCEPTCONN 30
25#define SO_BROADCAST 6
26#define SO_DONTROUTE 5
27#define SO_ERROR 4
28#define SO_KEEPALIVE 9
29#define SO_LINGER 13
30#define SO_OOBINLINE 10
31#define SO_RCVBUF 8
32#define SO_RCVLOWAT 18
33#define SO_RCVTIMEO 20
34#define SO_REUSEADDR 2
35#define SO_SNDBUF 7
36#define SO_SNDLOWAT 19
37#define SO_SNDTIMEO 21
38#define SO_TYPE 3
\ No newline at end of file
lib/libc/include/generic-glibc/bits/socket.h+6-92
......@@ -349,98 +349,12 @@ struct ucred
349349};
350350#endif
351351
352/* Ugly workaround for unclean kernel headers. */
353#ifndef __USE_MISC
354# ifndef FIOGETOWN
355# define __SYS_SOCKET_H_undef_FIOGETOWN
356# endif
357# ifndef FIOSETOWN
358# define __SYS_SOCKET_H_undef_FIOSETOWN
359# endif
360# ifndef SIOCATMARK
361# define __SYS_SOCKET_H_undef_SIOCATMARK
362# endif
363# ifndef SIOCGPGRP
364# define __SYS_SOCKET_H_undef_SIOCGPGRP
365# endif
366# ifndef SIOCGSTAMP
367# define __SYS_SOCKET_H_undef_SIOCGSTAMP
368# endif
369# ifndef SIOCGSTAMPNS
370# define __SYS_SOCKET_H_undef_SIOCGSTAMPNS
371# endif
372# ifndef SIOCSPGRP
373# define __SYS_SOCKET_H_undef_SIOCSPGRP
374# endif
375#endif
376#ifndef IOCSIZE_MASK
377# define __SYS_SOCKET_H_undef_IOCSIZE_MASK
378#endif
379#ifndef IOCSIZE_SHIFT
380# define __SYS_SOCKET_H_undef_IOCSIZE_SHIFT
381#endif
382#ifndef IOC_IN
383# define __SYS_SOCKET_H_undef_IOC_IN
384#endif
385#ifndef IOC_INOUT
386# define __SYS_SOCKET_H_undef_IOC_INOUT
387#endif
388#ifndef IOC_OUT
389# define __SYS_SOCKET_H_undef_IOC_OUT
390#endif
391
392/* Get socket manipulation related informations from kernel headers. */
393#include <asm/socket.h>
394
395#ifndef __USE_MISC
396# ifdef __SYS_SOCKET_H_undef_FIOGETOWN
397# undef __SYS_SOCKET_H_undef_FIOGETOWN
398# undef FIOGETOWN
399# endif
400# ifdef __SYS_SOCKET_H_undef_FIOSETOWN
401# undef __SYS_SOCKET_H_undef_FIOSETOWN
402# undef FIOSETOWN
403# endif
404# ifdef __SYS_SOCKET_H_undef_SIOCATMARK
405# undef __SYS_SOCKET_H_undef_SIOCATMARK
406# undef SIOCATMARK
407# endif
408# ifdef __SYS_SOCKET_H_undef_SIOCGPGRP
409# undef __SYS_SOCKET_H_undef_SIOCGPGRP
410# undef SIOCGPGRP
411# endif
412# ifdef __SYS_SOCKET_H_undef_SIOCGSTAMP
413# undef __SYS_SOCKET_H_undef_SIOCGSTAMP
414# undef SIOCGSTAMP
415# endif
416# ifdef __SYS_SOCKET_H_undef_SIOCGSTAMPNS
417# undef __SYS_SOCKET_H_undef_SIOCGSTAMPNS
418# undef SIOCGSTAMPNS
419# endif
420# ifdef __SYS_SOCKET_H_undef_SIOCSPGRP
421# undef __SYS_SOCKET_H_undef_SIOCSPGRP
422# undef SIOCSPGRP
423# endif
424#endif
425#ifdef __SYS_SOCKET_H_undef_IOCSIZE_MASK
426# undef __SYS_SOCKET_H_undef_IOCSIZE_MASK
427# undef IOCSIZE_MASK
428#endif
429#ifdef __SYS_SOCKET_H_undef_IOCSIZE_SHIFT
430# undef __SYS_SOCKET_H_undef_IOCSIZE_SHIFT
431# undef IOCSIZE_SHIFT
432#endif
433#ifdef __SYS_SOCKET_H_undef_IOC_IN
434# undef __SYS_SOCKET_H_undef_IOC_IN
435# undef IOC_IN
436#endif
437#ifdef __SYS_SOCKET_H_undef_IOC_INOUT
438# undef __SYS_SOCKET_H_undef_IOC_INOUT
439# undef IOC_INOUT
440#endif
441#ifdef __SYS_SOCKET_H_undef_IOC_OUT
442# undef __SYS_SOCKET_H_undef_IOC_OUT
443# undef IOC_OUT
352#ifdef __USE_MISC
353# include <bits/types/time_t.h>
354# include <asm/socket.h>
355#else
356# define SO_DEBUG 1
357# include <bits/socket-constants.h>
444358#endif
445359
446360/* Structure used to manipulate the SO_LINGER option. */
lib/libc/include/generic-glibc/bits/statx-generic.h created+60
......@@ -0,0 +1,60 @@
1/* Generic statx-related definitions and declarations.
2 Copyright (C) 2018-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19/* This interface is based on <linux/stat.h> in Linux. */
20
21#ifndef _SYS_STAT_H
22# error Never include <bits/statx-generic.h> directly, include <sys/stat.h> instead.
23#endif
24
25#include <bits/types/struct_statx_timestamp.h>
26#include <bits/types/struct_statx.h>
27
28#ifndef STATX_TYPE
29# define STATX_TYPE 0x0001U
30# define STATX_MODE 0x0002U
31# define STATX_NLINK 0x0004U
32# define STATX_UID 0x0008U
33# define STATX_GID 0x0010U
34# define STATX_ATIME 0x0020U
35# define STATX_MTIME 0x0040U
36# define STATX_CTIME 0x0080U
37# define STATX_INO 0x0100U
38# define STATX_SIZE 0x0200U
39# define STATX_BLOCKS 0x0400U
40# define STATX_BASIC_STATS 0x07ffU
41# define STATX_ALL 0x0fffU
42# define STATX_BTIME 0x0800U
43# define STATX__RESERVED 0x80000000U
44
45# define STATX_ATTR_COMPRESSED 0x0004
46# define STATX_ATTR_IMMUTABLE 0x0010
47# define STATX_ATTR_APPEND 0x0020
48# define STATX_ATTR_NODUMP 0x0040
49# define STATX_ATTR_ENCRYPTED 0x0800
50# define STATX_ATTR_AUTOMOUNT 0x1000
51#endif /* !STATX_TYPE */
52
53__BEGIN_DECLS
54
55/* Fill *BUF with information about PATH in DIRFD. */
56int statx (int __dirfd, const char *__restrict __path, int __flags,
57 unsigned int __mask, struct statx *__restrict __buf)
58 __THROW __nonnull ((2, 5));
59
60__END_DECLS
\ No newline at end of file
lib/libc/include/generic-glibc/bits/statx.h+13-67
......@@ -1,4 +1,4 @@
1/* statx-related definitions and declarations.
1/* statx-related definitions and declarations. Linux version.
22 Copyright (C) 2018-2019 Free Software Foundation, Inc.
33 This file is part of the GNU C Library.
44
......@@ -19,73 +19,19 @@
1919/* This interface is based on <linux/stat.h> in Linux. */
2020
2121#ifndef _SYS_STAT_H
22# error Never include <bits/stat.x.h> directly, include <sys/stat.h> instead.
22# error Never include <bits/statx.h> directly, include <sys/stat.h> instead.
2323#endif
2424
25struct statx_timestamp
26{
27 __int64_t tv_sec;
28 __uint32_t tv_nsec;
29 __int32_t __statx_timestamp_pad1[1];
30};
25/* Use the Linux kernel header if available. */
3126
32/* Warning: The kernel may add additional fields to this struct in the
33 future. Only use this struct for calling the statx function, not
34 for storing data. (Expansion will be controlled by the mask
35 argument of the statx function.) */
36struct statx
37{
38 __uint32_t stx_mask;
39 __uint32_t stx_blksize;
40 __uint64_t stx_attributes;
41 __uint32_t stx_nlink;
42 __uint32_t stx_uid;
43 __uint32_t stx_gid;
44 __uint16_t stx_mode;
45 __uint16_t __statx_pad1[1];
46 __uint64_t stx_ino;
47 __uint64_t stx_size;
48 __uint64_t stx_blocks;
49 __uint64_t stx_attributes_mask;
50 struct statx_timestamp stx_atime;
51 struct statx_timestamp stx_btime;
52 struct statx_timestamp stx_ctime;
53 struct statx_timestamp stx_mtime;
54 __uint32_t stx_rdev_major;
55 __uint32_t stx_rdev_minor;
56 __uint32_t stx_dev_major;
57 __uint32_t stx_dev_minor;
58 __uint64_t __statx_pad2[14];
59};
60
61#define STATX_TYPE 0x0001U
62#define STATX_MODE 0x0002U
63#define STATX_NLINK 0x0004U
64#define STATX_UID 0x0008U
65#define STATX_GID 0x0010U
66#define STATX_ATIME 0x0020U
67#define STATX_MTIME 0x0040U
68#define STATX_CTIME 0x0080U
69#define STATX_INO 0x0100U
70#define STATX_SIZE 0x0200U
71#define STATX_BLOCKS 0x0400U
72#define STATX_BASIC_STATS 0x07ffU
73#define STATX_ALL 0x0fffU
74#define STATX_BTIME 0x0800U
75#define STATX__RESERVED 0x80000000U
76
77#define STATX_ATTR_COMPRESSED 0x0004
78#define STATX_ATTR_IMMUTABLE 0x0010
79#define STATX_ATTR_APPEND 0x0020
80#define STATX_ATTR_NODUMP 0x0040
81#define STATX_ATTR_ENCRYPTED 0x0800
82#define STATX_ATTR_AUTOMOUNT 0x1000
83
84__BEGIN_DECLS
85
86/* Fill *BUF with information about PATH in DIRFD. */
87int statx (int __dirfd, const char *__restrict __path, int __flags,
88 unsigned int __mask, struct statx *__restrict __buf)
89 __THROW __nonnull ((2, 5));
27/* Use "" to work around incorrect macro expansion of the
28 __has_include argument (GCC PR 80005). */
29#if __glibc_has_include ("linux/stat.h")
30# include "linux/stat.h"
31# ifdef STATX_TYPE
32# define __statx_timestamp_defined 1
33# define __statx_defined 1
34# endif
35#endif
9036
91__END_DECLS
\ No newline at end of file
37#include <bits/statx-generic.h>
\ No newline at end of file
lib/libc/include/generic-glibc/bits/stropts.h deleted-230
......@@ -1,230 +0,0 @@
1/* Copyright (C) 1998-2019 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
17
18#ifndef _STROPTS_H
19# error "Never include <bits/stropts.h> directly; use <stropts.h> instead."
20#endif
21
22#ifndef _BITS_STROPTS_H
23#define _BITS_STROPTS_H 1
24
25#include <bits/types.h>
26
27/* Macros used as `request' argument to `ioctl'. */
28#define __SID ('S' << 8)
29
30#define I_NREAD (__SID | 1) /* Counts the number of data bytes in the data
31 block in the first message. */
32#define I_PUSH (__SID | 2) /* Push STREAMS module onto top of the current
33 STREAM, just below the STREAM head. */
34#define I_POP (__SID | 3) /* Remove STREAMS module from just below the
35 STREAM head. */
36#define I_LOOK (__SID | 4) /* Retrieve the name of the module just below
37 the STREAM head and place it in a character
38 string. */
39#define I_FLUSH (__SID | 5) /* Flush all input and/or output. */
40#define I_SRDOPT (__SID | 6) /* Sets the read mode. */
41#define I_GRDOPT (__SID | 7) /* Returns the current read mode setting. */
42#define I_STR (__SID | 8) /* Construct an internal STREAMS `ioctl'
43 message and send that message downstream. */
44#define I_SETSIG (__SID | 9) /* Inform the STREAM head that the process
45 wants the SIGPOLL signal issued. */
46#define I_GETSIG (__SID |10) /* Return the events for which the calling
47 process is currently registered to be sent
48 a SIGPOLL signal. */
49#define I_FIND (__SID |11) /* Compares the names of all modules currently
50 present in the STREAM to the name pointed to
51 by `arg'. */
52#define I_LINK (__SID |12) /* Connect two STREAMs. */
53#define I_UNLINK (__SID |13) /* Disconnects the two STREAMs. */
54#define I_PEEK (__SID |15) /* Allows a process to retrieve the information
55 in the first message on the STREAM head read
56 queue without taking the message off the
57 queue. */
58#define I_FDINSERT (__SID |16) /* Create a message from the specified
59 buffer(s), adds information about another
60 STREAM, and send the message downstream. */
61#define I_SENDFD (__SID |17) /* Requests the STREAM associated with `fildes'
62 to send a message, containing a file
63 pointer, to the STREAM head at the other end
64 of a STREAMS pipe. */
65#define I_RECVFD (__SID |14) /* Non-EFT definition. */
66#define I_SWROPT (__SID |19) /* Set the write mode. */
67#define I_GWROPT (__SID |20) /* Return the current write mode setting. */
68#define I_LIST (__SID |21) /* List all the module names on the STREAM, up
69 to and including the topmost driver name. */
70#define I_PLINK (__SID |22) /* Connect two STREAMs with a persistent
71 link. */
72#define I_PUNLINK (__SID |23) /* Disconnect the two STREAMs that were
73 connected with a persistent link. */
74#define I_FLUSHBAND (__SID |28) /* Flush only band specified. */
75#define I_CKBAND (__SID |29) /* Check if the message of a given priority
76 band exists on the STREAM head read
77 queue. */
78#define I_GETBAND (__SID |30) /* Return the priority band of the first
79 message on the STREAM head read queue. */
80#define I_ATMARK (__SID |31) /* See if the current message on the STREAM
81 head read queue is "marked" by some module
82 downstream. */
83#define I_SETCLTIME (__SID |32) /* Set the time the STREAM head will delay when
84 a STREAM is closing and there is data on
85 the write queues. */
86#define I_GETCLTIME (__SID |33) /* Get current value for closing timeout. */
87#define I_CANPUT (__SID |34) /* Check if a certain band is writable. */
88
89
90/* Used in `I_LOOK' request. */
91#define FMNAMESZ 8 /* compatibility w/UnixWare/Solaris. */
92
93/* Flush options. */
94#define FLUSHR 0x01 /* Flush read queues. */
95#define FLUSHW 0x02 /* Flush write queues. */
96#define FLUSHRW 0x03 /* Flush read and write queues. */
97#ifdef __USE_GNU
98# define FLUSHBAND 0x04 /* Flush only specified band. */
99#endif
100
101/* Possible arguments for `I_SETSIG'. */
102#define S_INPUT 0x0001 /* A message, other than a high-priority
103 message, has arrived. */
104#define S_HIPRI 0x0002 /* A high-priority message is present. */
105#define S_OUTPUT 0x0004 /* The write queue for normal data is no longer
106 full. */
107#define S_MSG 0x0008 /* A STREAMS signal message that contains the
108 SIGPOLL signal reaches the front of the
109 STREAM head read queue. */
110#define S_ERROR 0x0010 /* Notification of an error condition. */
111#define S_HANGUP 0x0020 /* Notification of a hangup. */
112#define S_RDNORM 0x0040 /* A normal message has arrived. */
113#define S_WRNORM S_OUTPUT
114#define S_RDBAND 0x0080 /* A message with a non-zero priority has
115 arrived. */
116#define S_WRBAND 0x0100 /* The write queue for a non-zero priority
117 band is no longer full. */
118#define S_BANDURG 0x0200 /* When used in conjunction with S_RDBAND,
119 SIGURG is generated instead of SIGPOLL when
120 a priority message reaches the front of the
121 STREAM head read queue. */
122
123/* Option for `I_PEEK'. */
124#define RS_HIPRI 0x01 /* Only look for high-priority messages. */
125
126/* Options for `I_SRDOPT'. */
127#define RNORM 0x0000 /* Byte-STREAM mode, the default. */
128#define RMSGD 0x0001 /* Message-discard mode. */
129#define RMSGN 0x0002 /* Message-nondiscard mode. */
130#define RPROTDAT 0x0004 /* Deliver the control part of a message as
131 data. */
132#define RPROTDIS 0x0008 /* Discard the control part of a message,
133 delivering any data part. */
134#define RPROTNORM 0x0010 /* Fail `read' with EBADMSG if a message
135 containing a control part is at the front
136 of the STREAM head read queue. */
137#ifdef __USE_GNU
138# define RPROTMASK 0x001C /* The RPROT bits */
139#endif
140
141/* Possible mode for `I_SWROPT'. */
142#define SNDZERO 0x001 /* Send a zero-length message downstream when a
143 `write' of 0 bytes occurs. */
144#ifdef __USE_GNU
145# define SNDPIPE 0x002 /* Send SIGPIPE on write and putmsg if
146 sd_werror is set. */
147#endif
148
149/* Arguments for `I_ATMARK'. */
150#define ANYMARK 0x01 /* Check if the message is marked. */
151#define LASTMARK 0x02 /* Check if the message is the last one marked
152 on the queue. */
153
154/* Argument for `I_UNLINK'. */
155#ifdef __USE_GNU
156# define MUXID_ALL (-1) /* Unlink all STREAMs linked to the STREAM
157 associated with `fildes'. */
158#endif
159
160
161/* Macros for `getmsg', `getpmsg', `putmsg' and `putpmsg'. */
162#define MSG_HIPRI 0x01 /* Send/receive high priority message. */
163#define MSG_ANY 0x02 /* Receive any message. */
164#define MSG_BAND 0x04 /* Receive message from specified band. */
165
166/* Values returned by getmsg and getpmsg */
167#define MORECTL 1 /* More control information is left in
168 message. */
169#define MOREDATA 2 /* More data is left in message. */
170
171
172/* Structure used for the I_FLUSHBAND ioctl on streams. */
173struct bandinfo
174 {
175 unsigned char bi_pri;
176 int bi_flag;
177 };
178
179struct strbuf
180 {
181 int maxlen; /* Maximum buffer length. */
182 int len; /* Length of data. */
183 char *buf; /* Pointer to buffer. */
184 };
185
186struct strpeek
187 {
188 struct strbuf ctlbuf;
189 struct strbuf databuf;
190 t_uscalar_t flags; /* UnixWare/Solaris compatibility. */
191 };
192
193struct strfdinsert
194 {
195 struct strbuf ctlbuf;
196 struct strbuf databuf;
197 t_uscalar_t flags; /* UnixWare/Solaris compatibility. */
198 int fildes;
199 int offset;
200 };
201
202struct strioctl
203 {
204 int ic_cmd;
205 int ic_timout;
206 int ic_len;
207 char *ic_dp;
208 };
209
210struct strrecvfd
211 {
212 int fd;
213 uid_t uid;
214 gid_t gid;
215 char __fill[8]; /* UnixWare/Solaris compatibility */
216 };
217
218
219struct str_mlist
220 {
221 char l_name[FMNAMESZ + 1];
222 };
223
224struct str_list
225 {
226 int sl_nmods;
227 struct str_mlist *sl_modlist;
228 };
229
230#endif /* bits/stropts.h */
\ No newline at end of file
lib/libc/include/generic-glibc/bits/syscall.h+154-2
......@@ -1,11 +1,11 @@
11/* Generated at libc build time from syscall list. */
2/* The system call list corresponds to kernel 4.20. */
2/* The system call list corresponds to kernel 5.2. */
33
44#ifndef _SYSCALL_H
55# error "Never use <bits/syscall.h> directly; include <sys/syscall.h> instead."
66#endif
77
8#define __GLIBC_LINUX_VERSION_CODE 267264
8#define __GLIBC_LINUX_VERSION_CODE 328192
99
1010#ifdef __NR_FAST_atomic_update
1111# define SYS_FAST_atomic_update __NR_FAST_atomic_update
......@@ -115,6 +115,10 @@
115115# define SYS_break __NR_break
116116#endif
117117
118#ifdef __NR_breakpoint
119# define SYS_breakpoint __NR_breakpoint
120#endif
121
118122#ifdef __NR_brk
119123# define SYS_brk __NR_brk
120124#endif
......@@ -159,22 +163,42 @@
159163# define SYS_clock_adjtime __NR_clock_adjtime
160164#endif
161165
166#ifdef __NR_clock_adjtime64
167# define SYS_clock_adjtime64 __NR_clock_adjtime64
168#endif
169
162170#ifdef __NR_clock_getres
163171# define SYS_clock_getres __NR_clock_getres
164172#endif
165173
174#ifdef __NR_clock_getres_time64
175# define SYS_clock_getres_time64 __NR_clock_getres_time64
176#endif
177
166178#ifdef __NR_clock_gettime
167179# define SYS_clock_gettime __NR_clock_gettime
168180#endif
169181
182#ifdef __NR_clock_gettime64
183# define SYS_clock_gettime64 __NR_clock_gettime64
184#endif
185
170186#ifdef __NR_clock_nanosleep
171187# define SYS_clock_nanosleep __NR_clock_nanosleep
172188#endif
173189
190#ifdef __NR_clock_nanosleep_time64
191# define SYS_clock_nanosleep_time64 __NR_clock_nanosleep_time64
192#endif
193
174194#ifdef __NR_clock_settime
175195# define SYS_clock_settime __NR_clock_settime
176196#endif
177197
198#ifdef __NR_clock_settime64
199# define SYS_clock_settime64 __NR_clock_settime64
200#endif
201
178202#ifdef __NR_clone
179203# define SYS_clone __NR_clone
180204#endif
......@@ -367,6 +391,10 @@
367391# define SYS_fork __NR_fork
368392#endif
369393
394#ifdef __NR_fp_udfiex_crtl
395# define SYS_fp_udfiex_crtl __NR_fp_udfiex_crtl
396#endif
397
370398#ifdef __NR_free_hugepages
371399# define SYS_free_hugepages __NR_free_hugepages
372400#endif
......@@ -375,10 +403,26 @@
375403# define SYS_fremovexattr __NR_fremovexattr
376404#endif
377405
406#ifdef __NR_fsconfig
407# define SYS_fsconfig __NR_fsconfig
408#endif
409
378410#ifdef __NR_fsetxattr
379411# define SYS_fsetxattr __NR_fsetxattr
380412#endif
381413
414#ifdef __NR_fsmount
415# define SYS_fsmount __NR_fsmount
416#endif
417
418#ifdef __NR_fsopen
419# define SYS_fsopen __NR_fsopen
420#endif
421
422#ifdef __NR_fspick
423# define SYS_fspick __NR_fspick
424#endif
425
382426#ifdef __NR_fstat
383427# define SYS_fstat __NR_fstat
384428#endif
......@@ -419,6 +463,10 @@
419463# define SYS_futex __NR_futex
420464#endif
421465
466#ifdef __NR_futex_time64
467# define SYS_futex_time64 __NR_futex_time64
468#endif
469
422470#ifdef __NR_futimesat
423471# define SYS_futimesat __NR_futimesat
424472#endif
......@@ -439,6 +487,10 @@
439487# define SYS_get_thread_area __NR_get_thread_area
440488#endif
441489
490#ifdef __NR_get_tls
491# define SYS_get_tls __NR_get_tls
492#endif
493
442494#ifdef __NR_getcpu
443495# define SYS_getcpu __NR_getcpu
444496#endif
......@@ -655,6 +707,10 @@
655707# define SYS_io_pgetevents __NR_io_pgetevents
656708#endif
657709
710#ifdef __NR_io_pgetevents_time64
711# define SYS_io_pgetevents_time64 __NR_io_pgetevents_time64
712#endif
713
658714#ifdef __NR_io_setup
659715# define SYS_io_setup __NR_io_setup
660716#endif
......@@ -663,6 +719,18 @@
663719# define SYS_io_submit __NR_io_submit
664720#endif
665721
722#ifdef __NR_io_uring_enter
723# define SYS_io_uring_enter __NR_io_uring_enter
724#endif
725
726#ifdef __NR_io_uring_register
727# define SYS_io_uring_register __NR_io_uring_register
728#endif
729
730#ifdef __NR_io_uring_setup
731# define SYS_io_uring_setup __NR_io_uring_setup
732#endif
733
666734#ifdef __NR_ioctl
667735# define SYS_ioctl __NR_ioctl
668736#endif
......@@ -847,6 +915,10 @@
847915# define SYS_mount __NR_mount
848916#endif
849917
918#ifdef __NR_move_mount
919# define SYS_move_mount __NR_move_mount
920#endif
921
850922#ifdef __NR_move_pages
851923# define SYS_move_pages __NR_move_pages
852924#endif
......@@ -875,10 +947,18 @@
875947# define SYS_mq_timedreceive __NR_mq_timedreceive
876948#endif
877949
950#ifdef __NR_mq_timedreceive_time64
951# define SYS_mq_timedreceive_time64 __NR_mq_timedreceive_time64
952#endif
953
878954#ifdef __NR_mq_timedsend
879955# define SYS_mq_timedsend __NR_mq_timedsend
880956#endif
881957
958#ifdef __NR_mq_timedsend_time64
959# define SYS_mq_timedsend_time64 __NR_mq_timedsend_time64
960#endif
961
882962#ifdef __NR_mq_unlink
883963# define SYS_mq_unlink __NR_mq_unlink
884964#endif
......@@ -951,6 +1031,10 @@
9511031# define SYS_old_adjtimex __NR_old_adjtimex
9521032#endif
9531033
1034#ifdef __NR_old_getpagesize
1035# define SYS_old_getpagesize __NR_old_getpagesize
1036#endif
1037
9541038#ifdef __NR_oldfstat
9551039# define SYS_oldfstat __NR_oldfstat
9561040#endif
......@@ -983,6 +1067,10 @@
9831067# define SYS_open_by_handle_at __NR_open_by_handle_at
9841068#endif
9851069
1070#ifdef __NR_open_tree
1071# define SYS_open_tree __NR_open_tree
1072#endif
1073
9861074#ifdef __NR_openat
9871075# define SYS_openat __NR_openat
9881076#endif
......@@ -1459,6 +1547,10 @@
14591547# define SYS_personality __NR_personality
14601548#endif
14611549
1550#ifdef __NR_pidfd_send_signal
1551# define SYS_pidfd_send_signal __NR_pidfd_send_signal
1552#endif
1553
14621554#ifdef __NR_pipe
14631555# define SYS_pipe __NR_pipe
14641556#endif
......@@ -1491,6 +1583,10 @@
14911583# define SYS_ppoll __NR_ppoll
14921584#endif
14931585
1586#ifdef __NR_ppoll_time64
1587# define SYS_ppoll_time64 __NR_ppoll_time64
1588#endif
1589
14941590#ifdef __NR_prctl
14951591# define SYS_prctl __NR_prctl
14961592#endif
......@@ -1531,6 +1627,10 @@
15311627# define SYS_pselect6 __NR_pselect6
15321628#endif
15331629
1630#ifdef __NR_pselect6_time64
1631# define SYS_pselect6_time64 __NR_pselect6_time64
1632#endif
1633
15341634#ifdef __NR_ptrace
15351635# define SYS_ptrace __NR_ptrace
15361636#endif
......@@ -1599,6 +1699,10 @@
15991699# define SYS_recvmmsg __NR_recvmmsg
16001700#endif
16011701
1702#ifdef __NR_recvmmsg_time64
1703# define SYS_recvmmsg_time64 __NR_recvmmsg_time64
1704#endif
1705
16021706#ifdef __NR_recvmsg
16031707# define SYS_recvmsg __NR_recvmsg
16041708#endif
......@@ -1671,6 +1775,10 @@
16711775# define SYS_rt_sigtimedwait __NR_rt_sigtimedwait
16721776#endif
16731777
1778#ifdef __NR_rt_sigtimedwait_time64
1779# define SYS_rt_sigtimedwait_time64 __NR_rt_sigtimedwait_time64
1780#endif
1781
16741782#ifdef __NR_rt_tgsigqueueinfo
16751783# define SYS_rt_tgsigqueueinfo __NR_rt_tgsigqueueinfo
16761784#endif
......@@ -1731,6 +1839,10 @@
17311839# define SYS_sched_rr_get_interval __NR_sched_rr_get_interval
17321840#endif
17331841
1842#ifdef __NR_sched_rr_get_interval_time64
1843# define SYS_sched_rr_get_interval_time64 __NR_sched_rr_get_interval_time64
1844#endif
1845
17341846#ifdef __NR_sched_set_affinity
17351847# define SYS_sched_set_affinity __NR_sched_set_affinity
17361848#endif
......@@ -1783,6 +1895,10 @@
17831895# define SYS_semtimedop __NR_semtimedop
17841896#endif
17851897
1898#ifdef __NR_semtimedop_time64
1899# define SYS_semtimedop_time64 __NR_semtimedop_time64
1900#endif
1901
17861902#ifdef __NR_send
17871903# define SYS_send __NR_send
17881904#endif
......@@ -1823,6 +1939,10 @@
18231939# define SYS_set_tid_address __NR_set_tid_address
18241940#endif
18251941
1942#ifdef __NR_set_tls
1943# define SYS_set_tls __NR_set_tls
1944#endif
1945
18261946#ifdef __NR_setdomainname
18271947# define SYS_setdomainname __NR_setdomainname
18281948#endif
......@@ -2171,10 +2291,18 @@
21712291# define SYS_timer_gettime __NR_timer_gettime
21722292#endif
21732293
2294#ifdef __NR_timer_gettime64
2295# define SYS_timer_gettime64 __NR_timer_gettime64
2296#endif
2297
21742298#ifdef __NR_timer_settime
21752299# define SYS_timer_settime __NR_timer_settime
21762300#endif
21772301
2302#ifdef __NR_timer_settime64
2303# define SYS_timer_settime64 __NR_timer_settime64
2304#endif
2305
21782306#ifdef __NR_timerfd
21792307# define SYS_timerfd __NR_timerfd
21802308#endif
......@@ -2187,10 +2315,18 @@
21872315# define SYS_timerfd_gettime __NR_timerfd_gettime
21882316#endif
21892317
2318#ifdef __NR_timerfd_gettime64
2319# define SYS_timerfd_gettime64 __NR_timerfd_gettime64
2320#endif
2321
21902322#ifdef __NR_timerfd_settime
21912323# define SYS_timerfd_settime __NR_timerfd_settime
21922324#endif
21932325
2326#ifdef __NR_timerfd_settime64
2327# define SYS_timerfd_settime64 __NR_timerfd_settime64
2328#endif
2329
21942330#ifdef __NR_times
21952331# define SYS_times __NR_times
21962332#endif
......@@ -2211,6 +2347,10 @@
22112347# define SYS_tuxcall __NR_tuxcall
22122348#endif
22132349
2350#ifdef __NR_udftrap
2351# define SYS_udftrap __NR_udftrap
2352#endif
2353
22142354#ifdef __NR_ugetrlimit
22152355# define SYS_ugetrlimit __NR_ugetrlimit
22162356#endif
......@@ -2255,6 +2395,14 @@
22552395# define SYS_userfaultfd __NR_userfaultfd
22562396#endif
22572397
2398#ifdef __NR_usr26
2399# define SYS_usr26 __NR_usr26
2400#endif
2401
2402#ifdef __NR_usr32
2403# define SYS_usr32 __NR_usr32
2404#endif
2405
22582406#ifdef __NR_ustat
22592407# define SYS_ustat __NR_ustat
22602408#endif
......@@ -2267,6 +2415,10 @@
22672415# define SYS_utimensat __NR_utimensat
22682416#endif
22692417
2418#ifdef __NR_utimensat_time64
2419# define SYS_utimensat_time64 __NR_utimensat_time64
2420#endif
2421
22702422#ifdef __NR_utimes
22712423# define SYS_utimes __NR_utimes
22722424#endif
lib/libc/include/generic-glibc/bits/types.h+11-8
......@@ -87,7 +87,7 @@ __extension__ typedef unsigned long long int __uintmax_t;
8787 32 -- "natural" 32-bit type (always int)
8888 64 -- "natural" 64-bit type (long or long long)
8989 LONG32 -- 32-bit type, traditionally long
90 QUAD -- 64-bit type, always long long
90 QUAD -- 64-bit type, traditionally long long
9191 WORD -- natural type of __WORDSIZE bits (int or long)
9292 LONGWORD -- type of __WORDSIZE bits, traditionally long
9393
......@@ -113,14 +113,14 @@ __extension__ typedef unsigned long long int __uintmax_t;
113113#define __SLONGWORD_TYPE long int
114114#define __ULONGWORD_TYPE unsigned long int
115115#if __WORDSIZE == 32
116# define __SQUAD_TYPE __quad_t
117# define __UQUAD_TYPE __u_quad_t
116# define __SQUAD_TYPE __int64_t
117# define __UQUAD_TYPE __uint64_t
118118# define __SWORD_TYPE int
119119# define __UWORD_TYPE unsigned int
120120# define __SLONG32_TYPE long int
121121# define __ULONG32_TYPE unsigned long int
122# define __S64_TYPE __quad_t
123# define __U64_TYPE __u_quad_t
122# define __S64_TYPE __int64_t
123# define __U64_TYPE __uint64_t
124124/* We want __extension__ before typedef's that use nonstandard base types
125125 such as `long long' in C89 mode. */
126126# define __STD_TYPE __extension__ typedef
......@@ -213,10 +213,13 @@ __STD_TYPE __U32_TYPE __socklen_t;
213213 It is not currently necessary for this to be machine-specific. */
214214typedef int __sig_atomic_t;
215215
216#if __TIMESIZE == 64
216/* Seconds since the Epoch, visible to user code when time_t is too
217 narrow only for consistency with the old way of widening too-narrow
218 types. User code should never use __time64_t. */
219#if __TIMESIZE == 64 && defined __LIBC
217220# define __time64_t __time_t
218#else
219__STD_TYPE __TIME64_T_TYPE __time64_t; /* Seconds since the Epoch. */
221#elif __TIMESIZE != 64
222__STD_TYPE __TIME64_T_TYPE __time64_t;
220223#endif
221224
222225#undef __STD_TYPE
lib/libc/include/generic-glibc/bits/types/struct_statx.h created+55
......@@ -0,0 +1,55 @@
1/* Definition of the generic version of struct statx.
2 Copyright (C) 2018-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#ifndef _SYS_STAT_H
20# error Never include <bits/types/struct_statx.h> directly, include <sys/stat.h> instead.
21#endif
22
23#ifndef __statx_defined
24#define __statx_defined 1
25
26/* Warning: The kernel may add additional fields to this struct in the
27 future. Only use this struct for calling the statx function, not
28 for storing data. (Expansion will be controlled by the mask
29 argument of the statx function.) */
30struct statx
31{
32 __uint32_t stx_mask;
33 __uint32_t stx_blksize;
34 __uint64_t stx_attributes;
35 __uint32_t stx_nlink;
36 __uint32_t stx_uid;
37 __uint32_t stx_gid;
38 __uint16_t stx_mode;
39 __uint16_t __statx_pad1[1];
40 __uint64_t stx_ino;
41 __uint64_t stx_size;
42 __uint64_t stx_blocks;
43 __uint64_t stx_attributes_mask;
44 struct statx_timestamp stx_atime;
45 struct statx_timestamp stx_btime;
46 struct statx_timestamp stx_ctime;
47 struct statx_timestamp stx_mtime;
48 __uint32_t stx_rdev_major;
49 __uint32_t stx_rdev_minor;
50 __uint32_t stx_dev_major;
51 __uint32_t stx_dev_minor;
52 __uint64_t __statx_pad2[14];
53};
54
55#endif /* __statx_defined */
\ No newline at end of file
lib/libc/include/generic-glibc/bits/types/struct_statx_timestamp.h created+33
......@@ -0,0 +1,33 @@
1/* Definition of the generic version of struct statx_timestamp.
2 Copyright (C) 2018-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#ifndef _SYS_STAT_H
20# error Never include <bits/types/struct_statx_timestamp.h> directly, include <sys/stat.h> instead.
21#endif
22
23#ifndef __statx_timestamp_defined
24#define __statx_timestamp_defined 1
25
26struct statx_timestamp
27{
28 __int64_t tv_sec;
29 __uint32_t tv_nsec;
30 __int32_t __statx_timestamp_pad1[1];
31};
32
33#endif /* __statx_timestamp_defined */
\ No newline at end of file
lib/libc/include/generic-glibc/bits/xtitypes.h deleted-33
......@@ -1,33 +0,0 @@
1/* bits/xtitypes.h -- Define some types used by <bits/stropts.h>. Generic.
2 Copyright (C) 2002-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#ifndef _STROPTS_H
20# error "Never include <bits/xtitypes.h> directly; use <stropts.h> instead."
21#endif
22
23#ifndef _BITS_XTITYPES_H
24#define _BITS_XTITYPES_H 1
25
26#include <bits/types.h>
27
28/* This type is used by some structs in <bits/stropts.h>. */
29typedef __SLONGWORD_TYPE __t_scalar_t;
30typedef __ULONGWORD_TYPE __t_uscalar_t;
31
32
33#endif /* bits/xtitypes.h */
\ No newline at end of file
lib/libc/include/generic-glibc/dirent.h+2
......@@ -401,4 +401,6 @@ extern int versionsort64 (const struct dirent64 **__e1,
401401
402402__END_DECLS
403403
404#include <bits/dirent_ext.h>
405
404406#endif /* dirent.h */
\ No newline at end of file
lib/libc/include/generic-glibc/dlfcn.h+12
......@@ -180,7 +180,19 @@ typedef struct
180180{
181181 size_t dls_size; /* Size in bytes of the whole buffer. */
182182 unsigned int dls_cnt; /* Number of elements in `dls_serpath'. */
183# if __GNUC_PREREQ (3, 0)
184 /* The zero-length array avoids an unwanted array subscript check by
185 the compiler, while the surrounding anonymous union preserves the
186 historic size of the type. At the time of writing, GNU C does
187 not support structs with flexible array members in unions. */
188 __extension__ union
189 {
190 Dl_serpath dls_serpath[0]; /* Actually longer, dls_cnt elements. */
191 Dl_serpath __dls_serpath_pad[1];
192 };
193# else
183194 Dl_serpath dls_serpath[1]; /* Actually longer, dls_cnt elements. */
195# endif
184196} Dl_serinfo;
185197#endif /* __USE_GNU */
186198
lib/libc/include/generic-glibc/elf.h+30-2
......@@ -360,7 +360,7 @@ typedef struct
360360#define EM_RISCV 243 /* RISC-V */
361361
362362#define EM_BPF 247 /* Linux BPF -- in-kernel virtual machine */
363#define EM_CSKY 252 /* C_SKY */
363#define EM_CSKY 252 /* C-SKY */
364364
365365#define EM_NUM 253
366366
......@@ -809,9 +809,16 @@ typedef struct
809809#define NT_ARM_SYSTEM_CALL 0x404 /* ARM system call number */
810810#define NT_ARM_SVE 0x405 /* ARM Scalable Vector Extension
811811 registers */
812#define NT_ARM_PAC_MASK 0x406 /* ARM pointer authentication
813 code masks. */
814#define NT_ARM_PACA_KEYS 0x407 /* ARM pointer authentication
815 address keys. */
816#define NT_ARM_PACG_KEYS 0x408 /* ARM pointer authentication
817 generic key. */
812818#define NT_VMCOREDD 0x700 /* Vmcore Device Dump Note. */
813819#define NT_MIPS_DSP 0x800 /* MIPS DSP ASE registers. */
814820#define NT_MIPS_FP_MODE 0x801 /* MIPS floating-point mode. */
821#define NT_MIPS_MSA 0x802 /* MIPS SIMD registers. */
815822
816823/* Legal values for the note segment descriptor types for object files. */
817824
......@@ -987,6 +994,9 @@ typedef struct
987994#define DF_1_SINGLETON 0x02000000 /* Singleton symbols are used. */
988995#define DF_1_STUB 0x04000000
989996#define DF_1_PIE 0x08000000
997#define DF_1_KMOD 0x10000000
998#define DF_1_WEAKFILTER 0x20000000
999#define DF_1_NOCOMMON 0x40000000
9901000
9911001/* Flags for the feature selection in DT_FEATURE_1. */
9921002#define DTF_1_PARINIT 0x00000001
......@@ -2854,6 +2864,13 @@ enum
28542864#define R_AARCH64_TLSDESC 1031 /* TLS Descriptor. */
28552865#define R_AARCH64_IRELATIVE 1032 /* STT_GNU_IFUNC relocation. */
28562866
2867/* AArch64 specific values for the Dyn d_tag field. */
2868#define DT_AARCH64_VARIANT_PCS (DT_LOPROC + 5)
2869#define DT_AARCH64_NUM 6
2870
2871/* AArch64 specific values for the st_other field. */
2872#define STO_AARCH64_VARIANT_PCS 0x80
2873
28572874/* ARM relocs. */
28582875
28592876#define R_ARM_NONE 0 /* No reloc */
......@@ -3022,7 +3039,7 @@ enum
30223039/* Keep this the last entry. */
30233040#define R_ARM_NUM 256
30243041
3025/* csky */
3042/* C-SKY */
30263043#define R_CKCORE_NONE 0 /* no reloc */
30273044#define R_CKCORE_ADDR32 1 /* direct 32 bit (S + A) */
30283045#define R_CKCORE_PCRELIMM8BY4 2 /* disp ((S + A - P) >> 2) & 0xff */
......@@ -3086,6 +3103,17 @@ enum
30863103#define R_CKCORE_TLS_DTPOFF32 57
30873104#define R_CKCORE_TLS_TPOFF32 58
30883105
3106/* C-SKY elf header definition. */
3107#define EF_CSKY_ABIMASK 0XF0000000
3108#define EF_CSKY_OTHER 0X0FFF0000
3109#define EF_CSKY_PROCESSOR 0X0000FFFF
3110
3111#define EF_CSKY_ABIV1 0X10000000
3112#define EF_CSKY_ABIV2 0X20000000
3113
3114/* C-SKY attributes section. */
3115#define SHT_CSKY_ATTRIBUTES (SHT_LOPROC + 1)
3116
30893117/* IA-64 specific declarations. */
30903118
30913119/* Processor specific flags for the Ehdr e_flags field. */
lib/libc/include/generic-glibc/features.h+1-1
......@@ -439,7 +439,7 @@
439439/* Major and minor version number of the GNU C library package. Use
440440 these macros to test for features in specific releases. */
441441#define __GLIBC__ 2
442#define __GLIBC_MINOR__ 29
442#define __GLIBC_MINOR__ 30
443443
444444#define __GLIBC_PREREQ(maj, min) \
445445 ((__GLIBC__ << 16) + __GLIBC_MINOR__ >= ((maj) << 16) + (min))
lib/libc/include/generic-glibc/finclude/math-vector-fortran.h created+19
......@@ -0,0 +1,19 @@
1! Platform-specific declarations of SIMD math functions for Fortran. -*- f90 -*-
2! Copyright (C) 2019 Free Software Foundation, Inc.
3! This file is part of the GNU C Library.
4!
5! The GNU C Library is free software; you can redistribute it and/or
6! modify it under the terms of the GNU Lesser General Public
7! License as published by the Free Software Foundation; either
8! version 2.1 of the License, or (at your option) any later version.
9!
10! The GNU C Library is distributed in the hope that it will be useful,
11! but WITHOUT ANY WARRANTY; without even the implied warranty of
12! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13! Lesser General Public License for more details.
14!
15! You should have received a copy of the GNU Lesser General Public
16! License along with the GNU C Library; if not, see
17! <http://www.gnu.org/licenses/>.
18
19! No SIMD math functions are available for this platform.
\ No newline at end of file
lib/libc/include/generic-glibc/gconv.h+2-9
......@@ -86,6 +86,8 @@ struct __gconv_step
8686 struct __gconv_loaded_object *__shlib_handle;
8787 const char *__modname;
8888
89 /* For internal use by glibc. (Accesses to this member must occur
90 when the internal __gconv_lock mutex is acquired). */
8991 int __counter;
9092
9193 char *__from_name;
......@@ -142,13 +144,4 @@ typedef struct __gconv_info
142144 __extension__ struct __gconv_step_data __data[0];
143145} *__gconv_t;
144146
145/* Transliteration using the locale's data. */
146extern int __gconv_transliterate (struct __gconv_step *step,
147 struct __gconv_step_data *step_data,
148 const unsigned char *inbufstart,
149 const unsigned char **inbufp,
150 const unsigned char *inbufend,
151 unsigned char **outbufstart,
152 size_t *irreversible);
153
154147#endif /* gconv.h */
\ No newline at end of file
lib/libc/include/generic-glibc/gnu/stubs-32.h-2
......@@ -8,9 +8,7 @@
88#endif
99
1010#define __stub_chflags
11#define __stub_fattach
1211#define __stub_fchflags
13#define __stub_fdetach
1412#define __stub_gtty
1513#define __stub_lchmod
1614#define __stub_revoke
lib/libc/include/generic-glibc/gnu/stubs-64.h created+18
......@@ -0,0 +1,18 @@
1/* This file is automatically generated.
2 It defines a symbol `__stub_FUNCTION' for each function
3 in the C library which is a stub, meaning it will fail
4 every time called, usually setting errno to ENOSYS. */
5
6#ifdef _LIBC
7 #error Applications may not define the macro _LIBC
8#endif
9
10#define __stub_chflags
11#define __stub_fchflags
12#define __stub_gtty
13#define __stub_lchmod
14#define __stub_revoke
15#define __stub_setlogin
16#define __stub_sigreturn
17#define __stub_sstk
18#define __stub_stty
\ No newline at end of file
lib/libc/include/generic-glibc/gnu/stubs-hard.h-6
......@@ -11,15 +11,9 @@
1111#define __stub___compat_get_kernel_syms
1212#define __stub___compat_query_module
1313#define __stub_chflags
14#define __stub_fattach
1514#define __stub_fchflags
16#define __stub_fdetach
17#define __stub_getmsg
18#define __stub_getpmsg
1915#define __stub_gtty
2016#define __stub_lchmod
21#define __stub_putmsg
22#define __stub_putpmsg
2317#define __stub_revoke
2418#define __stub_setlogin
2519#define __stub_sigreturn
lib/libc/include/generic-glibc/gnu/stubs-n32_hard.h-2
......@@ -10,9 +10,7 @@
1010#define __stub___compat_bdflush
1111#define __stub___compat_uselib
1212#define __stub_chflags
13#define __stub_fattach
1413#define __stub_fchflags
15#define __stub_fdetach
1614#define __stub_gtty
1715#define __stub_lchmod
1816#define __stub_revoke
lib/libc/include/generic-glibc/gnu/stubs-n64_hard.h-2
......@@ -10,9 +10,7 @@
1010#define __stub___compat_bdflush
1111#define __stub___compat_uselib
1212#define __stub_chflags
13#define __stub_fattach
1413#define __stub_fchflags
15#define __stub_fdetach
1614#define __stub_gtty
1715#define __stub_lchmod
1816#define __stub_revoke
lib/libc/include/generic-glibc/gnu/stubs-o32_hard.h-2
......@@ -8,9 +8,7 @@
88#endif
99
1010#define __stub_chflags
11#define __stub_fattach
1211#define __stub_fchflags
13#define __stub_fdetach
1412#define __stub_gtty
1513#define __stub_lchmod
1614#define __stub_revoke
lib/libc/include/generic-glibc/gnu/stubs-soft.h-6
......@@ -11,15 +11,9 @@
1111#define __stub___compat_get_kernel_syms
1212#define __stub___compat_query_module
1313#define __stub_chflags
14#define __stub_fattach
1514#define __stub_fchflags
16#define __stub_fdetach
17#define __stub_getmsg
18#define __stub_getpmsg
1915#define __stub_gtty
2016#define __stub_lchmod
21#define __stub_putmsg
22#define __stub_putpmsg
2317#define __stub_revoke
2418#define __stub_setlogin
2519#define __stub_sigreturn
lib/libc/include/generic-glibc/malloc.h+10-10
......@@ -35,11 +35,12 @@
3535__BEGIN_DECLS
3636
3737/* Allocate SIZE bytes of memory. */
38extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;
38extern void *malloc (size_t __size) __THROW __attribute_malloc__
39 __attribute_alloc_size__ ((1)) __wur;
3940
4041/* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
4142extern void *calloc (size_t __nmemb, size_t __size)
42__THROW __attribute_malloc__ __wur;
43__THROW __attribute_malloc__ __attribute_alloc_size__ ((1, 2)) __wur;
4344
4445/* Re-allocate the previously allocated block in __ptr, making the new
4546 block SIZE bytes long. */
......@@ -47,7 +48,7 @@ __THROW __attribute_malloc__ __wur;
4748 the same pointer that was passed to it, aliasing needs to be allowed
4849 between objects pointed by the old and new pointers. */
4950extern void *realloc (void *__ptr, size_t __size)
50__THROW __attribute_warn_unused_result__;
51__THROW __attribute_warn_unused_result__ __attribute_alloc_size__ ((2));
5152
5253/* Re-allocate the previously allocated block in PTR, making the new
5354 block large enough for NMEMB elements of SIZE bytes each. */
......@@ -55,21 +56,23 @@ __THROW __attribute_warn_unused_result__;
5556 the same pointer that was passed to it, aliasing needs to be allowed
5657 between objects pointed by the old and new pointers. */
5758extern void *reallocarray (void *__ptr, size_t __nmemb, size_t __size)
58__THROW __attribute_warn_unused_result__;
59__THROW __attribute_warn_unused_result__ __attribute_alloc_size__ ((2, 3));
5960
6061/* Free a block allocated by `malloc', `realloc' or `calloc'. */
6162extern void free (void *__ptr) __THROW;
6263
6364/* Allocate SIZE bytes allocated to ALIGNMENT bytes. */
6465extern void *memalign (size_t __alignment, size_t __size)
65__THROW __attribute_malloc__ __wur;
66__THROW __attribute_malloc__ __attribute_alloc_size__ ((2)) __wur;
6667
6768/* Allocate SIZE bytes on a page boundary. */
68extern void *valloc (size_t __size) __THROW __attribute_malloc__ __wur;
69extern void *valloc (size_t __size) __THROW __attribute_malloc__
70 __attribute_alloc_size__ ((1)) __wur;
6971
7072/* Equivalent to valloc(minimum-page-that-holds(n)), that is, round up
7173 __size to nearest pagesize. */
72extern void *pvalloc (size_t __size) __THROW __attribute_malloc__ __wur;
74extern void *pvalloc (size_t __size) __THROW __attribute_malloc__
75 __attribute_alloc_size__ ((1)) __wur;
7376
7477/* Underlying allocation function; successive calls should return
7578 contiguous pieces of memory. */
......@@ -156,9 +159,6 @@ extern void *(*__MALLOC_HOOK_VOLATILE __memalign_hook)(size_t __alignment,
156159__MALLOC_DEPRECATED;
157160extern void (*__MALLOC_HOOK_VOLATILE __after_morecore_hook) (void);
158161
159/* Activate a standard set of debugging hooks. */
160extern void __malloc_check_init (void) __THROW __MALLOC_DEPRECATED;
161
162162
163163__END_DECLS
164164#endif /* malloc.h */
\ No newline at end of file
lib/libc/include/generic-glibc/math.h+11-6
......@@ -874,7 +874,8 @@ enum
874874 the __SUPPORT_SNAN__ check may be skipped for those versions. */
875875
876876/* Return number of classification appropriate for X. */
877# if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__ \
877# if ((__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \
878 || __glibc_clang_prereq (2,8)) \
878879 && (!defined __OPTIMIZE_SIZE__ || defined __cplusplus)
879880 /* The check for __cplusplus allows the use of the builtin, even
880881 when optimization for size is on. This is provided for
......@@ -889,7 +890,7 @@ enum
889890# endif
890891
891892/* Return nonzero value if sign of X is negative. */
892# if __GNUC_PREREQ (6,0)
893# if __GNUC_PREREQ (6,0) || __glibc_clang_prereq (3,3)
893894# define signbit(x) __builtin_signbit (x)
894895# elif defined __cplusplus
895896 /* In C++ mode, __MATH_TG cannot be used, because it relies on
......@@ -907,14 +908,16 @@ enum
907908# endif
908909
909910/* Return nonzero value if X is not +-Inf or NaN. */
910# if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
911# if (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \
912 || __glibc_clang_prereq (2,8)
911913# define isfinite(x) __builtin_isfinite (x)
912914# else
913915# define isfinite(x) __MATH_TG ((x), __finite, (x))
914916# endif
915917
916918/* Return nonzero value if X is neither zero, subnormal, Inf, nor NaN. */
917# if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
919# if (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \
920 || __glibc_clang_prereq (2,8)
918921# define isnormal(x) __builtin_isnormal (x)
919922# else
920923# define isnormal(x) (fpclassify (x) == FP_NORMAL)
......@@ -922,7 +925,8 @@ enum
922925
923926/* Return nonzero value if X is a NaN. We could use `fpclassify' but
924927 we already have this functions `__isnan' and it is faster. */
925# if __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
928# if (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \
929 || __glibc_clang_prereq (2,8)
926930# define isnan(x) __builtin_isnan (x)
927931# else
928932# define isnan(x) __MATH_TG ((x), __isnan, (x))
......@@ -939,7 +943,8 @@ enum
939943# define isinf(x) \
940944 (__builtin_types_compatible_p (__typeof (x), _Float128) \
941945 ? __isinff128 (x) : __builtin_isinf_sign (x))
942# elif __GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__
946# elif (__GNUC_PREREQ (4,4) && !defined __SUPPORT_SNAN__) \
947 || __glibc_clang_prereq (3,7)
943948# define isinf(x) __builtin_isinf_sign (x)
944949# else
945950# define isinf(x) __MATH_TG ((x), __isinf, (x))
lib/libc/include/generic-glibc/netinet/igmp.h+1
......@@ -86,6 +86,7 @@ struct igmp {
8686
8787#define IGMP_MTRACE_RESP 0x1e /* traceroute resp.(to sender)*/
8888#define IGMP_MTRACE 0x1f /* mcast traceroute messages */
89#define IGMP_MRDISC_ADV 0x30 /* From RFC4286. */
8990
9091#define IGMP_MAX_HOST_REPORT_DELAY 10 /* max delay for response to */
9192 /* query (in seconds) according */
lib/libc/include/generic-glibc/netinet/in.h+1
......@@ -204,6 +204,7 @@ enum
204204#define INADDR_UNSPEC_GROUP ((in_addr_t) 0xe0000000) /* 224.0.0.0 */
205205#define INADDR_ALLHOSTS_GROUP ((in_addr_t) 0xe0000001) /* 224.0.0.1 */
206206#define INADDR_ALLRTRS_GROUP ((in_addr_t) 0xe0000002) /* 224.0.0.2 */
207#define INADDR_ALLSNOOPERS_GROUP ((in_addr_t) 0xe000006a) /* 224.0.0.106 */
207208#define INADDR_MAX_LOCAL_GROUP ((in_addr_t) 0xe00000ff) /* 224.0.0.255 */
208209
209210#if !__USE_KERNEL_IPV6_DEFS
lib/libc/include/generic-glibc/netinet/udp.h+1
......@@ -82,6 +82,7 @@ struct udphdr
8282#define UDP_NO_CHECK6_RX 102 /* Disable accepting checksum for UDP
8383 over IPv6. */
8484#define UDP_SEGMENT 103 /* Set GSO segmentation size. */
85#define UDP_GRO 104 /* This socket can receive UDP GRO packets. */
8586
8687/* UDP encapsulation types */
8788#define UDP_ENCAP_ESPINUDP_NON_IKE 1 /* draft-ietf-ipsec-nat-t-ike-00/01 */
lib/libc/include/generic-glibc/pthread.h+36
......@@ -770,6 +770,13 @@ extern int pthread_mutex_timedlock (pthread_mutex_t *__restrict __mutex,
770770 __abstime) __THROWNL __nonnull ((1, 2));
771771#endif
772772
773#ifdef __USE_GNU
774extern int pthread_mutex_clocklock (pthread_mutex_t *__restrict __mutex,
775 clockid_t __clockid,
776 const struct timespec *__restrict
777 __abstime) __THROWNL __nonnull ((1, 3));
778#endif
779
773780/* Unlock a mutex. */
774781extern int pthread_mutex_unlock (pthread_mutex_t *__mutex)
775782 __THROWNL __nonnull ((1));
......@@ -909,6 +916,13 @@ extern int pthread_rwlock_timedrdlock (pthread_rwlock_t *__restrict __rwlock,
909916 __abstime) __THROWNL __nonnull ((1, 2));
910917# endif
911918
919# ifdef __USE_GNU
920extern int pthread_rwlock_clockrdlock (pthread_rwlock_t *__restrict __rwlock,
921 clockid_t __clockid,
922 const struct timespec *__restrict
923 __abstime) __THROWNL __nonnull ((1, 3));
924# endif
925
912926/* Acquire write lock for RWLOCK. */
913927extern int pthread_rwlock_wrlock (pthread_rwlock_t *__rwlock)
914928 __THROWNL __nonnull ((1));
......@@ -924,6 +938,13 @@ extern int pthread_rwlock_timedwrlock (pthread_rwlock_t *__restrict __rwlock,
924938 __abstime) __THROWNL __nonnull ((1, 2));
925939# endif
926940
941# ifdef __USE_GNU
942extern int pthread_rwlock_clockwrlock (pthread_rwlock_t *__restrict __rwlock,
943 clockid_t __clockid,
944 const struct timespec *__restrict
945 __abstime) __THROWNL __nonnull ((1, 3));
946# endif
947
927948/* Unlock RWLOCK. */
928949extern int pthread_rwlock_unlock (pthread_rwlock_t *__rwlock)
929950 __THROWNL __nonnull ((1));
......@@ -1003,6 +1024,21 @@ extern int pthread_cond_timedwait (pthread_cond_t *__restrict __cond,
10031024 const struct timespec *__restrict __abstime)
10041025 __nonnull ((1, 2, 3));
10051026
1027# ifdef __USE_GNU
1028/* Wait for condition variable COND to be signaled or broadcast until
1029 ABSTIME measured by the specified clock. MUTEX is assumed to be
1030 locked before. CLOCK is the clock to use. ABSTIME is an absolute
1031 time specification against CLOCK's epoch.
1032
1033 This function is a cancellation point and therefore not marked with
1034 __THROW. */
1035extern int pthread_cond_clockwait (pthread_cond_t *__restrict __cond,
1036 pthread_mutex_t *__restrict __mutex,
1037 __clockid_t __clock_id,
1038 const struct timespec *__restrict __abstime)
1039 __nonnull ((1, 2, 4));
1040# endif
1041
10061042/* Functions for handling condition variable attributes. */
10071043
10081044/* Initialize condition variable attribute ATTR. */
lib/libc/include/generic-glibc/resolv.h-4
......@@ -115,11 +115,7 @@ struct res_sym {
115115#define RES_DEFNAMES 0x00000080 /* use default domain name */
116116#define RES_STAYOPEN 0x00000100 /* Keep TCP socket open */
117117#define RES_DNSRCH 0x00000200 /* search up local domain tree */
118#define RES_INSECURE1 0x00000400 /* type 1 security disabled */
119#define RES_INSECURE2 0x00000800 /* type 2 security disabled */
120118#define RES_NOALIASES 0x00001000 /* shuts off HOSTALIASES feature */
121#define RES_USE_INET6 \
122 __glibc_macro_warning ("RES_USE_INET6 is deprecated") 0x00002000
123119#define RES_ROTATE 0x00004000 /* rotate ns list after each query */
124120#define RES_NOCHECKNAME \
125121 __glibc_macro_warning ("RES_NOCHECKNAME is deprecated") 0x00008000
lib/libc/include/generic-glibc/search.h+7
......@@ -150,6 +150,13 @@ typedef void (*__action_fn_t) (const void *__nodep, VISIT __value,
150150extern void twalk (const void *__root, __action_fn_t __action);
151151
152152#ifdef __USE_GNU
153/* Like twalk, but pass down a closure parameter instead of the
154 level. */
155extern void twalk_r (const void *__root,
156 void (*) (const void *__nodep, VISIT __value,
157 void *__closure),
158 void *__closure);
159
153160/* Callback type for function to free a tree node. If the keys are atomic
154161 data this function should do nothing. */
155162typedef void (*__free_fn_t) (void *__nodep);
lib/libc/include/generic-glibc/semaphore.h+20-10
......@@ -33,24 +33,26 @@ __BEGIN_DECLS
3333/* Initialize semaphore object SEM to VALUE. If PSHARED then share it
3434 with other processes. */
3535extern int sem_init (sem_t *__sem, int __pshared, unsigned int __value)
36 __THROW;
36 __THROW __nonnull ((1));
37
3738/* Free resources associated with semaphore object SEM. */
38extern int sem_destroy (sem_t *__sem) __THROW;
39extern int sem_destroy (sem_t *__sem) __THROW __nonnull ((1));
3940
4041/* Open a named semaphore NAME with open flags OFLAG. */
41extern sem_t *sem_open (const char *__name, int __oflag, ...) __THROW;
42extern sem_t *sem_open (const char *__name, int __oflag, ...)
43 __THROW __nonnull ((1));
4244
4345/* Close descriptor for named semaphore SEM. */
44extern int sem_close (sem_t *__sem) __THROW;
46extern int sem_close (sem_t *__sem) __THROW __nonnull ((1));
4547
4648/* Remove named semaphore NAME. */
47extern int sem_unlink (const char *__name) __THROW;
49extern int sem_unlink (const char *__name) __THROW __nonnull ((1));
4850
4951/* Wait for SEM being posted.
5052
5153 This function is a cancellation point and therefore not marked with
5254 __THROW. */
53extern int sem_wait (sem_t *__sem);
55extern int sem_wait (sem_t *__sem) __nonnull ((1));
5456
5557#ifdef __USE_XOPEN2K
5658/* Similar to `sem_wait' but wait only until ABSTIME.
......@@ -58,18 +60,26 @@ extern int sem_wait (sem_t *__sem);
5860 This function is a cancellation point and therefore not marked with
5961 __THROW. */
6062extern int sem_timedwait (sem_t *__restrict __sem,
61 const struct timespec *__restrict __abstime);
63 const struct timespec *__restrict __abstime)
64 __nonnull ((1, 2));
65#endif
66
67#ifdef __USE_GNU
68extern int sem_clockwait (sem_t *__restrict __sem,
69 clockid_t clock,
70 const struct timespec *__restrict __abstime)
71 __nonnull ((1, 3));
6272#endif
6373
6474/* Test whether SEM is posted. */
65extern int sem_trywait (sem_t *__sem) __THROWNL;
75extern int sem_trywait (sem_t *__sem) __THROWNL __nonnull ((1));
6676
6777/* Post SEM. */
68extern int sem_post (sem_t *__sem) __THROWNL;
78extern int sem_post (sem_t *__sem) __THROWNL __nonnull ((1));
6979
7080/* Get current value of SEM and store it in *SVAL. */
7181extern int sem_getvalue (sem_t *__restrict __sem, int *__restrict __sval)
72 __THROW;
82 __THROW __nonnull ((1, 2));
7383
7484
7585__END_DECLS
lib/libc/include/generic-glibc/signal.h+3
......@@ -370,6 +370,9 @@ extern int __libc_current_sigrtmax (void) __THROW;
370370#define SIGRTMIN (__libc_current_sigrtmin ())
371371#define SIGRTMAX (__libc_current_sigrtmax ())
372372
373/* System-specific extensions. */
374#include <bits/signal_ext.h>
375
373376__END_DECLS
374377
375378#endif /* not signal.h */
\ No newline at end of file
lib/libc/include/generic-glibc/stdlib.h+8-5
......@@ -536,10 +536,11 @@ extern int lcong48_r (unsigned short int __param[7],
536536#endif /* Use misc or X/Open. */
537537
538538/* Allocate SIZE bytes of memory. */
539extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;
539extern void *malloc (size_t __size) __THROW __attribute_malloc__
540 __attribute_alloc_size__ ((1)) __wur;
540541/* Allocate NMEMB elements of SIZE bytes each, all initialized to 0. */
541542extern void *calloc (size_t __nmemb, size_t __size)
542 __THROW __attribute_malloc__ __wur;
543 __THROW __attribute_malloc__ __attribute_alloc_size__ ((1, 2)) __wur;
543544
544545/* Re-allocate the previously allocated block
545546 in PTR, making the new block SIZE bytes long. */
......@@ -547,7 +548,7 @@ extern void *calloc (size_t __nmemb, size_t __size)
547548 the same pointer that was passed to it, aliasing needs to be allowed
548549 between objects pointed by the old and new pointers. */
549550extern void *realloc (void *__ptr, size_t __size)
550 __THROW __attribute_warn_unused_result__;
551 __THROW __attribute_warn_unused_result__ __attribute_alloc_size__ ((2));
551552
552553#ifdef __USE_MISC
553554/* Re-allocate the previously allocated block in PTR, making the new
......@@ -556,7 +557,8 @@ extern void *realloc (void *__ptr, size_t __size)
556557 the same pointer that was passed to it, aliasing needs to be allowed
557558 between objects pointed by the old and new pointers. */
558559extern void *reallocarray (void *__ptr, size_t __nmemb, size_t __size)
559 __THROW __attribute_warn_unused_result__;
560 __THROW __attribute_warn_unused_result__
561 __attribute_alloc_size__ ((2, 3));
560562#endif
561563
562564/* Free a block allocated by `malloc', `realloc' or `calloc'. */
......@@ -569,7 +571,8 @@ extern void free (void *__ptr) __THROW;
569571#if (defined __USE_XOPEN_EXTENDED && !defined __USE_XOPEN2K) \
570572 || defined __USE_MISC
571573/* Allocate SIZE bytes on a page boundary. The storage cannot be freed. */
572extern void *valloc (size_t __size) __THROW __attribute_malloc__ __wur;
574extern void *valloc (size_t __size) __THROW __attribute_malloc__
575 __attribute_alloc_size__ ((1)) __wur;
573576#endif
574577
575578#ifdef __USE_XOPEN2K
lib/libc/include/generic-glibc/stropts.h deleted-92
......@@ -1,92 +0,0 @@
1/* Copyright (C) 1998-2019 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
17
18#ifndef _STROPTS_H
19#define _STROPTS_H 1
20
21#include <features.h>
22#include <bits/types.h>
23#include <bits/xtitypes.h>
24
25#ifndef __gid_t_defined
26typedef __gid_t gid_t;
27# define __gid_t_defined
28#endif
29
30#ifndef __uid_t_defined
31typedef __uid_t uid_t;
32# define __uid_t_defined
33#endif
34
35typedef __t_scalar_t t_scalar_t;
36typedef __t_uscalar_t t_uscalar_t;
37
38/* Get system specific constants. */
39#include <bits/stropts.h>
40
41
42__BEGIN_DECLS
43
44/* Test whether FILDES is associated with a STREAM-based file. */
45extern int isastream (int __fildes) __THROW;
46
47/* Receive next message from a STREAMS file.
48
49 This function is a cancellation point and therefore not marked with
50 __THROW. */
51extern int getmsg (int __fildes, struct strbuf *__restrict __ctlptr,
52 struct strbuf *__restrict __dataptr,
53 int *__restrict __flagsp);
54
55/* Receive next message from a STREAMS file, with *FLAGSP allowing to
56 control which message.
57
58 This function is a cancellation point and therefore not marked with
59 __THROW. */
60extern int getpmsg (int __fildes, struct strbuf *__restrict __ctlptr,
61 struct strbuf *__restrict __dataptr,
62 int *__restrict __bandp, int *__restrict __flagsp);
63
64/* Perform the I/O control operation specified by REQUEST on FD.
65 One argument may follow; its presence and type depend on REQUEST.
66 Return value depends on REQUEST. Usually -1 indicates error. */
67extern int ioctl (int __fd, unsigned long int __request, ...) __THROW;
68
69/* Send a message on a STREAM.
70
71 This function is a cancellation point and therefore not marked with
72 __THROW. */
73extern int putmsg (int __fildes, const struct strbuf *__ctlptr,
74 const struct strbuf *__dataptr, int __flags);
75
76/* Send a message on a STREAM to the BAND.
77
78 This function is a cancellation point and therefore not marked with
79 __THROW. */
80extern int putpmsg (int __fildes, const struct strbuf *__ctlptr,
81 const struct strbuf *__dataptr, int __band, int __flags);
82
83/* Attach a STREAMS-based file descriptor FILDES to a file PATH in the
84 file system name space. */
85extern int fattach (int __fildes, const char *__path) __THROW;
86
87/* Detach a name PATH from a STREAMS-based file descriptor. */
88extern int fdetach (const char *__path) __THROW;
89
90__END_DECLS
91
92#endif /* stropts.h */
\ No newline at end of file
lib/libc/include/generic-glibc/sys/cdefs.h+8
......@@ -412,6 +412,14 @@
412412# define __glibc_has_attribute(attr) 0
413413#endif
414414
415#ifdef __has_include
416/* Do not use a function-like macro, so that __has_include can inhibit
417 macro expansion. */
418# define __glibc_has_include __has_include
419#else
420# define __glibc_has_include(header) 0
421#endif
422
415423#if (!defined _Noreturn \
416424 && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) < 201112 \
417425 && !__GNUC_PREREQ (4,7))
lib/libc/include/generic-glibc/sys/ifunc.h created+42
......@@ -0,0 +1,42 @@
1/* Definitions used by AArch64 indirect function resolvers.
2 Copyright (C) 2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#ifndef _SYS_IFUNC_H
20#define _SYS_IFUNC_H
21
22/* A second argument is passed to the ifunc resolver. */
23#define _IFUNC_ARG_HWCAP (1ULL << 62)
24
25/* The prototype of a gnu indirect function resolver on AArch64 is
26
27 ElfW(Addr) ifunc_resolver (uint64_t, const __ifunc_arg_t *);
28
29 the first argument should have the _IFUNC_ARG_HWCAP bit set and
30 the remaining bits should match the AT_HWCAP settings. */
31
32/* Second argument to an ifunc resolver. */
33struct __ifunc_arg_t
34{
35 unsigned long _size; /* Size of the struct, so it can grow. */
36 unsigned long _hwcap;
37 unsigned long _hwcap2;
38};
39
40typedef struct __ifunc_arg_t __ifunc_arg_t;
41
42#endif
\ No newline at end of file
lib/libc/include/generic-glibc/sys/io.h+151-15
......@@ -12,36 +12,172 @@
1212 Lesser General Public License for more details.
1313
1414 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library. If not, see
15 License along with the GNU C Library; if not, see
1616 <http://www.gnu.org/licenses/>. */
1717
1818#ifndef _SYS_IO_H
19
2019#define _SYS_IO_H 1
20
2121#include <features.h>
2222
2323__BEGIN_DECLS
2424
2525/* If TURN_ON is TRUE, request for permission to do direct i/o on the
2626 port numbers in the range [FROM,FROM+NUM-1]. Otherwise, turn I/O
27 permission off for that range. This call requires root privileges. */
27 permission off for that range. This call requires root privileges.
28
29 Portability note: not all Linux platforms support this call. Most
30 platforms based on the PC I/O architecture probably will, however.
31 E.g., Linux/Alpha for Alpha PCs supports this. */
2832extern int ioperm (unsigned long int __from, unsigned long int __num,
29 int __turn_on) __THROW;
33 int __turn_on) __THROW;
3034
31/* Set the I/O privilege level to LEVEL. If LEVEL is nonzero,
32 permission to access any I/O port is granted. This call requires
33 root privileges. */
35/* Set the I/O privilege level to LEVEL. If LEVEL>3, permission to
36 access any I/O port is granted. This call requires root
37 privileges. */
3438extern int iopl (int __level) __THROW;
3539
36/* The functions that actually perform reads and writes. */
37extern unsigned char inb (unsigned long int __port) __THROW;
38extern unsigned short int inw (unsigned long int __port) __THROW;
39extern unsigned long int inl (unsigned long int __port) __THROW;
40#if defined __GNUC__ && __GNUC__ >= 2
4041
41extern void outb (unsigned char __value, unsigned long int __port) __THROW;
42extern void outw (unsigned short __value, unsigned long int __port) __THROW;
43extern void outl (unsigned long __value, unsigned long int __port) __THROW;
42static __inline unsigned char
43inb (unsigned short int __port)
44{
45 unsigned char _v;
4446
45__END_DECLS
47 __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (__port));
48 return _v;
49}
50
51static __inline unsigned char
52inb_p (unsigned short int __port)
53{
54 unsigned char _v;
55
56 __asm__ __volatile__ ("inb %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (__port));
57 return _v;
58}
59
60static __inline unsigned short int
61inw (unsigned short int __port)
62{
63 unsigned short _v;
64
65 __asm__ __volatile__ ("inw %w1,%0":"=a" (_v):"Nd" (__port));
66 return _v;
67}
68
69static __inline unsigned short int
70inw_p (unsigned short int __port)
71{
72 unsigned short int _v;
73
74 __asm__ __volatile__ ("inw %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (__port));
75 return _v;
76}
77
78static __inline unsigned int
79inl (unsigned short int __port)
80{
81 unsigned int _v;
82
83 __asm__ __volatile__ ("inl %w1,%0":"=a" (_v):"Nd" (__port));
84 return _v;
85}
86
87static __inline unsigned int
88inl_p (unsigned short int __port)
89{
90 unsigned int _v;
91 __asm__ __volatile__ ("inl %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (__port));
92 return _v;
93}
94
95static __inline void
96outb (unsigned char __value, unsigned short int __port)
97{
98 __asm__ __volatile__ ("outb %b0,%w1": :"a" (__value), "Nd" (__port));
99}
46100
101static __inline void
102outb_p (unsigned char __value, unsigned short int __port)
103{
104 __asm__ __volatile__ ("outb %b0,%w1\noutb %%al,$0x80": :"a" (__value),
105 "Nd" (__port));
106}
107
108static __inline void
109outw (unsigned short int __value, unsigned short int __port)
110{
111 __asm__ __volatile__ ("outw %w0,%w1": :"a" (__value), "Nd" (__port));
112
113}
114
115static __inline void
116outw_p (unsigned short int __value, unsigned short int __port)
117{
118 __asm__ __volatile__ ("outw %w0,%w1\noutb %%al,$0x80": :"a" (__value),
119 "Nd" (__port));
120}
121
122static __inline void
123outl (unsigned int __value, unsigned short int __port)
124{
125 __asm__ __volatile__ ("outl %0,%w1": :"a" (__value), "Nd" (__port));
126}
127
128static __inline void
129outl_p (unsigned int __value, unsigned short int __port)
130{
131 __asm__ __volatile__ ("outl %0,%w1\noutb %%al,$0x80": :"a" (__value),
132 "Nd" (__port));
133}
134
135static __inline void
136insb (unsigned short int __port, void *__addr, unsigned long int __count)
137{
138 __asm__ __volatile__ ("cld ; rep ; insb":"=D" (__addr), "=c" (__count)
139 :"d" (__port), "0" (__addr), "1" (__count));
140}
141
142static __inline void
143insw (unsigned short int __port, void *__addr, unsigned long int __count)
144{
145 __asm__ __volatile__ ("cld ; rep ; insw":"=D" (__addr), "=c" (__count)
146 :"d" (__port), "0" (__addr), "1" (__count));
147}
148
149static __inline void
150insl (unsigned short int __port, void *__addr, unsigned long int __count)
151{
152 __asm__ __volatile__ ("cld ; rep ; insl":"=D" (__addr), "=c" (__count)
153 :"d" (__port), "0" (__addr), "1" (__count));
154}
155
156static __inline void
157outsb (unsigned short int __port, const void *__addr,
158 unsigned long int __count)
159{
160 __asm__ __volatile__ ("cld ; rep ; outsb":"=S" (__addr), "=c" (__count)
161 :"d" (__port), "0" (__addr), "1" (__count));
162}
163
164static __inline void
165outsw (unsigned short int __port, const void *__addr,
166 unsigned long int __count)
167{
168 __asm__ __volatile__ ("cld ; rep ; outsw":"=S" (__addr), "=c" (__count)
169 :"d" (__port), "0" (__addr), "1" (__count));
170}
171
172static __inline void
173outsl (unsigned short int __port, const void *__addr,
174 unsigned long int __count)
175{
176 __asm__ __volatile__ ("cld ; rep ; outsl":"=S" (__addr), "=c" (__count)
177 :"d" (__port), "0" (__addr), "1" (__count));
178}
179
180#endif /* GNU C */
181
182__END_DECLS
47183#endif /* _SYS_IO_H */
\ No newline at end of file
lib/libc/include/generic-glibc/sys/stropts.h deleted-1
......@@ -1 +0,0 @@
1#include <stropts.h>
\ No newline at end of file
lib/libc/include/generic-glibc/sys/sysctl.h+4-1
......@@ -18,6 +18,8 @@
1818#ifndef _SYS_SYSCTL_H
1919#define _SYS_SYSCTL_H 1
2020
21#warning "The <sys/sysctl.h> header is deprecated and will be removed."
22
2123#include <features.h>
2224#define __need_size_t
2325#include <stddef.h>
......@@ -66,7 +68,8 @@ __BEGIN_DECLS
6668
6769/* Read or write system parameters. */
6870extern int sysctl (int *__name, int __nlen, void *__oldval,
69 size_t *__oldlenp, void *__newval, size_t __newlen) __THROW;
71 size_t *__oldlenp, void *__newval, size_t __newlen) __THROW
72 __attribute_deprecated__;
7073
7174__END_DECLS
7275
lib/libc/include/generic-glibc/sys/types.h+8-25
......@@ -154,37 +154,20 @@ typedef unsigned int uint;
154154
155155#include <bits/stdint-intn.h>
156156
157#if !__GNUC_PREREQ (2, 7)
158
159157/* These were defined by ISO C without the first `_'. */
160typedef unsigned char u_int8_t;
161typedef unsigned short int u_int16_t;
162typedef unsigned int u_int32_t;
163# if __WORDSIZE == 64
164typedef unsigned long int u_int64_t;
165# else
166__extension__ typedef unsigned long long int u_int64_t;
167# endif
168
169typedef int register_t;
170
171#else
172
173/* For GCC 2.7 and later, we can use specific type-size attributes. */
174# define __u_intN_t(N, MODE) \
175 typedef unsigned int u_int##N##_t __attribute__ ((__mode__ (MODE)))
176
177__u_intN_t (8, __QI__);
178__u_intN_t (16, __HI__);
179__u_intN_t (32, __SI__);
180__u_intN_t (64, __DI__);
158typedef __uint8_t u_int8_t;
159typedef __uint16_t u_int16_t;
160typedef __uint32_t u_int32_t;
161typedef __uint64_t u_int64_t;
181162
163#if __GNUC_PREREQ (2, 7)
182164typedef int register_t __attribute__ ((__mode__ (__word__)));
183
165#else
166typedef int register_t;
167#endif
184168
185169/* Some code from BIND tests this macro to see if the types above are
186170 defined. */
187#endif
188171#define __BIT_TYPES_DEFINED__ 1
189172
190173
lib/libc/include/i386-linux-gnu/bits/math-vector-fortran.h deleted-43
......@@ -1,43 +0,0 @@
1! Platform-specific declarations of SIMD math functions for Fortran. -*- f90 -*-
2! Copyright (C) 2019 Free Software Foundation, Inc.
3! This file is part of the GNU C Library.
4!
5! The GNU C Library is free software; you can redistribute it and/or
6! modify it under the terms of the GNU Lesser General Public
7! License as published by the Free Software Foundation; either
8! version 2.1 of the License, or (at your option) any later version.
9!
10! The GNU C Library is distributed in the hope that it will be useful,
11! but WITHOUT ANY WARRANTY; without even the implied warranty of
12! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13! Lesser General Public License for more details.
14!
15! You should have received a copy of the GNU Lesser General Public
16! License along with the GNU C Library; if not, see
17! <http://www.gnu.org/licenses/>.
18
19!GCC$ builtin (cos) attributes simd (notinbranch) if('x86_64')
20!GCC$ builtin (cosf) attributes simd (notinbranch) if('x86_64')
21!GCC$ builtin (sin) attributes simd (notinbranch) if('x86_64')
22!GCC$ builtin (sinf) attributes simd (notinbranch) if('x86_64')
23!GCC$ builtin (sincos) attributes simd (notinbranch) if('x86_64')
24!GCC$ builtin (sincosf) attributes simd (notinbranch) if('x86_64')
25!GCC$ builtin (log) attributes simd (notinbranch) if('x86_64')
26!GCC$ builtin (logf) attributes simd (notinbranch) if('x86_64')
27!GCC$ builtin (exp) attributes simd (notinbranch) if('x86_64')
28!GCC$ builtin (expf) attributes simd (notinbranch) if('x86_64')
29!GCC$ builtin (pow) attributes simd (notinbranch) if('x86_64')
30!GCC$ builtin (powf) attributes simd (notinbranch) if('x86_64')
31
32!GCC$ builtin (cos) attributes simd (notinbranch) if('x32')
33!GCC$ builtin (cosf) attributes simd (notinbranch) if('x32')
34!GCC$ builtin (sin) attributes simd (notinbranch) if('x32')
35!GCC$ builtin (sinf) attributes simd (notinbranch) if('x32')
36!GCC$ builtin (sincos) attributes simd (notinbranch) if('x32')
37!GCC$ builtin (sincosf) attributes simd (notinbranch) if('x32')
38!GCC$ builtin (log) attributes simd (notinbranch) if('x32')
39!GCC$ builtin (logf) attributes simd (notinbranch) if('x32')
40!GCC$ builtin (exp) attributes simd (notinbranch) if('x32')
41!GCC$ builtin (expf) attributes simd (notinbranch) if('x32')
42!GCC$ builtin (pow) attributes simd (notinbranch) if('x32')
43!GCC$ builtin (powf) attributes simd (notinbranch) if('x32')
\ No newline at end of file
lib/libc/include/i386-linux-gnu/bits/xtitypes.h deleted-33
......@@ -1,33 +0,0 @@
1/* bits/xtitypes.h -- Define some types used by <bits/stropts.h>. x86-64.
2 Copyright (C) 2002-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#ifndef _STROPTS_H
20# error "Never include <bits/xtitypes.h> directly; use <stropts.h> instead."
21#endif
22
23#ifndef _BITS_XTITYPES_H
24#define _BITS_XTITYPES_H 1
25
26#include <bits/types.h>
27
28/* This type is used by some structs in <bits/stropts.h>. */
29typedef __SLONG32_TYPE __t_scalar_t;
30typedef __ULONG32_TYPE __t_uscalar_t;
31
32
33#endif /* bits/xtitypes.h */
\ No newline at end of file
lib/libc/include/i386-linux-gnu/finclude/math-vector-fortran.h created+43
......@@ -0,0 +1,43 @@
1! Platform-specific declarations of SIMD math functions for Fortran. -*- f90 -*-
2! Copyright (C) 2019 Free Software Foundation, Inc.
3! This file is part of the GNU C Library.
4!
5! The GNU C Library is free software; you can redistribute it and/or
6! modify it under the terms of the GNU Lesser General Public
7! License as published by the Free Software Foundation; either
8! version 2.1 of the License, or (at your option) any later version.
9!
10! The GNU C Library is distributed in the hope that it will be useful,
11! but WITHOUT ANY WARRANTY; without even the implied warranty of
12! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13! Lesser General Public License for more details.
14!
15! You should have received a copy of the GNU Lesser General Public
16! License along with the GNU C Library; if not, see
17! <http://www.gnu.org/licenses/>.
18
19!GCC$ builtin (cos) attributes simd (notinbranch) if('x86_64')
20!GCC$ builtin (cosf) attributes simd (notinbranch) if('x86_64')
21!GCC$ builtin (sin) attributes simd (notinbranch) if('x86_64')
22!GCC$ builtin (sinf) attributes simd (notinbranch) if('x86_64')
23!GCC$ builtin (sincos) attributes simd (notinbranch) if('x86_64')
24!GCC$ builtin (sincosf) attributes simd (notinbranch) if('x86_64')
25!GCC$ builtin (log) attributes simd (notinbranch) if('x86_64')
26!GCC$ builtin (logf) attributes simd (notinbranch) if('x86_64')
27!GCC$ builtin (exp) attributes simd (notinbranch) if('x86_64')
28!GCC$ builtin (expf) attributes simd (notinbranch) if('x86_64')
29!GCC$ builtin (pow) attributes simd (notinbranch) if('x86_64')
30!GCC$ builtin (powf) attributes simd (notinbranch) if('x86_64')
31
32!GCC$ builtin (cos) attributes simd (notinbranch) if('x32')
33!GCC$ builtin (cosf) attributes simd (notinbranch) if('x32')
34!GCC$ builtin (sin) attributes simd (notinbranch) if('x32')
35!GCC$ builtin (sinf) attributes simd (notinbranch) if('x32')
36!GCC$ builtin (sincos) attributes simd (notinbranch) if('x32')
37!GCC$ builtin (sincosf) attributes simd (notinbranch) if('x32')
38!GCC$ builtin (log) attributes simd (notinbranch) if('x32')
39!GCC$ builtin (logf) attributes simd (notinbranch) if('x32')
40!GCC$ builtin (exp) attributes simd (notinbranch) if('x32')
41!GCC$ builtin (expf) attributes simd (notinbranch) if('x32')
42!GCC$ builtin (pow) attributes simd (notinbranch) if('x32')
43!GCC$ builtin (powf) attributes simd (notinbranch) if('x32')
\ No newline at end of file
lib/libc/include/i386-linux-gnu/sys/io.h deleted-183
......@@ -1,183 +0,0 @@
1/* Copyright (C) 1996-2019 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
17
18#ifndef _SYS_IO_H
19#define _SYS_IO_H 1
20
21#include <features.h>
22
23__BEGIN_DECLS
24
25/* If TURN_ON is TRUE, request for permission to do direct i/o on the
26 port numbers in the range [FROM,FROM+NUM-1]. Otherwise, turn I/O
27 permission off for that range. This call requires root privileges.
28
29 Portability note: not all Linux platforms support this call. Most
30 platforms based on the PC I/O architecture probably will, however.
31 E.g., Linux/Alpha for Alpha PCs supports this. */
32extern int ioperm (unsigned long int __from, unsigned long int __num,
33 int __turn_on) __THROW;
34
35/* Set the I/O privilege level to LEVEL. If LEVEL>3, permission to
36 access any I/O port is granted. This call requires root
37 privileges. */
38extern int iopl (int __level) __THROW;
39
40#if defined __GNUC__ && __GNUC__ >= 2
41
42static __inline unsigned char
43inb (unsigned short int __port)
44{
45 unsigned char _v;
46
47 __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (__port));
48 return _v;
49}
50
51static __inline unsigned char
52inb_p (unsigned short int __port)
53{
54 unsigned char _v;
55
56 __asm__ __volatile__ ("inb %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (__port));
57 return _v;
58}
59
60static __inline unsigned short int
61inw (unsigned short int __port)
62{
63 unsigned short _v;
64
65 __asm__ __volatile__ ("inw %w1,%0":"=a" (_v):"Nd" (__port));
66 return _v;
67}
68
69static __inline unsigned short int
70inw_p (unsigned short int __port)
71{
72 unsigned short int _v;
73
74 __asm__ __volatile__ ("inw %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (__port));
75 return _v;
76}
77
78static __inline unsigned int
79inl (unsigned short int __port)
80{
81 unsigned int _v;
82
83 __asm__ __volatile__ ("inl %w1,%0":"=a" (_v):"Nd" (__port));
84 return _v;
85}
86
87static __inline unsigned int
88inl_p (unsigned short int __port)
89{
90 unsigned int _v;
91 __asm__ __volatile__ ("inl %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (__port));
92 return _v;
93}
94
95static __inline void
96outb (unsigned char __value, unsigned short int __port)
97{
98 __asm__ __volatile__ ("outb %b0,%w1": :"a" (__value), "Nd" (__port));
99}
100
101static __inline void
102outb_p (unsigned char __value, unsigned short int __port)
103{
104 __asm__ __volatile__ ("outb %b0,%w1\noutb %%al,$0x80": :"a" (__value),
105 "Nd" (__port));
106}
107
108static __inline void
109outw (unsigned short int __value, unsigned short int __port)
110{
111 __asm__ __volatile__ ("outw %w0,%w1": :"a" (__value), "Nd" (__port));
112
113}
114
115static __inline void
116outw_p (unsigned short int __value, unsigned short int __port)
117{
118 __asm__ __volatile__ ("outw %w0,%w1\noutb %%al,$0x80": :"a" (__value),
119 "Nd" (__port));
120}
121
122static __inline void
123outl (unsigned int __value, unsigned short int __port)
124{
125 __asm__ __volatile__ ("outl %0,%w1": :"a" (__value), "Nd" (__port));
126}
127
128static __inline void
129outl_p (unsigned int __value, unsigned short int __port)
130{
131 __asm__ __volatile__ ("outl %0,%w1\noutb %%al,$0x80": :"a" (__value),
132 "Nd" (__port));
133}
134
135static __inline void
136insb (unsigned short int __port, void *__addr, unsigned long int __count)
137{
138 __asm__ __volatile__ ("cld ; rep ; insb":"=D" (__addr), "=c" (__count)
139 :"d" (__port), "0" (__addr), "1" (__count));
140}
141
142static __inline void
143insw (unsigned short int __port, void *__addr, unsigned long int __count)
144{
145 __asm__ __volatile__ ("cld ; rep ; insw":"=D" (__addr), "=c" (__count)
146 :"d" (__port), "0" (__addr), "1" (__count));
147}
148
149static __inline void
150insl (unsigned short int __port, void *__addr, unsigned long int __count)
151{
152 __asm__ __volatile__ ("cld ; rep ; insl":"=D" (__addr), "=c" (__count)
153 :"d" (__port), "0" (__addr), "1" (__count));
154}
155
156static __inline void
157outsb (unsigned short int __port, const void *__addr,
158 unsigned long int __count)
159{
160 __asm__ __volatile__ ("cld ; rep ; outsb":"=S" (__addr), "=c" (__count)
161 :"d" (__port), "0" (__addr), "1" (__count));
162}
163
164static __inline void
165outsw (unsigned short int __port, const void *__addr,
166 unsigned long int __count)
167{
168 __asm__ __volatile__ ("cld ; rep ; outsw":"=S" (__addr), "=c" (__count)
169 :"d" (__port), "0" (__addr), "1" (__count));
170}
171
172static __inline void
173outsl (unsigned short int __port, const void *__addr,
174 unsigned long int __count)
175{
176 __asm__ __volatile__ ("cld ; rep ; outsl":"=S" (__addr), "=c" (__count)
177 :"d" (__port), "0" (__addr), "1" (__count));
178}
179
180#endif /* GNU C */
181
182__END_DECLS
183#endif /* _SYS_IO_H */
\ No newline at end of file
lib/libc/include/mips-linux-gnu/bits/socket-constants.h created+38
......@@ -0,0 +1,38 @@
1/* Socket constants which vary among Linux architectures. Version for MIPS.
2 Copyright (C) 2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#ifndef _SYS_SOCKET_H
20# error "Never include <bits/socket-constants.h> directly; use <sys/socket.h> instead."
21#endif
22
23#define SOL_SOCKET 65535
24#define SO_ACCEPTCONN 4105
25#define SO_BROADCAST 32
26#define SO_DONTROUTE 16
27#define SO_ERROR 4103
28#define SO_KEEPALIVE 8
29#define SO_LINGER 128
30#define SO_OOBINLINE 256
31#define SO_RCVBUF 4098
32#define SO_RCVLOWAT 4100
33#define SO_RCVTIMEO 4102
34#define SO_REUSEADDR 4
35#define SO_SNDBUF 4097
36#define SO_SNDLOWAT 4099
37#define SO_SNDTIMEO 4101
38#define SO_TYPE 4104
\ No newline at end of file
lib/libc/include/mips64-linux-gnuabi64/bits/socket-constants.h created+38
......@@ -0,0 +1,38 @@
1/* Socket constants which vary among Linux architectures. Version for MIPS.
2 Copyright (C) 2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#ifndef _SYS_SOCKET_H
20# error "Never include <bits/socket-constants.h> directly; use <sys/socket.h> instead."
21#endif
22
23#define SOL_SOCKET 65535
24#define SO_ACCEPTCONN 4105
25#define SO_BROADCAST 32
26#define SO_DONTROUTE 16
27#define SO_ERROR 4103
28#define SO_KEEPALIVE 8
29#define SO_LINGER 128
30#define SO_OOBINLINE 256
31#define SO_RCVBUF 4098
32#define SO_RCVLOWAT 4100
33#define SO_RCVTIMEO 4102
34#define SO_REUSEADDR 4
35#define SO_SNDBUF 4097
36#define SO_SNDLOWAT 4099
37#define SO_SNDTIMEO 4101
38#define SO_TYPE 4104
\ No newline at end of file
lib/libc/include/mips64-linux-gnuabin32/bits/socket-constants.h created+38
......@@ -0,0 +1,38 @@
1/* Socket constants which vary among Linux architectures. Version for MIPS.
2 Copyright (C) 2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#ifndef _SYS_SOCKET_H
20# error "Never include <bits/socket-constants.h> directly; use <sys/socket.h> instead."
21#endif
22
23#define SOL_SOCKET 65535
24#define SO_ACCEPTCONN 4105
25#define SO_BROADCAST 32
26#define SO_DONTROUTE 16
27#define SO_ERROR 4103
28#define SO_KEEPALIVE 8
29#define SO_LINGER 128
30#define SO_OOBINLINE 256
31#define SO_RCVBUF 4098
32#define SO_RCVLOWAT 4100
33#define SO_RCVTIMEO 4102
34#define SO_REUSEADDR 4
35#define SO_SNDBUF 4097
36#define SO_SNDLOWAT 4099
37#define SO_SNDTIMEO 4101
38#define SO_TYPE 4104
\ No newline at end of file
lib/libc/include/mips64el-linux-gnuabi64/bits/socket-constants.h created+38
......@@ -0,0 +1,38 @@
1/* Socket constants which vary among Linux architectures. Version for MIPS.
2 Copyright (C) 2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#ifndef _SYS_SOCKET_H
20# error "Never include <bits/socket-constants.h> directly; use <sys/socket.h> instead."
21#endif
22
23#define SOL_SOCKET 65535
24#define SO_ACCEPTCONN 4105
25#define SO_BROADCAST 32
26#define SO_DONTROUTE 16
27#define SO_ERROR 4103
28#define SO_KEEPALIVE 8
29#define SO_LINGER 128
30#define SO_OOBINLINE 256
31#define SO_RCVBUF 4098
32#define SO_RCVLOWAT 4100
33#define SO_RCVTIMEO 4102
34#define SO_REUSEADDR 4
35#define SO_SNDBUF 4097
36#define SO_SNDLOWAT 4099
37#define SO_SNDTIMEO 4101
38#define SO_TYPE 4104
\ No newline at end of file
lib/libc/include/mips64el-linux-gnuabin32/bits/socket-constants.h created+38
......@@ -0,0 +1,38 @@
1/* Socket constants which vary among Linux architectures. Version for MIPS.
2 Copyright (C) 2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#ifndef _SYS_SOCKET_H
20# error "Never include <bits/socket-constants.h> directly; use <sys/socket.h> instead."
21#endif
22
23#define SOL_SOCKET 65535
24#define SO_ACCEPTCONN 4105
25#define SO_BROADCAST 32
26#define SO_DONTROUTE 16
27#define SO_ERROR 4103
28#define SO_KEEPALIVE 8
29#define SO_LINGER 128
30#define SO_OOBINLINE 256
31#define SO_RCVBUF 4098
32#define SO_RCVLOWAT 4100
33#define SO_RCVTIMEO 4102
34#define SO_REUSEADDR 4
35#define SO_SNDBUF 4097
36#define SO_SNDLOWAT 4099
37#define SO_SNDTIMEO 4101
38#define SO_TYPE 4104
\ No newline at end of file
lib/libc/include/mipsel-linux-gnu/bits/socket-constants.h created+38
......@@ -0,0 +1,38 @@
1/* Socket constants which vary among Linux architectures. Version for MIPS.
2 Copyright (C) 2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#ifndef _SYS_SOCKET_H
20# error "Never include <bits/socket-constants.h> directly; use <sys/socket.h> instead."
21#endif
22
23#define SOL_SOCKET 65535
24#define SO_ACCEPTCONN 4105
25#define SO_BROADCAST 32
26#define SO_DONTROUTE 16
27#define SO_ERROR 4103
28#define SO_KEEPALIVE 8
29#define SO_LINGER 128
30#define SO_OOBINLINE 256
31#define SO_RCVBUF 4098
32#define SO_RCVLOWAT 4100
33#define SO_RCVTIMEO 4102
34#define SO_REUSEADDR 4
35#define SO_SNDBUF 4097
36#define SO_SNDLOWAT 4099
37#define SO_SNDTIMEO 4101
38#define SO_TYPE 4104
\ No newline at end of file
lib/libc/include/powerpc-linux-gnu/bits/fenvinline.h+30-7
......@@ -18,13 +18,36 @@
1818
1919#if defined __GNUC__ && !defined _SOFT_FLOAT && !defined __NO_FPRS__
2020
21/* Inline definition for fegetround. */
22# define __fegetround() \
23 (__extension__ ({ int __fegetround_result; \
24 __asm__ __volatile__ \
25 ("mcrfs 7,7 ; mfcr %0" \
26 : "=r"(__fegetround_result) : : "cr7"); \
27 __fegetround_result & 3; }))
21/* Inline definitions for fegetround. */
22# define __fegetround_ISA300() \
23 (__extension__ ({ \
24 union { double __d; unsigned long long __ll; } __u; \
25 __asm__ __volatile__ ( \
26 ".machine push; .machine \"power9\"; mffsl %0; .machine pop" \
27 : "=f" (__u.__d)); \
28 __u.__ll & 0x0000000000000003LL; \
29 }))
30
31# define __fegetround_ISA2() \
32 (__extension__ ({ \
33 int __fegetround_result; \
34 __asm__ __volatile__ ("mcrfs 7,7 ; mfcr %0" \
35 : "=r"(__fegetround_result) : : "cr7"); \
36 __fegetround_result & 3; \
37 }))
38
39# ifdef _ARCH_PWR9
40# define __fegetround() __fegetround_ISA300()
41# elif defined __BUILTIN_CPU_SUPPORTS__
42# define __fegetround() \
43 (__glibc_likely (__builtin_cpu_supports ("arch_3_00")) \
44 ? __fegetround_ISA300() \
45 : __fegetround_ISA2() \
46 )
47# else
48# define __fegetround() __fegetround_ISA2()
49# endif
50
2851# define fegetround() __fegetround ()
2952
3053# ifndef __NO_MATH_INLINES
lib/libc/include/powerpc-linux-gnu/bits/socket-constants.h created+38
......@@ -0,0 +1,38 @@
1/* Socket constants which vary among Linux architectures. Version for POWER.
2 Copyright (C) 2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#ifndef _SYS_SOCKET_H
20# error "Never include <bits/socket-constants.h> directly; use <sys/socket.h> instead."
21#endif
22
23#define SOL_SOCKET 1
24#define SO_ACCEPTCONN 30
25#define SO_BROADCAST 6
26#define SO_DONTROUTE 5
27#define SO_ERROR 4
28#define SO_KEEPALIVE 9
29#define SO_LINGER 13
30#define SO_OOBINLINE 10
31#define SO_RCVBUF 8
32#define SO_RCVLOWAT 16
33#define SO_RCVTIMEO 18
34#define SO_REUSEADDR 2
35#define SO_SNDBUF 7
36#define SO_SNDLOWAT 17
37#define SO_SNDTIMEO 19
38#define SO_TYPE 3
\ No newline at end of file
lib/libc/include/powerpc-linux-gnu/fpu_control.h+33-39
......@@ -19,6 +19,10 @@
1919#ifndef _FPU_CONTROL_H
2020#define _FPU_CONTROL_H
2121
22#if defined __SPE__ || (defined __NO_FPRS__ && !defined _SOFT_FLOAT)
23# error "SPE/e500 is no longer supported"
24#endif
25
2226#ifdef _SOFT_FLOAT
2327
2428# define _FPU_RESERVED 0xffffffff
......@@ -28,41 +32,6 @@ typedef unsigned int fpu_control_t;
2832# define _FPU_SETCW(cw) (void) (cw)
2933extern fpu_control_t __fpu_control;
3034
31#elif defined __NO_FPRS__ /* e500 */
32
33/* rounding control */
34# define _FPU_RC_NEAREST 0x00 /* RECOMMENDED */
35# define _FPU_RC_DOWN 0x03
36# define _FPU_RC_UP 0x02
37# define _FPU_RC_ZERO 0x01
38
39/* masking of interrupts */
40# define _FPU_MASK_ZM 0x10 /* zero divide */
41# define _FPU_MASK_OM 0x04 /* overflow */
42# define _FPU_MASK_UM 0x08 /* underflow */
43# define _FPU_MASK_XM 0x40 /* inexact */
44# define _FPU_MASK_IM 0x20 /* invalid operation */
45
46# define _FPU_RESERVED 0x00c10080 /* These bits are reserved and not changed. */
47
48/* Correct IEEE semantics require traps to be enabled at the hardware
49 level; the kernel then does the emulation and determines whether
50 generation of signals from those traps was enabled using prctl. */
51# define _FPU_DEFAULT 0x0000003c /* Default value. */
52# define _FPU_IEEE _FPU_DEFAULT
53
54/* Type of the control word. */
55typedef unsigned int fpu_control_t;
56
57/* Macros for accessing the hardware control word. */
58# define _FPU_GETCW(cw) \
59 __asm__ volatile ("mfspefscr %0" : "=r" (cw))
60# define _FPU_SETCW(cw) \
61 __asm__ volatile ("mtspefscr %0" : : "r" (cw))
62
63/* Default control word set at startup. */
64extern fpu_control_t __fpu_control;
65
6635#else /* PowerPC 6xx floating-point. */
6736
6837/* rounding control */
......@@ -71,6 +40,8 @@ extern fpu_control_t __fpu_control;
7140# define _FPU_RC_UP 0x02
7241# define _FPU_RC_ZERO 0x01
7342
43# define _FPU_MASK_RC (_FPU_RC_NEAREST|_FPU_RC_DOWN|_FPU_RC_UP|_FPU_RC_ZERO)
44
7445# define _FPU_MASK_NI 0x04 /* non-ieee mode */
7546
7647/* masking of interrupts */
......@@ -96,20 +67,43 @@ typedef unsigned int fpu_control_t;
9667/* Macros for accessing the hardware control word. */
9768# define _FPU_GETCW(cw) \
9869 ({union { double __d; unsigned long long __ll; } __u; \
99 register double __fr; \
100 __asm__ ("mffs %0" : "=f" (__fr)); \
101 __u.__d = __fr; \
70 __asm__ __volatile__("mffs %0" : "=f" (__u.__d)); \
10271 (cw) = (fpu_control_t) __u.__ll; \
10372 (fpu_control_t) __u.__ll; \
10473 })
10574
75# define _FPU_GET_RC_ISA300() \
76 ({union { double __d; unsigned long long __ll; } __u; \
77 __asm__ __volatile__( \
78 ".machine push; .machine \"power9\"; mffsl %0; .machine pop" \
79 : "=f" (__u.__d)); \
80 (fpu_control_t) (__u.__ll & _FPU_MASK_RC); \
81 })
82
83# ifdef _ARCH_PWR9
84# define _FPU_GET_RC() _FPU_GET_RC_ISA300()
85# elif defined __BUILTIN_CPU_SUPPORTS__
86# define _FPU_GET_RC() \
87 ({fpu_control_t __rc; \
88 __rc = __glibc_likely (__builtin_cpu_supports ("arch_3_00")) \
89 ? _FPU_GET_RC_ISA300 () \
90 : _FPU_GETCW (__rc) & _FPU_MASK_RC; \
91 __rc; \
92 })
93# else
94# define _FPU_GET_RC() \
95 ({fpu_control_t __rc = _FPU_GETCW (__rc) & _FPU_MASK_RC; \
96 __rc; \
97 })
98# endif
99
106100# define _FPU_SETCW(cw) \
107101 { union { double __d; unsigned long long __ll; } __u; \
108102 register double __fr; \
109103 __u.__ll = 0xfff80000LL << 32; /* This is a QNaN. */ \
110104 __u.__ll |= (cw) & 0xffffffffLL; \
111105 __fr = __u.__d; \
112 __asm__ ("mtfsf 255,%0" : : "f" (__fr)); \
106 __asm__ __volatile__("mtfsf 255,%0" : : "f" (__fr)); \
113107 }
114108
115109/* Default control word set at startup. */
lib/libc/include/powerpc64-linux-gnu/bits/fenvinline.h+30-7
......@@ -18,13 +18,36 @@
1818
1919#if defined __GNUC__ && !defined _SOFT_FLOAT && !defined __NO_FPRS__
2020
21/* Inline definition for fegetround. */
22# define __fegetround() \
23 (__extension__ ({ int __fegetround_result; \
24 __asm__ __volatile__ \
25 ("mcrfs 7,7 ; mfcr %0" \
26 : "=r"(__fegetround_result) : : "cr7"); \
27 __fegetround_result & 3; }))
21/* Inline definitions for fegetround. */
22# define __fegetround_ISA300() \
23 (__extension__ ({ \
24 union { double __d; unsigned long long __ll; } __u; \
25 __asm__ __volatile__ ( \
26 ".machine push; .machine \"power9\"; mffsl %0; .machine pop" \
27 : "=f" (__u.__d)); \
28 __u.__ll & 0x0000000000000003LL; \
29 }))
30
31# define __fegetround_ISA2() \
32 (__extension__ ({ \
33 int __fegetround_result; \
34 __asm__ __volatile__ ("mcrfs 7,7 ; mfcr %0" \
35 : "=r"(__fegetround_result) : : "cr7"); \
36 __fegetround_result & 3; \
37 }))
38
39# ifdef _ARCH_PWR9
40# define __fegetround() __fegetround_ISA300()
41# elif defined __BUILTIN_CPU_SUPPORTS__
42# define __fegetround() \
43 (__glibc_likely (__builtin_cpu_supports ("arch_3_00")) \
44 ? __fegetround_ISA300() \
45 : __fegetround_ISA2() \
46 )
47# else
48# define __fegetround() __fegetround_ISA2()
49# endif
50
2851# define fegetround() __fegetround ()
2952
3053# ifndef __NO_MATH_INLINES
lib/libc/include/powerpc64-linux-gnu/bits/socket-constants.h created+38
......@@ -0,0 +1,38 @@
1/* Socket constants which vary among Linux architectures. Version for POWER.
2 Copyright (C) 2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#ifndef _SYS_SOCKET_H
20# error "Never include <bits/socket-constants.h> directly; use <sys/socket.h> instead."
21#endif
22
23#define SOL_SOCKET 1
24#define SO_ACCEPTCONN 30
25#define SO_BROADCAST 6
26#define SO_DONTROUTE 5
27#define SO_ERROR 4
28#define SO_KEEPALIVE 9
29#define SO_LINGER 13
30#define SO_OOBINLINE 10
31#define SO_RCVBUF 8
32#define SO_RCVLOWAT 16
33#define SO_RCVTIMEO 18
34#define SO_REUSEADDR 2
35#define SO_SNDBUF 7
36#define SO_SNDLOWAT 17
37#define SO_SNDTIMEO 19
38#define SO_TYPE 3
\ No newline at end of file
lib/libc/include/powerpc64-linux-gnu/fpu_control.h+33-39
......@@ -19,6 +19,10 @@
1919#ifndef _FPU_CONTROL_H
2020#define _FPU_CONTROL_H
2121
22#if defined __SPE__ || (defined __NO_FPRS__ && !defined _SOFT_FLOAT)
23# error "SPE/e500 is no longer supported"
24#endif
25
2226#ifdef _SOFT_FLOAT
2327
2428# define _FPU_RESERVED 0xffffffff
......@@ -28,41 +32,6 @@ typedef unsigned int fpu_control_t;
2832# define _FPU_SETCW(cw) (void) (cw)
2933extern fpu_control_t __fpu_control;
3034
31#elif defined __NO_FPRS__ /* e500 */
32
33/* rounding control */
34# define _FPU_RC_NEAREST 0x00 /* RECOMMENDED */
35# define _FPU_RC_DOWN 0x03
36# define _FPU_RC_UP 0x02
37# define _FPU_RC_ZERO 0x01
38
39/* masking of interrupts */
40# define _FPU_MASK_ZM 0x10 /* zero divide */
41# define _FPU_MASK_OM 0x04 /* overflow */
42# define _FPU_MASK_UM 0x08 /* underflow */
43# define _FPU_MASK_XM 0x40 /* inexact */
44# define _FPU_MASK_IM 0x20 /* invalid operation */
45
46# define _FPU_RESERVED 0x00c10080 /* These bits are reserved and not changed. */
47
48/* Correct IEEE semantics require traps to be enabled at the hardware
49 level; the kernel then does the emulation and determines whether
50 generation of signals from those traps was enabled using prctl. */
51# define _FPU_DEFAULT 0x0000003c /* Default value. */
52# define _FPU_IEEE _FPU_DEFAULT
53
54/* Type of the control word. */
55typedef unsigned int fpu_control_t;
56
57/* Macros for accessing the hardware control word. */
58# define _FPU_GETCW(cw) \
59 __asm__ volatile ("mfspefscr %0" : "=r" (cw))
60# define _FPU_SETCW(cw) \
61 __asm__ volatile ("mtspefscr %0" : : "r" (cw))
62
63/* Default control word set at startup. */
64extern fpu_control_t __fpu_control;
65
6635#else /* PowerPC 6xx floating-point. */
6736
6837/* rounding control */
......@@ -71,6 +40,8 @@ extern fpu_control_t __fpu_control;
7140# define _FPU_RC_UP 0x02
7241# define _FPU_RC_ZERO 0x01
7342
43# define _FPU_MASK_RC (_FPU_RC_NEAREST|_FPU_RC_DOWN|_FPU_RC_UP|_FPU_RC_ZERO)
44
7445# define _FPU_MASK_NI 0x04 /* non-ieee mode */
7546
7647/* masking of interrupts */
......@@ -96,20 +67,43 @@ typedef unsigned int fpu_control_t;
9667/* Macros for accessing the hardware control word. */
9768# define _FPU_GETCW(cw) \
9869 ({union { double __d; unsigned long long __ll; } __u; \
99 register double __fr; \
100 __asm__ ("mffs %0" : "=f" (__fr)); \
101 __u.__d = __fr; \
70 __asm__ __volatile__("mffs %0" : "=f" (__u.__d)); \
10271 (cw) = (fpu_control_t) __u.__ll; \
10372 (fpu_control_t) __u.__ll; \
10473 })
10574
75# define _FPU_GET_RC_ISA300() \
76 ({union { double __d; unsigned long long __ll; } __u; \
77 __asm__ __volatile__( \
78 ".machine push; .machine \"power9\"; mffsl %0; .machine pop" \
79 : "=f" (__u.__d)); \
80 (fpu_control_t) (__u.__ll & _FPU_MASK_RC); \
81 })
82
83# ifdef _ARCH_PWR9
84# define _FPU_GET_RC() _FPU_GET_RC_ISA300()
85# elif defined __BUILTIN_CPU_SUPPORTS__
86# define _FPU_GET_RC() \
87 ({fpu_control_t __rc; \
88 __rc = __glibc_likely (__builtin_cpu_supports ("arch_3_00")) \
89 ? _FPU_GET_RC_ISA300 () \
90 : _FPU_GETCW (__rc) & _FPU_MASK_RC; \
91 __rc; \
92 })
93# else
94# define _FPU_GET_RC() \
95 ({fpu_control_t __rc = _FPU_GETCW (__rc) & _FPU_MASK_RC; \
96 __rc; \
97 })
98# endif
99
106100# define _FPU_SETCW(cw) \
107101 { union { double __d; unsigned long long __ll; } __u; \
108102 register double __fr; \
109103 __u.__ll = 0xfff80000LL << 32; /* This is a QNaN. */ \
110104 __u.__ll |= (cw) & 0xffffffffLL; \
111105 __fr = __u.__d; \
112 __asm__ ("mtfsf 255,%0" : : "f" (__fr)); \
106 __asm__ __volatile__("mtfsf 255,%0" : : "f" (__fr)); \
113107 }
114108
115109/* Default control word set at startup. */
lib/libc/include/powerpc64-linux-gnu/gnu/stubs-64-v1.h-2
......@@ -8,9 +8,7 @@
88#endif
99
1010#define __stub_chflags
11#define __stub_fattach
1211#define __stub_fchflags
13#define __stub_fdetach
1412#define __stub_gtty
1513#define __stub_lchmod
1614#define __stub_revoke
lib/libc/include/powerpc64le-linux-gnu/bits/fenvinline.h+30-7
......@@ -18,13 +18,36 @@
1818
1919#if defined __GNUC__ && !defined _SOFT_FLOAT && !defined __NO_FPRS__
2020
21/* Inline definition for fegetround. */
22# define __fegetround() \
23 (__extension__ ({ int __fegetround_result; \
24 __asm__ __volatile__ \
25 ("mcrfs 7,7 ; mfcr %0" \
26 : "=r"(__fegetround_result) : : "cr7"); \
27 __fegetround_result & 3; }))
21/* Inline definitions for fegetround. */
22# define __fegetround_ISA300() \
23 (__extension__ ({ \
24 union { double __d; unsigned long long __ll; } __u; \
25 __asm__ __volatile__ ( \
26 ".machine push; .machine \"power9\"; mffsl %0; .machine pop" \
27 : "=f" (__u.__d)); \
28 __u.__ll & 0x0000000000000003LL; \
29 }))
30
31# define __fegetround_ISA2() \
32 (__extension__ ({ \
33 int __fegetround_result; \
34 __asm__ __volatile__ ("mcrfs 7,7 ; mfcr %0" \
35 : "=r"(__fegetround_result) : : "cr7"); \
36 __fegetround_result & 3; \
37 }))
38
39# ifdef _ARCH_PWR9
40# define __fegetround() __fegetround_ISA300()
41# elif defined __BUILTIN_CPU_SUPPORTS__
42# define __fegetround() \
43 (__glibc_likely (__builtin_cpu_supports ("arch_3_00")) \
44 ? __fegetround_ISA300() \
45 : __fegetround_ISA2() \
46 )
47# else
48# define __fegetround() __fegetround_ISA2()
49# endif
50
2851# define fegetround() __fegetround ()
2952
3053# ifndef __NO_MATH_INLINES
lib/libc/include/powerpc64le-linux-gnu/bits/socket-constants.h created+38
......@@ -0,0 +1,38 @@
1/* Socket constants which vary among Linux architectures. Version for POWER.
2 Copyright (C) 2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#ifndef _SYS_SOCKET_H
20# error "Never include <bits/socket-constants.h> directly; use <sys/socket.h> instead."
21#endif
22
23#define SOL_SOCKET 1
24#define SO_ACCEPTCONN 30
25#define SO_BROADCAST 6
26#define SO_DONTROUTE 5
27#define SO_ERROR 4
28#define SO_KEEPALIVE 9
29#define SO_LINGER 13
30#define SO_OOBINLINE 10
31#define SO_RCVBUF 8
32#define SO_RCVLOWAT 16
33#define SO_RCVTIMEO 18
34#define SO_REUSEADDR 2
35#define SO_SNDBUF 7
36#define SO_SNDLOWAT 17
37#define SO_SNDTIMEO 19
38#define SO_TYPE 3
\ No newline at end of file
lib/libc/include/powerpc64le-linux-gnu/fpu_control.h+33-39
......@@ -19,6 +19,10 @@
1919#ifndef _FPU_CONTROL_H
2020#define _FPU_CONTROL_H
2121
22#if defined __SPE__ || (defined __NO_FPRS__ && !defined _SOFT_FLOAT)
23# error "SPE/e500 is no longer supported"
24#endif
25
2226#ifdef _SOFT_FLOAT
2327
2428# define _FPU_RESERVED 0xffffffff
......@@ -28,41 +32,6 @@ typedef unsigned int fpu_control_t;
2832# define _FPU_SETCW(cw) (void) (cw)
2933extern fpu_control_t __fpu_control;
3034
31#elif defined __NO_FPRS__ /* e500 */
32
33/* rounding control */
34# define _FPU_RC_NEAREST 0x00 /* RECOMMENDED */
35# define _FPU_RC_DOWN 0x03
36# define _FPU_RC_UP 0x02
37# define _FPU_RC_ZERO 0x01
38
39/* masking of interrupts */
40# define _FPU_MASK_ZM 0x10 /* zero divide */
41# define _FPU_MASK_OM 0x04 /* overflow */
42# define _FPU_MASK_UM 0x08 /* underflow */
43# define _FPU_MASK_XM 0x40 /* inexact */
44# define _FPU_MASK_IM 0x20 /* invalid operation */
45
46# define _FPU_RESERVED 0x00c10080 /* These bits are reserved and not changed. */
47
48/* Correct IEEE semantics require traps to be enabled at the hardware
49 level; the kernel then does the emulation and determines whether
50 generation of signals from those traps was enabled using prctl. */
51# define _FPU_DEFAULT 0x0000003c /* Default value. */
52# define _FPU_IEEE _FPU_DEFAULT
53
54/* Type of the control word. */
55typedef unsigned int fpu_control_t;
56
57/* Macros for accessing the hardware control word. */
58# define _FPU_GETCW(cw) \
59 __asm__ volatile ("mfspefscr %0" : "=r" (cw))
60# define _FPU_SETCW(cw) \
61 __asm__ volatile ("mtspefscr %0" : : "r" (cw))
62
63/* Default control word set at startup. */
64extern fpu_control_t __fpu_control;
65
6635#else /* PowerPC 6xx floating-point. */
6736
6837/* rounding control */
......@@ -71,6 +40,8 @@ extern fpu_control_t __fpu_control;
7140# define _FPU_RC_UP 0x02
7241# define _FPU_RC_ZERO 0x01
7342
43# define _FPU_MASK_RC (_FPU_RC_NEAREST|_FPU_RC_DOWN|_FPU_RC_UP|_FPU_RC_ZERO)
44
7445# define _FPU_MASK_NI 0x04 /* non-ieee mode */
7546
7647/* masking of interrupts */
......@@ -96,20 +67,43 @@ typedef unsigned int fpu_control_t;
9667/* Macros for accessing the hardware control word. */
9768# define _FPU_GETCW(cw) \
9869 ({union { double __d; unsigned long long __ll; } __u; \
99 register double __fr; \
100 __asm__ ("mffs %0" : "=f" (__fr)); \
101 __u.__d = __fr; \
70 __asm__ __volatile__("mffs %0" : "=f" (__u.__d)); \
10271 (cw) = (fpu_control_t) __u.__ll; \
10372 (fpu_control_t) __u.__ll; \
10473 })
10574
75# define _FPU_GET_RC_ISA300() \
76 ({union { double __d; unsigned long long __ll; } __u; \
77 __asm__ __volatile__( \
78 ".machine push; .machine \"power9\"; mffsl %0; .machine pop" \
79 : "=f" (__u.__d)); \
80 (fpu_control_t) (__u.__ll & _FPU_MASK_RC); \
81 })
82
83# ifdef _ARCH_PWR9
84# define _FPU_GET_RC() _FPU_GET_RC_ISA300()
85# elif defined __BUILTIN_CPU_SUPPORTS__
86# define _FPU_GET_RC() \
87 ({fpu_control_t __rc; \
88 __rc = __glibc_likely (__builtin_cpu_supports ("arch_3_00")) \
89 ? _FPU_GET_RC_ISA300 () \
90 : _FPU_GETCW (__rc) & _FPU_MASK_RC; \
91 __rc; \
92 })
93# else
94# define _FPU_GET_RC() \
95 ({fpu_control_t __rc = _FPU_GETCW (__rc) & _FPU_MASK_RC; \
96 __rc; \
97 })
98# endif
99
106100# define _FPU_SETCW(cw) \
107101 { union { double __d; unsigned long long __ll; } __u; \
108102 register double __fr; \
109103 __u.__ll = 0xfff80000LL << 32; /* This is a QNaN. */ \
110104 __u.__ll |= (cw) & 0xffffffffLL; \
111105 __fr = __u.__d; \
112 __asm__ ("mtfsf 255,%0" : : "f" (__fr)); \
106 __asm__ __volatile__("mtfsf 255,%0" : : "f" (__fr)); \
113107 }
114108
115109/* Default control word set at startup. */
lib/libc/include/powerpc64le-linux-gnu/gnu/stubs-64-v2.h-2
......@@ -8,9 +8,7 @@
88#endif
99
1010#define __stub_chflags
11#define __stub_fattach
1211#define __stub_fchflags
13#define __stub_fdetach
1412#define __stub_gtty
1513#define __stub_lchmod
1614#define __stub_revoke
lib/libc/include/riscv64-linux-gnu/gnu/stubs-lp64.h-6
......@@ -13,9 +13,7 @@
1313#define __stub___compat_query_module
1414#define __stub___compat_uselib
1515#define __stub_chflags
16#define __stub_fattach
1716#define __stub_fchflags
18#define __stub_fdetach
1917#define __stub_feclearexcept
2018#define __stub_fedisableexcept
2119#define __stub_feenableexcept
......@@ -33,12 +31,8 @@
3331#define __stub_fesetround
3432#define __stub_fetestexcept
3533#define __stub_feupdateenv
36#define __stub_getmsg
37#define __stub_getpmsg
3834#define __stub_gtty
3935#define __stub_lchmod
40#define __stub_putmsg
41#define __stub_putpmsg
4236#define __stub_revoke
4337#define __stub_setlogin
4438#define __stub_sigreturn
lib/libc/include/s390x-linux-gnu/bits/hwcap.h+5-1
......@@ -38,4 +38,8 @@
3838#define HWCAP_S390_VX 2048
3939#define HWCAP_S390_VXD 4096
4040#define HWCAP_S390_VXE 8192
41#define HWCAP_S390_GS 16384
\ No newline at end of file
41#define HWCAP_S390_GS 16384
42#define HWCAP_S390_VXRS_EXT2 32768
43#define HWCAP_S390_VXRS_PDE 65536
44#define HWCAP_S390_SORT 131072
45#define HWCAP_S390_DFLT 262144
\ No newline at end of file
lib/libc/include/s390x-linux-gnu/bits/xtitypes.h deleted-33
......@@ -1,33 +0,0 @@
1/* bits/xtitypes.h -- Define some types used by <bits/stropts.h>. S390/S390x
2 Copyright (C) 2002-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#ifndef _STROPTS_H
20# error "Never include <bits/xtitypes.h> directly; use <stropts.h> instead."
21#endif
22
23#ifndef _BITS_XTITYPES_H
24#define _BITS_XTITYPES_H 1
25
26#include <bits/types.h>
27
28/* This type is used by some structs in <bits/stropts.h>. */
29typedef __S32_TYPE __t_scalar_t;
30typedef __U32_TYPE __t_uscalar_t;
31
32
33#endif /* bits/xtitypes.h */
\ No newline at end of file
lib/libc/include/s390x-linux-gnu/gnu/stubs-64.h deleted-24
......@@ -1,24 +0,0 @@
1/* This file is automatically generated.
2 It defines a symbol `__stub_FUNCTION' for each function
3 in the C library which is a stub, meaning it will fail
4 every time called, usually setting errno to ENOSYS. */
5
6#ifdef _LIBC
7 #error Applications may not define the macro _LIBC
8#endif
9
10#define __stub_chflags
11#define __stub_fattach
12#define __stub_fchflags
13#define __stub_fdetach
14#define __stub_getmsg
15#define __stub_gtty
16#define __stub_lchmod
17#define __stub_pkey_alloc
18#define __stub_pkey_free
19#define __stub_putmsg
20#define __stub_revoke
21#define __stub_setlogin
22#define __stub_sigreturn
23#define __stub_sstk
24#define __stub_stty
\ No newline at end of file
lib/libc/include/sparc-linux-gnu/bits/socket-constants.h created+38
......@@ -0,0 +1,38 @@
1/* Socket constants which vary among Linux architectures. Version for SPARC.
2 Copyright (C) 2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#ifndef _SYS_SOCKET_H
20# error "Never include <bits/socket-constants.h> directly; use <sys/socket.h> instead."
21#endif
22
23#define SOL_SOCKET 65535
24#define SO_ACCEPTCONN 32768
25#define SO_BROADCAST 32
26#define SO_DONTROUTE 16
27#define SO_ERROR 4103
28#define SO_KEEPALIVE 8
29#define SO_LINGER 128
30#define SO_OOBINLINE 256
31#define SO_RCVBUF 4098
32#define SO_RCVLOWAT 2048
33#define SO_RCVTIMEO 8192
34#define SO_REUSEADDR 4
35#define SO_SNDBUF 4097
36#define SO_SNDLOWAT 4096
37#define SO_SNDTIMEO 16384
38#define SO_TYPE 4104
\ No newline at end of file
lib/libc/include/sparc-linux-gnu/gnu/stubs-64.h deleted-26
......@@ -1,26 +0,0 @@
1/* This file is automatically generated.
2 It defines a symbol `__stub_FUNCTION' for each function
3 in the C library which is a stub, meaning it will fail
4 every time called, usually setting errno to ENOSYS. */
5
6#ifdef _LIBC
7 #error Applications may not define the macro _LIBC
8#endif
9
10#define __stub_chflags
11#define __stub_fattach
12#define __stub_fchflags
13#define __stub_fdetach
14#define __stub_getmsg
15#define __stub_getpmsg
16#define __stub_gtty
17#define __stub_lchmod
18#define __stub_pkey_alloc
19#define __stub_pkey_free
20#define __stub_putmsg
21#define __stub_putpmsg
22#define __stub_revoke
23#define __stub_setlogin
24#define __stub_sigreturn
25#define __stub_sstk
26#define __stub_stty
\ No newline at end of file
lib/libc/include/sparcv9-linux-gnu/bits/socket-constants.h created+38
......@@ -0,0 +1,38 @@
1/* Socket constants which vary among Linux architectures. Version for SPARC.
2 Copyright (C) 2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#ifndef _SYS_SOCKET_H
20# error "Never include <bits/socket-constants.h> directly; use <sys/socket.h> instead."
21#endif
22
23#define SOL_SOCKET 65535
24#define SO_ACCEPTCONN 32768
25#define SO_BROADCAST 32
26#define SO_DONTROUTE 16
27#define SO_ERROR 4103
28#define SO_KEEPALIVE 8
29#define SO_LINGER 128
30#define SO_OOBINLINE 256
31#define SO_RCVBUF 4098
32#define SO_RCVLOWAT 2048
33#define SO_RCVTIMEO 8192
34#define SO_REUSEADDR 4
35#define SO_SNDBUF 4097
36#define SO_SNDLOWAT 4096
37#define SO_SNDTIMEO 16384
38#define SO_TYPE 4104
\ No newline at end of file
lib/libc/include/sparcv9-linux-gnu/gnu/stubs-32.h deleted-26
......@@ -1,26 +0,0 @@
1/* This file is automatically generated.
2 It defines a symbol `__stub_FUNCTION' for each function
3 in the C library which is a stub, meaning it will fail
4 every time called, usually setting errno to ENOSYS. */
5
6#ifdef _LIBC
7 #error Applications may not define the macro _LIBC
8#endif
9
10#define __stub_chflags
11#define __stub_fattach
12#define __stub_fchflags
13#define __stub_fdetach
14#define __stub_getmsg
15#define __stub_getpmsg
16#define __stub_gtty
17#define __stub_lchmod
18#define __stub_pkey_alloc
19#define __stub_pkey_free
20#define __stub_putmsg
21#define __stub_putpmsg
22#define __stub_revoke
23#define __stub_setlogin
24#define __stub_sigreturn
25#define __stub_sstk
26#define __stub_stty
\ No newline at end of file
lib/libc/include/x86_64-linux-gnu/bits/math-vector-fortran.h deleted-43
......@@ -1,43 +0,0 @@
1! Platform-specific declarations of SIMD math functions for Fortran. -*- f90 -*-
2! Copyright (C) 2019 Free Software Foundation, Inc.
3! This file is part of the GNU C Library.
4!
5! The GNU C Library is free software; you can redistribute it and/or
6! modify it under the terms of the GNU Lesser General Public
7! License as published by the Free Software Foundation; either
8! version 2.1 of the License, or (at your option) any later version.
9!
10! The GNU C Library is distributed in the hope that it will be useful,
11! but WITHOUT ANY WARRANTY; without even the implied warranty of
12! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13! Lesser General Public License for more details.
14!
15! You should have received a copy of the GNU Lesser General Public
16! License along with the GNU C Library; if not, see
17! <http://www.gnu.org/licenses/>.
18
19!GCC$ builtin (cos) attributes simd (notinbranch) if('x86_64')
20!GCC$ builtin (cosf) attributes simd (notinbranch) if('x86_64')
21!GCC$ builtin (sin) attributes simd (notinbranch) if('x86_64')
22!GCC$ builtin (sinf) attributes simd (notinbranch) if('x86_64')
23!GCC$ builtin (sincos) attributes simd (notinbranch) if('x86_64')
24!GCC$ builtin (sincosf) attributes simd (notinbranch) if('x86_64')
25!GCC$ builtin (log) attributes simd (notinbranch) if('x86_64')
26!GCC$ builtin (logf) attributes simd (notinbranch) if('x86_64')
27!GCC$ builtin (exp) attributes simd (notinbranch) if('x86_64')
28!GCC$ builtin (expf) attributes simd (notinbranch) if('x86_64')
29!GCC$ builtin (pow) attributes simd (notinbranch) if('x86_64')
30!GCC$ builtin (powf) attributes simd (notinbranch) if('x86_64')
31
32!GCC$ builtin (cos) attributes simd (notinbranch) if('x32')
33!GCC$ builtin (cosf) attributes simd (notinbranch) if('x32')
34!GCC$ builtin (sin) attributes simd (notinbranch) if('x32')
35!GCC$ builtin (sinf) attributes simd (notinbranch) if('x32')
36!GCC$ builtin (sincos) attributes simd (notinbranch) if('x32')
37!GCC$ builtin (sincosf) attributes simd (notinbranch) if('x32')
38!GCC$ builtin (log) attributes simd (notinbranch) if('x32')
39!GCC$ builtin (logf) attributes simd (notinbranch) if('x32')
40!GCC$ builtin (exp) attributes simd (notinbranch) if('x32')
41!GCC$ builtin (expf) attributes simd (notinbranch) if('x32')
42!GCC$ builtin (pow) attributes simd (notinbranch) if('x32')
43!GCC$ builtin (powf) attributes simd (notinbranch) if('x32')
\ No newline at end of file
lib/libc/include/x86_64-linux-gnu/bits/xtitypes.h deleted-33
......@@ -1,33 +0,0 @@
1/* bits/xtitypes.h -- Define some types used by <bits/stropts.h>. x86-64.
2 Copyright (C) 2002-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#ifndef _STROPTS_H
20# error "Never include <bits/xtitypes.h> directly; use <stropts.h> instead."
21#endif
22
23#ifndef _BITS_XTITYPES_H
24#define _BITS_XTITYPES_H 1
25
26#include <bits/types.h>
27
28/* This type is used by some structs in <bits/stropts.h>. */
29typedef __SLONG32_TYPE __t_scalar_t;
30typedef __ULONG32_TYPE __t_uscalar_t;
31
32
33#endif /* bits/xtitypes.h */
\ No newline at end of file
lib/libc/include/x86_64-linux-gnu/finclude/math-vector-fortran.h created+43
......@@ -0,0 +1,43 @@
1! Platform-specific declarations of SIMD math functions for Fortran. -*- f90 -*-
2! Copyright (C) 2019 Free Software Foundation, Inc.
3! This file is part of the GNU C Library.
4!
5! The GNU C Library is free software; you can redistribute it and/or
6! modify it under the terms of the GNU Lesser General Public
7! License as published by the Free Software Foundation; either
8! version 2.1 of the License, or (at your option) any later version.
9!
10! The GNU C Library is distributed in the hope that it will be useful,
11! but WITHOUT ANY WARRANTY; without even the implied warranty of
12! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13! Lesser General Public License for more details.
14!
15! You should have received a copy of the GNU Lesser General Public
16! License along with the GNU C Library; if not, see
17! <http://www.gnu.org/licenses/>.
18
19!GCC$ builtin (cos) attributes simd (notinbranch) if('x86_64')
20!GCC$ builtin (cosf) attributes simd (notinbranch) if('x86_64')
21!GCC$ builtin (sin) attributes simd (notinbranch) if('x86_64')
22!GCC$ builtin (sinf) attributes simd (notinbranch) if('x86_64')
23!GCC$ builtin (sincos) attributes simd (notinbranch) if('x86_64')
24!GCC$ builtin (sincosf) attributes simd (notinbranch) if('x86_64')
25!GCC$ builtin (log) attributes simd (notinbranch) if('x86_64')
26!GCC$ builtin (logf) attributes simd (notinbranch) if('x86_64')
27!GCC$ builtin (exp) attributes simd (notinbranch) if('x86_64')
28!GCC$ builtin (expf) attributes simd (notinbranch) if('x86_64')
29!GCC$ builtin (pow) attributes simd (notinbranch) if('x86_64')
30!GCC$ builtin (powf) attributes simd (notinbranch) if('x86_64')
31
32!GCC$ builtin (cos) attributes simd (notinbranch) if('x32')
33!GCC$ builtin (cosf) attributes simd (notinbranch) if('x32')
34!GCC$ builtin (sin) attributes simd (notinbranch) if('x32')
35!GCC$ builtin (sinf) attributes simd (notinbranch) if('x32')
36!GCC$ builtin (sincos) attributes simd (notinbranch) if('x32')
37!GCC$ builtin (sincosf) attributes simd (notinbranch) if('x32')
38!GCC$ builtin (log) attributes simd (notinbranch) if('x32')
39!GCC$ builtin (logf) attributes simd (notinbranch) if('x32')
40!GCC$ builtin (exp) attributes simd (notinbranch) if('x32')
41!GCC$ builtin (expf) attributes simd (notinbranch) if('x32')
42!GCC$ builtin (pow) attributes simd (notinbranch) if('x32')
43!GCC$ builtin (powf) attributes simd (notinbranch) if('x32')
\ No newline at end of file
lib/libc/include/x86_64-linux-gnu/gnu/stubs-64.h-4
......@@ -9,13 +9,9 @@
99
1010#define __stub___compat_bdflush
1111#define __stub_chflags
12#define __stub_fattach
1312#define __stub_fchflags
14#define __stub_fdetach
15#define __stub_getmsg
1613#define __stub_gtty
1714#define __stub_lchmod
18#define __stub_putmsg
1915#define __stub_revoke
2016#define __stub_setlogin
2117#define __stub_sigreturn
lib/libc/include/x86_64-linux-gnu/sys/io.h deleted-183
......@@ -1,183 +0,0 @@
1/* Copyright (C) 1996-2019 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
17
18#ifndef _SYS_IO_H
19#define _SYS_IO_H 1
20
21#include <features.h>
22
23__BEGIN_DECLS
24
25/* If TURN_ON is TRUE, request for permission to do direct i/o on the
26 port numbers in the range [FROM,FROM+NUM-1]. Otherwise, turn I/O
27 permission off for that range. This call requires root privileges.
28
29 Portability note: not all Linux platforms support this call. Most
30 platforms based on the PC I/O architecture probably will, however.
31 E.g., Linux/Alpha for Alpha PCs supports this. */
32extern int ioperm (unsigned long int __from, unsigned long int __num,
33 int __turn_on) __THROW;
34
35/* Set the I/O privilege level to LEVEL. If LEVEL>3, permission to
36 access any I/O port is granted. This call requires root
37 privileges. */
38extern int iopl (int __level) __THROW;
39
40#if defined __GNUC__ && __GNUC__ >= 2
41
42static __inline unsigned char
43inb (unsigned short int __port)
44{
45 unsigned char _v;
46
47 __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (__port));
48 return _v;
49}
50
51static __inline unsigned char
52inb_p (unsigned short int __port)
53{
54 unsigned char _v;
55
56 __asm__ __volatile__ ("inb %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (__port));
57 return _v;
58}
59
60static __inline unsigned short int
61inw (unsigned short int __port)
62{
63 unsigned short _v;
64
65 __asm__ __volatile__ ("inw %w1,%0":"=a" (_v):"Nd" (__port));
66 return _v;
67}
68
69static __inline unsigned short int
70inw_p (unsigned short int __port)
71{
72 unsigned short int _v;
73
74 __asm__ __volatile__ ("inw %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (__port));
75 return _v;
76}
77
78static __inline unsigned int
79inl (unsigned short int __port)
80{
81 unsigned int _v;
82
83 __asm__ __volatile__ ("inl %w1,%0":"=a" (_v):"Nd" (__port));
84 return _v;
85}
86
87static __inline unsigned int
88inl_p (unsigned short int __port)
89{
90 unsigned int _v;
91 __asm__ __volatile__ ("inl %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (__port));
92 return _v;
93}
94
95static __inline void
96outb (unsigned char __value, unsigned short int __port)
97{
98 __asm__ __volatile__ ("outb %b0,%w1": :"a" (__value), "Nd" (__port));
99}
100
101static __inline void
102outb_p (unsigned char __value, unsigned short int __port)
103{
104 __asm__ __volatile__ ("outb %b0,%w1\noutb %%al,$0x80": :"a" (__value),
105 "Nd" (__port));
106}
107
108static __inline void
109outw (unsigned short int __value, unsigned short int __port)
110{
111 __asm__ __volatile__ ("outw %w0,%w1": :"a" (__value), "Nd" (__port));
112
113}
114
115static __inline void
116outw_p (unsigned short int __value, unsigned short int __port)
117{
118 __asm__ __volatile__ ("outw %w0,%w1\noutb %%al,$0x80": :"a" (__value),
119 "Nd" (__port));
120}
121
122static __inline void
123outl (unsigned int __value, unsigned short int __port)
124{
125 __asm__ __volatile__ ("outl %0,%w1": :"a" (__value), "Nd" (__port));
126}
127
128static __inline void
129outl_p (unsigned int __value, unsigned short int __port)
130{
131 __asm__ __volatile__ ("outl %0,%w1\noutb %%al,$0x80": :"a" (__value),
132 "Nd" (__port));
133}
134
135static __inline void
136insb (unsigned short int __port, void *__addr, unsigned long int __count)
137{
138 __asm__ __volatile__ ("cld ; rep ; insb":"=D" (__addr), "=c" (__count)
139 :"d" (__port), "0" (__addr), "1" (__count));
140}
141
142static __inline void
143insw (unsigned short int __port, void *__addr, unsigned long int __count)
144{
145 __asm__ __volatile__ ("cld ; rep ; insw":"=D" (__addr), "=c" (__count)
146 :"d" (__port), "0" (__addr), "1" (__count));
147}
148
149static __inline void
150insl (unsigned short int __port, void *__addr, unsigned long int __count)
151{
152 __asm__ __volatile__ ("cld ; rep ; insl":"=D" (__addr), "=c" (__count)
153 :"d" (__port), "0" (__addr), "1" (__count));
154}
155
156static __inline void
157outsb (unsigned short int __port, const void *__addr,
158 unsigned long int __count)
159{
160 __asm__ __volatile__ ("cld ; rep ; outsb":"=S" (__addr), "=c" (__count)
161 :"d" (__port), "0" (__addr), "1" (__count));
162}
163
164static __inline void
165outsw (unsigned short int __port, const void *__addr,
166 unsigned long int __count)
167{
168 __asm__ __volatile__ ("cld ; rep ; outsw":"=S" (__addr), "=c" (__count)
169 :"d" (__port), "0" (__addr), "1" (__count));
170}
171
172static __inline void
173outsl (unsigned short int __port, const void *__addr,
174 unsigned long int __count)
175{
176 __asm__ __volatile__ ("cld ; rep ; outsl":"=S" (__addr), "=c" (__count)
177 :"d" (__port), "0" (__addr), "1" (__count));
178}
179
180#endif /* GNU C */
181
182__END_DECLS
183#endif /* _SYS_IO_H */
\ No newline at end of file
lib/libc/include/x86_64-linux-gnux32/bits/math-vector-fortran.h deleted-43
......@@ -1,43 +0,0 @@
1! Platform-specific declarations of SIMD math functions for Fortran. -*- f90 -*-
2! Copyright (C) 2019 Free Software Foundation, Inc.
3! This file is part of the GNU C Library.
4!
5! The GNU C Library is free software; you can redistribute it and/or
6! modify it under the terms of the GNU Lesser General Public
7! License as published by the Free Software Foundation; either
8! version 2.1 of the License, or (at your option) any later version.
9!
10! The GNU C Library is distributed in the hope that it will be useful,
11! but WITHOUT ANY WARRANTY; without even the implied warranty of
12! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13! Lesser General Public License for more details.
14!
15! You should have received a copy of the GNU Lesser General Public
16! License along with the GNU C Library; if not, see
17! <http://www.gnu.org/licenses/>.
18
19!GCC$ builtin (cos) attributes simd (notinbranch) if('x86_64')
20!GCC$ builtin (cosf) attributes simd (notinbranch) if('x86_64')
21!GCC$ builtin (sin) attributes simd (notinbranch) if('x86_64')
22!GCC$ builtin (sinf) attributes simd (notinbranch) if('x86_64')
23!GCC$ builtin (sincos) attributes simd (notinbranch) if('x86_64')
24!GCC$ builtin (sincosf) attributes simd (notinbranch) if('x86_64')
25!GCC$ builtin (log) attributes simd (notinbranch) if('x86_64')
26!GCC$ builtin (logf) attributes simd (notinbranch) if('x86_64')
27!GCC$ builtin (exp) attributes simd (notinbranch) if('x86_64')
28!GCC$ builtin (expf) attributes simd (notinbranch) if('x86_64')
29!GCC$ builtin (pow) attributes simd (notinbranch) if('x86_64')
30!GCC$ builtin (powf) attributes simd (notinbranch) if('x86_64')
31
32!GCC$ builtin (cos) attributes simd (notinbranch) if('x32')
33!GCC$ builtin (cosf) attributes simd (notinbranch) if('x32')
34!GCC$ builtin (sin) attributes simd (notinbranch) if('x32')
35!GCC$ builtin (sinf) attributes simd (notinbranch) if('x32')
36!GCC$ builtin (sincos) attributes simd (notinbranch) if('x32')
37!GCC$ builtin (sincosf) attributes simd (notinbranch) if('x32')
38!GCC$ builtin (log) attributes simd (notinbranch) if('x32')
39!GCC$ builtin (logf) attributes simd (notinbranch) if('x32')
40!GCC$ builtin (exp) attributes simd (notinbranch) if('x32')
41!GCC$ builtin (expf) attributes simd (notinbranch) if('x32')
42!GCC$ builtin (pow) attributes simd (notinbranch) if('x32')
43!GCC$ builtin (powf) attributes simd (notinbranch) if('x32')
\ No newline at end of file
lib/libc/include/x86_64-linux-gnux32/bits/xtitypes.h deleted-33
......@@ -1,33 +0,0 @@
1/* bits/xtitypes.h -- Define some types used by <bits/stropts.h>. x86-64.
2 Copyright (C) 2002-2019 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19#ifndef _STROPTS_H
20# error "Never include <bits/xtitypes.h> directly; use <stropts.h> instead."
21#endif
22
23#ifndef _BITS_XTITYPES_H
24#define _BITS_XTITYPES_H 1
25
26#include <bits/types.h>
27
28/* This type is used by some structs in <bits/stropts.h>. */
29typedef __SLONG32_TYPE __t_scalar_t;
30typedef __ULONG32_TYPE __t_uscalar_t;
31
32
33#endif /* bits/xtitypes.h */
\ No newline at end of file
lib/libc/include/x86_64-linux-gnux32/finclude/math-vector-fortran.h created+43
......@@ -0,0 +1,43 @@
1! Platform-specific declarations of SIMD math functions for Fortran. -*- f90 -*-
2! Copyright (C) 2019 Free Software Foundation, Inc.
3! This file is part of the GNU C Library.
4!
5! The GNU C Library is free software; you can redistribute it and/or
6! modify it under the terms of the GNU Lesser General Public
7! License as published by the Free Software Foundation; either
8! version 2.1 of the License, or (at your option) any later version.
9!
10! The GNU C Library is distributed in the hope that it will be useful,
11! but WITHOUT ANY WARRANTY; without even the implied warranty of
12! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13! Lesser General Public License for more details.
14!
15! You should have received a copy of the GNU Lesser General Public
16! License along with the GNU C Library; if not, see
17! <http://www.gnu.org/licenses/>.
18
19!GCC$ builtin (cos) attributes simd (notinbranch) if('x86_64')
20!GCC$ builtin (cosf) attributes simd (notinbranch) if('x86_64')
21!GCC$ builtin (sin) attributes simd (notinbranch) if('x86_64')
22!GCC$ builtin (sinf) attributes simd (notinbranch) if('x86_64')
23!GCC$ builtin (sincos) attributes simd (notinbranch) if('x86_64')
24!GCC$ builtin (sincosf) attributes simd (notinbranch) if('x86_64')
25!GCC$ builtin (log) attributes simd (notinbranch) if('x86_64')
26!GCC$ builtin (logf) attributes simd (notinbranch) if('x86_64')
27!GCC$ builtin (exp) attributes simd (notinbranch) if('x86_64')
28!GCC$ builtin (expf) attributes simd (notinbranch) if('x86_64')
29!GCC$ builtin (pow) attributes simd (notinbranch) if('x86_64')
30!GCC$ builtin (powf) attributes simd (notinbranch) if('x86_64')
31
32!GCC$ builtin (cos) attributes simd (notinbranch) if('x32')
33!GCC$ builtin (cosf) attributes simd (notinbranch) if('x32')
34!GCC$ builtin (sin) attributes simd (notinbranch) if('x32')
35!GCC$ builtin (sinf) attributes simd (notinbranch) if('x32')
36!GCC$ builtin (sincos) attributes simd (notinbranch) if('x32')
37!GCC$ builtin (sincosf) attributes simd (notinbranch) if('x32')
38!GCC$ builtin (log) attributes simd (notinbranch) if('x32')
39!GCC$ builtin (logf) attributes simd (notinbranch) if('x32')
40!GCC$ builtin (exp) attributes simd (notinbranch) if('x32')
41!GCC$ builtin (expf) attributes simd (notinbranch) if('x32')
42!GCC$ builtin (pow) attributes simd (notinbranch) if('x32')
43!GCC$ builtin (powf) attributes simd (notinbranch) if('x32')
\ No newline at end of file
lib/libc/include/x86_64-linux-gnux32/gnu/stubs-x32.h-4
......@@ -14,13 +14,9 @@
1414#define __stub___compat_query_module
1515#define __stub___compat_uselib
1616#define __stub_chflags
17#define __stub_fattach
1817#define __stub_fchflags
19#define __stub_fdetach
20#define __stub_getmsg
2118#define __stub_gtty
2219#define __stub_lchmod
23#define __stub_putmsg
2420#define __stub_revoke
2521#define __stub_setlogin
2622#define __stub_sigreturn
lib/libc/include/x86_64-linux-gnux32/sys/io.h deleted-183
......@@ -1,183 +0,0 @@
1/* Copyright (C) 1996-2019 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
17
18#ifndef _SYS_IO_H
19#define _SYS_IO_H 1
20
21#include <features.h>
22
23__BEGIN_DECLS
24
25/* If TURN_ON is TRUE, request for permission to do direct i/o on the
26 port numbers in the range [FROM,FROM+NUM-1]. Otherwise, turn I/O
27 permission off for that range. This call requires root privileges.
28
29 Portability note: not all Linux platforms support this call. Most
30 platforms based on the PC I/O architecture probably will, however.
31 E.g., Linux/Alpha for Alpha PCs supports this. */
32extern int ioperm (unsigned long int __from, unsigned long int __num,
33 int __turn_on) __THROW;
34
35/* Set the I/O privilege level to LEVEL. If LEVEL>3, permission to
36 access any I/O port is granted. This call requires root
37 privileges. */
38extern int iopl (int __level) __THROW;
39
40#if defined __GNUC__ && __GNUC__ >= 2
41
42static __inline unsigned char
43inb (unsigned short int __port)
44{
45 unsigned char _v;
46
47 __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (__port));
48 return _v;
49}
50
51static __inline unsigned char
52inb_p (unsigned short int __port)
53{
54 unsigned char _v;
55
56 __asm__ __volatile__ ("inb %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (__port));
57 return _v;
58}
59
60static __inline unsigned short int
61inw (unsigned short int __port)
62{
63 unsigned short _v;
64
65 __asm__ __volatile__ ("inw %w1,%0":"=a" (_v):"Nd" (__port));
66 return _v;
67}
68
69static __inline unsigned short int
70inw_p (unsigned short int __port)
71{
72 unsigned short int _v;
73
74 __asm__ __volatile__ ("inw %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (__port));
75 return _v;
76}
77
78static __inline unsigned int
79inl (unsigned short int __port)
80{
81 unsigned int _v;
82
83 __asm__ __volatile__ ("inl %w1,%0":"=a" (_v):"Nd" (__port));
84 return _v;
85}
86
87static __inline unsigned int
88inl_p (unsigned short int __port)
89{
90 unsigned int _v;
91 __asm__ __volatile__ ("inl %w1,%0\noutb %%al,$0x80":"=a" (_v):"Nd" (__port));
92 return _v;
93}
94
95static __inline void
96outb (unsigned char __value, unsigned short int __port)
97{
98 __asm__ __volatile__ ("outb %b0,%w1": :"a" (__value), "Nd" (__port));
99}
100
101static __inline void
102outb_p (unsigned char __value, unsigned short int __port)
103{
104 __asm__ __volatile__ ("outb %b0,%w1\noutb %%al,$0x80": :"a" (__value),
105 "Nd" (__port));
106}
107
108static __inline void
109outw (unsigned short int __value, unsigned short int __port)
110{
111 __asm__ __volatile__ ("outw %w0,%w1": :"a" (__value), "Nd" (__port));
112
113}
114
115static __inline void
116outw_p (unsigned short int __value, unsigned short int __port)
117{
118 __asm__ __volatile__ ("outw %w0,%w1\noutb %%al,$0x80": :"a" (__value),
119 "Nd" (__port));
120}
121
122static __inline void
123outl (unsigned int __value, unsigned short int __port)
124{
125 __asm__ __volatile__ ("outl %0,%w1": :"a" (__value), "Nd" (__port));
126}
127
128static __inline void
129outl_p (unsigned int __value, unsigned short int __port)
130{
131 __asm__ __volatile__ ("outl %0,%w1\noutb %%al,$0x80": :"a" (__value),
132 "Nd" (__port));
133}
134
135static __inline void
136insb (unsigned short int __port, void *__addr, unsigned long int __count)
137{
138 __asm__ __volatile__ ("cld ; rep ; insb":"=D" (__addr), "=c" (__count)
139 :"d" (__port), "0" (__addr), "1" (__count));
140}
141
142static __inline void
143insw (unsigned short int __port, void *__addr, unsigned long int __count)
144{
145 __asm__ __volatile__ ("cld ; rep ; insw":"=D" (__addr), "=c" (__count)
146 :"d" (__port), "0" (__addr), "1" (__count));
147}
148
149static __inline void
150insl (unsigned short int __port, void *__addr, unsigned long int __count)
151{
152 __asm__ __volatile__ ("cld ; rep ; insl":"=D" (__addr), "=c" (__count)
153 :"d" (__port), "0" (__addr), "1" (__count));
154}
155
156static __inline void
157outsb (unsigned short int __port, const void *__addr,
158 unsigned long int __count)
159{
160 __asm__ __volatile__ ("cld ; rep ; outsb":"=S" (__addr), "=c" (__count)
161 :"d" (__port), "0" (__addr), "1" (__count));
162}
163
164static __inline void
165outsw (unsigned short int __port, const void *__addr,
166 unsigned long int __count)
167{
168 __asm__ __volatile__ ("cld ; rep ; outsw":"=S" (__addr), "=c" (__count)
169 :"d" (__port), "0" (__addr), "1" (__count));
170}
171
172static __inline void
173outsl (unsigned short int __port, const void *__addr,
174 unsigned long int __count)
175{
176 __asm__ __volatile__ ("cld ; rep ; outsl":"=S" (__addr), "=c" (__count)
177 :"d" (__port), "0" (__addr), "1" (__count));
178}
179
180#endif /* GNU C */
181
182__END_DECLS
183#endif /* _SYS_IO_H */
\ No newline at end of file
src-self-hosted/arg.zig+2-2
......@@ -5,7 +5,7 @@ const mem = std.mem;
55
66const Allocator = mem.Allocator;
77const ArrayList = std.ArrayList;
8const HashMap = std.HashMap;
8const StringHashMap = std.StringHashMap;
99
1010fn trimStart(slice: []const u8, ch: u8) []const u8 {
1111 var i: usize = 0;
......@@ -73,7 +73,7 @@ fn readFlagArguments(allocator: *Allocator, args: []const []const u8, required:
7373 }
7474}
7575
76const HashMapFlags = HashMap([]const u8, FlagArg, std.hash.Fnv1a_32.hash, mem.eql_slice_u8);
76const HashMapFlags = StringHashMap(FlagArg);
7777
7878// A store for querying found flags and positional arguments.
7979pub const Args = struct {
src-self-hosted/compilation.zig+1-1
......@@ -249,7 +249,7 @@ pub const Compilation = struct {
249249 const ArrayTypeTable = std.HashMap(*const Type.Array.Key, *Type.Array, Type.Array.Key.hash, Type.Array.Key.eql);
250250 const PtrTypeTable = std.HashMap(*const Type.Pointer.Key, *Type.Pointer, Type.Pointer.Key.hash, Type.Pointer.Key.eql);
251251 const FnTypeTable = std.HashMap(*const Type.Fn.Key, *Type.Fn, Type.Fn.Key.hash, Type.Fn.Key.eql);
252 const TypeTable = std.HashMap([]const u8, *Type, mem.hash_slice_u8, mem.eql_slice_u8);
252 const TypeTable = std.StringHashMap(*Type);
253253
254254 const CompileErrList = std.ArrayList(*Msg);
255255
src-self-hosted/decl.zig+1-1
......@@ -20,7 +20,7 @@ pub const Decl = struct {
2020 // TODO when we destroy the decl, deref the tree scope
2121 tree_scope: *Scope.AstTree,
2222
23 pub const Table = std.HashMap([]const u8, *Decl, mem.hash_slice_u8, mem.eql_slice_u8);
23 pub const Table = std.StringHashMap(*Decl);
2424
2525 pub fn cast(base: *Decl, comptime T: type) ?*T {
2626 if (base.id != @field(Id, @typeName(T))) return null;
src-self-hosted/main.zig+1-1
......@@ -541,7 +541,7 @@ const Fmt = struct {
541541 color: errmsg.Color,
542542 loop: *event.Loop,
543543
544 const SeenMap = std.HashMap([]const u8, void, mem.hash_slice_u8, mem.eql_slice_u8);
544 const SeenMap = std.StringHashMap(void);
545545};
546546
547547fn parseLibcPaths(allocator: *Allocator, libc: *LibCInstallation, libc_paths_file: []const u8) void {
src-self-hosted/package.zig+1-1
......@@ -10,7 +10,7 @@ pub const Package = struct {
1010 /// relative to root_src_dir
1111 table: Table,
1212
13 pub const Table = std.HashMap([]const u8, *Package, mem.hash_slice_u8, mem.eql_slice_u8);
13 pub const Table = std.StringHashMap(*Package);
1414
1515 /// makes internal copies of root_src_dir and root_src_path
1616 /// allocator should be an arena allocator because Package never frees anything
src-self-hosted/stage1.zig+2-2
......@@ -343,7 +343,7 @@ const Fmt = struct {
343343 color: errmsg.Color,
344344 allocator: *mem.Allocator,
345345
346 const SeenMap = std.HashMap([]const u8, void, mem.hash_slice_u8, mem.eql_slice_u8);
346 const SeenMap = std.StringHashMap(void);
347347};
348348
349349fn printErrMsgToFile(
......@@ -376,7 +376,7 @@ fn printErrMsgToFile(
376376 const text = text_buf.toOwnedSlice();
377377
378378 const stream = &file.outStream().stream;
379 try stream.print( "{}:{}:{}: error: {}\n", path, start_loc.line + 1, start_loc.column + 1, text);
379 try stream.print("{}:{}:{}: error: {}\n", path, start_loc.line + 1, start_loc.column + 1, text);
380380
381381 if (!color_on) return;
382382
src/all_types.hpp+73-14
......@@ -25,6 +25,7 @@ struct ZigFn;
2525struct Scope;
2626struct ScopeBlock;
2727struct ScopeFnDef;
28struct ScopeExpr;
2829struct ZigType;
2930struct ZigVar;
3031struct ErrorTableEntry;
......@@ -47,6 +48,7 @@ struct ResultLoc;
4748struct ResultLocPeer;
4849struct ResultLocPeerParent;
4950struct ResultLocBitCast;
51struct ResultLocReturn;
5052
5153enum PtrLen {
5254 PtrLenUnknown,
......@@ -54,6 +56,14 @@ enum PtrLen {
5456 PtrLenC,
5557};
5658
59// This one corresponds to the builtin.zig enum.
60enum BuiltinPtrSize {
61 BuiltinPtrSizeOne,
62 BuiltinPtrSizeMany,
63 BuiltinPtrSizeSlice,
64 BuiltinPtrSizeC,
65};
66
5767enum UndefAllowed {
5868 UndefOk,
5969 UndefBad,
......@@ -595,6 +605,12 @@ enum CallingConvention {
595605 CallingConventionAsync,
596606};
597607
608enum FnInline {
609 FnInlineAuto,
610 FnInlineAlways,
611 FnInlineNever,
612};
613
598614struct AstNodeFnProto {
599615 VisibMod visib_mod;
600616 Buf *name;
......@@ -604,7 +620,7 @@ struct AstNodeFnProto {
604620 bool is_var_args;
605621 bool is_extern;
606622 bool is_export;
607 bool is_inline;
623 FnInline fn_inline;
608624 CallingConvention cc;
609625 AstNode *fn_def_node;
610626 // populated if this is an extern declaration
......@@ -743,11 +759,17 @@ struct AstNodeUnwrapOptional {
743759 AstNode *expr;
744760};
745761
762enum CallModifier {
763 CallModifierNone,
764 CallModifierAsync,
765 CallModifierNoAsync,
766 CallModifierBuiltin,
767};
768
746769struct AstNodeFnCallExpr {
747770 AstNode *fn_ref_expr;
748771 ZigList<AstNode *> params;
749 bool is_builtin;
750 bool is_async;
772 CallModifier modifier;
751773 bool seen; // used by @compileLog
752774};
753775
......@@ -1445,12 +1467,6 @@ enum FnAnalState {
14451467 FnAnalStateInvalid,
14461468};
14471469
1448enum FnInline {
1449 FnInlineAuto,
1450 FnInlineAlways,
1451 FnInlineNever,
1452};
1453
14541470struct GlobalExport {
14551471 Buf name;
14561472 GlobalLinkageId linkage;
......@@ -1534,6 +1550,7 @@ enum BuiltinFnId {
15341550 BuiltinFnIdMemberName,
15351551 BuiltinFnIdField,
15361552 BuiltinFnIdTypeInfo,
1553 BuiltinFnIdType,
15371554 BuiltinFnIdHasField,
15381555 BuiltinFnIdTypeof,
15391556 BuiltinFnIdAddWithOverflow,
......@@ -1664,6 +1681,7 @@ enum PanicMsgId {
16641681 PanicMsgIdResumedAnAwaitingFn,
16651682 PanicMsgIdFrameTooSmall,
16661683 PanicMsgIdResumedFnPendingAwait,
1684 PanicMsgIdBadNoAsyncCall,
16671685
16681686 PanicMsgIdCount,
16691687};
......@@ -1954,6 +1972,8 @@ struct CodeGen {
19541972 ZigFn *panic_fn;
19551973 TldFn *panic_tld_fn;
19561974
1975 ZigFn *largest_frame_fn;
1976
19571977 WantPIC want_pic;
19581978 WantStackCheck want_stack_check;
19591979 CacheHash cache_hash;
......@@ -1986,9 +2006,11 @@ struct CodeGen {
19862006 bool generate_error_name_table;
19872007 bool enable_cache; // mutually exclusive with output_dir
19882008 bool enable_time_report;
2009 bool enable_stack_report;
19892010 bool system_linker_hack;
19902011 bool reported_bad_link_libc_error;
19912012 bool is_dynamic; // shared library rather than static library. dynamic musl rather than static musl.
2013 bool need_frame_size_prefix_data;
19922014
19932015 //////////////////////////// Participates in Input Parameter Cache Hash
19942016 /////// Note: there is a separate cache hash for builtin.zig, when adding fields,
......@@ -2051,7 +2073,7 @@ struct CodeGen {
20512073};
20522074
20532075struct ZigVar {
2054 Buf name;
2076 const char *name;
20552077 ConstExprValue *const_value;
20562078 ZigType *var_type;
20572079 LLVMValueRef value_ref;
......@@ -2066,7 +2088,6 @@ struct ZigVar {
20662088 LLVMValueRef param_value_ref;
20672089 size_t mem_slot_index;
20682090 IrExecutable *owner_exec;
2069 size_t ref_count;
20702091
20712092 // In an inline loop, multiple variables may be created,
20722093 // In this case, a reference to a variable should follow
......@@ -2076,6 +2097,7 @@ struct ZigVar {
20762097 ZigList<GlobalExport> export_list;
20772098
20782099 uint32_t align_bytes;
2100 uint32_t ref_count;
20792101
20802102 bool shadowable;
20812103 bool src_is_const;
......@@ -2106,6 +2128,7 @@ enum ScopeId {
21062128 ScopeIdCompTime,
21072129 ScopeIdRuntime,
21082130 ScopeIdTypeOf,
2131 ScopeIdExpr,
21092132};
21102133
21112134struct Scope {
......@@ -2211,6 +2234,7 @@ struct ScopeLoop {
22112234 ZigList<IrInstruction *> *incoming_values;
22122235 ZigList<IrBasicBlock *> *incoming_blocks;
22132236 ResultLocPeerParent *peer_parent;
2237 ScopeExpr *spill_scope;
22142238};
22152239
22162240// This scope blocks certain things from working such as comptime continue
......@@ -2253,6 +2277,24 @@ struct ScopeTypeOf {
22532277 Scope base;
22542278};
22552279
2280enum MemoizedBool {
2281 MemoizedBoolUnknown,
2282 MemoizedBoolFalse,
2283 MemoizedBoolTrue,
2284};
2285
2286// This scope is created for each expression.
2287// It's used to identify when an instruction needs to be spilled,
2288// so that it can be accessed after a suspend point.
2289struct ScopeExpr {
2290 Scope base;
2291
2292 ScopeExpr **children_ptr;
2293 size_t children_len;
2294
2295 MemoizedBool need_spill;
2296};
2297
22562298// synchronized with code in define_builtin_compile_vars
22572299enum AtomicOrder {
22582300 AtomicOrderUnordered,
......@@ -2435,6 +2477,7 @@ enum IrInstructionId {
24352477 IrInstructionIdByteOffsetOf,
24362478 IrInstructionIdBitOffsetOf,
24372479 IrInstructionIdTypeInfo,
2480 IrInstructionIdType,
24382481 IrInstructionIdHasField,
24392482 IrInstructionIdTypeId,
24402483 IrInstructionIdSetEvalBranchQuota,
......@@ -2491,6 +2534,10 @@ struct IrInstruction {
24912534 // with this child field.
24922535 IrInstruction *child;
24932536 IrBasicBlock *owner_bb;
2537 // Nearly any instruction can have to be stored as a local variable before suspending
2538 // and then loaded after resuming, in case there is an expression with a suspend point
2539 // in it, such as: x + await y
2540 IrInstruction *spill;
24942541 IrInstructionId id;
24952542 // true if this instruction was generated by zig and not from user code
24962543 bool is_gen;
......@@ -2718,8 +2765,10 @@ struct IrInstructionCallSrc {
27182765 ResultLoc *result_loc;
27192766
27202767 IrInstruction *new_stack;
2768
27212769 FnInline fn_inline;
2722 bool is_async;
2770 CallModifier modifier;
2771
27232772 bool is_async_call_builtin;
27242773 bool is_comptime;
27252774};
......@@ -2733,10 +2782,11 @@ struct IrInstructionCallGen {
27332782 IrInstruction **args;
27342783 IrInstruction *result_loc;
27352784 IrInstruction *frame_result_loc;
2736
27372785 IrInstruction *new_stack;
2786
27382787 FnInline fn_inline;
2739 bool is_async;
2788 CallModifier modifier;
2789
27402790 bool is_async_call_builtin;
27412791};
27422792
......@@ -3471,6 +3521,12 @@ struct IrInstructionTypeInfo {
34713521 IrInstruction *type_value;
34723522};
34733523
3524struct IrInstructionType {
3525 IrInstruction base;
3526
3527 IrInstruction *type_info;
3528};
3529
34743530struct IrInstructionHasField {
34753531 IrInstruction base;
34763532
......@@ -3567,6 +3623,7 @@ struct IrInstructionAddImplicitReturnType {
35673623 IrInstruction base;
35683624
35693625 IrInstruction *value;
3626 ResultLocReturn *result_loc_ret;
35703627};
35713628
35723629// For float ops which take a single argument
......@@ -3793,6 +3850,8 @@ struct ResultLocVar {
37933850
37943851struct ResultLocReturn {
37953852 ResultLoc base;
3853
3854 bool implicit_return_type_done;
37963855};
37973856
37983857struct IrSuspendPosition {
src/analyze.cpp+337-88
......@@ -96,6 +96,30 @@ static ScopeDecls **get_container_scope_ptr(ZigType *type_entry) {
9696 zig_unreachable();
9797}
9898
99static ScopeExpr *find_expr_scope(Scope *scope) {
100 for (;;) {
101 switch (scope->id) {
102 case ScopeIdExpr:
103 return reinterpret_cast<ScopeExpr *>(scope);
104 case ScopeIdDefer:
105 case ScopeIdDeferExpr:
106 case ScopeIdDecls:
107 case ScopeIdFnDef:
108 case ScopeIdCompTime:
109 case ScopeIdVarDecl:
110 case ScopeIdCImport:
111 case ScopeIdSuspend:
112 case ScopeIdTypeOf:
113 case ScopeIdBlock:
114 return nullptr;
115 case ScopeIdLoop:
116 case ScopeIdRuntime:
117 scope = scope->parent;
118 continue;
119 }
120 }
121}
122
99123ScopeDecls *get_container_scope(ZigType *type_entry) {
100124 return *get_container_scope_ptr(type_entry);
101125}
......@@ -203,6 +227,20 @@ Scope *create_typeof_scope(CodeGen *g, AstNode *node, Scope *parent) {
203227 return &scope->base;
204228}
205229
230ScopeExpr *create_expr_scope(CodeGen *g, AstNode *node, Scope *parent) {
231 ScopeExpr *scope = allocate<ScopeExpr>(1);
232 init_scope(g, &scope->base, ScopeIdExpr, node, parent);
233 ScopeExpr *parent_expr = find_expr_scope(parent);
234 if (parent_expr != nullptr) {
235 size_t new_len = parent_expr->children_len + 1;
236 parent_expr->children_ptr = reallocate_nonzero<ScopeExpr *>(
237 parent_expr->children_ptr, parent_expr->children_len, new_len);
238 parent_expr->children_ptr[parent_expr->children_len] = scope;
239 parent_expr->children_len = new_len;
240 }
241 return scope;
242}
243
206244ZigType *get_scope_import(Scope *scope) {
207245 while (scope) {
208246 if (scope->id == ScopeIdDecls) {
......@@ -1719,6 +1757,32 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
17191757 return g->builtin_types.entry_invalid;
17201758 }
17211759
1760 switch (specified_return_type->id) {
1761 case ZigTypeIdInvalid:
1762 zig_unreachable();
1763
1764 case ZigTypeIdUndefined:
1765 case ZigTypeIdNull:
1766 case ZigTypeIdArgTuple:
1767 add_node_error(g, fn_proto->return_type,
1768 buf_sprintf("return type '%s' not allowed", buf_ptr(&specified_return_type->name)));
1769 return g->builtin_types.entry_invalid;
1770
1771 case ZigTypeIdOpaque:
1772 {
1773 ErrorMsg* msg = add_node_error(g, fn_proto->return_type,
1774 buf_sprintf("opaque return type '%s' not allowed", buf_ptr(&specified_return_type->name)));
1775 Tld *tld = find_decl(g, &fn_entry->fndef_scope->base, &specified_return_type->name);
1776 if (tld != nullptr) {
1777 add_error_note(g, msg, tld->source_node, buf_sprintf("declared here"));
1778 }
1779 return g->builtin_types.entry_invalid;
1780 }
1781
1782 default:
1783 break;
1784 }
1785
17221786 if (fn_proto->auto_err_set) {
17231787 ZigType *inferred_err_set_type = get_auto_err_set_type(g, fn_entry);
17241788 if ((err = type_resolve(g, specified_return_type, ResolveStatusSizeKnown)))
......@@ -1744,15 +1808,11 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
17441808
17451809 switch (fn_type_id.return_type->id) {
17461810 case ZigTypeIdInvalid:
1747 zig_unreachable();
1748
17491811 case ZigTypeIdUndefined:
17501812 case ZigTypeIdNull:
17511813 case ZigTypeIdArgTuple:
17521814 case ZigTypeIdOpaque:
1753 add_node_error(g, fn_proto->return_type,
1754 buf_sprintf("return type '%s' not allowed", buf_ptr(&fn_type_id.return_type->name)));
1755 return g->builtin_types.entry_invalid;
1815 zig_unreachable();
17561816
17571817 case ZigTypeIdComptimeFloat:
17581818 case ZigTypeIdComptimeInt:
......@@ -2043,34 +2103,30 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) {
20432103
20442104
20452105 // Resolve types for fields
2046 if (!packed) {
2047 for (size_t i = 0; i < field_count; i += 1) {
2048 TypeStructField *field = &struct_type->data.structure.fields[i];
2049 ZigType *field_type = resolve_struct_field_type(g, field);
2050 if (field_type == nullptr) {
2051 struct_type->data.structure.resolve_status = ResolveStatusInvalid;
2052 return err;
2053 }
2054
2055 if ((err = type_resolve(g, field_type, ResolveStatusSizeKnown))) {
2056 struct_type->data.structure.resolve_status = ResolveStatusInvalid;
2057 return err;
2058 }
2106 for (size_t i = 0; i < field_count; i += 1) {
2107 TypeStructField *field = &struct_type->data.structure.fields[i];
2108 ZigType *field_type = resolve_struct_field_type(g, field);
2109 if (field_type == nullptr) {
2110 struct_type->data.structure.resolve_status = ResolveStatusInvalid;
2111 return err;
2112 }
20592113
2060 if (struct_type->data.structure.layout == ContainerLayoutExtern &&
2061 !type_allowed_in_extern(g, field_type))
2062 {
2063 add_node_error(g, field->decl_node,
2064 buf_sprintf("extern structs cannot contain fields of type '%s'",
2065 buf_ptr(&field_type->name)));
2066 struct_type->data.structure.resolve_status = ResolveStatusInvalid;
2067 return ErrorSemanticAnalyzeFail;
2068 }
2114 if ((err = type_resolve(g, field_type, ResolveStatusSizeKnown))) {
2115 struct_type->data.structure.resolve_status = ResolveStatusInvalid;
2116 return err;
2117 }
20692118
2119 if (struct_type->data.structure.layout == ContainerLayoutExtern &&
2120 !type_allowed_in_extern(g, field_type))
2121 {
2122 add_node_error(g, field->decl_node,
2123 buf_sprintf("extern structs cannot contain fields of type '%s'",
2124 buf_ptr(&field_type->name)));
2125 struct_type->data.structure.resolve_status = ResolveStatusInvalid;
2126 return ErrorSemanticAnalyzeFail;
20702127 }
20712128 }
20722129
2073
20742130 return ErrorNone;
20752131}
20762132
......@@ -2671,6 +2727,10 @@ static Error resolve_struct_alignment(CodeGen *g, ZigType *struct_type) {
26712727 }
26722728 }
26732729
2730 if (!type_has_bits(struct_type)) {
2731 assert(struct_type->abi_align == 0);
2732 }
2733
26742734 struct_type->data.structure.resolve_loop_flag_other = false;
26752735
26762736 if (struct_type->data.structure.resolve_status == ResolveStatusInvalid) {
......@@ -3062,8 +3122,7 @@ ZigFn *create_fn(CodeGen *g, AstNode *proto_node) {
30623122 assert(proto_node->type == NodeTypeFnProto);
30633123 AstNodeFnProto *fn_proto = &proto_node->data.fn_proto;
30643124
3065 FnInline inline_value = fn_proto->is_inline ? FnInlineAlways : FnInlineAuto;
3066 ZigFn *fn_entry = create_fn_raw(g, inline_value);
3125 ZigFn *fn_entry = create_fn_raw(g, fn_proto->fn_inline);
30673126
30683127 fn_entry->proto_node = proto_node;
30693128 fn_entry->body_node = (proto_node->data.fn_proto.fn_def_node == nullptr) ? nullptr :
......@@ -3111,26 +3170,26 @@ ZigType *get_test_fn_type(CodeGen *g) {
31113170 return g->test_fn_type;
31123171}
31133172
3114void add_var_export(CodeGen *g, ZigVar *var, Buf *symbol_name, GlobalLinkageId linkage) {
3173void add_var_export(CodeGen *g, ZigVar *var, const char *symbol_name, GlobalLinkageId linkage) {
31153174 GlobalExport *global_export = var->export_list.add_one();
31163175 memset(global_export, 0, sizeof(GlobalExport));
3117 buf_init_from_buf(&global_export->name, symbol_name);
3176 buf_init_from_str(&global_export->name, symbol_name);
31183177 global_export->linkage = linkage;
31193178}
31203179
3121void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, Buf *symbol_name, GlobalLinkageId linkage, bool ccc) {
3180void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage, bool ccc) {
31223181 if (ccc) {
3123 if (buf_eql_str(symbol_name, "main") && g->libc_link_lib != nullptr) {
3182 if (strcmp(symbol_name, "main") == 0 && g->libc_link_lib != nullptr) {
31243183 g->have_c_main = true;
3125 } else if (buf_eql_str(symbol_name, "WinMain") &&
3184 } else if (strcmp(symbol_name, "WinMain") == 0 &&
31263185 g->zig_target->os == OsWindows)
31273186 {
31283187 g->have_winmain = true;
3129 } else if (buf_eql_str(symbol_name, "WinMainCRTStartup") &&
3188 } else if (strcmp(symbol_name, "WinMainCRTStartup") == 0 &&
31303189 g->zig_target->os == OsWindows)
31313190 {
31323191 g->have_winmain_crt_startup = true;
3133 } else if (buf_eql_str(symbol_name, "DllMainCRTStartup") &&
3192 } else if (strcmp(symbol_name, "DllMainCRTStartup") == 0 &&
31343193 g->zig_target->os == OsWindows)
31353194 {
31363195 g->have_dllmain_crt_startup = true;
......@@ -3139,7 +3198,7 @@ void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, Buf *symbol_name, GlobalLi
31393198
31403199 GlobalExport *fn_export = fn_table_entry->export_list.add_one();
31413200 memset(fn_export, 0, sizeof(GlobalExport));
3142 buf_init_from_buf(&fn_export->name, symbol_name);
3201 buf_init_from_str(&fn_export->name, symbol_name);
31433202 fn_export->linkage = linkage;
31443203}
31453204
......@@ -3163,7 +3222,7 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
31633222
31643223 if (fn_proto->is_export) {
31653224 bool ccc = (fn_proto->cc == CallingConventionUnspecified || fn_proto->cc == CallingConventionC);
3166 add_fn_export(g, fn_table_entry, &fn_table_entry->symbol_name, GlobalLinkageIdStrong, ccc);
3225 add_fn_export(g, fn_table_entry, buf_ptr(&fn_table_entry->symbol_name), GlobalLinkageIdStrong, ccc);
31673226 }
31683227
31693228 if (!is_extern) {
......@@ -3522,7 +3581,7 @@ ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf
35223581 variable_entry->src_arg_index = SIZE_MAX;
35233582
35243583 assert(name);
3525 buf_init_from_buf(&variable_entry->name, name);
3584 variable_entry->name = strdup(buf_ptr(name));
35263585
35273586 if ((err = type_resolve(g, var_type, ResolveStatusAlignmentKnown))) {
35283587 variable_entry->var_type = g->builtin_types.entry_invalid;
......@@ -3670,7 +3729,7 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var, bool allow_lazy) {
36703729 }
36713730
36723731 if (is_export) {
3673 add_var_export(g, tld_var->var, &tld_var->var->name, GlobalLinkageIdStrong);
3732 add_var_export(g, tld_var->var, tld_var->var->name, GlobalLinkageIdStrong);
36743733 }
36753734
36763735 g->global_vars.append(tld_var);
......@@ -3879,7 +3938,7 @@ ZigVar *find_variable(CodeGen *g, Scope *scope, Buf *name, ScopeFnDef **crossed_
38793938 while (scope) {
38803939 if (scope->id == ScopeIdVarDecl) {
38813940 ScopeVarDecl *var_scope = (ScopeVarDecl *)scope;
3882 if (buf_eql_buf(name, &var_scope->var->name)) {
3941 if (buf_eql_str(name, var_scope->var->name)) {
38833942 if (crossed_fndef_scope != nullptr)
38843943 *crossed_fndef_scope = my_crossed_fndef_scope;
38853944 return var_scope->var;
......@@ -4191,7 +4250,7 @@ bool fn_is_async(ZigFn *fn) {
41914250 return fn->inferred_async_node != inferred_async_none;
41924251}
41934252
4194static void add_async_error_notes(CodeGen *g, ErrorMsg *msg, ZigFn *fn) {
4253void add_async_error_notes(CodeGen *g, ErrorMsg *msg, ZigFn *fn) {
41954254 assert(fn->inferred_async_node != nullptr);
41964255 assert(fn->inferred_async_node != inferred_async_checking);
41974256 assert(fn->inferred_async_node != inferred_async_none);
......@@ -4215,7 +4274,7 @@ static void add_async_error_notes(CodeGen *g, ErrorMsg *msg, ZigFn *fn) {
42154274 add_error_note(g, msg, fn->inferred_async_node,
42164275 buf_sprintf("await here is a suspend point"));
42174276 } else if (fn->inferred_async_node->type == NodeTypeFnCallExpr &&
4218 fn->inferred_async_node->data.fn_call_expr.is_builtin)
4277 fn->inferred_async_node->data.fn_call_expr.modifier == CallModifierBuiltin)
42194278 {
42204279 add_error_note(g, msg, fn->inferred_async_node,
42214280 buf_sprintf("@frame() causes function to be async"));
......@@ -4229,33 +4288,44 @@ static void add_async_error_notes(CodeGen *g, ErrorMsg *msg, ZigFn *fn) {
42294288// ErrorIsAsync - yes async
42304289// ErrorSemanticAnalyzeFail - compile error emitted result is invalid
42314290static Error analyze_callee_async(CodeGen *g, ZigFn *fn, ZigFn *callee, AstNode *call_node,
4232 bool must_not_be_async)
4291 bool must_not_be_async, CallModifier modifier)
42334292{
4234 if (callee->type_entry->data.fn.fn_type_id.cc != CallingConventionUnspecified)
4293 if (modifier == CallModifierNoAsync)
42354294 return ErrorNone;
4236 if (callee->anal_state == FnAnalStateReady) {
4237 analyze_fn_body(g, callee);
4238 if (callee->anal_state == FnAnalStateInvalid) {
4239 return ErrorSemanticAnalyzeFail;
4240 }
4295 bool callee_is_async = false;
4296 switch (callee->type_entry->data.fn.fn_type_id.cc) {
4297 case CallingConventionUnspecified:
4298 break;
4299 case CallingConventionAsync:
4300 callee_is_async = true;
4301 break;
4302 default:
4303 return ErrorNone;
42414304 }
4242 bool callee_is_async;
4243 if (callee->anal_state == FnAnalStateComplete) {
4244 analyze_fn_async(g, callee, true);
4245 if (callee->anal_state == FnAnalStateInvalid) {
4246 return ErrorSemanticAnalyzeFail;
4305 if (!callee_is_async) {
4306 if (callee->anal_state == FnAnalStateReady) {
4307 analyze_fn_body(g, callee);
4308 if (callee->anal_state == FnAnalStateInvalid) {
4309 return ErrorSemanticAnalyzeFail;
4310 }
42474311 }
4248 callee_is_async = fn_is_async(callee);
4249 } else {
4250 // If it's already been determined, use that value. Otherwise
4251 // assume non-async, emit an error later if it turned out to be async.
4252 if (callee->inferred_async_node == nullptr ||
4253 callee->inferred_async_node == inferred_async_checking)
4254 {
4255 callee->assumed_non_async = call_node;
4256 callee_is_async = false;
4312 if (callee->anal_state == FnAnalStateComplete) {
4313 analyze_fn_async(g, callee, true);
4314 if (callee->anal_state == FnAnalStateInvalid) {
4315 return ErrorSemanticAnalyzeFail;
4316 }
4317 callee_is_async = fn_is_async(callee);
42574318 } else {
4258 callee_is_async = callee->inferred_async_node != inferred_async_none;
4319 // If it's already been determined, use that value. Otherwise
4320 // assume non-async, emit an error later if it turned out to be async.
4321 if (callee->inferred_async_node == nullptr ||
4322 callee->inferred_async_node == inferred_async_checking)
4323 {
4324 callee->assumed_non_async = call_node;
4325 callee_is_async = false;
4326 } else {
4327 callee_is_async = callee->inferred_async_node != inferred_async_none;
4328 }
42594329 }
42604330 }
42614331 if (callee_is_async) {
......@@ -4313,7 +4383,9 @@ static void analyze_fn_async(CodeGen *g, ZigFn *fn, bool resolve_frame) {
43134383 // TODO function pointer call here, could be anything
43144384 continue;
43154385 }
4316 switch (analyze_callee_async(g, fn, call->fn_entry, call->base.source_node, must_not_be_async)) {
4386 switch (analyze_callee_async(g, fn, call->fn_entry, call->base.source_node, must_not_be_async,
4387 call->modifier))
4388 {
43174389 case ErrorSemanticAnalyzeFail:
43184390 fn->anal_state = FnAnalStateInvalid;
43194391 return;
......@@ -4330,7 +4402,11 @@ static void analyze_fn_async(CodeGen *g, ZigFn *fn, bool resolve_frame) {
43304402 }
43314403 for (size_t i = 0; i < fn->await_list.length; i += 1) {
43324404 IrInstructionAwaitGen *await = fn->await_list.at(i);
4333 switch (analyze_callee_async(g, fn, await->target_fn, await->base.source_node, must_not_be_async)) {
4405 // TODO If this is a noasync await, it doesn't count
4406 // https://github.com/ziglang/zig/issues/3157
4407 switch (analyze_callee_async(g, fn, await->target_fn, await->base.source_node, must_not_be_async,
4408 CallModifierNone))
4409 {
43344410 case ErrorSemanticAnalyzeFail:
43354411 fn->anal_state = FnAnalStateInvalid;
43364412 return;
......@@ -4415,7 +4491,7 @@ static void analyze_fn_ir(CodeGen *g, ZigFn *fn, AstNode *return_type_node) {
44154491
44164492 if (g->verbose_ir) {
44174493 fprintf(stderr, "fn %s() { // (analyzed)\n", buf_ptr(&fn->symbol_name));
4418 ir_print(g, stderr, &fn->analyzed_executable, 4, 2);
4494 ir_print(g, stderr, &fn->analyzed_executable, 4, IrPassGen);
44194495 fprintf(stderr, "}\n");
44204496 }
44214497 fn->anal_state = FnAnalStateComplete;
......@@ -4448,8 +4524,8 @@ static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry) {
44484524 if (g->verbose_ir) {
44494525 fprintf(stderr, "\n");
44504526 ast_render(stderr, fn_table_entry->body_node, 4);
4451 fprintf(stderr, "\n{ // (IR)\n");
4452 ir_print(g, stderr, &fn_table_entry->ir_executable, 4, 1);
4527 fprintf(stderr, "\nfn %s() { // (IR)\n", buf_ptr(&fn_table_entry->symbol_name));
4528 ir_print(g, stderr, &fn_table_entry->ir_executable, 4, IrPassSrc);
44534529 fprintf(stderr, "}\n");
44544530 }
44554531
......@@ -5638,6 +5714,83 @@ static ZigType *get_async_fn_type(CodeGen *g, ZigType *orig_fn_type) {
56385714 return fn_type;
56395715}
56405716
5717// Traverse up to the very top ExprScope, which has children.
5718// We have just arrived at the top from a child. That child,
5719// and its next siblings, do not need to be marked. But the previous
5720// siblings do.
5721// x + (await y)
5722// vs
5723// (await y) + x
5724static void mark_suspension_point(Scope *scope) {
5725 ScopeExpr *child_expr_scope = (scope->id == ScopeIdExpr) ? reinterpret_cast<ScopeExpr *>(scope) : nullptr;
5726 bool looking_for_exprs = true;
5727 for (;;) {
5728 scope = scope->parent;
5729 switch (scope->id) {
5730 case ScopeIdDeferExpr:
5731 case ScopeIdDecls:
5732 case ScopeIdFnDef:
5733 case ScopeIdCompTime:
5734 case ScopeIdCImport:
5735 case ScopeIdSuspend:
5736 case ScopeIdTypeOf:
5737 return;
5738 case ScopeIdVarDecl:
5739 case ScopeIdDefer:
5740 case ScopeIdBlock:
5741 looking_for_exprs = false;
5742 continue;
5743 case ScopeIdRuntime:
5744 continue;
5745 case ScopeIdLoop: {
5746 ScopeLoop *loop_scope = reinterpret_cast<ScopeLoop *>(scope);
5747 if (loop_scope->spill_scope != nullptr) {
5748 loop_scope->spill_scope->need_spill = MemoizedBoolTrue;
5749 }
5750 looking_for_exprs = false;
5751 continue;
5752 }
5753 case ScopeIdExpr: {
5754 if (!looking_for_exprs) {
5755 // Now we're only looking for a block, to see if it's in a loop (see the case ScopeIdBlock)
5756 continue;
5757 }
5758 ScopeExpr *parent_expr_scope = reinterpret_cast<ScopeExpr *>(scope);
5759 if (child_expr_scope != nullptr) {
5760 for (size_t i = 0; parent_expr_scope->children_ptr[i] != child_expr_scope; i += 1) {
5761 assert(i < parent_expr_scope->children_len);
5762 parent_expr_scope->children_ptr[i]->need_spill = MemoizedBoolTrue;
5763 }
5764 }
5765 parent_expr_scope->need_spill = MemoizedBoolTrue;
5766 child_expr_scope = parent_expr_scope;
5767 continue;
5768 }
5769 }
5770 }
5771}
5772
5773static bool scope_needs_spill(Scope *scope) {
5774 ScopeExpr *scope_expr = find_expr_scope(scope);
5775 if (scope_expr == nullptr) return false;
5776
5777 switch (scope_expr->need_spill) {
5778 case MemoizedBoolUnknown:
5779 if (scope_needs_spill(scope_expr->base.parent)) {
5780 scope_expr->need_spill = MemoizedBoolTrue;
5781 return true;
5782 } else {
5783 scope_expr->need_spill = MemoizedBoolFalse;
5784 return false;
5785 }
5786 case MemoizedBoolFalse:
5787 return false;
5788 case MemoizedBoolTrue:
5789 return true;
5790 }
5791 zig_unreachable();
5792}
5793
56415794static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
56425795 Error err;
56435796
......@@ -5766,16 +5919,87 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
57665919 if (!fn_is_async(callee))
57675920 continue;
57685921
5769 IrInstructionAllocaGen *alloca_gen = allocate<IrInstructionAllocaGen>(1);
5770 alloca_gen->base.id = IrInstructionIdAllocaGen;
5771 alloca_gen->base.source_node = call->base.source_node;
5772 alloca_gen->base.scope = call->base.scope;
5773 alloca_gen->base.value.type = get_pointer_to_type(g, callee_frame_type, false);
5774 alloca_gen->base.ref_count = 1;
5775 alloca_gen->name_hint = "";
5776 fn->alloca_gen_list.append(alloca_gen);
5777 call->frame_result_loc = &alloca_gen->base;
5922 mark_suspension_point(call->base.scope);
5923
5924 call->frame_result_loc = ir_create_alloca(g, call->base.scope, call->base.source_node, fn,
5925 callee_frame_type, "");
5926 }
5927 // Since this frame is async, an await might represent a suspend point, and
5928 // therefore need to spill. It also needs to mark expr scopes as having to spill.
5929 // For example: foo() + await z
5930 // The funtion call result of foo() must be spilled.
5931 for (size_t i = 0; i < fn->await_list.length; i += 1) {
5932 IrInstructionAwaitGen *await = fn->await_list.at(i);
5933 // TODO If this is a noasync await, it doesn't suspend
5934 // https://github.com/ziglang/zig/issues/3157
5935 if (await->base.value.special != ConstValSpecialRuntime) {
5936 // Known at comptime. No spill, no suspend.
5937 continue;
5938 }
5939 if (await->target_fn != nullptr) {
5940 // we might not need to suspend
5941 analyze_fn_async(g, await->target_fn, false);
5942 if (await->target_fn->anal_state == FnAnalStateInvalid) {
5943 frame_type->data.frame.locals_struct = g->builtin_types.entry_invalid;
5944 return ErrorSemanticAnalyzeFail;
5945 }
5946 if (!fn_is_async(await->target_fn)) {
5947 // This await does not represent a suspend point. No spill needed,
5948 // and no need to mark ExprScope.
5949 continue;
5950 }
5951 }
5952 // This await is a suspend point, but it might not need a spill.
5953 // We do need to mark the ExprScope as having a suspend point in it.
5954 mark_suspension_point(await->base.scope);
5955
5956 if (await->result_loc != nullptr) {
5957 // If there's a result location, that is the spill
5958 continue;
5959 }
5960 if (await->base.ref_count == 0)
5961 continue;
5962 if (!type_has_bits(await->base.value.type))
5963 continue;
5964 await->result_loc = ir_create_alloca(g, await->base.scope, await->base.source_node, fn,
5965 await->base.value.type, "");
5966 }
5967 for (size_t block_i = 0; block_i < fn->analyzed_executable.basic_block_list.length; block_i += 1) {
5968 IrBasicBlock *block = fn->analyzed_executable.basic_block_list.at(block_i);
5969 for (size_t instr_i = 0; instr_i < block->instruction_list.length; instr_i += 1) {
5970 IrInstruction *instruction = block->instruction_list.at(instr_i);
5971 if (instruction->id == IrInstructionIdSuspendFinish) {
5972 mark_suspension_point(instruction->scope);
5973 }
5974 }
5975 }
5976 // Now that we've marked all the expr scopes that have to spill, we go over the instructions
5977 // and spill the relevant ones.
5978 for (size_t block_i = 0; block_i < fn->analyzed_executable.basic_block_list.length; block_i += 1) {
5979 IrBasicBlock *block = fn->analyzed_executable.basic_block_list.at(block_i);
5980 for (size_t instr_i = 0; instr_i < block->instruction_list.length; instr_i += 1) {
5981 IrInstruction *instruction = block->instruction_list.at(instr_i);
5982 if (instruction->id == IrInstructionIdAwaitGen ||
5983 instruction->id == IrInstructionIdVarPtr ||
5984 instruction->id == IrInstructionIdDeclRef ||
5985 instruction->id == IrInstructionIdAllocaGen)
5986 {
5987 // This instruction does its own spilling specially, or otherwise doesn't need it.
5988 continue;
5989 }
5990 if (instruction->value.special != ConstValSpecialRuntime)
5991 continue;
5992 if (instruction->ref_count == 0)
5993 continue;
5994 if (!type_has_bits(instruction->value.type))
5995 continue;
5996 if (scope_needs_spill(instruction->scope)) {
5997 instruction->spill = ir_create_alloca(g, instruction->scope, instruction->source_node,
5998 fn, instruction->value.type, "");
5999 }
6000 }
57786001 }
6002
57796003 FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id;
57806004 ZigType *ptr_return_type = get_pointer_to_type(g, fn_type_id->return_type, false);
57816005
......@@ -5858,6 +6082,11 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
58586082 frame_type->abi_size = frame_type->data.frame.locals_struct->abi_size;
58596083 frame_type->abi_align = frame_type->data.frame.locals_struct->abi_align;
58606084 frame_type->size_in_bits = frame_type->data.frame.locals_struct->size_in_bits;
6085
6086 if (g->largest_frame_fn == nullptr || frame_type->abi_size > g->largest_frame_fn->frame_type->abi_size) {
6087 g->largest_frame_fn = fn;
6088 }
6089
58616090 return ErrorNone;
58626091}
58636092
......@@ -6216,9 +6445,7 @@ void eval_min_max_value(CodeGen *g, ZigType *type_entry, ConstExprValue *const_v
62166445}
62176446
62186447static void render_const_val_ptr(CodeGen *g, Buf *buf, ConstExprValue *const_val, ZigType *type_entry) {
6219 assert(type_entry->id == ZigTypeIdPointer);
6220
6221 if (type_entry->data.pointer.child_type->id == ZigTypeIdOpaque) {
6448 if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.child_type->id == ZigTypeIdOpaque) {
62226449 buf_append_buf(buf, &type_entry->name);
62236450 return;
62246451 }
......@@ -7683,12 +7910,19 @@ static void resolve_llvm_types_enum(CodeGen *g, ZigType *enum_type, ResolveStatu
76837910static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveStatus wanted_resolve_status) {
76847911 if (union_type->data.unionation.resolve_status >= wanted_resolve_status) return;
76857912
7913 bool packed = (union_type->data.unionation.layout == ContainerLayoutPacked);
7914
76867915 TypeUnionField *most_aligned_union_member = union_type->data.unionation.most_aligned_union_member;
76877916 ZigType *tag_type = union_type->data.unionation.tag_type;
76887917 uint32_t gen_field_count = union_type->data.unionation.gen_field_count;
76897918 if (gen_field_count == 0) {
7690 union_type->llvm_type = get_llvm_type(g, tag_type);
7691 union_type->llvm_di_type = get_llvm_di_type(g, tag_type);
7919 if (tag_type == nullptr) {
7920 union_type->llvm_type = g->builtin_types.entry_void->llvm_type;
7921 union_type->llvm_di_type = g->builtin_types.entry_void->llvm_di_type;
7922 } else {
7923 union_type->llvm_type = get_llvm_type(g, tag_type);
7924 union_type->llvm_di_type = get_llvm_di_type(g, tag_type);
7925 }
76927926 union_type->data.unionation.resolve_status = ResolveStatusLLVMFull;
76937927 return;
76947928 }
......@@ -7744,9 +7978,9 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta
77447978 most_aligned_union_member->type_entry->llvm_type,
77457979 get_llvm_type(g, padding_array),
77467980 };
7747 LLVMStructSetBody(union_type->llvm_type, union_element_types, 2, false);
7981 LLVMStructSetBody(union_type->llvm_type, union_element_types, 2, packed);
77487982 } else {
7749 LLVMStructSetBody(union_type->llvm_type, &most_aligned_union_member->type_entry->llvm_type, 1, false);
7983 LLVMStructSetBody(union_type->llvm_type, &most_aligned_union_member->type_entry->llvm_type, 1, packed);
77507984 }
77517985 union_type->data.unionation.union_llvm_type = union_type->llvm_type;
77527986 union_type->data.unionation.gen_tag_index = SIZE_MAX;
......@@ -7785,7 +8019,7 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta
77858019 LLVMTypeRef root_struct_element_types[2];
77868020 root_struct_element_types[union_type->data.unionation.gen_tag_index] = get_llvm_type(g, tag_type);
77878021 root_struct_element_types[union_type->data.unionation.gen_union_index] = union_type_ref;
7788 LLVMStructSetBody(union_type->llvm_type, root_struct_element_types, 2, false);
8022 LLVMStructSetBody(union_type->llvm_type, root_struct_element_types, 2, packed);
77898023
77908024 // create debug type for union
77918025 ZigLLVMDIType *union_di_type = ZigLLVMCreateDebugUnionType(g->dbuilder,
......@@ -8495,3 +8729,18 @@ void src_assert(bool ok, AstNode *source_node) {
84958729 const char *msg = "assertion failed. This is a bug in the Zig compiler.";
84968730 stage2_panic(msg, strlen(msg));
84978731}
8732
8733IrInstruction *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node, ZigFn *fn,
8734 ZigType *var_type, const char *name_hint)
8735{
8736 IrInstructionAllocaGen *alloca_gen = allocate<IrInstructionAllocaGen>(1);
8737 alloca_gen->base.id = IrInstructionIdAllocaGen;
8738 alloca_gen->base.source_node = source_node;
8739 alloca_gen->base.scope = scope;
8740 alloca_gen->base.value.type = get_pointer_to_type(g, var_type, false);
8741 alloca_gen->base.ref_count = 1;
8742 alloca_gen->name_hint = name_hint;
8743 fn->alloca_gen_list.append(alloca_gen);
8744 return &alloca_gen->base;
8745}
8746
src/analyze.hpp+8-2
......@@ -114,6 +114,7 @@ ScopeFnDef *create_fndef_scope(CodeGen *g, AstNode *node, Scope *parent, ZigFn *
114114Scope *create_comptime_scope(CodeGen *g, AstNode *node, Scope *parent);
115115Scope *create_runtime_scope(CodeGen *g, AstNode *node, Scope *parent, IrInstruction *is_comptime);
116116Scope *create_typeof_scope(CodeGen *g, AstNode *node, Scope *parent);
117ScopeExpr *create_expr_scope(CodeGen *g, AstNode *node, Scope *parent);
117118
118119void init_const_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *str);
119120ConstExprValue *create_const_str_lit(CodeGen *g, Buf *str);
......@@ -188,8 +189,8 @@ ZigType *get_align_amt_type(CodeGen *g);
188189ZigPackage *new_anonymous_package(void);
189190
190191Buf *const_value_to_buffer(ConstExprValue *const_val);
191void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, Buf *symbol_name, GlobalLinkageId linkage, bool ccc);
192void add_var_export(CodeGen *g, ZigVar *fn_table_entry, Buf *symbol_name, GlobalLinkageId linkage);
192void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage, bool ccc);
193void add_var_export(CodeGen *g, ZigVar *fn_table_entry, const char *symbol_name, GlobalLinkageId linkage);
193194
194195
195196ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name);
......@@ -256,4 +257,9 @@ Error type_val_resolve_zero_bits(CodeGen *g, ConstExprValue *type_val, ZigType *
256257ZigType *resolve_union_field_type(CodeGen *g, TypeUnionField *union_field);
257258ZigType *resolve_struct_field_type(CodeGen *g, TypeStructField *struct_field);
258259
260void add_async_error_notes(CodeGen *g, ErrorMsg *msg, ZigFn *fn);
261
262IrInstruction *ir_create_alloca(CodeGen *g, Scope *scope, AstNode *source_node, ZigFn *fn,
263 ZigType *var_type, const char *name_hint);
264
259265#endif
src/ast_render.cpp+20-8
......@@ -124,8 +124,13 @@ static const char *export_string(bool is_export) {
124124// zig_unreachable();
125125//}
126126
127static const char *inline_string(bool is_inline) {
128 return is_inline ? "inline " : "";
127static const char *inline_string(FnInline fn_inline) {
128 switch (fn_inline) {
129 case FnInlineAlways: return "inline ";
130 case FnInlineNever: return "noinline ";
131 case FnInlineAuto: return "";
132 }
133 zig_unreachable();
129134}
130135
131136static const char *const_or_var_string(bool is_const) {
......@@ -436,7 +441,7 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
436441 const char *pub_str = visib_mod_string(node->data.fn_proto.visib_mod);
437442 const char *extern_str = extern_string(node->data.fn_proto.is_extern);
438443 const char *export_str = export_string(node->data.fn_proto.is_export);
439 const char *inline_str = inline_string(node->data.fn_proto.is_inline);
444 const char *inline_str = inline_string(node->data.fn_proto.fn_inline);
440445 fprintf(ar->f, "%s%s%s%sfn ", pub_str, inline_str, export_str, extern_str);
441446 if (node->data.fn_proto.name != nullptr) {
442447 print_symbol(ar, node->data.fn_proto.name);
......@@ -693,11 +698,18 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
693698 }
694699 case NodeTypeFnCallExpr:
695700 {
696 if (node->data.fn_call_expr.is_builtin) {
697 fprintf(ar->f, "@");
698 }
699 if (node->data.fn_call_expr.is_async) {
700 fprintf(ar->f, "async ");
701 switch (node->data.fn_call_expr.modifier) {
702 case CallModifierNone:
703 break;
704 case CallModifierBuiltin:
705 fprintf(ar->f, "@");
706 break;
707 case CallModifierAsync:
708 fprintf(ar->f, "async ");
709 break;
710 case CallModifierNoAsync:
711 fprintf(ar->f, "noasync ");
712 break;
701713 }
702714 AstNode *fn_ref_node = node->data.fn_call_expr.fn_ref_expr;
703715 bool grouped = (fn_ref_node->type != NodeTypePrefixOpExpr && fn_ref_node->type != NodeTypePointerType);
src/buffer.hpp+5
......@@ -57,6 +57,11 @@ static inline void buf_deinit(Buf *buf) {
5757 buf->list.deinit();
5858}
5959
60static inline void buf_destroy(Buf *buf) {
61 buf_deinit(buf);
62 free(buf);
63}
64
6065static inline void buf_init_from_mem(Buf *buf, const char *ptr, size_t len) {
6166 assert(len != SIZE_MAX);
6267 buf->list.resize(len + 1);
src/codegen.cpp+216-85
......@@ -183,9 +183,12 @@ static void render_const_val(CodeGen *g, ConstExprValue *const_val, const char *
183183static void render_const_val_global(CodeGen *g, ConstExprValue *const_val, const char *name);
184184static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const char *name);
185185static void generate_error_name_table(CodeGen *g);
186static bool value_is_all_undef(ConstExprValue *const_val);
186static bool value_is_all_undef(CodeGen *g, ConstExprValue *const_val);
187187static void gen_undef_init(CodeGen *g, uint32_t ptr_align_bytes, ZigType *value_type, LLVMValueRef ptr);
188188static LLVMValueRef build_alloca(CodeGen *g, ZigType *type_entry, const char *name, uint32_t alignment);
189static LLVMValueRef gen_await_early_return(CodeGen *g, IrInstruction *source_instr,
190 LLVMValueRef target_frame_ptr, ZigType *result_type, ZigType *ptr_result_type,
191 LLVMValueRef result_loc, bool non_async);
189192
190193static void addLLVMAttr(LLVMValueRef val, LLVMAttributeIndex attr_index, const char *attr_name) {
191194 unsigned kind_id = LLVMGetEnumAttributeKindForName(attr_name, strlen(attr_name));
......@@ -231,18 +234,23 @@ static void addLLVMArgAttrInt(LLVMValueRef fn_val, unsigned param_index, const c
231234 return addLLVMAttrInt(fn_val, param_index + 1, attr_name, attr_val);
232235}
233236
234static bool is_symbol_available(CodeGen *g, Buf *name) {
235 return g->exported_symbol_names.maybe_get(name) == nullptr && g->external_prototypes.maybe_get(name) == nullptr;
237static bool is_symbol_available(CodeGen *g, const char *name) {
238 Buf *buf_name = buf_create_from_str(name);
239 bool result =
240 g->exported_symbol_names.maybe_get(buf_name) == nullptr &&
241 g->external_prototypes.maybe_get(buf_name) == nullptr;
242 buf_destroy(buf_name);
243 return result;
236244}
237245
238static Buf *get_mangled_name(CodeGen *g, Buf *original_name, bool external_linkage) {
246static const char *get_mangled_name(CodeGen *g, const char *original_name, bool external_linkage) {
239247 if (external_linkage || is_symbol_available(g, original_name)) {
240248 return original_name;
241249 }
242250
243251 int n = 0;
244252 for (;; n += 1) {
245 Buf *new_name = buf_sprintf("%s.%d", buf_ptr(original_name), n);
253 const char *new_name = buf_ptr(buf_sprintf("%s.%d", original_name, n));
246254 if (is_symbol_available(g, new_name)) {
247255 return new_name;
248256 }
......@@ -384,8 +392,8 @@ static bool codegen_have_frame_pointer(CodeGen *g) {
384392}
385393
386394static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) {
387 Buf *unmangled_name = &fn->symbol_name;
388 Buf *symbol_name;
395 const char *unmangled_name = buf_ptr(&fn->symbol_name);
396 const char *symbol_name;
389397 GlobalLinkageId linkage;
390398 if (fn->body_node == nullptr) {
391399 symbol_name = unmangled_name;
......@@ -395,7 +403,7 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) {
395403 linkage = GlobalLinkageIdInternal;
396404 } else {
397405 GlobalExport *fn_export = &fn->export_list.items[0];
398 symbol_name = &fn_export->name;
406 symbol_name = buf_ptr(&fn_export->name);
399407 linkage = fn_export->linkage;
400408 }
401409
......@@ -405,7 +413,7 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) {
405413 g->zig_target->arch == ZigLLVM_x86)
406414 {
407415 // prevent llvm name mangling
408 symbol_name = buf_sprintf("\x01_%s", buf_ptr(symbol_name));
416 symbol_name = buf_ptr(buf_sprintf("\x01_%s", symbol_name));
409417 }
410418
411419 bool is_async = fn_is_async(fn);
......@@ -417,13 +425,16 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) {
417425 LLVMTypeRef fn_llvm_type = fn->raw_type_ref;
418426 LLVMValueRef llvm_fn = nullptr;
419427 if (fn->body_node == nullptr) {
420 LLVMValueRef existing_llvm_fn = LLVMGetNamedFunction(g->module, buf_ptr(symbol_name));
428 LLVMValueRef existing_llvm_fn = LLVMGetNamedFunction(g->module, symbol_name);
421429 if (existing_llvm_fn) {
422430 return LLVMConstBitCast(existing_llvm_fn, LLVMPointerType(fn_llvm_type, 0));
423431 } else {
424 auto entry = g->exported_symbol_names.maybe_get(symbol_name);
432 Buf *buf_symbol_name = buf_create_from_str(symbol_name);
433 auto entry = g->exported_symbol_names.maybe_get(buf_symbol_name);
434 buf_destroy(buf_symbol_name);
435
425436 if (entry == nullptr) {
426 llvm_fn = LLVMAddFunction(g->module, buf_ptr(symbol_name), fn_llvm_type);
437 llvm_fn = LLVMAddFunction(g->module, symbol_name, fn_llvm_type);
427438
428439 if (target_is_wasm(g->zig_target)) {
429440 assert(fn->proto_node->type == NodeTypeFnProto);
......@@ -437,7 +448,7 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) {
437448 TldFn *tld_fn = reinterpret_cast<TldFn *>(entry->value);
438449 // Make the raw_type_ref populated
439450 resolve_llvm_types_fn(g, tld_fn->fn_entry);
440 tld_fn->fn_entry->llvm_value = LLVMAddFunction(g->module, buf_ptr(symbol_name),
451 tld_fn->fn_entry->llvm_value = LLVMAddFunction(g->module, symbol_name,
441452 tld_fn->fn_entry->raw_type_ref);
442453 llvm_fn = LLVMConstBitCast(tld_fn->fn_entry->llvm_value, LLVMPointerType(fn_llvm_type, 0));
443454 return llvm_fn;
......@@ -445,7 +456,7 @@ static LLVMValueRef make_fn_llvm_value(CodeGen *g, ZigFn *fn) {
445456 }
446457 } else {
447458 if (llvm_fn == nullptr) {
448 llvm_fn = LLVMAddFunction(g->module, buf_ptr(symbol_name), fn_llvm_type);
459 llvm_fn = LLVMAddFunction(g->module, symbol_name, fn_llvm_type);
449460 }
450461
451462 for (size_t i = 1; i < fn->export_list.length; i += 1) {
......@@ -646,6 +657,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) {
646657 case ScopeIdCompTime:
647658 case ScopeIdRuntime:
648659 case ScopeIdTypeOf:
660 case ScopeIdExpr:
649661 return get_di_scope(g, scope->parent);
650662 }
651663 zig_unreachable();
......@@ -920,6 +932,8 @@ static Buf *panic_msg_buf(PanicMsgId msg_id) {
920932 return buf_create_from_str("frame too small");
921933 case PanicMsgIdResumedFnPendingAwait:
922934 return buf_create_from_str("resumed an async function which can only be awaited");
935 case PanicMsgIdBadNoAsyncCall:
936 return buf_create_from_str("async function called with noasync suspended");
923937 }
924938 zig_unreachable();
925939}
......@@ -1052,8 +1066,8 @@ static LLVMValueRef get_add_error_return_trace_addr_fn(CodeGen *g) {
10521066 };
10531067 LLVMTypeRef fn_type_ref = LLVMFunctionType(LLVMVoidType(), arg_types, 2, false);
10541068
1055 Buf *fn_name = get_mangled_name(g, buf_create_from_str("__zig_add_err_ret_trace_addr"), false);
1056 LLVMValueRef fn_val = LLVMAddFunction(g->module, buf_ptr(fn_name), fn_type_ref);
1069 const char *fn_name = get_mangled_name(g, "__zig_add_err_ret_trace_addr", false);
1070 LLVMValueRef fn_val = LLVMAddFunction(g->module, fn_name, fn_type_ref);
10571071 addLLVMFnAttr(fn_val, "alwaysinline");
10581072 LLVMSetLinkage(fn_val, LLVMInternalLinkage);
10591073 LLVMSetFunctionCallConv(fn_val, get_llvm_cc(g, CallingConventionUnspecified));
......@@ -1132,8 +1146,8 @@ static LLVMValueRef get_return_err_fn(CodeGen *g) {
11321146 };
11331147 LLVMTypeRef fn_type_ref = LLVMFunctionType(LLVMVoidType(), arg_types, 1, false);
11341148
1135 Buf *fn_name = get_mangled_name(g, buf_create_from_str("__zig_return_error"), false);
1136 LLVMValueRef fn_val = LLVMAddFunction(g->module, buf_ptr(fn_name), fn_type_ref);
1149 const char *fn_name = get_mangled_name(g, "__zig_return_error", false);
1150 LLVMValueRef fn_val = LLVMAddFunction(g->module, fn_name, fn_type_ref);
11371151 addLLVMFnAttr(fn_val, "noinline"); // so that we can look at return address
11381152 addLLVMFnAttr(fn_val, "cold");
11391153 LLVMSetLinkage(fn_val, LLVMInternalLinkage);
......@@ -1202,7 +1216,7 @@ static LLVMValueRef get_safety_crash_err_fn(CodeGen *g) {
12021216 LLVMSetLinkage(msg_prefix, LLVMInternalLinkage);
12031217 LLVMSetGlobalConstant(msg_prefix, true);
12041218
1205 Buf *fn_name = get_mangled_name(g, buf_create_from_str("__zig_fail_unwrap"), false);
1219 const char *fn_name = get_mangled_name(g, "__zig_fail_unwrap", false);
12061220 LLVMTypeRef fn_type_ref;
12071221 if (g->have_err_ret_tracing) {
12081222 LLVMTypeRef arg_types[] = {
......@@ -1216,7 +1230,7 @@ static LLVMValueRef get_safety_crash_err_fn(CodeGen *g) {
12161230 };
12171231 fn_type_ref = LLVMFunctionType(LLVMVoidType(), arg_types, 1, false);
12181232 }
1219 LLVMValueRef fn_val = LLVMAddFunction(g->module, buf_ptr(fn_name), fn_type_ref);
1233 LLVMValueRef fn_val = LLVMAddFunction(g->module, fn_name, fn_type_ref);
12201234 addLLVMFnAttr(fn_val, "noreturn");
12211235 addLLVMFnAttr(fn_val, "cold");
12221236 LLVMSetLinkage(fn_val, LLVMInternalLinkage);
......@@ -1639,7 +1653,6 @@ static void gen_assign_raw(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_type,
16391653 LLVMValueRef ored_value = LLVMBuildOr(g->builder, shifted_value, anded_containing_int, "");
16401654
16411655 gen_store(g, ored_value, ptr, ptr_type);
1642 return;
16431656}
16441657
16451658static void gen_var_debug_decl(CodeGen *g, ZigVar *var) {
......@@ -1656,6 +1669,19 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) {
16561669 if (!type_has_bits(instruction->value.type))
16571670 return nullptr;
16581671 if (!instruction->llvm_value) {
1672 if (instruction->id == IrInstructionIdAwaitGen) {
1673 IrInstructionAwaitGen *await = reinterpret_cast<IrInstructionAwaitGen*>(instruction);
1674 if (await->result_loc != nullptr) {
1675 return get_handle_value(g, ir_llvm_value(g, await->result_loc),
1676 await->result_loc->value.type->data.pointer.child_type, await->result_loc->value.type);
1677 }
1678 }
1679 if (instruction->spill != nullptr) {
1680 ZigType *ptr_type = instruction->spill->value.type;
1681 src_assert(ptr_type->id == ZigTypeIdPointer, instruction->source_node);
1682 return get_handle_value(g, ir_llvm_value(g, instruction->spill),
1683 ptr_type->data.pointer.child_type, instruction->spill->value.type);
1684 }
16591685 src_assert(instruction->value.special != ConstValSpecialRuntime, instruction->source_node);
16601686 assert(instruction->value.type);
16611687 render_const_val(g, &instruction->value, "");
......@@ -1787,7 +1813,7 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_
17871813 fn_walk->data.types.param_di_types->append(get_llvm_di_type(g, ty));
17881814 break;
17891815 case FnWalkIdVars: {
1790 var->value_ref = build_alloca(g, ty, buf_ptr(&var->name), var->align_bytes);
1816 var->value_ref = build_alloca(g, ty, var->name, var->align_bytes);
17911817 di_arg_index = fn_walk->data.vars.gen_i;
17921818 fn_walk->data.vars.gen_i += 1;
17931819 dest_ty = ty;
......@@ -1898,7 +1924,7 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_
18981924 }
18991925 case FnWalkIdVars: {
19001926 di_arg_index = fn_walk->data.vars.gen_i;
1901 var->value_ref = build_alloca(g, ty, buf_ptr(&var->name), var->align_bytes);
1927 var->value_ref = build_alloca(g, ty, var->name, var->align_bytes);
19021928 fn_walk->data.vars.gen_i += 1;
19031929 dest_ty = ty;
19041930 goto var_ok;
......@@ -1931,7 +1957,7 @@ var_ok:
19311957 if (dest_ty != nullptr && var->decl_node) {
19321958 // arg index + 1 because the 0 index is return value
19331959 var->di_loc_var = ZigLLVMCreateParameterVariable(g->dbuilder, get_di_scope(g, var->parent_scope),
1934 buf_ptr(&var->name), fn_walk->data.vars.import->data.structure.root_struct->di_file,
1960 var->name, fn_walk->data.vars.import->data.structure.root_struct->di_file,
19351961 (unsigned)(var->decl_node->line + 1),
19361962 get_llvm_di_type(g, dest_ty), !g->strip_debug_symbols, 0, di_arg_index + 1);
19371963 }
......@@ -2042,8 +2068,8 @@ static LLVMValueRef get_merge_err_ret_traces_fn_val(CodeGen *g) {
20422068 };
20432069 LLVMTypeRef fn_type_ref = LLVMFunctionType(LLVMVoidType(), param_types, 2, false);
20442070
2045 Buf *fn_name = get_mangled_name(g, buf_create_from_str("__zig_merge_error_return_traces"), false);
2046 LLVMValueRef fn_val = LLVMAddFunction(g->module, buf_ptr(fn_name), fn_type_ref);
2071 const char *fn_name = get_mangled_name(g, "__zig_merge_error_return_traces", false);
2072 LLVMValueRef fn_val = LLVMAddFunction(g->module, fn_name, fn_type_ref);
20472073 LLVMSetLinkage(fn_val, LLVMInternalLinkage);
20482074 LLVMSetFunctionCallConv(fn_val, get_llvm_cc(g, CallingConventionUnspecified));
20492075 addLLVMFnAttr(fn_val, "nounwind");
......@@ -3377,7 +3403,7 @@ static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutable *executable, IrI
33773403 return LLVMBuildTrunc(g->builder, shifted_value, get_llvm_type(g, child_type), "");
33783404}
33793405
3380static bool value_is_all_undef_array(ConstExprValue *const_val, size_t len) {
3406static bool value_is_all_undef_array(CodeGen *g, ConstExprValue *const_val, size_t len) {
33813407 switch (const_val->data.x_array.special) {
33823408 case ConstArraySpecialUndef:
33833409 return true;
......@@ -3385,7 +3411,7 @@ static bool value_is_all_undef_array(ConstExprValue *const_val, size_t len) {
33853411 return false;
33863412 case ConstArraySpecialNone:
33873413 for (size_t i = 0; i < len; i += 1) {
3388 if (!value_is_all_undef(&const_val->data.x_array.data.s_none.elements[i]))
3414 if (!value_is_all_undef(g, &const_val->data.x_array.data.s_none.elements[i]))
33893415 return false;
33903416 }
33913417 return true;
......@@ -3393,7 +3419,12 @@ static bool value_is_all_undef_array(ConstExprValue *const_val, size_t len) {
33933419 zig_unreachable();
33943420}
33953421
3396static bool value_is_all_undef(ConstExprValue *const_val) {
3422static bool value_is_all_undef(CodeGen *g, ConstExprValue *const_val) {
3423 Error err;
3424 if (const_val->special == ConstValSpecialLazy &&
3425 (err = ir_resolve_lazy(g, nullptr, const_val)))
3426 report_errors_and_exit(g);
3427
33973428 switch (const_val->special) {
33983429 case ConstValSpecialLazy:
33993430 zig_unreachable();
......@@ -3404,14 +3435,14 @@ static bool value_is_all_undef(ConstExprValue *const_val) {
34043435 case ConstValSpecialStatic:
34053436 if (const_val->type->id == ZigTypeIdStruct) {
34063437 for (size_t i = 0; i < const_val->type->data.structure.src_field_count; i += 1) {
3407 if (!value_is_all_undef(&const_val->data.x_struct.fields[i]))
3438 if (!value_is_all_undef(g, &const_val->data.x_struct.fields[i]))
34083439 return false;
34093440 }
34103441 return true;
34113442 } else if (const_val->type->id == ZigTypeIdArray) {
3412 return value_is_all_undef_array(const_val, const_val->type->data.array.len);
3443 return value_is_all_undef_array(g, const_val, const_val->type->data.array.len);
34133444 } else if (const_val->type->id == ZigTypeIdVector) {
3414 return value_is_all_undef_array(const_val, const_val->type->data.vector.len);
3445 return value_is_all_undef_array(g, const_val, const_val->type->data.vector.len);
34153446 } else {
34163447 return false;
34173448 }
......@@ -3532,7 +3563,7 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir
35323563 return nullptr;
35333564 }
35343565
3535 bool have_init_expr = !value_is_all_undef(&instruction->value->value);
3566 bool have_init_expr = !value_is_all_undef(g, &instruction->value->value);
35363567 if (have_init_expr) {
35373568 LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr);
35383569 LLVMValueRef value = ir_llvm_value(g, instruction->value);
......@@ -3720,12 +3751,11 @@ static void render_async_spills(CodeGen *g) {
37203751 continue;
37213752 }
37223753
3723 var->value_ref = LLVMBuildStructGEP(g->builder, g->cur_frame_ptr, async_var_index,
3724 buf_ptr(&var->name));
3754 var->value_ref = LLVMBuildStructGEP(g->builder, g->cur_frame_ptr, async_var_index, var->name);
37253755 async_var_index += 1;
37263756 if (var->decl_node) {
37273757 var->di_loc_var = ZigLLVMCreateAutoVariable(g->dbuilder, get_di_scope(g, var->parent_scope),
3728 buf_ptr(&var->name), import->data.structure.root_struct->di_file,
3758 var->name, import->data.structure.root_struct->di_file,
37293759 (unsigned)(var->decl_node->line + 1),
37303760 get_llvm_di_type(g, var->var_type), !g->strip_debug_symbols, 0);
37313761 gen_var_debug_decl(g, var);
......@@ -3768,6 +3798,7 @@ static void render_async_var_decls(CodeGen *g, Scope *scope) {
37683798 case ScopeIdCompTime:
37693799 case ScopeIdRuntime:
37703800 case ScopeIdTypeOf:
3801 case ScopeIdExpr:
37713802 scope = scope->parent;
37723803 continue;
37733804 }
......@@ -3775,6 +3806,7 @@ static void render_async_var_decls(CodeGen *g, Scope *scope) {
37753806}
37763807
37773808static LLVMValueRef gen_frame_size(CodeGen *g, LLVMValueRef fn_val) {
3809 assert(g->need_frame_size_prefix_data);
37783810 LLVMTypeRef usize_llvm_type = g->builtin_types.entry_usize->llvm_type;
37793811 LLVMTypeRef ptr_usize_llvm_type = LLVMPointerType(usize_llvm_type, 0);
37803812 LLVMValueRef casted_fn_val = LLVMBuildBitCast(g->builder, fn_val, ptr_usize_llvm_type, "");
......@@ -3836,7 +3868,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
38363868 LLVMValueRef ret_ptr;
38373869 if (callee_is_async) {
38383870 if (instruction->new_stack == nullptr) {
3839 if (instruction->is_async) {
3871 if (instruction->modifier == CallModifierAsync) {
38403872 frame_result_loc = result_loc;
38413873 } else {
38423874 frame_result_loc = ir_llvm_value(g, instruction->frame_result_loc);
......@@ -3877,7 +3909,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
38773909 }
38783910 }
38793911 }
3880 if (instruction->is_async) {
3912 if (instruction->modifier == CallModifierAsync) {
38813913 if (instruction->new_stack == nullptr) {
38823914 awaiter_init_val = zero;
38833915
......@@ -3902,9 +3934,15 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
39023934 // even if prefix_arg_err_ret_stack is true, let the async function do its own
39033935 // initialization.
39043936 } else {
3905 // async function called as a normal function
3906
3907 awaiter_init_val = LLVMBuildPtrToInt(g->builder, g->cur_frame_ptr, usize_type_ref, ""); // caller's own frame pointer
3937 if (instruction->modifier == CallModifierNoAsync && !fn_is_async(g->cur_fn)) {
3938 // Async function called as a normal function, and calling function is not async.
3939 // This is allowed because it was called with `noasync` which asserts that it will
3940 // never suspend.
3941 awaiter_init_val = zero;
3942 } else {
3943 // async function called as a normal function
3944 awaiter_init_val = LLVMBuildPtrToInt(g->builder, g->cur_frame_ptr, usize_type_ref, ""); // caller's own frame pointer
3945 }
39083946 if (ret_has_bits) {
39093947 if (result_loc == nullptr) {
39103948 // return type is a scalar, but we still need a pointer to it. Use the async fn frame.
......@@ -3945,7 +3983,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
39453983 LLVMValueRef ret_ptr_ptr = LLVMBuildStructGEP(g->builder, frame_result_loc, frame_ret_start, "");
39463984 LLVMBuildStore(g->builder, ret_ptr, ret_ptr_ptr);
39473985 }
3948 } else if (instruction->is_async) {
3986 } else if (instruction->modifier == CallModifierAsync) {
39493987 // Async call of blocking function
39503988 if (instruction->new_stack != nullptr) {
39513989 zig_panic("TODO @asyncCall of non-async function");
......@@ -4042,13 +4080,39 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
40424080 gen_param_values.at(arg_i));
40434081 }
40444082
4045 if (instruction->is_async) {
4083 if (instruction->modifier == CallModifierAsync) {
40464084 gen_resume(g, fn_val, frame_result_loc, ResumeIdCall);
40474085 if (instruction->new_stack != nullptr) {
40484086 return LLVMBuildBitCast(g->builder, frame_result_loc,
40494087 get_llvm_type(g, instruction->base.value.type), "");
40504088 }
40514089 return nullptr;
4090 } else if (instruction->modifier == CallModifierNoAsync && !fn_is_async(g->cur_fn)) {
4091 gen_resume(g, fn_val, frame_result_loc, ResumeIdCall);
4092
4093 if (ir_want_runtime_safety(g, &instruction->base)) {
4094 LLVMValueRef awaiter_ptr = LLVMBuildStructGEP(g->builder, frame_result_loc,
4095 frame_awaiter_index, "");
4096 LLVMValueRef all_ones = LLVMConstAllOnes(usize_type_ref);
4097 LLVMValueRef prev_val = gen_maybe_atomic_op(g, LLVMAtomicRMWBinOpXchg, awaiter_ptr,
4098 all_ones, LLVMAtomicOrderingRelease);
4099 LLVMValueRef ok_val = LLVMBuildICmp(g->builder, LLVMIntEQ, prev_val, all_ones, "");
4100
4101 LLVMBasicBlockRef bad_block = LLVMAppendBasicBlock(g->cur_fn_val, "NoAsyncPanic");
4102 LLVMBasicBlockRef ok_block = LLVMAppendBasicBlock(g->cur_fn_val, "NoAsyncOk");
4103 LLVMBuildCondBr(g->builder, ok_val, ok_block, bad_block);
4104
4105 // The async function suspended, but this noasync call asserted it wouldn't.
4106 LLVMPositionBuilderAtEnd(g->builder, bad_block);
4107 gen_safety_crash(g, PanicMsgIdBadNoAsyncCall);
4108
4109 LLVMPositionBuilderAtEnd(g->builder, ok_block);
4110 }
4111
4112 ZigType *result_type = instruction->base.value.type;
4113 ZigType *ptr_result_type = get_pointer_to_type(g, result_type, true);
4114 return gen_await_early_return(g, &instruction->base, frame_result_loc,
4115 result_type, ptr_result_type, result_loc, true);
40524116 } else {
40534117 ZigType *ptr_result_type = get_pointer_to_type(g, src_return_type, true);
40544118
......@@ -4065,8 +4129,14 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
40654129 if (!type_has_bits(src_return_type))
40664130 return nullptr;
40674131
4068 if (result_loc != nullptr)
4069 return get_handle_value(g, result_loc, src_return_type, ptr_result_type);
4132 if (result_loc != nullptr) {
4133 if (instruction->result_loc->id == IrInstructionIdReturnPtr) {
4134 instruction->base.spill = nullptr;
4135 return g->cur_ret_ptr;
4136 } else {
4137 return get_handle_value(g, result_loc, src_return_type, ptr_result_type);
4138 }
4139 }
40704140
40714141 LLVMValueRef result_ptr = LLVMBuildStructGEP(g->builder, frame_result_loc, frame_ret_start + 2, "");
40724142 return LLVMBuildLoad(g->builder, result_ptr, "");
......@@ -4076,7 +4146,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
40764146 if (instruction->new_stack == nullptr || instruction->is_async_call_builtin) {
40774147 result = ZigLLVMBuildCall(g->builder, fn_val,
40784148 gen_param_values.items, (unsigned)gen_param_values.length, llvm_cc, fn_inline, "");
4079 } else if (instruction->is_async) {
4149 } else if (instruction->modifier == CallModifierAsync) {
40804150 zig_panic("TODO @asyncCall of non-async function");
40814151 } else {
40824152 LLVMValueRef stacksave_fn_val = get_stacksave_fn_val(g);
......@@ -4101,7 +4171,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
41014171 LLVMValueRef store_instr = LLVMBuildStore(g->builder, result, result_loc);
41024172 LLVMSetAlignment(store_instr, get_ptr_align(g, instruction->result_loc->value.type));
41034173 return result_loc;
4104 } else if (!callee_is_async && instruction->is_async) {
4174 } else if (!callee_is_async && instruction->modifier == CallModifierAsync) {
41054175 LLVMBuildStore(g->builder, result, ret_ptr);
41064176 return result_loc;
41074177 } else {
......@@ -4112,6 +4182,8 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr
41124182static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executable,
41134183 IrInstructionStructFieldPtr *instruction)
41144184{
4185 Error err;
4186
41154187 if (instruction->base.value.special != ConstValSpecialRuntime)
41164188 return nullptr;
41174189
......@@ -4129,6 +4201,11 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa
41294201 return struct_ptr;
41304202 }
41314203
4204 ZigType *struct_type = (struct_ptr_type->id == ZigTypeIdPointer) ?
4205 struct_ptr_type->data.pointer.child_type : struct_ptr_type;
4206 if ((err = type_resolve(g, struct_type, ResolveStatusLLVMFull)))
4207 report_errors_and_exit(g);
4208
41324209 assert(field->gen_index != SIZE_MAX);
41334210 return LLVMBuildStructGEP(g->builder, struct_ptr, (unsigned)field->gen_index, "");
41344211}
......@@ -4583,8 +4660,9 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, ZigType *enum_type) {
45834660 LLVMTypeRef fn_type_ref = LLVMFunctionType(LLVMPointerType(get_llvm_type(g, u8_slice_type), 0),
45844661 &tag_int_llvm_type, 1, false);
45854662
4586 Buf *fn_name = get_mangled_name(g, buf_sprintf("__zig_tag_name_%s", buf_ptr(&enum_type->name)), false);
4587 LLVMValueRef fn_val = LLVMAddFunction(g->module, buf_ptr(fn_name), fn_type_ref);
4663 const char *fn_name = get_mangled_name(g,
4664 buf_ptr(buf_sprintf("__zig_tag_name_%s", buf_ptr(&enum_type->name))), false);
4665 LLVMValueRef fn_val = LLVMAddFunction(g->module, fn_name, fn_type_ref);
45884666 LLVMSetLinkage(fn_val, LLVMInternalLinkage);
45894667 LLVMSetFunctionCallConv(fn_val, get_llvm_cc(g, CallingConventionUnspecified));
45904668 addLLVMFnAttr(fn_val, "nounwind");
......@@ -4879,7 +4957,7 @@ static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutable *executable, IrIns
48794957 ZigType *ptr_type = instruction->dest_ptr->value.type;
48804958 assert(ptr_type->id == ZigTypeIdPointer);
48814959
4882 bool val_is_undef = value_is_all_undef(&instruction->byte->value);
4960 bool val_is_undef = value_is_all_undef(g, &instruction->byte->value);
48834961 LLVMValueRef fill_char;
48844962 if (val_is_undef) {
48854963 fill_char = LLVMConstInt(LLVMInt8Type(), 0xaa, false);
......@@ -5595,7 +5673,6 @@ static LLVMValueRef ir_render_await(CodeGen *g, IrExecutable *executable, IrInst
55955673 // At this point resuming the function will continue from resume_bb.
55965674 // This code is as if it is running inside the suspend block.
55975675
5598
55995676 // supply the awaiter return pointer
56005677 if (type_has_bits(result_type)) {
56015678 LLVMValueRef awaiter_ret_ptr_ptr = LLVMBuildStructGEP(g->builder, target_frame_ptr, frame_ret_start + 1, "");
......@@ -5653,9 +5730,8 @@ static LLVMValueRef ir_render_await(CodeGen *g, IrExecutable *executable, IrInst
56535730 LLVMBuildBr(g->builder, end_bb);
56545731
56555732 LLVMPositionBuilderAtEnd(g->builder, end_bb);
5656 if (type_has_bits(result_type) && result_loc != nullptr) {
5657 return get_handle_value(g, result_loc, result_type, ptr_result_type);
5658 }
5733 // Rely on the spill for the llvm_value to be populated.
5734 // See the implementation of ir_llvm_value.
56595735 return nullptr;
56605736}
56615737
......@@ -5762,6 +5838,7 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
57625838 case IrInstructionIdByteOffsetOf:
57635839 case IrInstructionIdBitOffsetOf:
57645840 case IrInstructionIdTypeInfo:
5841 case IrInstructionIdType:
57655842 case IrInstructionIdHasField:
57665843 case IrInstructionIdTypeId:
57675844 case IrInstructionIdSetEvalBranchQuota:
......@@ -5992,6 +6069,11 @@ static void ir_render(CodeGen *g, ZigFn *fn_entry) {
59926069 set_debug_location(g, instruction);
59936070 }
59946071 instruction->llvm_value = ir_render_instruction(g, executable, instruction);
6072 if (instruction->spill != nullptr) {
6073 LLVMValueRef spill_ptr = ir_llvm_value(g, instruction->spill);
6074 gen_assign_raw(g, spill_ptr, instruction->spill->value.type, instruction->llvm_value);
6075 instruction->llvm_value = nullptr;
6076 }
59956077 }
59966078 current_block->llvm_exit_block = LLVMGetInsertBlock(g->builder);
59976079 }
......@@ -6845,7 +6927,7 @@ static void generate_error_name_table(CodeGen *g) {
68456927 LLVMValueRef err_name_table_init = LLVMConstArray(get_llvm_type(g, str_type), values, (unsigned)g->errors_by_index.length);
68466928
68476929 g->err_name_table = LLVMAddGlobal(g->module, LLVMTypeOf(err_name_table_init),
6848 buf_ptr(get_mangled_name(g, buf_create_from_str("__zig_err_name_table"), false)));
6930 get_mangled_name(g, buf_ptr(buf_create_from_str("__zig_err_name_table")), false));
68496931 LLVMSetInitializer(g->err_name_table, err_name_table_init);
68506932 LLVMSetLinkage(g->err_name_table, LLVMPrivateLinkage);
68516933 LLVMSetGlobalConstant(g->err_name_table, true);
......@@ -6886,8 +6968,8 @@ static void gen_global_var(CodeGen *g, ZigVar *var, LLVMValueRef init_val,
68866968 assert(import);
68876969
68886970 bool is_local_to_unit = true;
6889 ZigLLVMCreateGlobalVariable(g->dbuilder, get_di_scope(g, var->parent_scope), buf_ptr(&var->name),
6890 buf_ptr(&var->name), import->data.structure.root_struct->di_file,
6971 ZigLLVMCreateGlobalVariable(g->dbuilder, get_di_scope(g, var->parent_scope), var->name,
6972 var->name, import->data.structure.root_struct->di_file,
68916973 (unsigned)(var->decl_node->line + 1),
68926974 get_llvm_di_type(g, type_entry), is_local_to_unit);
68936975
......@@ -6969,8 +7051,8 @@ static void do_code_gen(CodeGen *g) {
69697051 assert(var->decl_node);
69707052
69717053 GlobalLinkageId linkage;
6972 Buf *unmangled_name = &var->name;
6973 Buf *symbol_name;
7054 const char *unmangled_name = var->name;
7055 const char *symbol_name;
69747056 if (var->export_list.length == 0) {
69757057 if (var->decl_node->data.variable_declaration.is_extern) {
69767058 symbol_name = unmangled_name;
......@@ -6981,19 +7063,19 @@ static void do_code_gen(CodeGen *g) {
69817063 }
69827064 } else {
69837065 GlobalExport *global_export = &var->export_list.items[0];
6984 symbol_name = &global_export->name;
7066 symbol_name = buf_ptr(&global_export->name);
69857067 linkage = global_export->linkage;
69867068 }
69877069
69887070 LLVMValueRef global_value;
69897071 bool externally_initialized = var->decl_node->data.variable_declaration.expr == nullptr;
69907072 if (externally_initialized) {
6991 LLVMValueRef existing_llvm_var = LLVMGetNamedGlobal(g->module, buf_ptr(symbol_name));
7073 LLVMValueRef existing_llvm_var = LLVMGetNamedGlobal(g->module, symbol_name);
69927074 if (existing_llvm_var) {
69937075 global_value = LLVMConstBitCast(existing_llvm_var,
69947076 LLVMPointerType(get_llvm_type(g, var->var_type), 0));
69957077 } else {
6996 global_value = LLVMAddGlobal(g->module, get_llvm_type(g, var->var_type), buf_ptr(symbol_name));
7078 global_value = LLVMAddGlobal(g->module, get_llvm_type(g, var->var_type), symbol_name);
69977079 // TODO debug info for the extern variable
69987080
69997081 LLVMSetLinkage(global_value, to_llvm_linkage(linkage));
......@@ -7004,8 +7086,8 @@ static void do_code_gen(CodeGen *g) {
70047086 }
70057087 } else {
70067088 bool exported = (linkage != GlobalLinkageIdInternal);
7007 render_const_val(g, var->const_value, buf_ptr(symbol_name));
7008 render_const_val_global(g, var->const_value, buf_ptr(symbol_name));
7089 render_const_val(g, var->const_value, symbol_name);
7090 render_const_val_global(g, var->const_value, symbol_name);
70097091 global_value = var->const_value->global_refs->llvm_global;
70107092
70117093 if (exported) {
......@@ -7090,6 +7172,21 @@ static void do_code_gen(CodeGen *g) {
70907172 }
70917173
70927174 if (!is_async) {
7175 // allocate async frames for noasync calls & awaits to async functions
7176 for (size_t i = 0; i < fn_table_entry->call_list.length; i += 1) {
7177 IrInstructionCallGen *call = fn_table_entry->call_list.at(i);
7178 if (call->fn_entry == nullptr)
7179 continue;
7180 if (!fn_is_async(call->fn_entry))
7181 continue;
7182 if (call->modifier != CallModifierNoAsync)
7183 continue;
7184 if (call->frame_result_loc != nullptr)
7185 continue;
7186 ZigType *callee_frame_type = get_fn_frame_type(g, call->fn_entry);
7187 call->frame_result_loc = ir_create_alloca(g, call->base.scope, call->base.source_node,
7188 fn_table_entry, callee_frame_type, "");
7189 }
70937190 // allocate temporary stack data
70947191 for (size_t alloca_i = 0; alloca_i < fn_table_entry->alloca_gen_list.length; alloca_i += 1) {
70957192 IrInstructionAllocaGen *instruction = fn_table_entry->alloca_gen_list.at(alloca_i);
......@@ -7145,7 +7242,7 @@ static void do_code_gen(CodeGen *g) {
71457242
71467243 if (var->src_arg_index == SIZE_MAX) {
71477244 var->di_loc_var = ZigLLVMCreateAutoVariable(g->dbuilder, get_di_scope(g, var->parent_scope),
7148 buf_ptr(&var->name), import->data.structure.root_struct->di_file, (unsigned)(var->decl_node->line + 1),
7245 var->name, import->data.structure.root_struct->di_file, (unsigned)(var->decl_node->line + 1),
71497246 get_llvm_di_type(g, var->var_type), !g->strip_debug_symbols, 0);
71507247
71517248 } else if (is_c_abi) {
......@@ -7165,11 +7262,11 @@ static void do_code_gen(CodeGen *g) {
71657262 var->value_ref = LLVMGetParam(fn, gen_info->gen_index);
71667263 } else {
71677264 gen_type = var->var_type;
7168 var->value_ref = build_alloca(g, var->var_type, buf_ptr(&var->name), var->align_bytes);
7265 var->value_ref = build_alloca(g, var->var_type, var->name, var->align_bytes);
71697266 }
71707267 if (var->decl_node) {
71717268 var->di_loc_var = ZigLLVMCreateParameterVariable(g->dbuilder, get_di_scope(g, var->parent_scope),
7172 buf_ptr(&var->name), import->data.structure.root_struct->di_file,
7269 var->name, import->data.structure.root_struct->di_file,
71737270 (unsigned)(var->decl_node->line + 1),
71747271 get_llvm_di_type(g, gen_type), !g->strip_debug_symbols, 0, (unsigned)(gen_info->gen_index+1));
71757272 }
......@@ -7208,7 +7305,9 @@ static void do_code_gen(CodeGen *g) {
72087305
72097306 LLVMTypeRef usize_type_ref = g->builtin_types.entry_usize->llvm_type;
72107307 LLVMValueRef size_val = LLVMConstInt(usize_type_ref, fn_table_entry->frame_type->abi_size, false);
7211 ZigLLVMFunctionSetPrefixData(fn_table_entry->llvm_value, size_val);
7308 if (g->need_frame_size_prefix_data) {
7309 ZigLLVMFunctionSetPrefixData(fn_table_entry->llvm_value, size_val);
7310 }
72127311
72137312 if (!g->strip_debug_symbols) {
72147313 AstNode *source_node = fn_table_entry->proto_node;
......@@ -7296,10 +7395,8 @@ static void do_code_gen(CodeGen *g) {
72967395 LLVMDumpModule(g->module);
72977396 }
72987397
7299#ifndef NDEBUG
73007398 char *error = nullptr;
73017399 LLVMVerifyModule(g->module, LLVMAbortProcessAction, &error);
7302#endif
73037400}
73047401
73057402static void zig_llvm_emit_output(CodeGen *g) {
......@@ -7587,6 +7684,7 @@ static void define_builtin_fns(CodeGen *g) {
75877684 create_builtin_fn(g, BuiltinFnIdMemberName, "memberName", 2);
75887685 create_builtin_fn(g, BuiltinFnIdField, "field", 2);
75897686 create_builtin_fn(g, BuiltinFnIdTypeInfo, "typeInfo", 1);
7687 create_builtin_fn(g, BuiltinFnIdType, "Type", 1);
75907688 create_builtin_fn(g, BuiltinFnIdHasField, "hasField", 2);
75917689 create_builtin_fn(g, BuiltinFnIdTypeof, "typeOf", 1); // TODO rename to TypeOf
75927690 create_builtin_fn(g, BuiltinFnIdAddWithOverflow, "addWithOverflow", 4);
......@@ -8149,20 +8247,25 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
81498247 " };\n"
81508248 " };\n"
81518249 "};\n\n");
8152 assert(ContainerLayoutAuto == 0);
8153 assert(ContainerLayoutExtern == 1);
8154 assert(ContainerLayoutPacked == 2);
8155
8156 assert(CallingConventionUnspecified == 0);
8157 assert(CallingConventionC == 1);
8158 assert(CallingConventionCold == 2);
8159 assert(CallingConventionNaked == 3);
8160 assert(CallingConventionStdcall == 4);
8161 assert(CallingConventionAsync == 5);
8162
8163 assert(FnInlineAuto == 0);
8164 assert(FnInlineAlways == 1);
8165 assert(FnInlineNever == 2);
8250 static_assert(ContainerLayoutAuto == 0, "");
8251 static_assert(ContainerLayoutExtern == 1, "");
8252 static_assert(ContainerLayoutPacked == 2, "");
8253
8254 static_assert(CallingConventionUnspecified == 0, "");
8255 static_assert(CallingConventionC == 1, "");
8256 static_assert(CallingConventionCold == 2, "");
8257 static_assert(CallingConventionNaked == 3, "");
8258 static_assert(CallingConventionStdcall == 4, "");
8259 static_assert(CallingConventionAsync == 5, "");
8260
8261 static_assert(FnInlineAuto == 0, "");
8262 static_assert(FnInlineAlways == 1, "");
8263 static_assert(FnInlineNever == 2, "");
8264
8265 static_assert(BuiltinPtrSizeOne == 0, "");
8266 static_assert(BuiltinPtrSizeMany == 1, "");
8267 static_assert(BuiltinPtrSizeSlice == 2, "");
8268 static_assert(BuiltinPtrSizeC == 3, "");
81668269 }
81678270 {
81688271 buf_appendf(contents,
......@@ -8458,8 +8561,21 @@ static void init(CodeGen *g) {
84588561 Buf *producer = buf_sprintf("zig %d.%d.%d", ZIG_VERSION_MAJOR, ZIG_VERSION_MINOR, ZIG_VERSION_PATCH);
84598562 const char *flags = "";
84608563 unsigned runtime_version = 0;
8564
8565 // For macOS stack traces, we want to avoid having to parse the compilation unit debug
8566 // info. As long as each debug info file has a path independent of the compilation unit
8567 // directory (DW_AT_comp_dir), then we never have to look at the compilation unit debug
8568 // info. If we provide an absolute path to LLVM here for the compilation unit debug info,
8569 // LLVM will emit DWARF info that depends on DW_AT_comp_dir. To avoid this, we pass "."
8570 // for the compilation unit directory. This forces each debug file to have a directory
8571 // rather than be relative to DW_AT_comp_dir. According to DWARF 5, debug files will
8572 // no longer reference DW_AT_comp_dir, for the purpose of being able to support the
8573 // common practice of stripping all but the line number sections from an executable.
8574 const char *compile_unit_dir = target_os_is_darwin(g->zig_target->os) ? "." :
8575 buf_ptr(&g->root_package->root_src_dir);
8576
84618577 ZigLLVMDIFile *compile_unit_file = ZigLLVMCreateFile(g->dbuilder, buf_ptr(g->root_out_name),
8462 buf_ptr(&g->root_package->root_src_dir));
8578 compile_unit_dir);
84638579 g->compile_unit = ZigLLVMCreateCompileUnit(g->dbuilder, ZigLLVMLang_DW_LANG_C99(),
84648580 compile_unit_file, buf_ptr(producer), is_optimized, flags, runtime_version,
84658581 "", 0, !g->strip_debug_symbols);
......@@ -8674,6 +8790,11 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_pa
86748790 }
86758791 }
86768792
8793 for (size_t i = 0; i < g->framework_dirs.length; i += 1) {
8794 args.append("-iframework");
8795 args.append(g->framework_dirs.at(i));
8796 }
8797
86778798 // According to Rich Felker libc headers are supposed to go before C language headers.
86788799 // However as noted by @dimenus, appending libc headers before c_headers breaks intrinsics
86798800 // and other compiler specific items.
......@@ -8896,6 +9017,15 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {
88969017 for (size_t i = 0; i < g->test_fns.length; i += 1) {
88979018 ZigFn *test_fn_entry = g->test_fns.at(i);
88989019
9020 if (fn_is_async(test_fn_entry)) {
9021 ErrorMsg *msg = add_node_error(g, test_fn_entry->proto_node,
9022 buf_create_from_str("test functions cannot be async"));
9023 add_error_note(g, msg, test_fn_entry->proto_node,
9024 buf_sprintf("this restriction may be lifted in the future. See https://github.com/ziglang/zig/issues/3117 for more details"));
9025 add_async_error_notes(g, msg, test_fn_entry);
9026 continue;
9027 }
9028
88999029 ConstExprValue *this_val = &test_fn_array->data.x_array.data.s_none.elements[i];
89009030 this_val->special = ConstValSpecialStatic;
89019031 this_val->type = struct_type;
......@@ -8915,6 +9045,7 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) {
89159045 fn_field->data.x_ptr.mut = ConstPtrMutComptimeConst;
89169046 fn_field->data.x_ptr.data.fn.fn_entry = test_fn_entry;
89179047 }
9048 report_errors_and_maybe_exit(g);
89189049
89199050 ConstExprValue *test_fn_slice = create_const_slice(g, test_fn_array, 0, g->test_fns.length, true);
89209051
src/ir.cpp+445-81
......@@ -197,6 +197,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source
197197static IrInstruction *ir_gen_union_init_expr(IrBuilder *irb, Scope *scope, AstNode *source_node,
198198 IrInstruction *union_type, IrInstruction *field_name, AstNode *expr_node,
199199 LVal lval, ResultLoc *parent_result_loc);
200static void ir_reset_result(ResultLoc *result_loc);
200201
201202static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *const_val) {
202203 assert(get_src_ptr_type(const_val->type) != nullptr);
......@@ -912,6 +913,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionTypeInfo *) {
912913 return IrInstructionIdTypeInfo;
913914}
914915
916static constexpr IrInstructionId ir_instruction_id(IrInstructionType *) {
917 return IrInstructionIdType;
918}
919
915920static constexpr IrInstructionId ir_instruction_id(IrInstructionHasField *) {
916921 return IrInstructionIdHasField;
917922}
......@@ -1384,7 +1389,7 @@ static IrInstruction *ir_build_union_field_ptr(IrBuilder *irb, Scope *scope, Ast
13841389
13851390static IrInstruction *ir_build_call_src(IrBuilder *irb, Scope *scope, AstNode *source_node,
13861391 ZigFn *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args,
1387 bool is_comptime, FnInline fn_inline, bool is_async, bool is_async_call_builtin,
1392 bool is_comptime, FnInline fn_inline, CallModifier modifier, bool is_async_call_builtin,
13881393 IrInstruction *new_stack, ResultLoc *result_loc)
13891394{
13901395 IrInstructionCallSrc *call_instruction = ir_build_instruction<IrInstructionCallSrc>(irb, scope, source_node);
......@@ -1394,7 +1399,7 @@ static IrInstruction *ir_build_call_src(IrBuilder *irb, Scope *scope, AstNode *s
13941399 call_instruction->fn_inline = fn_inline;
13951400 call_instruction->args = args;
13961401 call_instruction->arg_count = arg_count;
1397 call_instruction->is_async = is_async;
1402 call_instruction->modifier = modifier;
13981403 call_instruction->is_async_call_builtin = is_async_call_builtin;
13991404 call_instruction->new_stack = new_stack;
14001405 call_instruction->result_loc = result_loc;
......@@ -1402,7 +1407,7 @@ static IrInstruction *ir_build_call_src(IrBuilder *irb, Scope *scope, AstNode *s
14021407 if (fn_ref != nullptr) ir_ref_instruction(fn_ref, irb->current_basic_block);
14031408 for (size_t i = 0; i < arg_count; i += 1)
14041409 ir_ref_instruction(args[i], irb->current_basic_block);
1405 if (is_async && new_stack != nullptr) {
1410 if (modifier == CallModifierAsync && new_stack != nullptr) {
14061411 // in this case the arg at the end is the return pointer
14071412 ir_ref_instruction(args[arg_count], irb->current_basic_block);
14081413 }
......@@ -1413,7 +1418,7 @@ static IrInstruction *ir_build_call_src(IrBuilder *irb, Scope *scope, AstNode *s
14131418
14141419static IrInstructionCallGen *ir_build_call_gen(IrAnalyze *ira, IrInstruction *source_instruction,
14151420 ZigFn *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args,
1416 FnInline fn_inline, bool is_async, IrInstruction *new_stack, bool is_async_call_builtin,
1421 FnInline fn_inline, CallModifier modifier, IrInstruction *new_stack, bool is_async_call_builtin,
14171422 IrInstruction *result_loc, ZigType *return_type)
14181423{
14191424 IrInstructionCallGen *call_instruction = ir_build_instruction<IrInstructionCallGen>(&ira->new_irb,
......@@ -1424,7 +1429,7 @@ static IrInstructionCallGen *ir_build_call_gen(IrAnalyze *ira, IrInstruction *so
14241429 call_instruction->fn_inline = fn_inline;
14251430 call_instruction->args = args;
14261431 call_instruction->arg_count = arg_count;
1427 call_instruction->is_async = is_async;
1432 call_instruction->modifier = modifier;
14281433 call_instruction->is_async_call_builtin = is_async_call_builtin;
14291434 call_instruction->new_stack = new_stack;
14301435 call_instruction->result_loc = result_loc;
......@@ -2907,6 +2912,15 @@ static IrInstruction *ir_build_type_info(IrBuilder *irb, Scope *scope, AstNode *
29072912 return &instruction->base;
29082913}
29092914
2915static IrInstruction *ir_build_type(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *type_info) {
2916 IrInstructionType *instruction = ir_build_instruction<IrInstructionType>(irb, scope, source_node);
2917 instruction->type_info = type_info;
2918
2919 ir_ref_instruction(type_info, irb->current_basic_block);
2920
2921 return &instruction->base;
2922}
2923
29102924static IrInstruction *ir_build_type_id(IrBuilder *irb, Scope *scope, AstNode *source_node,
29112925 IrInstruction *type_value)
29122926{
......@@ -3072,10 +3086,11 @@ static IrInstruction *ir_build_save_err_ret_addr(IrBuilder *irb, Scope *scope, A
30723086}
30733087
30743088static IrInstruction *ir_build_add_implicit_return_type(IrBuilder *irb, Scope *scope, AstNode *source_node,
3075 IrInstruction *value)
3089 IrInstruction *value, ResultLocReturn *result_loc_ret)
30763090{
30773091 IrInstructionAddImplicitReturnType *instruction = ir_build_instruction<IrInstructionAddImplicitReturnType>(irb, scope, source_node);
30783092 instruction->value = value;
3093 instruction->result_loc_ret = result_loc_ret;
30793094
30803095 ir_ref_instruction(value, irb->current_basic_block);
30813096
......@@ -3349,6 +3364,7 @@ static void ir_count_defers(IrBuilder *irb, Scope *inner_scope, Scope *outer_sco
33493364 case ScopeIdCompTime:
33503365 case ScopeIdRuntime:
33513366 case ScopeIdTypeOf:
3367 case ScopeIdExpr:
33523368 scope = scope->parent;
33533369 continue;
33543370 case ScopeIdDeferExpr:
......@@ -3405,6 +3421,7 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o
34053421 case ScopeIdCompTime:
34063422 case ScopeIdRuntime:
34073423 case ScopeIdTypeOf:
3424 case ScopeIdExpr:
34083425 scope = scope->parent;
34093426 continue;
34103427 case ScopeIdDeferExpr:
......@@ -3492,7 +3509,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
34923509 return_value = ir_build_const_void(irb, scope, node);
34933510 }
34943511
3495 ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, node, return_value));
3512 ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, node, return_value, result_loc_ret));
34963513
34973514 size_t defer_counts[2];
34983515 ir_count_defers(irb, scope, outer_scope, defer_counts);
......@@ -3567,7 +3584,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node,
35673584 ir_set_cursor_at_end_and_append_block(irb, return_block);
35683585 IrInstruction *err_val_ptr = ir_build_unwrap_err_code(irb, scope, node, err_union_ptr);
35693586 IrInstruction *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr);
3570 ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, node, err_val));
3587 ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, node, err_val, nullptr));
35713588 IrInstructionSpillBegin *spill_begin = ir_build_spill_begin(irb, scope, node, err_val,
35723589 SpillIdRetErrCode);
35733590 ResultLocReturn *result_loc_ret = allocate<ResultLocReturn>(1);
......@@ -3611,7 +3628,7 @@ static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_s
36113628 }
36123629
36133630 if (name) {
3614 buf_init_from_buf(&variable_entry->name, name);
3631 variable_entry->name = strdup(buf_ptr(name));
36153632
36163633 if (!skip_name_check) {
36173634 ZigVar *existing_var = find_variable(codegen, parent_scope, name, nullptr);
......@@ -3644,7 +3661,7 @@ static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_s
36443661 // TODO make this name not actually be in scope. user should be able to make a variable called "_anon"
36453662 // might already be solved, let's just make sure it has test coverage
36463663 // maybe we put a prefix on this so the debug info doesn't clobber user debug info for same named variables
3647 buf_init_from_str(&variable_entry->name, "_anon");
3664 variable_entry->name = "_anon";
36483665 }
36493666
36503667 variable_entry->src_is_const = src_is_const;
......@@ -3677,6 +3694,7 @@ static ResultLocPeer *create_peer_result(ResultLocPeerParent *peer_parent) {
36773694 result->base.id = ResultLocIdPeer;
36783695 result->base.source_instruction = peer_parent->base.source_instruction;
36793696 result->parent = peer_parent;
3697 result->base.allow_write_through_const = peer_parent->parent->allow_write_through_const;
36803698 return result;
36813699}
36823700
......@@ -3799,7 +3817,7 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode
37993817 // no need for save_err_ret_addr because this cannot return error
38003818 // only generate unconditional defers
38013819
3802 ir_mark_gen(ir_build_add_implicit_return_type(irb, child_scope, block_node, result));
3820 ir_mark_gen(ir_build_add_implicit_return_type(irb, child_scope, block_node, result, nullptr));
38033821 ir_gen_defers_for_block(irb, child_scope, outer_block_scope, false);
38043822 return ir_mark_gen(ir_build_return(irb, child_scope, result->source_node, result));
38053823}
......@@ -4396,10 +4414,10 @@ static IrInstruction *ir_gen_async_call(IrBuilder *irb, Scope *scope, AstNode *a
43964414
43974415 args[arg_count] = ret_ptr;
43984416
4399 bool is_async = await_node == nullptr;
4417 CallModifier modifier = (await_node == nullptr) ? CallModifierAsync : CallModifierNone;
44004418 bool is_async_call_builtin = true;
44014419 IrInstruction *call = ir_build_call_src(irb, scope, call_node, nullptr, fn_ref, arg_count, args, false,
4402 FnInlineAuto, is_async, is_async_call_builtin, bytes, result_loc);
4420 FnInlineAuto, modifier, is_async_call_builtin, bytes, result_loc);
44034421 return ir_lval_wrap(irb, scope, call, lval, result_loc);
44044422}
44054423
......@@ -5046,6 +5064,16 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
50465064 IrInstruction *type_info = ir_build_type_info(irb, scope, node, arg0_value);
50475065 return ir_lval_wrap(irb, scope, type_info, lval, result_loc);
50485066 }
5067 case BuiltinFnIdType:
5068 {
5069 AstNode *arg_node = node->data.fn_call_expr.params.at(0);
5070 IrInstruction *arg = ir_gen_node(irb, arg_node, scope);
5071 if (arg == irb->codegen->invalid_instruction)
5072 return arg;
5073
5074 IrInstruction *type = ir_build_type(irb, scope, node, arg);
5075 return ir_lval_wrap(irb, scope, type, lval, result_loc);
5076 }
50495077 case BuiltinFnIdBreakpoint:
50505078 return ir_lval_wrap(irb, scope, ir_build_breakpoint(irb, scope, node), lval, result_loc);
50515079 case BuiltinFnIdReturnAddress:
......@@ -5276,7 +5304,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
52765304 FnInline fn_inline = (builtin_fn->id == BuiltinFnIdInlineCall) ? FnInlineAlways : FnInlineNever;
52775305
52785306 IrInstruction *call = ir_build_call_src(irb, scope, node, nullptr, fn_ref, arg_count, args, false,
5279 fn_inline, false, false, nullptr, result_loc);
5307 fn_inline, CallModifierNone, false, nullptr, result_loc);
52805308 return ir_lval_wrap(irb, scope, call, lval, result_loc);
52815309 }
52825310 case BuiltinFnIdNewStackCall:
......@@ -5309,7 +5337,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
53095337 }
53105338
53115339 IrInstruction *call = ir_build_call_src(irb, scope, node, nullptr, fn_ref, arg_count, args, false,
5312 FnInlineAuto, false, false, new_stack, result_loc);
5340 FnInlineAuto, CallModifierNone, false, new_stack, result_loc);
53135341 return ir_lval_wrap(irb, scope, call, lval, result_loc);
53145342 }
53155343 case BuiltinFnIdAsyncCall:
......@@ -5598,7 +5626,7 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node
55985626{
55995627 assert(node->type == NodeTypeFnCallExpr);
56005628
5601 if (node->data.fn_call_expr.is_builtin)
5629 if (node->data.fn_call_expr.modifier == CallModifierBuiltin)
56025630 return ir_gen_builtin_fn_call(irb, scope, node, lval, result_loc);
56035631
56045632 AstNode *fn_ref_node = node->data.fn_call_expr.fn_ref_expr;
......@@ -5615,9 +5643,8 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node
56155643 return args[i];
56165644 }
56175645
5618 bool is_async = node->data.fn_call_expr.is_async;
56195646 IrInstruction *fn_call = ir_build_call_src(irb, scope, node, nullptr, fn_ref, arg_count, args, false,
5620 FnInlineAuto, is_async, false, nullptr, result_loc);
5647 FnInlineAuto, node->data.fn_call_expr.modifier, false, nullptr, result_loc);
56215648 return ir_lval_wrap(irb, scope, fn_call, lval, result_loc);
56225649}
56235650
......@@ -6440,7 +6467,9 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
64406467 }
64416468 assert(elem_node->type == NodeTypeSymbol);
64426469
6443 IrInstruction *array_val_ptr = ir_gen_node_extra(irb, array_node, parent_scope, LValPtr, nullptr);
6470 ScopeExpr *spill_scope = create_expr_scope(irb->codegen, node, parent_scope);
6471
6472 IrInstruction *array_val_ptr = ir_gen_node_extra(irb, array_node, &spill_scope->base, LValPtr, nullptr);
64446473 if (array_val_ptr == irb->codegen->invalid_instruction)
64456474 return array_val_ptr;
64466475
......@@ -6477,11 +6506,11 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
64776506
64786507 Buf *len_field_name = buf_create_from_str("len");
64796508 IrInstruction *len_ref = ir_build_field_ptr(irb, parent_scope, node, array_val_ptr, len_field_name, false);
6480 IrInstruction *len_val = ir_build_load_ptr(irb, parent_scope, node, len_ref);
6509 IrInstruction *len_val = ir_build_load_ptr(irb, &spill_scope->base, node, len_ref);
64816510 ir_build_br(irb, parent_scope, node, cond_block, is_comptime);
64826511
64836512 ir_set_cursor_at_end_and_append_block(irb, cond_block);
6484 IrInstruction *index_val = ir_build_load_ptr(irb, parent_scope, node, index_ptr);
6513 IrInstruction *index_val = ir_build_load_ptr(irb, &spill_scope->base, node, index_ptr);
64856514 IrInstruction *cond = ir_build_bin_op(irb, parent_scope, node, IrBinOpCmpLessThan, index_val, len_val, false);
64866515 IrBasicBlock *after_cond_block = irb->current_basic_block;
64876516 IrInstruction *void_else_value = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, parent_scope, node));
......@@ -6491,7 +6520,8 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
64916520 ResultLocPeerParent *peer_parent = ir_build_result_peers(irb, cond_br_inst, end_block, result_loc, is_comptime);
64926521
64936522 ir_set_cursor_at_end_and_append_block(irb, body_block);
6494 IrInstruction *elem_ptr = ir_build_elem_ptr(irb, parent_scope, node, array_val_ptr, index_val, false,
6523 Scope *elem_ptr_scope = node->data.for_expr.elem_is_ptr ? parent_scope : &spill_scope->base;
6524 IrInstruction *elem_ptr = ir_build_elem_ptr(irb, elem_ptr_scope, node, array_val_ptr, index_val, false,
64956525 PtrLenSingle, nullptr);
64966526 // TODO make it an error to write to element variable or i variable.
64976527 Buf *elem_var_name = elem_node->data.symbol_expr.symbol;
......@@ -6499,7 +6529,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
64996529 Scope *child_scope = elem_var->child_scope;
65006530
65016531 IrInstruction *var_ptr = node->data.for_expr.elem_is_ptr ?
6502 ir_build_ref(irb, parent_scope, elem_node, elem_ptr, true, false) : elem_ptr;
6532 ir_build_ref(irb, &spill_scope->base, elem_node, elem_ptr, true, false) : elem_ptr;
65036533 ir_build_var_decl_src(irb, parent_scope, elem_node, elem_var, nullptr, var_ptr);
65046534
65056535 ZigList<IrInstruction *> incoming_values = {0};
......@@ -6512,6 +6542,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo
65126542 loop_scope->incoming_values = &incoming_values;
65136543 loop_scope->lval = LValNone;
65146544 loop_scope->peer_parent = peer_parent;
6545 loop_scope->spill_scope = spill_scope;
65156546
65166547 // Note the body block of the loop is not the place that lval and result_loc are used -
65176548 // it's actually in break statements, handled similarly to return statements.
......@@ -7911,7 +7942,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n
79117942 assert(node->type == NodeTypeAwaitExpr);
79127943
79137944 AstNode *expr_node = node->data.await_expr.expr;
7914 if (expr_node->type == NodeTypeFnCallExpr && expr_node->data.fn_call_expr.is_builtin) {
7945 if (expr_node->type == NodeTypeFnCallExpr && expr_node->data.fn_call_expr.modifier == CallModifierBuiltin) {
79157946 AstNode *fn_ref_expr = expr_node->data.fn_call_expr.fn_ref_expr;
79167947 Buf *name = fn_ref_expr->data.symbol_expr.symbol;
79177948 auto entry = irb->codegen->builtin_fn_table.maybe_get(name);
......@@ -8133,7 +8164,15 @@ static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *sc
81338164 result_loc = no_result_loc();
81348165 ir_build_reset_result(irb, scope, node, result_loc);
81358166 }
8136 IrInstruction *result = ir_gen_node_raw(irb, node, scope, lval, result_loc);
8167 Scope *child_scope;
8168 if (irb->exec->is_inline ||
8169 (irb->exec->fn_entry != nullptr && irb->exec->fn_entry->child_scope == scope))
8170 {
8171 child_scope = scope;
8172 } else {
8173 child_scope = &create_expr_scope(irb->codegen, node, scope)->base;
8174 }
8175 IrInstruction *result = ir_gen_node_raw(irb, node, child_scope, lval, result_loc);
81378176 if (result == irb->codegen->invalid_instruction) {
81388177 if (irb->exec->first_err_trace_msg == nullptr) {
81398178 irb->exec->first_err_trace_msg = irb->codegen->trace_err;
......@@ -8184,7 +8223,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec
81848223 }
81858224
81868225 if (!instr_is_unreachable(result)) {
8187 ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, result->source_node, result));
8226 ir_mark_gen(ir_build_add_implicit_return_type(irb, scope, result->source_node, result, nullptr));
81888227 // no need for save_err_ret_addr because this cannot return error
81898228 ir_mark_gen(ir_build_return(irb, scope, result->source_node, result));
81908229 }
......@@ -10869,7 +10908,7 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod
1086910908 fprintf(stderr, "\nSource: ");
1087010909 ast_render(stderr, node, 4);
1087110910 fprintf(stderr, "\n{ // (IR)\n");
10872 ir_print(codegen, stderr, ir_executable, 2, 1);
10911 ir_print(codegen, stderr, ir_executable, 2, IrPassSrc);
1087310912 fprintf(stderr, "}\n");
1087410913 }
1087510914 IrExecutable *analyzed_executable = allocate<IrExecutable>(1);
......@@ -10890,7 +10929,7 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod
1089010929
1089110930 if (codegen->verbose_ir) {
1089210931 fprintf(stderr, "{ // (analyzed)\n");
10893 ir_print(codegen, stderr, analyzed_executable, 2, 2);
10932 ir_print(codegen, stderr, analyzed_executable, 2, IrPassGen);
1089410933 fprintf(stderr, "}\n");
1089510934 }
1089610935
......@@ -12058,6 +12097,29 @@ static bool is_pointery_and_elem_is_not_pointery(ZigType *ty) {
1205812097 return false;
1205912098}
1206012099
12100static IrInstruction *ir_analyze_enum_literal(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
12101 ZigType *enum_type)
12102{
12103 assert(enum_type->id == ZigTypeIdEnum);
12104
12105 Error err;
12106 if ((err = type_resolve(ira->codegen, enum_type, ResolveStatusZeroBitsKnown)))
12107 return ira->codegen->invalid_instruction;
12108
12109 TypeEnumField *field = find_enum_type_field(enum_type, value->value.data.x_enum_literal);
12110 if (field == nullptr) {
12111 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("enum '%s' has no field named '%s'",
12112 buf_ptr(&enum_type->name), buf_ptr(value->value.data.x_enum_literal)));
12113 add_error_note(ira->codegen, msg, enum_type->data.enumeration.decl_node,
12114 buf_sprintf("'%s' declared here", buf_ptr(&enum_type->name)));
12115 return ira->codegen->invalid_instruction;
12116 }
12117 IrInstruction *result = ir_const(ira, source_instr, enum_type);
12118 bigint_init_bigint(&result->value.data.x_enum_tag, &field->value);
12119
12120 return result;
12121}
12122
1206112123static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_instr,
1206212124 ZigType *wanted_type, IrInstruction *value, ResultLoc *result_loc)
1206312125{
......@@ -12416,21 +12478,31 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
1241612478 }
1241712479
1241812480 // cast from enum literal to enum with matching field name
12419 if (actual_type->id == ZigTypeIdEnumLiteral && wanted_type->id == ZigTypeIdEnum) {
12420 if ((err = type_resolve(ira->codegen, wanted_type, ResolveStatusZeroBitsKnown)))
12421 return ira->codegen->invalid_instruction;
12481 if (actual_type->id == ZigTypeIdEnumLiteral && wanted_type->id == ZigTypeIdEnum)
12482 {
12483 return ir_analyze_enum_literal(ira, source_instr, value, wanted_type);
12484 }
1242212485
12423 TypeEnumField *field = find_enum_type_field(wanted_type, value->value.data.x_enum_literal);
12424 if (field == nullptr) {
12425 ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("enum '%s' has no field named '%s'",
12426 buf_ptr(&wanted_type->name), buf_ptr(value->value.data.x_enum_literal)));
12427 add_error_note(ira->codegen, msg, wanted_type->data.enumeration.decl_node,
12428 buf_sprintf("'%s' declared here", buf_ptr(&wanted_type->name)));
12429 return ira->codegen->invalid_instruction;
12430 }
12431 IrInstruction *result = ir_const(ira, source_instr, wanted_type);
12432 bigint_init_bigint(&result->value.data.x_enum_tag, &field->value);
12433 return result;
12486 // cast from enum literal to optional enum
12487 if (actual_type->id == ZigTypeIdEnumLiteral &&
12488 (wanted_type->id == ZigTypeIdOptional && wanted_type->data.maybe.child_type->id == ZigTypeIdEnum))
12489 {
12490 IrInstruction *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.maybe.child_type);
12491 if (result == ira->codegen->invalid_instruction)
12492 return result;
12493
12494 return ir_analyze_optional_wrap(ira, result, value, wanted_type, result_loc);
12495 }
12496
12497 // cast from enum literal to error union when payload is an enum
12498 if (actual_type->id == ZigTypeIdEnumLiteral &&
12499 (wanted_type->id == ZigTypeIdErrorUnion && wanted_type->data.error_union.payload_type->id == ZigTypeIdEnum))
12500 {
12501 IrInstruction *result = ir_analyze_enum_literal(ira, source_instr, value, wanted_type->data.error_union.payload_type);
12502 if (result == ira->codegen->invalid_instruction)
12503 return result;
12504
12505 return ir_analyze_err_wrap_payload(ira, result, value, wanted_type, result_loc);
1243412506 }
1243512507
1243612508 // cast from union to the enum type of the union
......@@ -12883,7 +12955,9 @@ static IrInstruction *ir_analyze_instruction_add_implicit_return_type(IrAnalyze
1288312955 if (type_is_invalid(value->value.type))
1288412956 return ir_unreach_error(ira);
1288512957
12886 ira->src_implicit_return_type_list.append(value);
12958 if (instruction->result_loc_ret == nullptr || !instruction->result_loc_ret->implicit_return_type_done) {
12959 ira->src_implicit_return_type_list.append(value);
12960 }
1288712961
1288812962 return ir_const_void(ira, &instruction->base);
1288912963}
......@@ -13154,6 +13228,46 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1315413228 ir_add_error_node(ira, source_node, buf_sprintf("comparison of '%s' with null",
1315513229 buf_ptr(&non_null_type->name)));
1315613230 return ira->codegen->invalid_instruction;
13231 } else if (is_equality_cmp && (
13232 (op1->value.type->id == ZigTypeIdEnumLiteral && op2->value.type->id == ZigTypeIdUnion) ||
13233 (op2->value.type->id == ZigTypeIdEnumLiteral && op1->value.type->id == ZigTypeIdUnion)))
13234 {
13235 // Support equality comparison between a union's tag value and a enum literal
13236 IrInstruction *union_val = op1->value.type->id == ZigTypeIdUnion ? op1 : op2;
13237 IrInstruction *enum_val = op1->value.type->id == ZigTypeIdUnion ? op2 : op1;
13238
13239 ZigType *tag_type = union_val->value.type->data.unionation.tag_type;
13240 assert(tag_type != nullptr);
13241
13242 IrInstruction *casted_union = ir_implicit_cast(ira, union_val, tag_type);
13243 if (type_is_invalid(casted_union->value.type))
13244 return ira->codegen->invalid_instruction;
13245
13246 IrInstruction *casted_val = ir_implicit_cast(ira, enum_val, tag_type);
13247 if (type_is_invalid(casted_val->value.type))
13248 return ira->codegen->invalid_instruction;
13249
13250 if (instr_is_comptime(casted_union)) {
13251 ConstExprValue *const_union_val = ir_resolve_const(ira, casted_union, UndefBad);
13252 if (!const_union_val)
13253 return ira->codegen->invalid_instruction;
13254
13255 ConstExprValue *const_enum_val = ir_resolve_const(ira, casted_val, UndefBad);
13256 if (!const_enum_val)
13257 return ira->codegen->invalid_instruction;
13258
13259 Cmp cmp_result = bigint_cmp(&const_union_val->data.x_union.tag, &const_enum_val->data.x_enum_tag);
13260 bool bool_result = (op_id == IrBinOpCmpEq) ? cmp_result == CmpEQ : cmp_result != CmpEQ;
13261
13262 return ir_const_bool(ira, &bin_op_instruction->base, bool_result);
13263 }
13264
13265 IrInstruction *result = ir_build_bin_op(&ira->new_irb,
13266 bin_op_instruction->base.scope, bin_op_instruction->base.source_node,
13267 op_id, casted_union, casted_val, bin_op_instruction->safety_check_on);
13268 result->value.type = ira->codegen->builtin_types.entry_bool;
13269
13270 return result;
1315713271 }
1315813272
1315913273 if (op1->value.type->id == ZigTypeIdErrorSet && op2->value.type->id == ZigTypeIdErrorSet) {
......@@ -13678,7 +13792,7 @@ static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *b
1367813792 return ira->codegen->invalid_instruction;
1367913793
1368013794 if (op1->value.type->id != ZigTypeIdInt && op1->value.type->id != ZigTypeIdComptimeInt) {
13681 ir_add_error(ira, &bin_op_instruction->base,
13795 ir_add_error(ira, bin_op_instruction->op1,
1368213796 buf_sprintf("bit shifting operation expected integer type, found '%s'",
1368313797 buf_ptr(&op1->value.type->name)));
1368413798 return ira->codegen->invalid_instruction;
......@@ -13688,6 +13802,13 @@ static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *b
1368813802 if (type_is_invalid(op2->value.type))
1368913803 return ira->codegen->invalid_instruction;
1369013804
13805 if (op2->value.type->id != ZigTypeIdInt && op2->value.type->id != ZigTypeIdComptimeInt) {
13806 ir_add_error(ira, bin_op_instruction->op2,
13807 buf_sprintf("shift amount has to be an integer type, but found '%s'",
13808 buf_ptr(&op2->value.type->name)));
13809 return ira->codegen->invalid_instruction;
13810 }
13811
1369113812 IrInstruction *casted_op2;
1369213813 IrBinOp op_id = bin_op_instruction->op_id;
1369313814 if (op1->value.type->id == ZigTypeIdComptimeInt) {
......@@ -14478,7 +14599,8 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira,
1447814599 // We make a new variable so that it can hold a different type, and so the debug info can
1447914600 // be distinct.
1448014601 ZigVar *new_var = create_local_var(ira->codegen, var->decl_node, var->child_scope,
14481 &var->name, var->src_is_const, var->gen_is_const, var->shadowable, var->is_comptime, true);
14602 buf_create_from_str(var->name), var->src_is_const, var->gen_is_const,
14603 var->shadowable, var->is_comptime, true);
1448214604 new_var->owner_exec = var->owner_exec;
1448314605 new_var->align_bytes = var->align_bytes;
1448414606 if (var->mem_slot_index != SIZE_MAX) {
......@@ -14621,7 +14743,8 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
1462114743 case CallingConventionNaked:
1462214744 case CallingConventionCold:
1462314745 case CallingConventionStdcall:
14624 add_fn_export(ira->codegen, fn_entry, symbol_name, global_linkage_id, cc == CallingConventionC);
14746 add_fn_export(ira->codegen, fn_entry, buf_ptr(symbol_name), global_linkage_id,
14747 cc == CallingConventionC);
1462514748 break;
1462614749 }
1462714750 } break;
......@@ -14759,7 +14882,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
1475914882 if (load_ptr->ptr->id == IrInstructionIdVarPtr) {
1476014883 IrInstructionVarPtr *var_ptr = reinterpret_cast<IrInstructionVarPtr *>(load_ptr->ptr);
1476114884 ZigVar *var = var_ptr->var;
14762 add_var_export(ira->codegen, var, symbol_name, global_linkage_id);
14885 add_var_export(ira->codegen, var, buf_ptr(symbol_name), global_linkage_id);
1476314886 }
1476414887 }
1476514888
......@@ -14839,6 +14962,12 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in
1483914962 if (align != 0) {
1484014963 if ((err = type_resolve(ira->codegen, var_type, ResolveStatusAlignmentKnown)))
1484114964 return ira->codegen->invalid_instruction;
14965 if (!type_has_bits(var_type)) {
14966 ir_add_error(ira, source_inst,
14967 buf_sprintf("variable '%s' of zero-bit type '%s' has no in-memory representation, it cannot be aligned",
14968 name_hint, buf_ptr(&var_type->name)));
14969 return ira->codegen->invalid_instruction;
14970 }
1484214971 }
1484314972 assert(result->base.value.data.x_ptr.special != ConstPtrSpecialInvalid);
1484414973
......@@ -14907,6 +15036,24 @@ static void set_up_result_loc_for_inferred_comptime(IrInstruction *ptr) {
1490715036 ptr->value.data.x_ptr.data.ref.pointee = undef_child;
1490815037}
1490915038
15039static bool ir_result_has_type(ResultLoc *result_loc) {
15040 switch (result_loc->id) {
15041 case ResultLocIdInvalid:
15042 case ResultLocIdPeerParent:
15043 zig_unreachable();
15044 case ResultLocIdNone:
15045 case ResultLocIdPeer:
15046 return false;
15047 case ResultLocIdReturn:
15048 case ResultLocIdInstruction:
15049 case ResultLocIdBitCast:
15050 return true;
15051 case ResultLocIdVar:
15052 return reinterpret_cast<ResultLocVar *>(result_loc)->var->decl_node->data.variable_declaration.type != nullptr;
15053 }
15054 zig_unreachable();
15055}
15056
1491015057// when calling this function, at the callsite must check for result type noreturn and propagate it up
1491115058static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspend_source_instr,
1491215059 ResultLoc *result_loc, ZigType *value_type, IrInstruction *value, bool force_runtime, bool non_null_comptime)
......@@ -15036,14 +15183,23 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe
1503615183 bool is_comptime;
1503715184 if (!ir_resolve_comptime(ira, peer_parent->is_comptime->child, &is_comptime))
1503815185 return ira->codegen->invalid_instruction;
15039 peer_parent->skipped = is_comptime;
15040 if (peer_parent->skipped) {
15186 if (is_comptime) {
15187 peer_parent->skipped = true;
1504115188 if (non_null_comptime) {
1504215189 return ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,
1504315190 value_type, value, force_runtime, non_null_comptime, true);
1504415191 }
1504515192 return nullptr;
1504615193 }
15194 if (ir_result_has_type(peer_parent->parent)) {
15195 if (peer_parent->parent->id == ResultLocIdReturn && value != nullptr) {
15196 reinterpret_cast<ResultLocReturn *>(peer_parent->parent)->implicit_return_type_done = true;
15197 ira->src_implicit_return_type_list.append(value);
15198 }
15199 peer_parent->skipped = true;
15200 return ir_resolve_result(ira, suspend_source_instr, peer_parent->parent,
15201 value_type, value, force_runtime, true, true);
15202 }
1504715203
1504815204 if (peer_parent->resolved_type == nullptr) {
1504915205 if (peer_parent->end_bb->suspend_instruction_ref == nullptr) {
......@@ -15253,9 +15409,11 @@ static void ir_reset_result(ResultLoc *result_loc) {
1525315409 alloca_src->base.child = nullptr;
1525415410 break;
1525515411 }
15412 case ResultLocIdReturn:
15413 reinterpret_cast<ResultLocReturn *>(result_loc)->implicit_return_type_done = false;
15414 break;
1525615415 case ResultLocIdPeer:
1525715416 case ResultLocIdNone:
15258 case ResultLocIdReturn:
1525915417 case ResultLocIdInstruction:
1526015418 case ResultLocIdBitCast:
1526115419 break;
......@@ -15305,7 +15463,7 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc
1530515463 ZigType *anyframe_type = get_any_frame_type(ira->codegen, fn_ret_type);
1530615464
1530715465 IrInstructionCallGen *call_gen = ir_build_call_gen(ira, &call_instruction->base, fn_entry, fn_ref,
15308 arg_count, casted_args, FnInlineAuto, true, casted_new_stack,
15466 arg_count, casted_args, FnInlineAuto, CallModifierAsync, casted_new_stack,
1530915467 call_instruction->is_async_call_builtin, ret_ptr, anyframe_type);
1531015468 return &call_gen->base;
1531115469 } else {
......@@ -15319,8 +15477,8 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc
1531915477 if (type_is_invalid(result_loc->value.type))
1532015478 return ira->codegen->invalid_instruction;
1532115479 return &ir_build_call_gen(ira, &call_instruction->base, fn_entry, fn_ref, arg_count,
15322 casted_args, FnInlineAuto, true, casted_new_stack, call_instruction->is_async_call_builtin,
15323 result_loc, frame_type)->base;
15480 casted_args, FnInlineAuto, CallModifierAsync, casted_new_stack,
15481 call_instruction->is_async_call_builtin, result_loc, frame_type)->base;
1532415482 }
1532515483}
1532615484static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node,
......@@ -15671,6 +15829,7 @@ static IrInstruction *analyze_casted_new_stack(IrAnalyze *ira, IrInstructionCall
1567115829 ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8,
1567215830 false, false, PtrLenUnknown, target_fn_align(ira->codegen->zig_target), 0, 0, false);
1567315831 ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr);
15832 ira->codegen->need_frame_size_prefix_data = true;
1567415833 return ir_implicit_cast(ira, new_stack, u8_slice);
1567515834 }
1567615835}
......@@ -16070,7 +16229,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1607016229 return ira->codegen->invalid_instruction;
1607116230
1607216231 size_t impl_param_count = impl_fn_type_id->param_count;
16073 if (call_instruction->is_async) {
16232 if (call_instruction->modifier == CallModifierAsync) {
1607416233 IrInstruction *result = ir_analyze_async_call(ira, call_instruction, impl_fn, impl_fn->type_entry,
1607516234 nullptr, casted_args, impl_param_count, casted_new_stack);
1607616235 return ir_finish_anal(ira, result);
......@@ -16097,14 +16256,17 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1609716256 result_loc = nullptr;
1609816257 }
1609916258
16100 if (impl_fn_type_id->cc == CallingConventionAsync && parent_fn_entry->inferred_async_node == nullptr) {
16259 if (impl_fn_type_id->cc == CallingConventionAsync &&
16260 parent_fn_entry->inferred_async_node == nullptr &&
16261 call_instruction->modifier != CallModifierNoAsync)
16262 {
1610116263 parent_fn_entry->inferred_async_node = fn_ref->source_node;
1610216264 parent_fn_entry->inferred_async_fn = impl_fn;
1610316265 }
1610416266
1610516267 IrInstructionCallGen *new_call_instruction = ir_build_call_gen(ira, &call_instruction->base,
1610616268 impl_fn, nullptr, impl_param_count, casted_args, fn_inline,
16107 false, casted_new_stack, call_instruction->is_async_call_builtin, result_loc,
16269 call_instruction->modifier, casted_new_stack, call_instruction->is_async_call_builtin, result_loc,
1610816270 impl_fn_type_id->return_type);
1610916271
1611016272 if (get_scope_typeof(call_instruction->base.scope) == nullptr) {
......@@ -16221,13 +16383,16 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1622116383 if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value.type))
1622216384 return ira->codegen->invalid_instruction;
1622316385
16224 if (call_instruction->is_async) {
16386 if (call_instruction->modifier == CallModifierAsync) {
1622516387 IrInstruction *result = ir_analyze_async_call(ira, call_instruction, fn_entry, fn_type, fn_ref,
1622616388 casted_args, call_param_count, casted_new_stack);
1622716389 return ir_finish_anal(ira, result);
1622816390 }
1622916391
16230 if (fn_type_id->cc == CallingConventionAsync && parent_fn_entry->inferred_async_node == nullptr) {
16392 if (fn_type_id->cc == CallingConventionAsync &&
16393 parent_fn_entry->inferred_async_node == nullptr &&
16394 call_instruction->modifier != CallModifierNoAsync)
16395 {
1623116396 parent_fn_entry->inferred_async_node = fn_ref->source_node;
1623216397 parent_fn_entry->inferred_async_fn = fn_entry;
1623316398 }
......@@ -16254,7 +16419,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
1625416419 }
1625516420
1625616421 IrInstructionCallGen *new_call_instruction = ir_build_call_gen(ira, &call_instruction->base, fn_entry, fn_ref,
16257 call_param_count, casted_args, fn_inline, false, casted_new_stack,
16422 call_param_count, casted_args, fn_inline, call_instruction->modifier, casted_new_stack,
1625816423 call_instruction->is_async_call_builtin, result_loc, return_type);
1625916424 if (get_scope_typeof(call_instruction->base.scope) == nullptr) {
1626016425 parent_fn_entry->call_list.append(new_call_instruction);
......@@ -16461,6 +16626,15 @@ static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *ins
1646116626 if (type_is_invalid(expr_type))
1646216627 return ira->codegen->invalid_instruction;
1646316628
16629 if (!(expr_type->id == ZigTypeIdInt || expr_type->id == ZigTypeIdComptimeInt ||
16630 expr_type->id == ZigTypeIdFloat || expr_type->id == ZigTypeIdComptimeFloat ||
16631 expr_type->id == ZigTypeIdVector))
16632 {
16633 ir_add_error(ira, &instruction->base,
16634 buf_sprintf("negation of type '%s'", buf_ptr(&expr_type->name)));
16635 return ira->codegen->invalid_instruction;
16636 }
16637
1646416638 bool is_wrap_op = (instruction->op_id == IrUnOpNegationWrap);
1646516639
1646616640 ZigType *scalar_type = (expr_type->id == ZigTypeIdVector) ? expr_type->data.vector.elem_type : expr_type;
......@@ -16810,10 +16984,21 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
1681016984 return new_incoming_values.at(0);
1681116985 }
1681216986
16813 ZigType *resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.source_node, nullptr,
16814 new_incoming_values.items, new_incoming_values.length);
16815 if (type_is_invalid(resolved_type))
16816 return ira->codegen->invalid_instruction;
16987 ZigType *resolved_type;
16988 if (peer_parent != nullptr && ir_result_has_type(peer_parent->parent)) {
16989 if (peer_parent->parent->id == ResultLocIdReturn) {
16990 resolved_type = ira->explicit_return_type;
16991 } else {
16992 ZigType *resolved_loc_ptr_type = peer_parent->parent->resolved_loc->value.type;
16993 ir_assert(resolved_loc_ptr_type->id == ZigTypeIdPointer, &phi_instruction->base);
16994 resolved_type = resolved_loc_ptr_type->data.pointer.child_type;
16995 }
16996 } else {
16997 resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.source_node, nullptr,
16998 new_incoming_values.items, new_incoming_values.length);
16999 if (type_is_invalid(resolved_type))
17000 return ira->codegen->invalid_instruction;
17001 }
1681717002
1681817003 switch (type_has_one_possible_value(ira->codegen, resolved_type)) {
1681917004 case OnePossibleValueInvalid:
......@@ -16880,7 +17065,7 @@ static IrInstruction *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructi
1688017065 IrInstruction *result = ir_get_var_ptr(ira, &instruction->base, var);
1688117066 if (instruction->crossed_fndef_scope != nullptr && !instr_is_comptime(result)) {
1688217067 ErrorMsg *msg = ir_add_error(ira, &instruction->base,
16883 buf_sprintf("'%s' not accessible from inner function", buf_ptr(&var->name)));
17068 buf_sprintf("'%s' not accessible from inner function", var->name));
1688417069 add_error_note(ira->codegen, msg, instruction->crossed_fndef_scope->base.source_node,
1688517070 buf_sprintf("crossed function definition here"));
1688617071 add_error_note(ira->codegen, msg, var->decl_node,
......@@ -17463,7 +17648,12 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
1746317648 return ir_analyze_container_member_access_inner(ira, bare_type, field_name,
1746417649 source_instr, container_ptr, container_type);
1746517650 }
17466 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field->type_entry,
17651
17652 ZigType *field_type = resolve_union_field_type(ira->codegen, field);
17653 if (field_type == nullptr)
17654 return ira->codegen->invalid_instruction;
17655
17656 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type,
1746717657 is_const, is_volatile, PtrLenSingle, 0, 0, 0, false);
1746817658 if (instr_is_comptime(container_ptr)) {
1746917659 ConstExprValue *ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
......@@ -17480,7 +17670,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_
1748017670 if (initializing) {
1748117671 ConstExprValue *payload_val = create_const_vals(1);
1748217672 payload_val->special = ConstValSpecialUndef;
17483 payload_val->type = field->type_entry;
17673 payload_val->type = field_type;
1748417674 payload_val->parent.id = ConstParentIdUnion;
1748517675 payload_val->parent.data.p_union.union_val = union_val;
1748617676
......@@ -17587,7 +17777,8 @@ static IrInstruction *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_
1758717777 return ir_error_dependency_loop(ira, source_instruction);
1758817778 }
1758917779 if (tld_var->extern_lib_name != nullptr) {
17590 add_link_lib_symbol(ira, tld_var->extern_lib_name, &var->name, source_instruction->source_node);
17780 add_link_lib_symbol(ira, tld_var->extern_lib_name, buf_create_from_str(var->name),
17781 source_instruction->source_node);
1759117782 }
1759217783
1759317784 return ir_get_var_ptr(ira, source_instruction, var);
......@@ -19544,6 +19735,11 @@ static IrInstruction *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstr
1954419735 if (type_is_invalid(msg->value.type))
1954519736 return ira->codegen->invalid_instruction;
1954619737 buf_resize(&buf, 0);
19738 if (msg->value.special == ConstValSpecialLazy) {
19739 // Resolve any lazy value that's passed, we need its value
19740 if (ir_resolve_lazy(ira->codegen, msg->source_node, &msg->value))
19741 return ira->codegen->invalid_instruction;
19742 }
1954719743 render_const_value(ira->codegen, &buf, &msg->value);
1954819744 const char *comma_str = (i != 0) ? ", " : "";
1954919745 fprintf(stderr, "%s%s", comma_str, buf_ptr(&buf));
......@@ -20041,8 +20237,9 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
2004120237 for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) {
2004220238 ZigVar *arg_var = fn_entry->variable_list.at(fn_arg_index);
2004320239 ConstExprValue *fn_arg_name_val = &fn_arg_name_array->data.x_array.data.s_none.elements[fn_arg_index];
20044 ConstExprValue *arg_name = create_const_str_lit(ira->codegen, &arg_var->name);
20045 init_const_slice(ira->codegen, fn_arg_name_val, arg_name, 0, buf_len(&arg_var->name), true);
20240 ConstExprValue *arg_name = create_const_str_lit(ira->codegen,
20241 buf_create_from_str(arg_var->name));
20242 init_const_slice(ira->codegen, fn_arg_name_val, arg_name, 0, strlen(arg_var->name), true);
2004620243 fn_arg_name_val->parent.id = ConstParentIdArray;
2004720244 fn_arg_name_val->parent.data.p_array.array_val = fn_arg_name_array;
2004820245 fn_arg_name_val->parent.data.p_array.elem_index = fn_arg_index;
......@@ -20080,14 +20277,27 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr
2008020277 return ErrorNone;
2008120278}
2008220279
20083static uint32_t ptr_len_to_size_enum_index(PtrLen ptr_len) {
20280static BuiltinPtrSize ptr_len_to_size_enum_index(PtrLen ptr_len) {
2008420281 switch (ptr_len) {
2008520282 case PtrLenSingle:
20086 return 0;
20283 return BuiltinPtrSizeOne;
2008720284 case PtrLenUnknown:
20088 return 1;
20285 return BuiltinPtrSizeMany;
2008920286 case PtrLenC:
20090 return 3;
20287 return BuiltinPtrSizeC;
20288 }
20289 zig_unreachable();
20290}
20291
20292static PtrLen size_enum_index_to_ptr_len(BuiltinPtrSize size_enum_index) {
20293 switch (size_enum_index) {
20294 case BuiltinPtrSizeOne:
20295 return PtrLenSingle;
20296 case BuiltinPtrSizeMany:
20297 case BuiltinPtrSizeSlice:
20298 return PtrLenUnknown;
20299 case BuiltinPtrSizeC:
20300 return PtrLenC;
2009120301 }
2009220302 zig_unreachable();
2009320303}
......@@ -20095,10 +20305,10 @@ static uint32_t ptr_len_to_size_enum_index(PtrLen ptr_len) {
2009520305static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_type_entry) {
2009620306 Error err;
2009720307 ZigType *attrs_type;
20098 uint32_t size_enum_index;
20308 BuiltinPtrSize size_enum_index;
2009920309 if (is_slice(ptr_type_entry)) {
2010020310 attrs_type = ptr_type_entry->data.structure.fields[slice_ptr_index].type_entry;
20101 size_enum_index = 2;
20311 size_enum_index = BuiltinPtrSizeSlice;
2010220312 } else if (ptr_type_entry->id == ZigTypeIdPointer) {
2010320313 attrs_type = ptr_type_entry;
2010420314 size_enum_index = ptr_len_to_size_enum_index(ptr_type_entry->data.pointer.ptr_len);
......@@ -20777,6 +20987,148 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira,
2077720987 return result;
2077820988}
2077920989
20990static ConstExprValue *get_const_field(IrAnalyze *ira, ConstExprValue *struct_value, const char *name, size_t field_index)
20991{
20992 ensure_field_index(struct_value->type, name, field_index);
20993 assert(struct_value->data.x_struct.fields[field_index].special == ConstValSpecialStatic);
20994 return &struct_value->data.x_struct.fields[field_index];
20995}
20996
20997static bool get_const_field_bool(IrAnalyze *ira, ConstExprValue *struct_value, const char *name, size_t field_index)
20998{
20999 ConstExprValue *value = get_const_field(ira, struct_value, name, field_index);
21000 assert(value->type == ira->codegen->builtin_types.entry_bool);
21001 return value->data.x_bool;
21002}
21003
21004static BigInt *get_const_field_lit_int(IrAnalyze *ira, ConstExprValue *struct_value, const char *name, size_t field_index)
21005{
21006 ConstExprValue *value = get_const_field(ira, struct_value, name, field_index);
21007 assert(value->type == ira->codegen->builtin_types.entry_num_lit_int);
21008 return &value->data.x_bigint;
21009}
21010
21011static ZigType *get_const_field_meta_type(IrAnalyze *ira, ConstExprValue *struct_value, const char *name, size_t field_index)
21012{
21013 ConstExprValue *value = get_const_field(ira, struct_value, name, field_index);
21014 assert(value->type == ira->codegen->builtin_types.entry_type);
21015 return value->data.x_type;
21016}
21017
21018static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, ZigTypeId tagTypeId, ConstExprValue *payload) {
21019 switch (tagTypeId) {
21020 case ZigTypeIdInvalid:
21021 zig_unreachable();
21022 case ZigTypeIdMetaType:
21023 return ira->codegen->builtin_types.entry_type;
21024 case ZigTypeIdVoid:
21025 return ira->codegen->builtin_types.entry_void;
21026 case ZigTypeIdBool:
21027 return ira->codegen->builtin_types.entry_bool;
21028 case ZigTypeIdUnreachable:
21029 return ira->codegen->builtin_types.entry_unreachable;
21030 case ZigTypeIdInt:
21031 assert(payload->special == ConstValSpecialStatic);
21032 assert(payload->type == ir_type_info_get_type(ira, "Int", nullptr));
21033 return get_int_type(ira->codegen,
21034 get_const_field_bool(ira, payload, "is_signed", 0),
21035 bigint_as_u32(get_const_field_lit_int(ira, payload, "bits", 1)));
21036 case ZigTypeIdFloat:
21037 {
21038 assert(payload->special == ConstValSpecialStatic);
21039 assert(payload->type == ir_type_info_get_type(ira, "Float", nullptr));
21040 uint32_t bits = bigint_as_u32(get_const_field_lit_int(ira, payload, "bits", 0));
21041 switch (bits) {
21042 case 16: return ira->codegen->builtin_types.entry_f16;
21043 case 32: return ira->codegen->builtin_types.entry_f32;
21044 case 64: return ira->codegen->builtin_types.entry_f64;
21045 case 128: return ira->codegen->builtin_types.entry_f128;
21046 }
21047 ir_add_error(ira, instruction,
21048 buf_sprintf("%d-bit float unsupported", bits));
21049 return nullptr;
21050 }
21051 case ZigTypeIdPointer:
21052 {
21053 ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr);
21054 assert(payload->special == ConstValSpecialStatic);
21055 assert(payload->type == type_info_pointer_type);
21056 ConstExprValue *size_value = get_const_field(ira, payload, "size", 0);
21057 assert(size_value->type == ir_type_info_get_type(ira, "Size", type_info_pointer_type));
21058 BuiltinPtrSize size_enum_index = (BuiltinPtrSize)bigint_as_u32(&size_value->data.x_enum_tag);
21059 PtrLen ptr_len = size_enum_index_to_ptr_len(size_enum_index);
21060 ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen,
21061 get_const_field_meta_type(ira, payload, "child", 4),
21062 get_const_field_bool(ira, payload, "is_const", 1),
21063 get_const_field_bool(ira, payload, "is_volatile", 2),
21064 ptr_len,
21065 bigint_as_u32(get_const_field_lit_int(ira, payload, "alignment", 3)),
21066 0, // bit_offset_in_host
21067 0, // host_int_bytes
21068 get_const_field_bool(ira, payload, "is_allowzero", 5)
21069 );
21070 if (size_enum_index != 2)
21071 return ptr_type;
21072 return get_slice_type(ira->codegen, ptr_type);
21073 }
21074 case ZigTypeIdArray:
21075 assert(payload->special == ConstValSpecialStatic);
21076 assert(payload->type == ir_type_info_get_type(ira, "Array", nullptr));
21077 return get_array_type(ira->codegen,
21078 get_const_field_meta_type(ira, payload, "child", 1),
21079 bigint_as_u64(get_const_field_lit_int(ira, payload, "len", 0))
21080 );
21081 case ZigTypeIdComptimeFloat:
21082 return ira->codegen->builtin_types.entry_num_lit_float;
21083 case ZigTypeIdComptimeInt:
21084 return ira->codegen->builtin_types.entry_num_lit_int;
21085 case ZigTypeIdUndefined:
21086 return ira->codegen->builtin_types.entry_undef;
21087 case ZigTypeIdNull:
21088 return ira->codegen->builtin_types.entry_null;
21089 case ZigTypeIdOptional:
21090 case ZigTypeIdErrorUnion:
21091 case ZigTypeIdErrorSet:
21092 case ZigTypeIdEnum:
21093 case ZigTypeIdOpaque:
21094 case ZigTypeIdFnFrame:
21095 case ZigTypeIdAnyFrame:
21096 case ZigTypeIdVector:
21097 case ZigTypeIdEnumLiteral:
21098 ir_add_error(ira, instruction, buf_sprintf(
21099 "TODO implement @Type for 'TypeInfo.%s': see https://github.com/ziglang/zig/issues/2907", type_id_name(tagTypeId)));
21100 return nullptr;
21101 case ZigTypeIdUnion:
21102 case ZigTypeIdFn:
21103 case ZigTypeIdBoundFn:
21104 case ZigTypeIdArgTuple:
21105 case ZigTypeIdStruct:
21106 ir_add_error(ira, instruction, buf_sprintf(
21107 "@Type not availble for 'TypeInfo.%s'", type_id_name(tagTypeId)));
21108 return nullptr;
21109 }
21110 zig_unreachable();
21111}
21112
21113static IrInstruction *ir_analyze_instruction_type(IrAnalyze *ira, IrInstructionType *instruction) {
21114 IrInstruction *type_info_ir = instruction->type_info->child;
21115 if (type_is_invalid(type_info_ir->value.type))
21116 return ira->codegen->invalid_instruction;
21117
21118 IrInstruction *casted_ir = ir_implicit_cast(ira, type_info_ir, ir_type_info_get_type(ira, nullptr, nullptr));
21119 if (type_is_invalid(casted_ir->value.type))
21120 return ira->codegen->invalid_instruction;
21121
21122 ConstExprValue *type_info_value = ir_resolve_const(ira, casted_ir, UndefBad);
21123 if (!type_info_value)
21124 return ira->codegen->invalid_instruction;
21125 ZigTypeId typeId = type_id_at_index(bigint_as_usize(&type_info_value->data.x_union.tag));
21126 ZigType *type = type_info_to_type(ira, type_info_ir, typeId, type_info_value->data.x_union.payload);
21127 if (!type)
21128 return ira->codegen->invalid_instruction;
21129 return ir_const_type(ira, &instruction->base, type);
21130}
21131
2078021132static IrInstruction *ir_analyze_instruction_type_id(IrAnalyze *ira,
2078121133 IrInstructionTypeId *instruction)
2078221134{
......@@ -21036,15 +21388,20 @@ static IrInstruction *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstruct
2103621388 if (type_is_invalid(value->value.type))
2103721389 return ira->codegen->invalid_instruction;
2103821390
21039 Buf *define_value = ir_resolve_str(ira, value);
21040 if (!define_value)
21041 return ira->codegen->invalid_instruction;
21391 Buf *define_value = nullptr;
21392 // The second parameter is either a string or void (equivalent to "")
21393 if (value->value.type->id != ZigTypeIdVoid) {
21394 define_value = ir_resolve_str(ira, value);
21395 if (!define_value)
21396 return ira->codegen->invalid_instruction;
21397 }
2104221398
2104321399 Buf *c_import_buf = exec_c_import_buf(ira->new_irb.exec);
2104421400 // We check for this error in pass1
2104521401 assert(c_import_buf);
2104621402
21047 buf_appendf(c_import_buf, "#define %s %s\n", buf_ptr(define_name), buf_ptr(define_value));
21403 buf_appendf(c_import_buf, "#define %s %s\n", buf_ptr(define_name),
21404 define_value ? buf_ptr(define_value) : "");
2104821405
2104921406 return ir_const_void(ira, &instruction->base);
2105021407}
......@@ -22533,6 +22890,8 @@ static IrInstruction *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstru
2253322890 return ira->codegen->invalid_instruction;
2253422891 }
2253522892
22893 ira->codegen->need_frame_size_prefix_data = true;
22894
2253622895 IrInstruction *result = ir_build_frame_size_gen(&ira->new_irb, instruction->base.scope,
2253722896 instruction->base.source_node, fn);
2253822897 result->value.type = ira->codegen->builtin_types.entry_usize;
......@@ -24823,7 +25182,7 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct
2482325182 if (result_loc->value.type->id == ZigTypeIdUnreachable)
2482425183 return result_loc;
2482525184
24826 if (!was_written) {
25185 if (!was_written || instruction->result_loc->id == ResultLocIdPeer) {
2482725186 IrInstruction *store_ptr = ir_analyze_store_ptr(ira, &instruction->base, result_loc, value,
2482825187 instruction->result_loc->allow_write_through_const);
2482925188 if (type_is_invalid(store_ptr->value.type)) {
......@@ -24831,7 +25190,9 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct
2483125190 }
2483225191 }
2483325192
24834 if (result_loc->value.data.x_ptr.mut == ConstPtrMutInfer) {
25193 if (result_loc->value.data.x_ptr.mut == ConstPtrMutInfer &&
25194 instruction->result_loc->id != ResultLocIdPeer)
25195 {
2483525196 if (instr_is_comptime(value)) {
2483625197 result_loc->value.data.x_ptr.mut = ConstPtrMutComptimeConst;
2483725198 } else {
......@@ -25281,6 +25642,8 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction
2528125642 return ir_analyze_instruction_bit_offset_of(ira, (IrInstructionBitOffsetOf *)instruction);
2528225643 case IrInstructionIdTypeInfo:
2528325644 return ir_analyze_instruction_type_info(ira, (IrInstructionTypeInfo *) instruction);
25645 case IrInstructionIdType:
25646 return ir_analyze_instruction_type(ira, (IrInstructionType *)instruction);
2528425647 case IrInstructionIdHasField:
2528525648 return ir_analyze_instruction_has_field(ira, (IrInstructionHasField *) instruction);
2528625649 case IrInstructionIdTypeId:
......@@ -25584,6 +25947,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {
2558425947 case IrInstructionIdByteOffsetOf:
2558525948 case IrInstructionIdBitOffsetOf:
2558625949 case IrInstructionIdTypeInfo:
25950 case IrInstructionIdType:
2558725951 case IrInstructionIdHasField:
2558825952 case IrInstructionIdTypeId:
2558925953 case IrInstructionIdAlignCast:
src/ir.hpp+5
......@@ -10,6 +10,11 @@
1010
1111#include "all_types.hpp"
1212
13enum IrPass {
14 IrPassSrc,
15 IrPassGen,
16};
17
1318bool ir_gen(CodeGen *g, AstNode *node, Scope *scope, IrExecutable *ir_executable);
1419bool ir_gen_fn(CodeGen *g, ZigFn *fn_entry);
1520
src/ir_print.cpp+43-14
......@@ -22,7 +22,7 @@ using InstructionSet = HashMap<IrInstruction*, uint8_t, hash_instruction_ptr, in
2222using InstructionList = ZigList<IrInstruction*>;
2323
2424struct IrPrint {
25 size_t pass_num;
25 IrPass pass;
2626 CodeGen *codegen;
2727 FILE *f;
2828 int indent;
......@@ -280,6 +280,8 @@ static const char* ir_instruction_type_str(IrInstruction* instruction) {
280280 return "BitOffsetOf";
281281 case IrInstructionIdTypeInfo:
282282 return "TypeInfo";
283 case IrInstructionIdType:
284 return "Type";
283285 case IrInstructionIdHasField:
284286 return "HasField";
285287 case IrInstructionIdTypeId:
......@@ -389,7 +391,7 @@ static void ir_print_const_value(IrPrint *irp, ConstExprValue *const_val) {
389391
390392static void ir_print_var_instruction(IrPrint *irp, IrInstruction *instruction) {
391393 fprintf(irp->f, "#%" ZIG_PRI_usize "", instruction->debug_id);
392 if (irp->pass_num == 2 && irp->printed.maybe_get(instruction) == nullptr) {
394 if (irp->pass != IrPassSrc && irp->printed.maybe_get(instruction) == nullptr) {
393395 irp->printed.put(instruction, 0);
394396 irp->pending.append(instruction);
395397 }
......@@ -529,7 +531,7 @@ static void ir_print_bin_op(IrPrint *irp, IrInstructionBinOp *bin_op_instruction
529531
530532static void ir_print_decl_var_src(IrPrint *irp, IrInstructionDeclVarSrc *decl_var_instruction) {
531533 const char *var_or_const = decl_var_instruction->var->gen_is_const ? "const" : "var";
532 const char *name = buf_ptr(&decl_var_instruction->var->name);
534 const char *name = decl_var_instruction->var->name;
533535 if (decl_var_instruction->var_type) {
534536 fprintf(irp->f, "%s %s: ", var_or_const, name);
535537 ir_print_other_instruction(irp, decl_var_instruction->var_type);
......@@ -606,8 +608,17 @@ static void ir_print_result_loc(IrPrint *irp, ResultLoc *result_loc) {
606608}
607609
608610static void ir_print_call_src(IrPrint *irp, IrInstructionCallSrc *call_instruction) {
609 if (call_instruction->is_async) {
610 fprintf(irp->f, "async ");
611 switch (call_instruction->modifier) {
612 case CallModifierNone:
613 break;
614 case CallModifierAsync:
615 fprintf(irp->f, "async ");
616 break;
617 case CallModifierNoAsync:
618 fprintf(irp->f, "noasync ");
619 break;
620 case CallModifierBuiltin:
621 zig_unreachable();
611622 }
612623 if (call_instruction->fn_entry) {
613624 fprintf(irp->f, "%s", buf_ptr(&call_instruction->fn_entry->symbol_name));
......@@ -627,8 +638,17 @@ static void ir_print_call_src(IrPrint *irp, IrInstructionCallSrc *call_instructi
627638}
628639
629640static void ir_print_call_gen(IrPrint *irp, IrInstructionCallGen *call_instruction) {
630 if (call_instruction->is_async) {
631 fprintf(irp->f, "async ");
641 switch (call_instruction->modifier) {
642 case CallModifierNone:
643 break;
644 case CallModifierAsync:
645 fprintf(irp->f, "async ");
646 break;
647 case CallModifierNoAsync:
648 fprintf(irp->f, "noasync ");
649 break;
650 case CallModifierBuiltin:
651 zig_unreachable();
632652 }
633653 if (call_instruction->fn_entry) {
634654 fprintf(irp->f, "%s", buf_ptr(&call_instruction->fn_entry->symbol_name));
......@@ -727,7 +747,7 @@ static void ir_print_elem_ptr(IrPrint *irp, IrInstructionElemPtr *instruction) {
727747}
728748
729749static void ir_print_var_ptr(IrPrint *irp, IrInstructionVarPtr *instruction) {
730 fprintf(irp->f, "&%s", buf_ptr(&instruction->var->name));
750 fprintf(irp->f, "&%s", instruction->var->name);
731751}
732752
733753static void ir_print_return_ptr(IrPrint *irp, IrInstructionReturnPtr *instruction) {
......@@ -1627,6 +1647,12 @@ static void ir_print_type_info(IrPrint *irp, IrInstructionTypeInfo *instruction)
16271647 fprintf(irp->f, ")");
16281648}
16291649
1650static void ir_print_type(IrPrint *irp, IrInstructionType *instruction) {
1651 fprintf(irp->f, "@Type(");
1652 ir_print_other_instruction(irp, instruction->type_info);
1653 fprintf(irp->f, ")");
1654}
1655
16301656static void ir_print_has_field(IrPrint *irp, IrInstructionHasField *instruction) {
16311657 fprintf(irp->f, "@hasField(");
16321658 ir_print_other_instruction(irp, instruction->container_type);
......@@ -1826,7 +1852,7 @@ static void ir_print_mul_add(IrPrint *irp, IrInstructionMulAdd *instruction) {
18261852static void ir_print_decl_var_gen(IrPrint *irp, IrInstructionDeclVarGen *decl_var_instruction) {
18271853 ZigVar *var = decl_var_instruction->var;
18281854 const char *var_or_const = decl_var_instruction->var->gen_is_const ? "const" : "var";
1829 const char *name = buf_ptr(&decl_var_instruction->var->name);
1855 const char *name = decl_var_instruction->var->name;
18301856 fprintf(irp->f, "%s %s: %s align(%u) = ", var_or_const, name, buf_ptr(&var->var_type->name),
18311857 var->align_bytes);
18321858
......@@ -2258,6 +2284,9 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction, bool
22582284 case IrInstructionIdTypeInfo:
22592285 ir_print_type_info(irp, (IrInstructionTypeInfo *)instruction);
22602286 break;
2287 case IrInstructionIdType:
2288 ir_print_type(irp, (IrInstructionType *)instruction);
2289 break;
22612290 case IrInstructionIdHasField:
22622291 ir_print_has_field(irp, (IrInstructionHasField *)instruction);
22632292 break;
......@@ -2388,10 +2417,10 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction, bool
23882417 fprintf(irp->f, "\n");
23892418}
23902419
2391void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, size_t pass_num) {
2420void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, IrPass pass) {
23922421 IrPrint ir_print = {};
23932422 IrPrint *irp = &ir_print;
2394 irp->pass_num = pass_num;
2423 irp->pass = pass;
23952424 irp->codegen = codegen;
23962425 irp->f = f;
23972426 irp->indent = indent_size;
......@@ -2405,7 +2434,7 @@ void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_si
24052434 fprintf(irp->f, "%s_%" ZIG_PRI_usize ":\n", current_block->name_hint, current_block->debug_id);
24062435 for (size_t instr_i = 0; instr_i < current_block->instruction_list.length; instr_i += 1) {
24072436 IrInstruction *instruction = current_block->instruction_list.at(instr_i);
2408 if (irp->pass_num == 2) {
2437 if (irp->pass != IrPassSrc) {
24092438 irp->printed.put(instruction, 0);
24102439 irp->pending.clear();
24112440 }
......@@ -2419,10 +2448,10 @@ void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_si
24192448 irp->printed.deinit();
24202449}
24212450
2422void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction, int indent_size, size_t pass_num) {
2451void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction, int indent_size, IrPass pass) {
24232452 IrPrint ir_print = {};
24242453 IrPrint *irp = &ir_print;
2425 irp->pass_num = pass_num;
2454 irp->pass = pass;
24262455 irp->codegen = codegen;
24272456 irp->f = f;
24282457 irp->indent = indent_size;
src/ir_print.hpp+2-2
......@@ -12,7 +12,7 @@
1212
1313#include <stdio.h>
1414
15void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, size_t pass_num);
16void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction, int indent_size, size_t pass_num);
15void ir_print(CodeGen *codegen, FILE *f, IrExecutable *executable, int indent_size, IrPass pass);
16void ir_print_instruction(CodeGen *codegen, FILE *f, IrInstruction *instruction, int indent_size, IrPass pass);
1717
1818#endif
src/main.cpp+20-1
......@@ -16,6 +16,7 @@
1616#include "libc_installation.hpp"
1717#include "userland.h"
1818#include "glibc.hpp"
19#include "stack_report.hpp"
1920
2021#include <stdio.h>
2122
......@@ -62,6 +63,7 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) {
6263 " -fPIC enable Position Independent Code\n"
6364 " -fno-PIC disable Position Independent Code\n"
6465 " -ftime-report print timing diagnostics\n"
66 " -fstack-report print stack size diagnostics\n"
6567 " --libc [file] Provide a file which specifies libc paths\n"
6668 " --name [name] override output name\n"
6769 " --output-dir [dir] override output directory (defaults to cwd)\n"
......@@ -101,6 +103,7 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) {
101103 " --version-script [path] provide a version .map file\n"
102104 " --object [obj] add object file to build\n"
103105 " -L[dir] alias for --library-path\n"
106 " -l[lib] alias for --library\n"
104107 " -rdynamic add all symbols to the dynamic symbol table\n"
105108 " -rpath [path] add directory to the runtime library search path\n"
106109 " --subsystem [subsystem] (windows) /SUBSYSTEM:<subsystem> to the linker\n"
......@@ -475,6 +478,7 @@ int main(int argc, char **argv) {
475478 size_t ver_minor = 0;
476479 size_t ver_patch = 0;
477480 bool timing_info = false;
481 bool stack_report = false;
478482 const char *cache_dir = nullptr;
479483 CliPkg *cur_pkg = allocate<CliPkg>(1);
480484 BuildMode build_mode = BuildModeDebug;
......@@ -663,6 +667,8 @@ int main(int argc, char **argv) {
663667 each_lib_rpath = true;
664668 } else if (strcmp(arg, "-ftime-report") == 0) {
665669 timing_info = true;
670 } else if (strcmp(arg, "-fstack-report") == 0) {
671 stack_report = true;
666672 } else if (strcmp(arg, "--enable-valgrind") == 0) {
667673 valgrind_support = ValgrindSupportEnabled;
668674 } else if (strcmp(arg, "--disable-valgrind") == 0) {
......@@ -688,6 +694,12 @@ int main(int argc, char **argv) {
688694 } else if (arg[1] == 'L' && arg[2] != 0) {
689695 // alias for --library-path
690696 lib_dirs.append(&arg[2]);
697 } else if (arg[1] == 'l' && arg[2] != 0) {
698 // alias for --library
699 const char *l = &arg[2];
700 if (strcmp(l, "c") == 0)
701 have_libc = true;
702 link_libs.append(l);
691703 } else if (arg[1] == 'F' && arg[2] != 0) {
692704 framework_dirs.append(&arg[2]);
693705 } else if (strcmp(arg, "--pkg-begin") == 0) {
......@@ -778,7 +790,7 @@ int main(int argc, char **argv) {
778790 lib_dirs.append(argv[i]);
779791 } else if (strcmp(arg, "-F") == 0) {
780792 framework_dirs.append(argv[i]);
781 } else if (strcmp(arg, "--library") == 0) {
793 } else if (strcmp(arg, "--library") == 0 || strcmp(arg, "-l") == 0) {
782794 if (strcmp(argv[i], "c") == 0)
783795 have_libc = true;
784796 link_libs.append(argv[i]);
......@@ -1129,6 +1141,7 @@ int main(int argc, char **argv) {
11291141 g->subsystem = subsystem;
11301142
11311143 g->enable_time_report = timing_info;
1144 g->enable_stack_report = stack_report;
11321145 codegen_set_out_name(g, buf_out_name);
11331146 codegen_set_lib_version(g, ver_major, ver_minor, ver_patch);
11341147 g->want_single_threaded = want_single_threaded;
......@@ -1216,6 +1229,8 @@ int main(int argc, char **argv) {
12161229 codegen_build_and_link(g);
12171230 if (timing_info)
12181231 codegen_print_timing_report(g, stdout);
1232 if (stack_report)
1233 zig_print_stack_report(g, stdout);
12191234
12201235 if (cmd == CmdRun) {
12211236 const char *exec_path = buf_ptr(&g->output_file_path);
......@@ -1265,6 +1280,10 @@ int main(int argc, char **argv) {
12651280 codegen_print_timing_report(g, stdout);
12661281 }
12671282
1283 if (stack_report) {
1284 zig_print_stack_report(g, stdout);
1285 }
1286
12681287 Buf *test_exe_path_unresolved = &g->output_file_path;
12691288 Buf *test_exe_path = buf_alloc();
12701289 *test_exe_path = os_path_resolve(&test_exe_path_unresolved, 1);
src/os.cpp+24
......@@ -45,6 +45,7 @@ typedef SSIZE_T ssize_t;
4545#include <sys/types.h>
4646#include <sys/stat.h>
4747#include <sys/wait.h>
48#include <sys/resource.h>
4849#include <fcntl.h>
4950#include <limits.h>
5051#include <spawn.h>
......@@ -1374,6 +1375,29 @@ int os_init(void) {
13741375#elif defined(__MACH__)
13751376 host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &macos_monotonic_clock);
13761377 host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &macos_calendar_clock);
1378#endif
1379#if defined(ZIG_OS_POSIX)
1380 // Raise the open file descriptor limit.
1381 // Code lifted from node.js
1382 struct rlimit lim;
1383 if (getrlimit(RLIMIT_NOFILE, &lim) == 0 && lim.rlim_cur != lim.rlim_max) {
1384 // Do a binary search for the limit.
1385 rlim_t min = lim.rlim_cur;
1386 rlim_t max = 1 << 20;
1387 // But if there's a defined upper bound, don't search, just set it.
1388 if (lim.rlim_max != RLIM_INFINITY) {
1389 min = lim.rlim_max;
1390 max = lim.rlim_max;
1391 }
1392 do {
1393 lim.rlim_cur = min + (max - min) / 2;
1394 if (setrlimit(RLIMIT_NOFILE, &lim)) {
1395 max = lim.rlim_cur;
1396 } else {
1397 min = lim.rlim_cur;
1398 }
1399 } while (min + 1 < max);
1400 }
13771401#endif
13781402 return 0;
13791403}
src/parser.cpp+31-16
......@@ -113,7 +113,7 @@ static AstNode *ast_parse_multiply_op(ParseContext *pc);
113113static AstNode *ast_parse_prefix_op(ParseContext *pc);
114114static AstNode *ast_parse_prefix_type_op(ParseContext *pc);
115115static AstNode *ast_parse_suffix_op(ParseContext *pc);
116static AstNode *ast_parse_fn_call_argumnets(ParseContext *pc);
116static AstNode *ast_parse_fn_call_arguments(ParseContext *pc);
117117static AstNode *ast_parse_array_type_start(ParseContext *pc);
118118static AstNode *ast_parse_ptr_type_start(ParseContext *pc);
119119static AstNode *ast_parse_container_decl_auto(ParseContext *pc);
......@@ -578,7 +578,7 @@ static AstNode *ast_parse_top_level_comptime(ParseContext *pc) {
578578}
579579
580580// TopLevelDecl
581// <- (KEYWORD_export / KEYWORD_extern STRINGLITERAL? / KEYWORD_inline)? FnProto (SEMICOLON / Block)
581// <- (KEYWORD_export / KEYWORD_extern STRINGLITERAL? / (KEYWORD_inline / KEYWORD_noinline))? FnProto (SEMICOLON / Block)
582582// / (KEYWORD_export / KEYWORD_extern STRINGLITERAL?)? KEYWORD_threadlocal? VarDecl
583583// / KEYWORD_use Expr SEMICOLON
584584static AstNode *ast_parse_top_level_decl(ParseContext *pc, VisibMod visib_mod) {
......@@ -587,12 +587,14 @@ static AstNode *ast_parse_top_level_decl(ParseContext *pc, VisibMod visib_mod) {
587587 first = eat_token_if(pc, TokenIdKeywordExtern);
588588 if (first == nullptr)
589589 first = eat_token_if(pc, TokenIdKeywordInline);
590 if (first == nullptr)
591 first = eat_token_if(pc, TokenIdKeywordNoInline);
590592 if (first != nullptr) {
591593 Token *lib_name = nullptr;
592594 if (first->id == TokenIdKeywordExtern)
593595 lib_name = eat_token_if(pc, TokenIdStringLiteral);
594596
595 if (first->id != TokenIdKeywordInline) {
597 if (first->id != TokenIdKeywordInline && first->id != TokenIdKeywordNoInline) {
596598 Token *thread_local_kw = eat_token_if(pc, TokenIdKeywordThreadLocal);
597599 AstNode *var_decl = ast_parse_var_decl(pc);
598600 if (var_decl != nullptr) {
......@@ -623,8 +625,19 @@ static AstNode *ast_parse_top_level_decl(ParseContext *pc, VisibMod visib_mod) {
623625 fn_proto->data.fn_proto.visib_mod = visib_mod;
624626 fn_proto->data.fn_proto.is_extern = first->id == TokenIdKeywordExtern;
625627 fn_proto->data.fn_proto.is_export = first->id == TokenIdKeywordExport;
626 fn_proto->data.fn_proto.is_inline = first->id == TokenIdKeywordInline;
628 switch (first->id) {
629 case TokenIdKeywordInline:
630 fn_proto->data.fn_proto.fn_inline = FnInlineAlways;
631 break;
632 case TokenIdKeywordNoInline:
633 fn_proto->data.fn_proto.fn_inline = FnInlineNever;
634 break;
635 default:
636 fn_proto->data.fn_proto.fn_inline = FnInlineAuto;
637 break;
638 }
627639 fn_proto->data.fn_proto.lib_name = token_buf(lib_name);
640
628641 AstNode *res = fn_proto;
629642 if (body != nullptr) {
630643 res = ast_create_node_copy_line_info(pc, NodeTypeFnDef, fn_proto);
......@@ -1390,12 +1403,14 @@ static AstNode *ast_parse_error_union_expr(ParseContext *pc) {
13901403}
13911404
13921405// SuffixExpr
1393// <- KEYWORD_async PrimaryTypeExpr SuffixOp* FnCallArguments
1406// <- KEYWORD_async PrimaryTypeExpr SuffixOp* FnCallArguments
1407// / KEYWORD_noasync PrimaryTypeExpr SuffixOp* FnCallArguments
13941408// / PrimaryTypeExpr (SuffixOp / FnCallArguments)*
13951409static AstNode *ast_parse_suffix_expr(ParseContext *pc) {
1396 Token *async_token = eat_token_if(pc, TokenIdKeywordAsync);
1397 if (async_token != nullptr) {
1398 if (eat_token_if(pc, TokenIdKeywordFn) != nullptr) {
1410 Token *async_token = eat_token(pc);
1411 bool is_async = async_token->id == TokenIdKeywordAsync;
1412 if (is_async || async_token->id == TokenIdKeywordNoAsync) {
1413 if (is_async && eat_token_if(pc, TokenIdKeywordFn) != nullptr) {
13991414 // HACK: If we see the keyword `fn`, then we assume that
14001415 // we are parsing an async fn proto, and not a call.
14011416 // We therefore put back all tokens consumed by the async
......@@ -1434,24 +1449,24 @@ static AstNode *ast_parse_suffix_expr(ParseContext *pc) {
14341449 child = suffix;
14351450 }
14361451
1437 // TODO: Both *_async_prefix and *_fn_call_argumnets returns an
1452 // TODO: Both *_async_prefix and *_fn_call_arguments returns an
14381453 // AstNode *. All we really want here is the arguments of
14391454 // the call we parse. We therefor "leak" the node for now.
14401455 // Wait till we get async rework to fix this.
1441 AstNode *args = ast_parse_fn_call_argumnets(pc);
1456 AstNode *args = ast_parse_fn_call_arguments(pc);
14421457 if (args == nullptr)
14431458 ast_invalid_token_error(pc, peek_token(pc));
14441459
14451460 assert(args->type == NodeTypeFnCallExpr);
14461461
14471462 AstNode *res = ast_create_node(pc, NodeTypeFnCallExpr, async_token);
1448 res->data.fn_call_expr.is_async = true;
1463 res->data.fn_call_expr.modifier = is_async ? CallModifierAsync : CallModifierNoAsync;
14491464 res->data.fn_call_expr.seen = false;
14501465 res->data.fn_call_expr.fn_ref_expr = child;
14511466 res->data.fn_call_expr.params = args->data.fn_call_expr.params;
1452 res->data.fn_call_expr.is_builtin = false;
14531467 return res;
14541468 }
1469 put_back_token(pc);
14551470
14561471 AstNode *res = ast_parse_primary_type_expr(pc);
14571472 if (res == nullptr)
......@@ -1483,7 +1498,7 @@ static AstNode *ast_parse_suffix_expr(ParseContext *pc) {
14831498 continue;
14841499 }
14851500
1486 AstNode * call = ast_parse_fn_call_argumnets(pc);
1501 AstNode * call = ast_parse_fn_call_arguments(pc);
14871502 if (call != nullptr) {
14881503 assert(call->type == NodeTypeFnCallExpr);
14891504 call->data.fn_call_expr.fn_ref_expr = res;
......@@ -1539,7 +1554,7 @@ static AstNode *ast_parse_primary_type_expr(ParseContext *pc) {
15391554 name = buf_create_from_str("export");
15401555 }
15411556
1542 AstNode *res = ast_expect(pc, ast_parse_fn_call_argumnets);
1557 AstNode *res = ast_expect(pc, ast_parse_fn_call_arguments);
15431558 AstNode *name_sym = ast_create_node(pc, NodeTypeSymbol, token);
15441559 name_sym->data.symbol_expr.symbol = name;
15451560
......@@ -1547,7 +1562,7 @@ static AstNode *ast_parse_primary_type_expr(ParseContext *pc) {
15471562 res->line = at_sign->start_line;
15481563 res->column = at_sign->start_column;
15491564 res->data.fn_call_expr.fn_ref_expr = name_sym;
1550 res->data.fn_call_expr.is_builtin = true;
1565 res->data.fn_call_expr.modifier = CallModifierBuiltin;
15511566 return res;
15521567 }
15531568
......@@ -2659,7 +2674,7 @@ static AstNode *ast_parse_suffix_op(ParseContext *pc) {
26592674}
26602675
26612676// FnCallArguments <- LPAREN ExprList RPAREN
2662static AstNode *ast_parse_fn_call_argumnets(ParseContext *pc) {
2677static AstNode *ast_parse_fn_call_arguments(ParseContext *pc) {
26632678 Token *paren = eat_token_if(pc, TokenIdLParen);
26642679 if (paren == nullptr)
26652680 return nullptr;
src/stack_report.cpp created+121
......@@ -0,0 +1,121 @@
1/*
2 * Copyright (c) 2019 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#include "stack_report.hpp"
9
10static void tree_print(FILE *f, ZigType *ty, size_t indent);
11
12static void pretty_print_bytes(FILE *f, double n) {
13 if (n > 1024.0 * 1024.0 * 1024.0) {
14 fprintf(f, "%.02f GiB", n / 1024.0 / 1024.0 / 1024.0);
15 return;
16 }
17 if (n > 1024.0 * 1024.0) {
18 fprintf(f, "%.02f MiB", n / 1024.0 / 1024.0);
19 return;
20 }
21 if (n > 1024.0) {
22 fprintf(f, "%.02f KiB", n / 1024.0);
23 return;
24 }
25 fprintf(f, "%.02f bytes", n );
26 return;
27}
28
29static int compare_type_abi_sizes_desc(const void *a, const void *b) {
30 uint64_t size_a = (*(ZigType * const*)(a))->abi_size;
31 uint64_t size_b = (*(ZigType * const*)(b))->abi_size;
32 if (size_a > size_b)
33 return -1;
34 if (size_a < size_b)
35 return 1;
36 return 0;
37}
38
39static void start_child(FILE *f, size_t indent) {
40 fprintf(f, "\n");
41 for (size_t i = 0; i < indent; i += 1) {
42 fprintf(f, " ");
43 }
44}
45
46static void start_peer(FILE *f, size_t indent) {
47 fprintf(f, ",\n");
48 for (size_t i = 0; i < indent; i += 1) {
49 fprintf(f, " ");
50 }
51}
52
53static void tree_print_struct(FILE *f, ZigType *struct_type, size_t indent) {
54 ZigList<ZigType *> children = {};
55 uint64_t sum_from_fields = 0;
56 for (size_t i = 0; i < struct_type->data.structure.src_field_count; i += 1) {
57 TypeStructField *field = &struct_type->data.structure.fields[i];
58 children.append(field->type_entry);
59 sum_from_fields += field->type_entry->abi_size;
60 }
61 qsort(children.items, children.length, sizeof(ZigType *), compare_type_abi_sizes_desc);
62
63 start_peer(f, indent);
64 fprintf(f, "\"padding\": \"%" ZIG_PRI_u64 "\"", struct_type->abi_size - sum_from_fields);
65
66 start_peer(f, indent);
67 fprintf(f, "\"fields\": [");
68
69 for (size_t i = 0; i < children.length; i += 1) {
70 if (i == 0) {
71 start_child(f, indent + 1);
72 } else {
73 start_peer(f, indent + 1);
74 }
75 fprintf(f, "{");
76
77 ZigType *child_type = children.at(i);
78 tree_print(f, child_type, indent + 2);
79
80 start_child(f, indent + 1);
81 fprintf(f, "}");
82 }
83
84 start_child(f, indent);
85 fprintf(f, "]");
86}
87
88static void tree_print(FILE *f, ZigType *ty, size_t indent) {
89 start_child(f, indent);
90 fprintf(f, "\"type\": \"%s\"", buf_ptr(&ty->name));
91
92 start_peer(f, indent);
93 fprintf(f, "\"sizef\": \"");
94 pretty_print_bytes(f, ty->abi_size);
95 fprintf(f, "\"");
96
97 start_peer(f, indent);
98 fprintf(f, "\"size\": \"%" ZIG_PRI_u64 "\"", ty->abi_size);
99
100 switch (ty->id) {
101 case ZigTypeIdFnFrame:
102 return tree_print_struct(f, ty->data.frame.locals_struct, indent);
103 case ZigTypeIdStruct:
104 return tree_print_struct(f, ty, indent);
105 default:
106 start_child(f, indent);
107 return;
108 }
109}
110
111void zig_print_stack_report(CodeGen *g, FILE *f) {
112 if (g->largest_frame_fn == nullptr) {
113 fprintf(f, "{\"error\": \"No async function frames in entire compilation.\"}\n");
114 return;
115 }
116 fprintf(f, "{");
117 tree_print(f, g->largest_frame_fn->frame_type, 1);
118
119 start_child(f, 0);
120 fprintf(f, "}\n");
121}
src/stack_report.hpp created+16
......@@ -0,0 +1,16 @@
1/*
2 * Copyright (c) 2019 Andrew Kelley
3 *
4 * This file is part of zig, which is MIT licensed.
5 * See http://opensource.org/licenses/MIT
6 */
7
8#ifndef ZIG_STACK_REPORT_HPP
9#define ZIG_STACK_REPORT_HPP
10
11#include "all_types.hpp"
12#include <stdio.h>
13
14void zig_print_stack_report(CodeGen *g, FILE *f);
15
16#endif
src/target.cpp+4-4
......@@ -1441,6 +1441,10 @@ const char *arch_stack_pointer_register_name(ZigLLVM_ArchType arch) {
14411441 return "esp";
14421442 case ZigLLVM_x86_64:
14431443 return "rsp";
1444 case ZigLLVM_arm:
1445 case ZigLLVM_armeb:
1446 case ZigLLVM_thumb:
1447 case ZigLLVM_thumbeb:
14441448 case ZigLLVM_aarch64:
14451449 case ZigLLVM_aarch64_be:
14461450 case ZigLLVM_aarch64_32:
......@@ -1448,12 +1452,9 @@ const char *arch_stack_pointer_register_name(ZigLLVM_ArchType arch) {
14481452 case ZigLLVM_riscv64:
14491453 return "sp";
14501454
1451 case ZigLLVM_arm:
1452 case ZigLLVM_thumb:
14531455 case ZigLLVM_amdgcn:
14541456 case ZigLLVM_amdil:
14551457 case ZigLLVM_amdil64:
1456 case ZigLLVM_armeb:
14571458 case ZigLLVM_arc:
14581459 case ZigLLVM_avr:
14591460 case ZigLLVM_bpfeb:
......@@ -1485,7 +1486,6 @@ const char *arch_stack_pointer_register_name(ZigLLVM_ArchType arch) {
14851486 case ZigLLVM_systemz:
14861487 case ZigLLVM_tce:
14871488 case ZigLLVM_tcele:
1488 case ZigLLVM_thumbeb:
14891489 case ZigLLVM_wasm32:
14901490 case ZigLLVM_wasm64:
14911491 case ZigLLVM_xcore:
src/tokenizer.cpp+4
......@@ -132,6 +132,8 @@ static const struct ZigKeyword zig_keywords[] = {
132132 {"inline", TokenIdKeywordInline},
133133 {"nakedcc", TokenIdKeywordNakedCC},
134134 {"noalias", TokenIdKeywordNoAlias},
135 {"noasync", TokenIdKeywordNoAsync},
136 {"noinline", TokenIdKeywordNoInline},
135137 {"null", TokenIdKeywordNull},
136138 {"or", TokenIdKeywordOr},
137139 {"orelse", TokenIdKeywordOrElse},
......@@ -1553,6 +1555,8 @@ const char * token_name(TokenId id) {
15531555 case TokenIdKeywordInline: return "inline";
15541556 case TokenIdKeywordNakedCC: return "nakedcc";
15551557 case TokenIdKeywordNoAlias: return "noalias";
1558 case TokenIdKeywordNoAsync: return "noasync";
1559 case TokenIdKeywordNoInline: return "noinline";
15561560 case TokenIdKeywordNull: return "null";
15571561 case TokenIdKeywordOr: return "or";
15581562 case TokenIdKeywordOrElse: return "orelse";
src/tokenizer.hpp+2
......@@ -74,9 +74,11 @@ enum TokenId {
7474 TokenIdKeywordFor,
7575 TokenIdKeywordIf,
7676 TokenIdKeywordInline,
77 TokenIdKeywordNoInline,
7778 TokenIdKeywordLinkSection,
7879 TokenIdKeywordNakedCC,
7980 TokenIdKeywordNoAlias,
81 TokenIdKeywordNoAsync,
8082 TokenIdKeywordNull,
8183 TokenIdKeywordOr,
8284 TokenIdKeywordOrElse,
src/translate_c.cpp+2-2
......@@ -253,7 +253,7 @@ static AstNode *trans_create_node_symbol_str(Context *c, const char *name) {
253253static AstNode *trans_create_node_builtin_fn_call(Context *c, Buf *name) {
254254 AstNode *node = trans_create_node(c, NodeTypeFnCallExpr);
255255 node->data.fn_call_expr.fn_ref_expr = trans_create_node_symbol(c, name);
256 node->data.fn_call_expr.is_builtin = true;
256 node->data.fn_call_expr.modifier = CallModifierBuiltin;
257257 return node;
258258}
259259
......@@ -432,7 +432,7 @@ static AstNode *trans_create_node_inline_fn(Context *c, Buf *fn_name, AstNode *r
432432 AstNode *fn_proto = trans_create_node(c, NodeTypeFnProto);
433433 fn_proto->data.fn_proto.visib_mod = c->visib_mod;
434434 fn_proto->data.fn_proto.name = fn_name;
435 fn_proto->data.fn_proto.is_inline = true;
435 fn_proto->data.fn_proto.fn_inline = FnInlineAlways;
436436 fn_proto->data.fn_proto.return_type = src_proto_node->data.fn_proto.return_type; // TODO ok for these to alias?
437437
438438 fn_def->data.fn_def.fn_proto = fn_proto;
src/zig_llvm.cpp+1
......@@ -853,6 +853,7 @@ const char *ZigLLVMGetSubArchTypeName(ZigLLVM_SubArchType sub_arch) {
853853
854854void ZigLLVMAddModuleDebugInfoFlag(LLVMModuleRef module) {
855855 unwrap(module)->addModuleFlag(Module::Warning, "Debug Info Version", DEBUG_METADATA_VERSION);
856 unwrap(module)->addModuleFlag(Module::Warning, "Dwarf Version", 4);
856857}
857858
858859void ZigLLVMAddModuleCodeViewFlag(LLVMModuleRef module) {
std/bloom_filter.zig created+253
......@@ -0,0 +1,253 @@
1const builtin = @import("builtin");
2const std = @import("std.zig");
3const math = std.math;
4const debug = std.debug;
5const assert = std.debug.assert;
6const testing = std.testing;
7
8/// There is a trade off of how quickly to fill a bloom filter;
9/// the number of items is:
10/// n_items / K * ln(2)
11/// the rate of false positives is:
12/// (1-e^(-K*N/n_items))^K
13/// where N is the number of items
14pub fn BloomFilter(
15 /// Size of bloom filter in cells, must be a power of two.
16 comptime n_items: usize,
17 /// Number of cells to set per item
18 comptime K: usize,
19 /// Cell type, should be:
20 /// - `bool` for a standard bloom filter
21 /// - an unsigned integer type for a counting bloom filter
22 comptime Cell: type,
23 /// endianess of the Cell
24 comptime endian: builtin.Endian,
25 /// Hash function to use
26 comptime hash: fn (out: []u8, Ki: usize, in: []const u8) void,
27) type {
28 assert(n_items > 0);
29 assert(math.isPowerOfTwo(n_items));
30 assert(K > 0);
31 const cellEmpty = if (Cell == bool) false else Cell(0);
32 const cellMax = if (Cell == bool) true else math.maxInt(Cell);
33 const n_bytes = (n_items * comptime std.meta.bitCount(Cell)) / 8;
34 assert(n_bytes > 0);
35 const Io = std.packed_int_array.PackedIntIo(Cell, endian);
36
37 return struct {
38 const Self = @This();
39 pub const items = n_items;
40 pub const Index = math.IntFittingRange(0, n_items - 1);
41
42 data: [n_bytes]u8 = [_]u8{0} ** n_bytes,
43
44 pub fn reset(self: *Self) void {
45 std.mem.set(u8, self.data[0..], 0);
46 }
47
48 pub fn @"union"(x: Self, y: Self) Self {
49 var r = Self{ .data = undefined };
50 inline for (x.data) |v, i| {
51 r.data[i] = v | y.data[i];
52 }
53 return r;
54 }
55
56 pub fn intersection(x: Self, y: Self) Self {
57 var r = Self{ .data = undefined };
58 inline for (x.data) |v, i| {
59 r.data[i] = v & y.data[i];
60 }
61 return r;
62 }
63
64 pub fn getCell(self: Self, cell: Index) Cell {
65 return Io.get(self.data, cell, 0);
66 }
67
68 pub fn incrementCell(self: *Self, cell: Index) void {
69 if (Cell == bool or Cell == u1) {
70 // skip the 'get' operation
71 Io.set(&self.data, cell, 0, cellMax);
72 } else {
73 const old = Io.get(self.data, cell, 0);
74 if (old != cellMax) {
75 Io.set(&self.data, cell, 0, old + 1);
76 }
77 }
78 }
79
80 pub fn clearCell(self: *Self, cell: Index) void {
81 Io.set(&self.data, cell, 0, cellEmpty);
82 }
83
84 pub fn add(self: *Self, item: []const u8) void {
85 comptime var i = 0;
86 inline while (i < K) : (i += 1) {
87 var K_th_bit: packed struct { x: Index } = undefined;
88 hash(std.mem.asBytes(&K_th_bit), i, item);
89 incrementCell(self, K_th_bit.x);
90 }
91 }
92
93 pub fn contains(self: Self, item: []const u8) bool {
94 comptime var i = 0;
95 inline while (i < K) : (i += 1) {
96 var K_th_bit: packed struct { x: Index } = undefined;
97 hash(std.mem.asBytes(&K_th_bit), i, item);
98 if (getCell(self, K_th_bit.x) == cellEmpty)
99 return false;
100 }
101 return true;
102 }
103
104 pub fn resize(self: Self, comptime newsize: usize) BloomFilter(newsize, K, Cell, endian, hash) {
105 var r: BloomFilter(newsize, K, Cell, endian, hash) = undefined;
106 if (newsize < n_items) {
107 std.mem.copy(u8, r.data[0..], self.data[0..r.data.len]);
108 var copied: usize = r.data.len;
109 while (copied < self.data.len) : (copied += r.data.len) {
110 for (self.data[copied .. copied + r.data.len]) |s, i| {
111 r.data[i] |= s;
112 }
113 }
114 } else if (newsize == n_items) {
115 r = self;
116 } else if (newsize > n_items) {
117 var copied: usize = 0;
118 while (copied < r.data.len) : (copied += self.data.len) {
119 std.mem.copy(u8, r.data[copied .. copied + self.data.len], self.data);
120 }
121 }
122 return r;
123 }
124
125 /// Returns number of non-zero cells
126 pub fn popCount(self: Self) Index {
127 var n: Index = 0;
128 if (Cell == bool or Cell == u1) {
129 for (self.data) |b, i| {
130 n += @popCount(u8, b);
131 }
132 } else {
133 var i: usize = 0;
134 while (i < n_items) : (i += 1) {
135 const cell = self.getCell(@intCast(Index, i));
136 n += if (if (Cell == bool) cell else cell > 0) Index(1) else Index(0);
137 }
138 }
139 return n;
140 }
141
142 pub fn estimateItems(self: Self) f64 {
143 const m = comptime @intToFloat(f64, n_items);
144 const k = comptime @intToFloat(f64, K);
145 const X = @intToFloat(f64, self.popCount());
146 return (comptime (-m / k)) * math.log1p(X * comptime (-1 / m));
147 }
148 };
149}
150
151fn hashFunc(out: []u8, Ki: usize, in: []const u8) void {
152 var st = std.crypto.gimli.Hash.init();
153 st.update(std.mem.asBytes(&Ki));
154 st.update(in);
155 st.final(out);
156}
157
158test "std.BloomFilter" {
159 inline for ([_]type{ bool, u1, u2, u3, u4 }) |Cell| {
160 const emptyCell = if (Cell == bool) false else Cell(0);
161 const BF = BloomFilter(128 * 8, 8, Cell, builtin.endian, hashFunc);
162 var bf = BF{};
163 var i: usize = undefined;
164 // confirm that it is initialised to the empty filter
165 i = 0;
166 while (i < BF.items) : (i += 1) {
167 testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i)));
168 }
169 testing.expectEqual(BF.Index(0), bf.popCount());
170 testing.expectEqual(f64(0), bf.estimateItems());
171 // fill in a few items
172 bf.incrementCell(42);
173 bf.incrementCell(255);
174 bf.incrementCell(256);
175 bf.incrementCell(257);
176 // check that they were set
177 testing.expectEqual(true, bf.getCell(42) != emptyCell);
178 testing.expectEqual(true, bf.getCell(255) != emptyCell);
179 testing.expectEqual(true, bf.getCell(256) != emptyCell);
180 testing.expectEqual(true, bf.getCell(257) != emptyCell);
181 // clear just one of them; make sure the rest are still set
182 bf.clearCell(256);
183 testing.expectEqual(true, bf.getCell(42) != emptyCell);
184 testing.expectEqual(true, bf.getCell(255) != emptyCell);
185 testing.expectEqual(false, bf.getCell(256) != emptyCell);
186 testing.expectEqual(true, bf.getCell(257) != emptyCell);
187 // reset any of the ones we've set and confirm we're back to the empty filter
188 bf.clearCell(42);
189 bf.clearCell(255);
190 bf.clearCell(257);
191 i = 0;
192 while (i < BF.items) : (i += 1) {
193 testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i)));
194 }
195 testing.expectEqual(BF.Index(0), bf.popCount());
196 testing.expectEqual(f64(0), bf.estimateItems());
197
198 // Lets add a string
199 bf.add("foo");
200 testing.expectEqual(true, bf.contains("foo"));
201 {
202 // try adding same string again. make sure popcount is the same
203 const old_popcount = bf.popCount();
204 testing.expect(old_popcount > 0);
205 bf.add("foo");
206 testing.expectEqual(true, bf.contains("foo"));
207 testing.expectEqual(old_popcount, bf.popCount());
208 }
209
210 // Get back to empty filter via .reset
211 bf.reset();
212 // Double check that .reset worked
213 i = 0;
214 while (i < BF.items) : (i += 1) {
215 testing.expectEqual(emptyCell, bf.getCell(@intCast(BF.Index, i)));
216 }
217 testing.expectEqual(BF.Index(0), bf.popCount());
218 testing.expectEqual(f64(0), bf.estimateItems());
219
220 comptime var teststrings = [_][]const u8{
221 "foo",
222 "bar",
223 "a longer string",
224 "some more",
225 "the quick brown fox",
226 "unique string",
227 };
228 inline for (teststrings) |str| {
229 bf.add(str);
230 }
231 inline for (teststrings) |str| {
232 testing.expectEqual(true, bf.contains(str));
233 }
234
235 { // estimate should be close for low packing
236 const est = bf.estimateItems();
237 testing.expect(est > @intToFloat(f64, teststrings.len) - 1);
238 testing.expect(est < @intToFloat(f64, teststrings.len) + 1);
239 }
240
241 const larger_bf = bf.resize(4096);
242 inline for (teststrings) |str| {
243 testing.expectEqual(true, larger_bf.contains(str));
244 }
245 testing.expectEqual(u12(bf.popCount()) * (4096 / 1024), larger_bf.popCount());
246
247 const smaller_bf = bf.resize(64);
248 inline for (teststrings) |str| {
249 testing.expectEqual(true, smaller_bf.contains(str));
250 }
251 testing.expect(bf.popCount() <= u10(smaller_bf.popCount()) * (1024 / 64));
252 }
253}
std/buf_map.zig+2-2
......@@ -1,5 +1,5 @@
11const std = @import("std.zig");
2const HashMap = std.HashMap;
2const StringHashMap = std.StringHashMap;
33const mem = std.mem;
44const Allocator = mem.Allocator;
55const testing = std.testing;
......@@ -9,7 +9,7 @@ const testing = std.testing;
99pub const BufMap = struct {
1010 hash_map: BufMapHashMap,
1111
12 const BufMapHashMap = HashMap([]const u8, []const u8, mem.hash_slice_u8, mem.eql_slice_u8);
12 const BufMapHashMap = StringHashMap([]const u8);
1313
1414 pub fn init(allocator: *Allocator) BufMap {
1515 var self = BufMap{ .hash_map = BufMapHashMap.init(allocator) };
std/buf_set.zig+2-2
......@@ -1,5 +1,5 @@
11const std = @import("std.zig");
2const HashMap = @import("hash_map.zig").HashMap;
2const StringHashMap = std.StringHashMap;
33const mem = @import("mem.zig");
44const Allocator = mem.Allocator;
55const testing = std.testing;
......@@ -7,7 +7,7 @@ const testing = std.testing;
77pub const BufSet = struct {
88 hash_map: BufSetHashMap,
99
10 const BufSetHashMap = HashMap([]const u8, void, mem.hash_slice_u8, mem.eql_slice_u8);
10 const BufSetHashMap = StringHashMap(void);
1111
1212 pub fn init(a: *Allocator) BufSet {
1313 var self = BufSet{ .hash_map = BufSetHashMap.init(a) };
std/build.zig+21-17
......@@ -4,10 +4,11 @@ const io = std.io;
44const fs = std.fs;
55const mem = std.mem;
66const debug = std.debug;
7const panic = std.debug.panic;
78const assert = debug.assert;
89const warn = std.debug.warn;
910const ArrayList = std.ArrayList;
10const HashMap = std.HashMap;
11const StringHashMap = std.StringHashMap;
1112const Allocator = mem.Allocator;
1213const process = std.process;
1314const BufSet = std.BufSet;
......@@ -42,8 +43,8 @@ pub const Builder = struct {
4243 top_level_steps: ArrayList(*TopLevelStep),
4344 install_prefix: ?[]const u8,
4445 dest_dir: ?[]const u8,
45 lib_dir: ?[]const u8,
46 exe_dir: ?[]const u8,
46 lib_dir: []const u8,
47 exe_dir: []const u8,
4748 install_path: []const u8,
4849 search_prefixes: ArrayList([]const u8),
4950 installed_files: ArrayList(InstalledFile),
......@@ -60,8 +61,8 @@ pub const Builder = struct {
6061 C11,
6162 };
6263
63 const UserInputOptionsMap = HashMap([]const u8, UserInputOption, mem.hash_slice_u8, mem.eql_slice_u8);
64 const AvailableOptionsMap = HashMap([]const u8, AvailableOption, mem.hash_slice_u8, mem.eql_slice_u8);
64 const UserInputOptionsMap = StringHashMap(UserInputOption);
65 const AvailableOptionsMap = StringHashMap(AvailableOption);
6566
6667 const AvailableOption = struct {
6768 name: []const u8,
......@@ -129,8 +130,8 @@ pub const Builder = struct {
129130 .env_map = env_map,
130131 .search_prefixes = ArrayList([]const u8).init(allocator),
131132 .install_prefix = null,
132 .lib_dir = null,
133 .exe_dir = null,
133 .lib_dir = undefined,
134 .exe_dir = undefined,
134135 .dest_dir = env_map.get("DESTDIR"),
135136 .installed_files = ArrayList(InstalledFile).init(allocator),
136137 .install_tls = TopLevelStep{
......@@ -163,11 +164,13 @@ pub const Builder = struct {
163164 self.allocator.destroy(self);
164165 }
165166
167 /// This function is intended to be called by std/special/build_runner.zig, not a build.zig file.
166168 pub fn setInstallPrefix(self: *Builder, optional_prefix: ?[]const u8) void {
167169 self.install_prefix = optional_prefix;
168170 }
169171
170 fn resolveInstallPrefix(self: *Builder) void {
172 /// This function is intended to be called by std/special/build_runner.zig, not a build.zig file.
173 pub fn resolveInstallPrefix(self: *Builder) void {
171174 if (self.dest_dir) |dest_dir| {
172175 const install_prefix = self.install_prefix orelse "/usr";
173176 self.install_path = fs.path.join(self.allocator, [_][]const u8{ dest_dir, install_prefix }) catch unreachable;
......@@ -437,7 +440,7 @@ pub const Builder = struct {
437440 .description = description,
438441 };
439442 if ((self.available_options_map.put(name, available_option) catch unreachable) != null) {
440 debug.panic("Option '{}' declared twice", name);
443 panic("Option '{}' declared twice", name);
441444 }
442445 self.available_options_list.append(available_option) catch unreachable;
443446
......@@ -463,8 +466,8 @@ pub const Builder = struct {
463466 return null;
464467 },
465468 },
466 TypeId.Int => debug.panic("TODO integer options to build script"),
467 TypeId.Float => debug.panic("TODO float options to build script"),
469 TypeId.Int => panic("TODO integer options to build script"),
470 TypeId.Float => panic("TODO float options to build script"),
468471 TypeId.String => switch (entry.value.value) {
469472 UserValue.Flag => {
470473 warn("Expected -D{} to be a string, but received a boolean.\n", name);
......@@ -478,7 +481,7 @@ pub const Builder = struct {
478481 },
479482 UserValue.Scalar => |s| return s,
480483 },
481 TypeId.List => debug.panic("TODO list options to build script"),
484 TypeId.List => panic("TODO list options to build script"),
482485 }
483486 }
484487
......@@ -644,8 +647,6 @@ pub const Builder = struct {
644647 }
645648
646649 pub fn validateUserInputDidItFail(self: *Builder) bool {
647 self.resolveInstallPrefix();
648
649650 // make sure all args are used
650651 var it = self.user_input_options.iterator();
651652 while (true) {
......@@ -855,7 +856,7 @@ pub const Builder = struct {
855856 var stdout_file_in_stream = child.stdout.?.inStream();
856857 try stdout_file_in_stream.stream.readAllBuffer(&stdout, max_output_size);
857858
858 const term = child.wait() catch |err| std.debug.panic("unable to spawn {}: {}", argv[0], err);
859 const term = child.wait() catch |err| panic("unable to spawn {}: {}", argv[0], err);
859860 switch (term) {
860861 .Exited => |code| {
861862 if (code != 0) {
......@@ -882,8 +883,8 @@ pub const Builder = struct {
882883 fn getInstallPath(self: *Builder, dir: InstallDir, dest_rel_path: []const u8) []const u8 {
883884 const base_dir = switch (dir) {
884885 .Prefix => self.install_path,
885 .Bin => self.exe_dir.?,
886 .Lib => self.lib_dir.?,
886 .Bin => self.exe_dir,
887 .Lib => self.lib_dir,
887888 };
888889 return fs.path.resolve(
889890 self.allocator,
......@@ -1318,6 +1319,9 @@ pub const LibExeObjStep = struct {
13181319 }
13191320
13201321 fn initExtraArgs(builder: *Builder, name: []const u8, root_src: ?[]const u8, kind: Kind, is_dynamic: bool, ver: Version) LibExeObjStep {
1322 if (mem.indexOf(u8, name, "/") != null or mem.indexOf(u8, name, "\\") != null) {
1323 panic("invalid name: '{}'. It looks like a file path, but it is supposed to be the library or application name.", name);
1324 }
13211325 var self = LibExeObjStep{
13221326 .strip = false,
13231327 .builder = builder,
std/c.zig+1
......@@ -68,6 +68,7 @@ pub extern "c" fn open(path: [*]const u8, oflag: c_uint, ...) c_int;
6868pub extern "c" fn openat(fd: c_int, path: [*]const u8, oflag: c_uint, ...) c_int;
6969pub extern "c" fn raise(sig: c_int) c_int;
7070pub extern "c" fn read(fd: fd_t, buf: [*]u8, nbyte: usize) isize;
71pub extern "c" fn readv(fd: c_int, iov: [*]const iovec, iovcnt: c_uint) isize;
7172pub extern "c" fn pread(fd: fd_t, buf: [*]u8, nbyte: usize, offset: u64) isize;
7273pub extern "c" fn preadv(fd: c_int, iov: [*]const iovec, iovcnt: c_uint, offset: usize) isize;
7374pub extern "c" fn writev(fd: c_int, iov: [*]const iovec_const, iovcnt: c_uint) isize;
std/debug.zig+32-14
......@@ -330,14 +330,16 @@ pub fn writeCurrentStackTraceWindows(
330330 }
331331}
332332
333/// TODO once https://github.com/ziglang/zig/issues/3157 is fully implemented,
334/// make this `noasync fn` and remove the individual noasync calls.
333335pub fn printSourceAtAddress(debug_info: *DebugInfo, out_stream: var, address: usize, tty_color: bool) !void {
334336 if (windows.is_the_target) {
335 return printSourceAtAddressWindows(debug_info, out_stream, address, tty_color);
337 return noasync printSourceAtAddressWindows(debug_info, out_stream, address, tty_color);
336338 }
337339 if (os.darwin.is_the_target) {
338 return printSourceAtAddressMacOs(debug_info, out_stream, address, tty_color);
340 return noasync printSourceAtAddressMacOs(debug_info, out_stream, address, tty_color);
339341 }
340 return printSourceAtAddressPosix(debug_info, out_stream, address, tty_color);
342 return noasync printSourceAtAddressPosix(debug_info, out_stream, address, tty_color);
341343}
342344
343345fn printSourceAtAddressWindows(di: *DebugInfo, out_stream: var, relocated_address: usize, tty_color: bool) !void {
......@@ -793,7 +795,7 @@ fn printLineInfo(
793795 try out_stream.write(GREEN ++ "^" ++ RESET ++ "\n");
794796 }
795797 } else |err| switch (err) {
796 error.EndOfFile => {},
798 error.EndOfFile, error.FileNotFound => {},
797799 else => return err,
798800 }
799801 } else {
......@@ -816,16 +818,18 @@ pub const OpenSelfDebugInfoError = error{
816818 UnsupportedOperatingSystem,
817819};
818820
821/// TODO once https://github.com/ziglang/zig/issues/3157 is fully implemented,
822/// make this `noasync fn` and remove the individual noasync calls.
819823pub fn openSelfDebugInfo(allocator: *mem.Allocator) !DebugInfo {
820824 if (builtin.strip_debug_info)
821825 return error.MissingDebugInfo;
822826 if (windows.is_the_target) {
823 return openSelfDebugInfoWindows(allocator);
827 return noasync openSelfDebugInfoWindows(allocator);
824828 }
825829 if (os.darwin.is_the_target) {
826 return openSelfDebugInfoMacOs(allocator);
830 return noasync openSelfDebugInfoMacOs(allocator);
827831 }
828 return openSelfDebugInfoPosix(allocator);
832 return noasync openSelfDebugInfoPosix(allocator);
829833}
830834
831835fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo {
......@@ -1053,7 +1057,8 @@ fn openSelfDebugInfoPosix(allocator: *mem.Allocator) !DwarfInfo {
10531057 S.self_exe_file = try fs.openSelfExe();
10541058 errdefer S.self_exe_file.close();
10551059
1056 const self_exe_mmap_len = mem.alignForward(try S.self_exe_file.getEndPos(), mem.page_size);
1060 const self_exe_len = math.cast(usize, try S.self_exe_file.getEndPos()) catch return error.DebugInfoTooLarge;
1061 const self_exe_mmap_len = mem.alignForward(self_exe_len, mem.page_size);
10571062 const self_exe_mmap = try os.mmap(
10581063 null,
10591064 self_exe_mmap_len,
......@@ -1507,15 +1512,25 @@ fn parseFormValueBlock(allocator: *mem.Allocator, in_stream: var, size: usize) !
15071512}
15081513
15091514fn parseFormValueConstant(allocator: *mem.Allocator, in_stream: var, signed: bool, comptime size: i32) !FormValue {
1515 // TODO: Please forgive me, I've worked around zig not properly spilling some intermediate values here.
1516 // `noasync` should be removed from all the function calls once it is fixed.
15101517 return FormValue{
15111518 .Const = Constant{
15121519 .signed = signed,
15131520 .payload = switch (size) {
1514 1 => try in_stream.readIntLittle(u8),
1515 2 => try in_stream.readIntLittle(u16),
1516 4 => try in_stream.readIntLittle(u32),
1517 8 => try in_stream.readIntLittle(u64),
1518 -1 => if (signed) @bitCast(u64, try leb.readILEB128(i64, in_stream)) else try leb.readULEB128(u64, in_stream),
1521 1 => try noasync in_stream.readIntLittle(u8),
1522 2 => try noasync in_stream.readIntLittle(u16),
1523 4 => try noasync in_stream.readIntLittle(u32),
1524 8 => try noasync in_stream.readIntLittle(u64),
1525 -1 => blk: {
1526 if (signed) {
1527 const x = try noasync leb.readILEB128(i64, in_stream);
1528 break :blk @bitCast(u64, x);
1529 } else {
1530 const x = try noasync leb.readULEB128(u64, in_stream);
1531 break :blk x;
1532 }
1533 },
15191534 else => @compileError("Invalid size"),
15201535 },
15211536 },
......@@ -1583,7 +1598,10 @@ fn parseFormValue(allocator: *mem.Allocator, in_stream: var, form_id: u64, is_64
15831598 DW.FORM_strp => FormValue{ .StrPtr = try parseFormValueDwarfOffsetSize(in_stream, is_64) },
15841599 DW.FORM_indirect => {
15851600 const child_form_id = try leb.readULEB128(u64, in_stream);
1586 return parseFormValue(allocator, in_stream, child_form_id, is_64);
1601 const F = @typeOf(async parseFormValue(allocator, in_stream, child_form_id, is_64));
1602 var frame = try allocator.create(F);
1603 defer allocator.destroy(frame);
1604 return await @asyncCall(frame, {}, parseFormValue, allocator, in_stream, child_form_id, is_64);
15871605 },
15881606 else => error.InvalidDebugInfo,
15891607 };
std/event.zig-2
......@@ -6,7 +6,6 @@ pub const Locked = @import("event/locked.zig").Locked;
66pub const RwLock = @import("event/rwlock.zig").RwLock;
77pub const RwLocked = @import("event/rwlocked.zig").RwLocked;
88pub const Loop = @import("event/loop.zig").Loop;
9pub const io = @import("event/io.zig");
109pub const fs = @import("event/fs.zig");
1110pub const net = @import("event/net.zig");
1211
......@@ -15,7 +14,6 @@ test "import event tests" {
1514 _ = @import("event/fs.zig");
1615 _ = @import("event/future.zig");
1716 _ = @import("event/group.zig");
18 _ = @import("event/io.zig");
1917 _ = @import("event/lock.zig");
2018 _ = @import("event/locked.zig");
2119 _ = @import("event/rwlock.zig");
std/event/future.zig+1-5
......@@ -104,11 +104,7 @@ fn testFuture(loop: *Loop) void {
104104 var b = async waitOnFuture(&future);
105105 resolveFuture(&future);
106106
107 // TODO https://github.com/ziglang/zig/issues/3077
108 //const result = (await a) + (await b);
109 const a_result = await a;
110 const b_result = await b;
111 const result = a_result + b_result;
107 const result = (await a) + (await b);
112108
113109 testing.expect(result == 12);
114110}
std/event/io.zig deleted-76
......@@ -1,76 +0,0 @@
1const std = @import("../std.zig");
2const builtin = @import("builtin");
3const assert = std.debug.assert;
4const mem = std.mem;
5
6pub fn InStream(comptime ReadError: type) type {
7 return struct {
8 const Self = @This();
9 pub const Error = ReadError;
10
11 /// Return the number of bytes read. It may be less than buffer.len.
12 /// If the number of bytes read is 0, it means end of stream.
13 /// End of stream is not an error condition.
14 readFn: async fn (self: *Self, buffer: []u8) Error!usize,
15
16 /// Return the number of bytes read. It may be less than buffer.len.
17 /// If the number of bytes read is 0, it means end of stream.
18 /// End of stream is not an error condition.
19 pub async fn read(self: *Self, buffer: []u8) !usize {
20 return self.readFn(self, buffer);
21 }
22
23 /// Return the number of bytes read. If it is less than buffer.len
24 /// it means end of stream.
25 pub async fn readFull(self: *Self, buffer: []u8) !usize {
26 var index: usize = 0;
27 while (index != buf.len) {
28 const amt_read = try self.read(buf[index..]);
29 if (amt_read == 0) return index;
30 index += amt_read;
31 }
32 return index;
33 }
34
35 /// Same as `readFull` but end of stream returns `error.EndOfStream`.
36 pub async fn readNoEof(self: *Self, buf: []u8) !void {
37 const amt_read = try self.readFull(buf[index..]);
38 if (amt_read < buf.len) return error.EndOfStream;
39 }
40
41 pub async fn readIntLittle(self: *Self, comptime T: type) !T {
42 var bytes: [@sizeOf(T)]u8 = undefined;
43 try self.readNoEof(bytes[0..]);
44 return mem.readIntLittle(T, &bytes);
45 }
46
47 pub async fn readIntBe(self: *Self, comptime T: type) !T {
48 var bytes: [@sizeOf(T)]u8 = undefined;
49 try self.readNoEof(bytes[0..]);
50 return mem.readIntBig(T, &bytes);
51 }
52
53 pub async fn readInt(self: *Self, comptime T: type, endian: builtin.Endian) !T {
54 var bytes: [@sizeOf(T)]u8 = undefined;
55 try self.readNoEof(bytes[0..]);
56 return mem.readInt(T, &bytes, endian);
57 }
58
59 pub async fn readStruct(self: *Self, comptime T: type) !T {
60 // Only extern and packed structs have defined in-memory layout.
61 comptime assert(@typeInfo(T).Struct.layout != builtin.TypeInfo.ContainerLayout.Auto);
62 var res: [1]T = undefined;
63 try self.readNoEof(@sliceToBytes(res[0..]));
64 return res[0];
65 }
66 };
67}
68
69pub fn OutStream(comptime WriteError: type) type {
70 return struct {
71 const Self = @This();
72 pub const Error = WriteError;
73
74 writeFn: async fn (self: *Self, buffer: []u8) Error!void,
75 };
76}
std/event/loop.zig+5-9
......@@ -86,18 +86,10 @@ pub const Loop = struct {
8686 };
8787 };
8888
89 pub const IoMode = enum {
90 blocking,
91 evented,
92 mixed,
93 };
94 pub const io_mode: IoMode = if (@hasDecl(root, "io_mode")) root.io_mode else IoMode.blocking;
9589 var global_instance_state: Loop = undefined;
96 threadlocal var per_thread_instance: ?*Loop = null;
97 const default_instance: ?*Loop = switch (io_mode) {
90 const default_instance: ?*Loop = switch (std.io.mode) {
9891 .blocking => null,
9992 .evented => &global_instance_state,
100 .mixed => per_thread_instance,
10193 };
10294 pub const instance: ?*Loop = if (@hasDecl(root, "event_loop")) root.event_loop else default_instance;
10395
......@@ -470,6 +462,10 @@ pub const Loop = struct {
470462 }
471463 }
472464
465 pub fn waitUntilFdReadable(self: *Loop, fd: os.fd_t) !void {
466 return self.linuxWaitFd(fd, os.EPOLLET | os.EPOLLIN);
467 }
468
473469 pub async fn bsdWaitKev(self: *Loop, ident: usize, filter: i16, fflags: u32) !os.Kevent {
474470 var resume_node = ResumeNode.Basic{
475471 .base = ResumeNode{
std/fmt/parse_float.zig+11-3
......@@ -110,9 +110,7 @@ fn convertRepr(comptime T: type, n: FloatRepr) T {
110110 q.shiftLeft1(s); // q = p << 1
111111 r.shiftLeft1(q); // r = p << 2
112112 s.shiftLeft1(r); // p = p << 3
113 q.add(s); // p = (p << 3) + (p << 1)
114
115 exp -= 1;
113 s.add(q); // p = (p << 3) + (p << 1)
116114
117115 while (s.d2 & mask28 != 0) {
118116 q.shiftRight1(s);
......@@ -402,6 +400,13 @@ test "fmt.parseFloat" {
402400 expectEqual((try parseFloat(T, "+0")), 0.0);
403401 expectEqual((try parseFloat(T, "-0")), 0.0);
404402
403 expectEqual((try parseFloat(T, "0e0")), 0);
404 expectEqual((try parseFloat(T, "2e3")), 2000.0);
405 expectEqual((try parseFloat(T, "1e0")), 1.0);
406 expectEqual((try parseFloat(T, "-2e3")), -2000.0);
407 expectEqual((try parseFloat(T, "-1e0")), -1.0);
408 expectEqual((try parseFloat(T, "1.234e3")), 1234);
409
405410 expect(approxEq(T, try parseFloat(T, "3.141"), 3.141, epsilon));
406411 expect(approxEq(T, try parseFloat(T, "-3.141"), -3.141, epsilon));
407412
......@@ -413,6 +418,9 @@ test "fmt.parseFloat" {
413418 expectEqual((try parseFloat(T, "-INF")), -std.math.inf(T));
414419
415420 if (T != f16) {
421 expect(approxEq(T, try parseFloat(T, "1e-2"), 0.01, epsilon));
422 expect(approxEq(T, try parseFloat(T, "1234e-2"), 12.34, epsilon));
423
416424 expect(approxEq(T, try parseFloat(T, "123142.1"), 123142.1, epsilon));
417425 expect(approxEq(T, try parseFloat(T, "-123142.1124"), T(-123142.1124), epsilon));
418426 expect(approxEq(T, try parseFloat(T, "0.7062146892655368"), T(0.7062146892655368), epsilon));
std/fs/file.zig+3-3
......@@ -261,9 +261,9 @@ pub const File = struct {
261261 return Stat{
262262 .size = @bitCast(u64, st.size),
263263 .mode = st.mode,
264 .atime = atime.tv_sec * std.time.ns_per_s + atime.tv_nsec,
265 .mtime = mtime.tv_sec * std.time.ns_per_s + mtime.tv_nsec,
266 .ctime = ctime.tv_sec * std.time.ns_per_s + ctime.tv_nsec,
264 .atime = i64(atime.tv_sec) * std.time.ns_per_s + atime.tv_nsec,
265 .mtime = i64(mtime.tv_sec) * std.time.ns_per_s + mtime.tv_nsec,
266 .ctime = i64(ctime.tv_sec) * std.time.ns_per_s + ctime.tv_nsec,
267267 };
268268 }
269269
std/hash/cityhash.zig+4-4
......@@ -214,7 +214,7 @@ pub const CityHash64 = struct {
214214 }
215215
216216 fn hashLen0To16(str: []const u8) u64 {
217 const len: u64 = @truncate(u64, str.len);
217 const len: u64 = u64(str.len);
218218 if (len >= 8) {
219219 const mul: u64 = k2 +% len *% 2;
220220 const a: u64 = fetch64(str.ptr) +% k2;
......@@ -240,7 +240,7 @@ pub const CityHash64 = struct {
240240 }
241241
242242 fn hashLen17To32(str: []const u8) u64 {
243 const len: u64 = @truncate(u64, str.len);
243 const len: u64 = u64(str.len);
244244 const mul: u64 = k2 +% len *% 2;
245245 const a: u64 = fetch64(str.ptr) *% k1;
246246 const b: u64 = fetch64(str.ptr + 8);
......@@ -251,7 +251,7 @@ pub const CityHash64 = struct {
251251 }
252252
253253 fn hashLen33To64(str: []const u8) u64 {
254 const len: u64 = @truncate(u64, str.len);
254 const len: u64 = u64(str.len);
255255 const mul: u64 = k2 +% len *% 2;
256256 const a: u64 = fetch64(str.ptr) *% k2;
257257 const b: u64 = fetch64(str.ptr + 8);
......@@ -305,7 +305,7 @@ pub const CityHash64 = struct {
305305 return hashLen33To64(str);
306306 }
307307
308 var len: u64 = @truncate(u64, str.len);
308 var len: u64 = u64(str.len);
309309
310310 var x: u64 = fetch64(str.ptr + str.len - 40);
311311 var y: u64 = fetch64(str.ptr + str.len - 16) +% fetch64(str.ptr + str.len - 56);
std/hash/murmur.zig+3-3
......@@ -98,9 +98,9 @@ pub const Murmur2_64 = struct {
9898
9999 pub fn hashWithSeed(str: []const u8, seed: u64) u64 {
100100 const m: u64 = 0xc6a4a7935bd1e995;
101 const len = @truncate(u64, str.len);
101 const len = u64(str.len);
102102 var h1: u64 = seed ^ (len *% m);
103 for (@ptrCast([*]allowzero align(1) const u64, str.ptr)[0..(len >> 3)]) |v| {
103 for (@ptrCast([*]allowzero align(1) const u64, str.ptr)[0..@intCast(usize, len >> 3)]) |v| {
104104 var k1: u64 = v;
105105 if (builtin.endian == builtin.Endian.Big)
106106 k1 = @byteSwap(u64, k1);
......@@ -114,7 +114,7 @@ pub const Murmur2_64 = struct {
114114 const offset = len - rest;
115115 if (rest > 0) {
116116 var k1: u64 = 0;
117 @memcpy(@ptrCast([*]u8, &k1), @ptrCast([*]const u8, &str[offset]), rest);
117 @memcpy(@ptrCast([*]u8, &k1), @ptrCast([*]const u8, &str[@intCast(usize, offset)]), @intCast(usize, rest));
118118 if (builtin.endian == builtin.Endian.Big)
119119 k1 = @byteSwap(u64, k1);
120120 h1 ^= k1;
std/hash_map.zig+1-3
......@@ -23,9 +23,7 @@ pub fn StringHashMap(comptime V: type) type {
2323}
2424
2525pub fn eqlString(a: []const u8, b: []const u8) bool {
26 if (a.len != b.len) return false;
27 if (a.ptr == b.ptr) return true;
28 return mem.compare(u8, a, b) == .Equal;
26 return mem.eql(u8, a, b);
2927}
3028
3129pub fn hashString(s: []const u8) u32 {
std/io.zig+14-174
......@@ -1,5 +1,6 @@
11const std = @import("std.zig");
22const builtin = @import("builtin");
3const root = @import("root");
34const c = std.c;
45
56const math = std.math;
......@@ -15,6 +16,18 @@ const fmt = std.fmt;
1516const File = std.fs.File;
1617const testing = std.testing;
1718
19pub const Mode = enum {
20 blocking,
21 evented,
22};
23pub const mode: Mode = if (@hasDecl(root, "io_mode"))
24 root.io_mode
25else if (@hasDecl(root, "event_loop"))
26 Mode.evented
27else
28 Mode.blocking;
29pub const is_async = mode != .blocking;
30
1831pub const GetStdIoError = os.windows.GetStdHandleError;
1932
2033pub fn getStdOut() GetStdIoError!File {
......@@ -44,180 +57,7 @@ pub fn getStdIn() GetStdIoError!File {
4457pub const SeekableStream = @import("io/seekable_stream.zig").SeekableStream;
4558pub const SliceSeekableInStream = @import("io/seekable_stream.zig").SliceSeekableInStream;
4659pub const COutStream = @import("io/c_out_stream.zig").COutStream;
47
48pub fn InStream(comptime ReadError: type) type {
49 return struct {
50 const Self = @This();
51 pub const Error = ReadError;
52
53 /// Return the number of bytes read. If the number read is smaller than buf.len, it
54 /// means the stream reached the end. Reaching the end of a stream is not an error
55 /// condition.
56 readFn: fn (self: *Self, buffer: []u8) Error!usize,
57
58 /// Replaces `buffer` contents by reading from the stream until it is finished.
59 /// If `buffer.len()` would exceed `max_size`, `error.StreamTooLong` is returned and
60 /// the contents read from the stream are lost.
61 pub fn readAllBuffer(self: *Self, buffer: *Buffer, max_size: usize) !void {
62 try buffer.resize(0);
63
64 var actual_buf_len: usize = 0;
65 while (true) {
66 const dest_slice = buffer.toSlice()[actual_buf_len..];
67 const bytes_read = try self.readFull(dest_slice);
68 actual_buf_len += bytes_read;
69
70 if (bytes_read != dest_slice.len) {
71 buffer.shrink(actual_buf_len);
72 return;
73 }
74
75 const new_buf_size = math.min(max_size, actual_buf_len + mem.page_size);
76 if (new_buf_size == actual_buf_len) return error.StreamTooLong;
77 try buffer.resize(new_buf_size);
78 }
79 }
80
81 /// Allocates enough memory to hold all the contents of the stream. If the allocated
82 /// memory would be greater than `max_size`, returns `error.StreamTooLong`.
83 /// Caller owns returned memory.
84 /// If this function returns an error, the contents from the stream read so far are lost.
85 pub fn readAllAlloc(self: *Self, allocator: *mem.Allocator, max_size: usize) ![]u8 {
86 var buf = Buffer.initNull(allocator);
87 defer buf.deinit();
88
89 try self.readAllBuffer(&buf, max_size);
90 return buf.toOwnedSlice();
91 }
92
93 /// Replaces `buffer` contents by reading from the stream until `delimiter` is found.
94 /// Does not include the delimiter in the result.
95 /// If `buffer.len()` would exceed `max_size`, `error.StreamTooLong` is returned and the contents
96 /// read from the stream so far are lost.
97 pub fn readUntilDelimiterBuffer(self: *Self, buffer: *Buffer, delimiter: u8, max_size: usize) !void {
98 try buffer.resize(0);
99
100 while (true) {
101 var byte: u8 = try self.readByte();
102
103 if (byte == delimiter) {
104 return;
105 }
106
107 if (buffer.len() == max_size) {
108 return error.StreamTooLong;
109 }
110
111 try buffer.appendByte(byte);
112 }
113 }
114
115 /// Allocates enough memory to read until `delimiter`. If the allocated
116 /// memory would be greater than `max_size`, returns `error.StreamTooLong`.
117 /// Caller owns returned memory.
118 /// If this function returns an error, the contents from the stream read so far are lost.
119 pub fn readUntilDelimiterAlloc(self: *Self, allocator: *mem.Allocator, delimiter: u8, max_size: usize) ![]u8 {
120 var buf = Buffer.initNull(allocator);
121 defer buf.deinit();
122
123 try self.readUntilDelimiterBuffer(&buf, delimiter, max_size);
124 return buf.toOwnedSlice();
125 }
126
127 /// Returns the number of bytes read. It may be less than buffer.len.
128 /// If the number of bytes read is 0, it means end of stream.
129 /// End of stream is not an error condition.
130 pub fn read(self: *Self, buffer: []u8) Error!usize {
131 return self.readFn(self, buffer);
132 }
133
134 /// Returns the number of bytes read. If the number read is smaller than buf.len, it
135 /// means the stream reached the end. Reaching the end of a stream is not an error
136 /// condition.
137 pub fn readFull(self: *Self, buffer: []u8) Error!usize {
138 var index: usize = 0;
139 while (index != buffer.len) {
140 const amt = try self.read(buffer[index..]);
141 if (amt == 0) return index;
142 index += amt;
143 }
144 return index;
145 }
146
147 /// Same as `readFull` but end of stream returns `error.EndOfStream`.
148 pub fn readNoEof(self: *Self, buf: []u8) !void {
149 const amt_read = try self.readFull(buf);
150 if (amt_read < buf.len) return error.EndOfStream;
151 }
152
153 /// Reads 1 byte from the stream or returns `error.EndOfStream`.
154 pub fn readByte(self: *Self) !u8 {
155 var result: [1]u8 = undefined;
156 try self.readNoEof(result[0..]);
157 return result[0];
158 }
159
160 /// Same as `readByte` except the returned byte is signed.
161 pub fn readByteSigned(self: *Self) !i8 {
162 return @bitCast(i8, try self.readByte());
163 }
164
165 /// Reads a native-endian integer
166 pub fn readIntNative(self: *Self, comptime T: type) !T {
167 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
168 try self.readNoEof(bytes[0..]);
169 return mem.readIntNative(T, &bytes);
170 }
171
172 /// Reads a foreign-endian integer
173 pub fn readIntForeign(self: *Self, comptime T: type) !T {
174 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
175 try self.readNoEof(bytes[0..]);
176 return mem.readIntForeign(T, &bytes);
177 }
178
179 pub fn readIntLittle(self: *Self, comptime T: type) !T {
180 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
181 try self.readNoEof(bytes[0..]);
182 return mem.readIntLittle(T, &bytes);
183 }
184
185 pub fn readIntBig(self: *Self, comptime T: type) !T {
186 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
187 try self.readNoEof(bytes[0..]);
188 return mem.readIntBig(T, &bytes);
189 }
190
191 pub fn readInt(self: *Self, comptime T: type, endian: builtin.Endian) !T {
192 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
193 try self.readNoEof(bytes[0..]);
194 return mem.readInt(T, &bytes, endian);
195 }
196
197 pub fn readVarInt(self: *Self, comptime ReturnType: type, endian: builtin.Endian, size: usize) !ReturnType {
198 assert(size <= @sizeOf(ReturnType));
199 var bytes_buf: [@sizeOf(ReturnType)]u8 = undefined;
200 const bytes = bytes_buf[0..size];
201 try self.readNoEof(bytes);
202 return mem.readVarInt(ReturnType, bytes, endian);
203 }
204
205 pub fn skipBytes(self: *Self, num_bytes: u64) !void {
206 var i: u64 = 0;
207 while (i < num_bytes) : (i += 1) {
208 _ = try self.readByte();
209 }
210 }
211
212 pub fn readStruct(self: *Self, comptime T: type) !T {
213 // Only extern and packed structs have defined in-memory layout.
214 comptime assert(@typeInfo(T).Struct.layout != builtin.TypeInfo.ContainerLayout.Auto);
215 var res: [1]T = undefined;
216 try self.readNoEof(@sliceToBytes(res[0..]));
217 return res[0];
218 }
219 };
220}
60pub const InStream = @import("io/in_stream.zig").InStream;
22161
22262pub fn OutStream(comptime WriteError: type) type {
22363 return struct {
std/io/in_stream.zig created+200
......@@ -0,0 +1,200 @@
1const std = @import("../std.zig");
2const builtin = @import("builtin");
3const root = @import("root");
4const math = std.math;
5const assert = std.debug.assert;
6const mem = std.mem;
7const Buffer = std.Buffer;
8
9pub const default_stack_size = 4 * 1024 * 1024;
10pub const stack_size: usize = if (@hasDecl(root, "stack_size_std_io_InStream"))
11 root.stack_size_std_io_InStream
12else
13 default_stack_size;
14pub const stack_align = 16;
15
16pub fn InStream(comptime ReadError: type) type {
17 return struct {
18 const Self = @This();
19 pub const Error = ReadError;
20 pub const ReadFn = if (std.io.is_async)
21 async fn (self: *Self, buffer: []u8) Error!usize
22 else
23 fn (self: *Self, buffer: []u8) Error!usize;
24
25 /// Returns the number of bytes read. It may be less than buffer.len.
26 /// If the number of bytes read is 0, it means end of stream.
27 /// End of stream is not an error condition.
28 readFn: ReadFn,
29
30 /// Returns the number of bytes read. It may be less than buffer.len.
31 /// If the number of bytes read is 0, it means end of stream.
32 /// End of stream is not an error condition.
33 pub fn read(self: *Self, buffer: []u8) Error!usize {
34 if (std.io.is_async) {
35 var stack_frame: [stack_size]u8 align(stack_align) = undefined;
36 // TODO https://github.com/ziglang/zig/issues/3068
37 var result: Error!usize = undefined;
38 return await @asyncCall(&stack_frame, &result, self.readFn, self, buffer);
39 } else {
40 return self.readFn(self, buffer);
41 }
42 }
43
44 /// Returns the number of bytes read. If the number read is smaller than buf.len, it
45 /// means the stream reached the end. Reaching the end of a stream is not an error
46 /// condition.
47 pub fn readFull(self: *Self, buffer: []u8) Error!usize {
48 var index: usize = 0;
49 while (index != buffer.len) {
50 const amt = try self.read(buffer[index..]);
51 if (amt == 0) return index;
52 index += amt;
53 }
54 return index;
55 }
56
57 /// Returns the number of bytes read. If the number read would be smaller than buf.len,
58 /// error.EndOfStream is returned instead.
59 pub fn readNoEof(self: *Self, buf: []u8) !void {
60 const amt_read = try self.readFull(buf);
61 if (amt_read < buf.len) return error.EndOfStream;
62 }
63
64 /// Replaces `buffer` contents by reading from the stream until it is finished.
65 /// If `buffer.len()` would exceed `max_size`, `error.StreamTooLong` is returned and
66 /// the contents read from the stream are lost.
67 pub fn readAllBuffer(self: *Self, buffer: *Buffer, max_size: usize) !void {
68 try buffer.resize(0);
69
70 var actual_buf_len: usize = 0;
71 while (true) {
72 const dest_slice = buffer.toSlice()[actual_buf_len..];
73 const bytes_read = try self.readFull(dest_slice);
74 actual_buf_len += bytes_read;
75
76 if (bytes_read != dest_slice.len) {
77 buffer.shrink(actual_buf_len);
78 return;
79 }
80
81 const new_buf_size = math.min(max_size, actual_buf_len + mem.page_size);
82 if (new_buf_size == actual_buf_len) return error.StreamTooLong;
83 try buffer.resize(new_buf_size);
84 }
85 }
86
87 /// Allocates enough memory to hold all the contents of the stream. If the allocated
88 /// memory would be greater than `max_size`, returns `error.StreamTooLong`.
89 /// Caller owns returned memory.
90 /// If this function returns an error, the contents from the stream read so far are lost.
91 pub fn readAllAlloc(self: *Self, allocator: *mem.Allocator, max_size: usize) ![]u8 {
92 var buf = Buffer.initNull(allocator);
93 defer buf.deinit();
94
95 try self.readAllBuffer(&buf, max_size);
96 return buf.toOwnedSlice();
97 }
98
99 /// Replaces `buffer` contents by reading from the stream until `delimiter` is found.
100 /// Does not include the delimiter in the result.
101 /// If `buffer.len()` would exceed `max_size`, `error.StreamTooLong` is returned and the contents
102 /// read from the stream so far are lost.
103 pub fn readUntilDelimiterBuffer(self: *Self, buffer: *Buffer, delimiter: u8, max_size: usize) !void {
104 try buffer.resize(0);
105
106 while (true) {
107 var byte: u8 = try self.readByte();
108
109 if (byte == delimiter) {
110 return;
111 }
112
113 if (buffer.len() == max_size) {
114 return error.StreamTooLong;
115 }
116
117 try buffer.appendByte(byte);
118 }
119 }
120
121 /// Allocates enough memory to read until `delimiter`. If the allocated
122 /// memory would be greater than `max_size`, returns `error.StreamTooLong`.
123 /// Caller owns returned memory.
124 /// If this function returns an error, the contents from the stream read so far are lost.
125 pub fn readUntilDelimiterAlloc(self: *Self, allocator: *mem.Allocator, delimiter: u8, max_size: usize) ![]u8 {
126 var buf = Buffer.initNull(allocator);
127 defer buf.deinit();
128
129 try self.readUntilDelimiterBuffer(&buf, delimiter, max_size);
130 return buf.toOwnedSlice();
131 }
132
133 /// Reads 1 byte from the stream or returns `error.EndOfStream`.
134 pub fn readByte(self: *Self) !u8 {
135 var result: [1]u8 = undefined;
136 try self.readNoEof(result[0..]);
137 return result[0];
138 }
139
140 /// Same as `readByte` except the returned byte is signed.
141 pub fn readByteSigned(self: *Self) !i8 {
142 return @bitCast(i8, try self.readByte());
143 }
144
145 /// Reads a native-endian integer
146 pub fn readIntNative(self: *Self, comptime T: type) !T {
147 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
148 try self.readNoEof(bytes[0..]);
149 return mem.readIntNative(T, &bytes);
150 }
151
152 /// Reads a foreign-endian integer
153 pub fn readIntForeign(self: *Self, comptime T: type) !T {
154 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
155 try self.readNoEof(bytes[0..]);
156 return mem.readIntForeign(T, &bytes);
157 }
158
159 pub fn readIntLittle(self: *Self, comptime T: type) !T {
160 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
161 try self.readNoEof(bytes[0..]);
162 return mem.readIntLittle(T, &bytes);
163 }
164
165 pub fn readIntBig(self: *Self, comptime T: type) !T {
166 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
167 try self.readNoEof(bytes[0..]);
168 return mem.readIntBig(T, &bytes);
169 }
170
171 pub fn readInt(self: *Self, comptime T: type, endian: builtin.Endian) !T {
172 var bytes: [(T.bit_count + 7) / 8]u8 = undefined;
173 try self.readNoEof(bytes[0..]);
174 return mem.readInt(T, &bytes, endian);
175 }
176
177 pub fn readVarInt(self: *Self, comptime ReturnType: type, endian: builtin.Endian, size: usize) !ReturnType {
178 assert(size <= @sizeOf(ReturnType));
179 var bytes_buf: [@sizeOf(ReturnType)]u8 = undefined;
180 const bytes = bytes_buf[0..size];
181 try self.readNoEof(bytes);
182 return mem.readVarInt(ReturnType, bytes, endian);
183 }
184
185 pub fn skipBytes(self: *Self, num_bytes: u64) !void {
186 var i: u64 = 0;
187 while (i < num_bytes) : (i += 1) {
188 _ = try self.readByte();
189 }
190 }
191
192 pub fn readStruct(self: *Self, comptime T: type) !T {
193 // Only extern and packed structs have defined in-memory layout.
194 comptime assert(@typeInfo(T).Struct.layout != builtin.TypeInfo.ContainerLayout.Auto);
195 var res: [1]T = undefined;
196 try self.readNoEof(@sliceToBytes(res[0..]));
197 return res[0];
198 }
199 };
200}
std/json.zig+2-2
......@@ -989,7 +989,7 @@ test "json.validate" {
989989const Allocator = std.mem.Allocator;
990990const ArenaAllocator = std.heap.ArenaAllocator;
991991const ArrayList = std.ArrayList;
992const HashMap = std.HashMap;
992const StringHashMap = std.StringHashMap;
993993
994994pub const ValueTree = struct {
995995 arena: ArenaAllocator,
......@@ -1000,7 +1000,7 @@ pub const ValueTree = struct {
10001000 }
10011001};
10021002
1003pub const ObjectMap = HashMap([]const u8, Value, mem.hash_slice_u8, mem.eql_slice_u8);
1003pub const ObjectMap = StringHashMap(Value);
10041004
10051005pub const Value = union(enum) {
10061006 Null,
std/mem.zig+13-25
......@@ -339,6 +339,7 @@ test "mem.lessThan" {
339339/// Compares two slices and returns whether they are equal.
340340pub fn eql(comptime T: type, a: []const T, b: []const T) bool {
341341 if (a.len != b.len) return false;
342 if (a.ptr == b.ptr) return true;
342343 for (a) |item, index| {
343344 if (b[index] != item) return false;
344345 }
......@@ -738,47 +739,34 @@ test "writeIntBig and writeIntLittle" {
738739 var buf9: [9]u8 = undefined;
739740
740741 writeIntBig(u0, &buf0, 0x0);
741 testing.expect(eql_slice_u8(buf0[0..], [_]u8{}));
742 testing.expect(eql(u8, buf0[0..], [_]u8{}));
742743 writeIntLittle(u0, &buf0, 0x0);
743 testing.expect(eql_slice_u8(buf0[0..], [_]u8{}));
744 testing.expect(eql(u8, buf0[0..], [_]u8{}));
744745
745746 writeIntBig(u8, &buf1, 0x12);
746 testing.expect(eql_slice_u8(buf1[0..], [_]u8{0x12}));
747 testing.expect(eql(u8, buf1[0..], [_]u8{0x12}));
747748 writeIntLittle(u8, &buf1, 0x34);
748 testing.expect(eql_slice_u8(buf1[0..], [_]u8{0x34}));
749 testing.expect(eql(u8, buf1[0..], [_]u8{0x34}));
749750
750751 writeIntBig(u16, &buf2, 0x1234);
751 testing.expect(eql_slice_u8(buf2[0..], [_]u8{ 0x12, 0x34 }));
752 testing.expect(eql(u8, buf2[0..], [_]u8{ 0x12, 0x34 }));
752753 writeIntLittle(u16, &buf2, 0x5678);
753 testing.expect(eql_slice_u8(buf2[0..], [_]u8{ 0x78, 0x56 }));
754 testing.expect(eql(u8, buf2[0..], [_]u8{ 0x78, 0x56 }));
754755
755756 writeIntBig(u72, &buf9, 0x123456789abcdef024);
756 testing.expect(eql_slice_u8(buf9[0..], [_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }));
757 testing.expect(eql(u8, buf9[0..], [_]u8{ 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0x24 }));
757758 writeIntLittle(u72, &buf9, 0xfedcba9876543210ec);
758 testing.expect(eql_slice_u8(buf9[0..], [_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }));
759 testing.expect(eql(u8, buf9[0..], [_]u8{ 0xec, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe }));
759760
760761 writeIntBig(i8, &buf1, -1);
761 testing.expect(eql_slice_u8(buf1[0..], [_]u8{0xff}));
762 testing.expect(eql(u8, buf1[0..], [_]u8{0xff}));
762763 writeIntLittle(i8, &buf1, -2);
763 testing.expect(eql_slice_u8(buf1[0..], [_]u8{0xfe}));
764 testing.expect(eql(u8, buf1[0..], [_]u8{0xfe}));
764765
765766 writeIntBig(i16, &buf2, -3);
766 testing.expect(eql_slice_u8(buf2[0..], [_]u8{ 0xff, 0xfd }));
767 testing.expect(eql(u8, buf2[0..], [_]u8{ 0xff, 0xfd }));
767768 writeIntLittle(i16, &buf2, -4);
768 testing.expect(eql_slice_u8(buf2[0..], [_]u8{ 0xfc, 0xff }));
769}
770
771pub fn hash_slice_u8(k: []const u8) u32 {
772 // FNV 32-bit hash
773 var h: u32 = 2166136261;
774 for (k) |b| {
775 h = (h ^ b) *% 16777619;
776 }
777 return h;
778}
779
780pub fn eql_slice_u8(a: []const u8, b: []const u8) bool {
781 return eql(u8, a, b);
769 testing.expect(eql(u8, buf2[0..], [_]u8{ 0xfc, 0xff }));
782770}
783771
784772/// Returns an iterator that iterates over the slices of `buffer` that are not
std/meta.zig+2-1
......@@ -74,9 +74,10 @@ test "std.meta.stringToEnum" {
7474
7575pub fn bitCount(comptime T: type) comptime_int {
7676 return switch (@typeInfo(T)) {
77 TypeId.Bool => 1,
7778 TypeId.Int => |info| info.bits,
7879 TypeId.Float => |info| info.bits,
79 else => @compileError("Expected int or float type, found '" ++ @typeName(T) ++ "'"),
80 else => @compileError("Expected bool, int or float type, found '" ++ @typeName(T) ++ "'"),
8081 };
8182}
8283
std/os.zig+18-24
......@@ -254,13 +254,18 @@ pub const ReadError = error{
254254 IsDir,
255255 OperationAborted,
256256 BrokenPipe,
257
258 /// This error occurs when no global event loop is configured,
259 /// and reading from the file descriptor would block.
260 WouldBlock,
261
257262 Unexpected,
258263};
259264
260265/// Returns the number of bytes that were read, which can be less than
261266/// buf.len. If 0 bytes were read, that means EOF.
262/// This function is for blocking file descriptors only. For non-blocking, see
263/// `readAsync`.
267/// If the application has a global event loop enabled, EAGAIN is handled
268/// via the event loop. Otherwise EAGAIN results in error.WouldBlock.
264269pub fn read(fd: fd_t, buf: []u8) ReadError!usize {
265270 if (windows.is_the_target) {
266271 return windows.ReadFile(fd, buf);
......@@ -279,28 +284,19 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {
279284 }
280285 }
281286
282 // Linux can return EINVAL when read amount is > 0x7ffff000
283 // See https://github.com/ziglang/zig/pull/743#issuecomment-363158274
284 // TODO audit this. Shawn Landden says that this is not actually true.
285 // if this logic should stay, move it to std.os.linux
286 const max_buf_len = 0x7ffff000;
287
288 var index: usize = 0;
289 while (index < buf.len) {
290 const want_to_read = math.min(buf.len - index, usize(max_buf_len));
291 const rc = system.read(fd, buf.ptr + index, want_to_read);
287 while (true) {
288 const rc = system.read(fd, buf.ptr, buf.len);
292289 switch (errno(rc)) {
293 0 => {
294 const amt_read = @intCast(usize, rc);
295 index += amt_read;
296 if (amt_read == want_to_read) continue;
297 // Read returned less than buf.len.
298 return index;
299 },
290 0 => return @intCast(usize, rc),
300291 EINTR => continue,
301292 EINVAL => unreachable,
302293 EFAULT => unreachable,
303 EAGAIN => unreachable, // This function is for blocking reads.
294 EAGAIN => if (std.event.Loop.instance) |loop| {
295 loop.waitUntilFdReadable(fd) catch return error.WouldBlock;
296 continue;
297 } else {
298 return error.WouldBlock;
299 },
304300 EBADF => unreachable, // Always a race condition.
305301 EIO => return error.InputOutput,
306302 EISDIR => return error.IsDir,
......@@ -313,8 +309,7 @@ pub fn read(fd: fd_t, buf: []u8) ReadError!usize {
313309}
314310
315311/// Number of bytes read is returned. Upon reading end-of-file, zero is returned.
316/// This function is for blocking file descriptors only. For non-blocking, see
317/// `preadvAsync`.
312/// This function is for blocking file descriptors only.
318313pub fn preadv(fd: fd_t, iov: []const iovec, offset: u64) ReadError!usize {
319314 if (darwin.is_the_target) {
320315 // Darwin does not have preadv but it does have pread.
......@@ -386,8 +381,7 @@ pub const WriteError = error{
386381};
387382
388383/// Write to a file descriptor. Keeps trying if it gets interrupted.
389/// This function is for blocking file descriptors only. For non-blocking, see
390/// `writeAsync`.
384/// This function is for blocking file descriptors only.
391385pub fn write(fd: fd_t, bytes: []const u8) WriteError!void {
392386 if (windows.is_the_target) {
393387 return windows.WriteFile(fd, bytes);
std/os/bits/linux.zig+1
......@@ -7,6 +7,7 @@ pub usingnamespace @import("linux/errno.zig");
77pub usingnamespace switch (builtin.arch) {
88 .x86_64 => @import("linux/x86_64.zig"),
99 .aarch64 => @import("linux/arm64.zig"),
10 .arm => @import("linux/arm-eabi.zig"),
1011 .riscv64 => @import("linux/riscv64.zig"),
1112 else => struct {},
1213};
std/os/bits/linux/arm-eabi.zig created+573
......@@ -0,0 +1,573 @@
1// arm-eabi-specific declarations that are intended to be imported into the POSIX namespace.
2
3const std = @import("../../std.zig");
4const linux = std.os.linux;
5const socklen_t = linux.socklen_t;
6const iovec = linux.iovec;
7const iovec_const = linux.iovec_const;
8
9pub const SYS_restart_syscall = 0;
10pub const SYS_exit = 1;
11pub const SYS_fork = 2;
12pub const SYS_read = 3;
13pub const SYS_write = 4;
14pub const SYS_open = 5;
15pub const SYS_close = 6;
16pub const SYS_creat = 8;
17pub const SYS_link = 9;
18pub const SYS_unlink = 10;
19pub const SYS_execve = 11;
20pub const SYS_chdir = 12;
21pub const SYS_mknod = 14;
22pub const SYS_chmod = 15;
23pub const SYS_lchown = 16;
24pub const SYS_lseek = 19;
25pub const SYS_getpid = 20;
26pub const SYS_mount = 21;
27pub const SYS_setuid = 23;
28pub const SYS_getuid = 24;
29pub const SYS_ptrace = 26;
30pub const SYS_pause = 29;
31pub const SYS_access = 33;
32pub const SYS_nice = 34;
33pub const SYS_sync = 36;
34pub const SYS_kill = 37;
35pub const SYS_rename = 38;
36pub const SYS_mkdir = 39;
37pub const SYS_rmdir = 40;
38pub const SYS_dup = 41;
39pub const SYS_pipe = 42;
40pub const SYS_times = 43;
41pub const SYS_brk = 45;
42pub const SYS_setgid = 46;
43pub const SYS_getgid = 47;
44pub const SYS_geteuid = 49;
45pub const SYS_getegid = 50;
46pub const SYS_acct = 51;
47pub const SYS_umount2 = 52;
48pub const SYS_ioctl = 54;
49pub const SYS_fcntl = 55;
50pub const SYS_setpgid = 57;
51pub const SYS_umask = 60;
52pub const SYS_chroot = 61;
53pub const SYS_ustat = 62;
54pub const SYS_dup2 = 63;
55pub const SYS_getppid = 64;
56pub const SYS_getpgrp = 65;
57pub const SYS_setsid = 66;
58pub const SYS_sigaction = 67;
59pub const SYS_setreuid = 70;
60pub const SYS_setregid = 71;
61pub const SYS_sigsuspend = 72;
62pub const SYS_sigpending = 73;
63pub const SYS_sethostname = 74;
64pub const SYS_setrlimit = 75;
65pub const SYS_getrusage = 77;
66pub const SYS_gettimeofday = 78;
67pub const SYS_settimeofday = 79;
68pub const SYS_getgroups = 80;
69pub const SYS_setgroups = 81;
70pub const SYS_symlink = 83;
71pub const SYS_readlink = 85;
72pub const SYS_uselib = 86;
73pub const SYS_swapon = 87;
74pub const SYS_reboot = 88;
75pub const SYS_munmap = 91;
76pub const SYS_truncate = 92;
77pub const SYS_ftruncate = 93;
78pub const SYS_fchmod = 94;
79pub const SYS_fchown = 95;
80pub const SYS_getpriority = 96;
81pub const SYS_setpriority = 97;
82pub const SYS_statfs = 99;
83pub const SYS_fstatfs = 100;
84pub const SYS_syslog = 103;
85pub const SYS_setitimer = 104;
86pub const SYS_getitimer = 105;
87pub const SYS_stat = 106;
88pub const SYS_lstat = 107;
89pub const SYS_fstat = 108;
90pub const SYS_vhangup = 111;
91pub const SYS_wait4 = 114;
92pub const SYS_swapoff = 115;
93pub const SYS_sysinfo = 116;
94pub const SYS_fsync = 118;
95pub const SYS_sigreturn = 119;
96pub const SYS_clone = 120;
97pub const SYS_setdomainname = 121;
98pub const SYS_uname = 122;
99pub const SYS_adjtimex = 124;
100pub const SYS_mprotect = 125;
101pub const SYS_sigprocmask = 126;
102pub const SYS_init_module = 128;
103pub const SYS_delete_module = 129;
104pub const SYS_quotactl = 131;
105pub const SYS_getpgid = 132;
106pub const SYS_fchdir = 133;
107pub const SYS_bdflush = 134;
108pub const SYS_sysfs = 135;
109pub const SYS_personality = 136;
110pub const SYS_setfsuid = 138;
111pub const SYS_setfsgid = 139;
112pub const SYS__llseek = 140;
113pub const SYS_getdents = 141;
114pub const SYS__newselect = 142;
115pub const SYS_flock = 143;
116pub const SYS_msync = 144;
117pub const SYS_readv = 145;
118pub const SYS_writev = 146;
119pub const SYS_getsid = 147;
120pub const SYS_fdatasync = 148;
121pub const SYS__sysctl = 149;
122pub const SYS_mlock = 150;
123pub const SYS_munlock = 151;
124pub const SYS_mlockall = 152;
125pub const SYS_munlockall = 153;
126pub const SYS_sched_setparam = 154;
127pub const SYS_sched_getparam = 155;
128pub const SYS_sched_setscheduler = 156;
129pub const SYS_sched_getscheduler = 157;
130pub const SYS_sched_yield = 158;
131pub const SYS_sched_get_priority_max = 159;
132pub const SYS_sched_get_priority_min = 160;
133pub const SYS_sched_rr_get_interval = 161;
134pub const SYS_nanosleep = 162;
135pub const SYS_mremap = 163;
136pub const SYS_setresuid = 164;
137pub const SYS_getresuid = 165;
138pub const SYS_poll = 168;
139pub const SYS_nfsservctl = 169;
140pub const SYS_setresgid = 170;
141pub const SYS_getresgid = 171;
142pub const SYS_prctl = 172;
143pub const SYS_rt_sigreturn = 173;
144pub const SYS_rt_sigaction = 174;
145pub const SYS_rt_sigprocmask = 175;
146pub const SYS_rt_sigpending = 176;
147pub const SYS_rt_sigtimedwait = 177;
148pub const SYS_rt_sigqueueinfo = 178;
149pub const SYS_rt_sigsuspend = 179;
150pub const SYS_pread64 = 180;
151pub const SYS_pwrite64 = 181;
152pub const SYS_chown = 182;
153pub const SYS_getcwd = 183;
154pub const SYS_capget = 184;
155pub const SYS_capset = 185;
156pub const SYS_sigaltstack = 186;
157pub const SYS_sendfile = 187;
158pub const SYS_vfork = 190;
159pub const SYS_ugetrlimit = 191;
160pub const SYS_mmap2 = 192;
161pub const SYS_truncate64 = 193;
162pub const SYS_ftruncate64 = 194;
163pub const SYS_stat64 = 195;
164pub const SYS_lstat64 = 196;
165pub const SYS_fstat64 = 197;
166pub const SYS_lchown32 = 198;
167pub const SYS_getuid32 = 199;
168pub const SYS_getgid32 = 200;
169pub const SYS_geteuid32 = 201;
170pub const SYS_getegid32 = 202;
171pub const SYS_setreuid32 = 203;
172pub const SYS_setregid32 = 204;
173pub const SYS_getgroups32 = 205;
174pub const SYS_setgroups32 = 206;
175pub const SYS_fchown32 = 207;
176pub const SYS_setresuid32 = 208;
177pub const SYS_getresuid32 = 209;
178pub const SYS_setresgid32 = 210;
179pub const SYS_getresgid32 = 211;
180pub const SYS_chown32 = 212;
181pub const SYS_setuid32 = 213;
182pub const SYS_setgid32 = 214;
183pub const SYS_setfsuid32 = 215;
184pub const SYS_setfsgid32 = 216;
185pub const SYS_getdents64 = 217;
186pub const SYS_pivot_root = 218;
187pub const SYS_mincore = 219;
188pub const SYS_madvise = 220;
189pub const SYS_fcntl64 = 221;
190pub const SYS_gettid = 224;
191pub const SYS_readahead = 225;
192pub const SYS_setxattr = 226;
193pub const SYS_lsetxattr = 227;
194pub const SYS_fsetxattr = 228;
195pub const SYS_getxattr = 229;
196pub const SYS_lgetxattr = 230;
197pub const SYS_fgetxattr = 231;
198pub const SYS_listxattr = 232;
199pub const SYS_llistxattr = 233;
200pub const SYS_flistxattr = 234;
201pub const SYS_removexattr = 235;
202pub const SYS_lremovexattr = 236;
203pub const SYS_fremovexattr = 237;
204pub const SYS_tkill = 238;
205pub const SYS_sendfile64 = 239;
206pub const SYS_futex = 240;
207pub const SYS_sched_setaffinity = 241;
208pub const SYS_sched_getaffinity = 242;
209pub const SYS_io_setup = 243;
210pub const SYS_io_destroy = 244;
211pub const SYS_io_getevents = 245;
212pub const SYS_io_submit = 246;
213pub const SYS_io_cancel = 247;
214pub const SYS_exit_group = 248;
215pub const SYS_lookup_dcookie = 249;
216pub const SYS_epoll_create = 250;
217pub const SYS_epoll_ctl = 251;
218pub const SYS_epoll_wait = 252;
219pub const SYS_remap_file_pages = 253;
220pub const SYS_set_tid_address = 256;
221pub const SYS_timer_create = 257;
222pub const SYS_timer_settime = 258;
223pub const SYS_timer_gettime = 259;
224pub const SYS_timer_getoverrun = 260;
225pub const SYS_timer_delete = 261;
226pub const SYS_clock_settime = 262;
227pub const SYS_clock_gettime = 263;
228pub const SYS_clock_getres = 264;
229pub const SYS_clock_nanosleep = 265;
230pub const SYS_statfs64 = 266;
231pub const SYS_fstatfs64 = 267;
232pub const SYS_tgkill = 268;
233pub const SYS_utimes = 269;
234pub const SYS_fadvise64_64 = 270;
235pub const SYS_arm_fadvise64_64 = 270;
236pub const SYS_pciconfig_iobase = 271;
237pub const SYS_pciconfig_read = 272;
238pub const SYS_pciconfig_write = 273;
239pub const SYS_mq_open = 274;
240pub const SYS_mq_unlink = 275;
241pub const SYS_mq_timedsend = 276;
242pub const SYS_mq_timedreceive = 277;
243pub const SYS_mq_notify = 278;
244pub const SYS_mq_getsetattr = 279;
245pub const SYS_waitid = 280;
246pub const SYS_socket = 281;
247pub const SYS_bind = 282;
248pub const SYS_connect = 283;
249pub const SYS_listen = 284;
250pub const SYS_accept = 285;
251pub const SYS_getsockname = 286;
252pub const SYS_getpeername = 287;
253pub const SYS_socketpair = 288;
254pub const SYS_send = 289;
255pub const SYS_sendto = 290;
256pub const SYS_recv = 291;
257pub const SYS_recvfrom = 292;
258pub const SYS_shutdown = 293;
259pub const SYS_setsockopt = 294;
260pub const SYS_getsockopt = 295;
261pub const SYS_sendmsg = 296;
262pub const SYS_recvmsg = 297;
263pub const SYS_semop = 298;
264pub const SYS_semget = 299;
265pub const SYS_semctl = 300;
266pub const SYS_msgsnd = 301;
267pub const SYS_msgrcv = 302;
268pub const SYS_msgget = 303;
269pub const SYS_msgctl = 304;
270pub const SYS_shmat = 305;
271pub const SYS_shmdt = 306;
272pub const SYS_shmget = 307;
273pub const SYS_shmctl = 308;
274pub const SYS_add_key = 309;
275pub const SYS_request_key = 310;
276pub const SYS_keyctl = 311;
277pub const SYS_semtimedop = 312;
278pub const SYS_vserver = 313;
279pub const SYS_ioprio_set = 314;
280pub const SYS_ioprio_get = 315;
281pub const SYS_inotify_init = 316;
282pub const SYS_inotify_add_watch = 317;
283pub const SYS_inotify_rm_watch = 318;
284pub const SYS_mbind = 319;
285pub const SYS_get_mempolicy = 320;
286pub const SYS_set_mempolicy = 321;
287pub const SYS_openat = 322;
288pub const SYS_mkdirat = 323;
289pub const SYS_mknodat = 324;
290pub const SYS_fchownat = 325;
291pub const SYS_futimesat = 326;
292pub const SYS_fstatat64 = 327;
293pub const SYS_unlinkat = 328;
294pub const SYS_renameat = 329;
295pub const SYS_linkat = 330;
296pub const SYS_symlinkat = 331;
297pub const SYS_readlinkat = 332;
298pub const SYS_fchmodat = 333;
299pub const SYS_faccessat = 334;
300pub const SYS_pselect6 = 335;
301pub const SYS_ppoll = 336;
302pub const SYS_unshare = 337;
303pub const SYS_set_robust_list = 338;
304pub const SYS_get_robust_list = 339;
305pub const SYS_splice = 340;
306pub const SYS_sync_file_range2 = 341;
307pub const SYS_arm_sync_file_range = 341;
308pub const SYS_tee = 342;
309pub const SYS_vmsplice = 343;
310pub const SYS_move_pages = 344;
311pub const SYS_getcpu = 345;
312pub const SYS_epoll_pwait = 346;
313pub const SYS_kexec_load = 347;
314pub const SYS_utimensat = 348;
315pub const SYS_signalfd = 349;
316pub const SYS_timerfd_create = 350;
317pub const SYS_eventfd = 351;
318pub const SYS_fallocate = 352;
319pub const SYS_timerfd_settime = 353;
320pub const SYS_timerfd_gettime = 354;
321pub const SYS_signalfd4 = 355;
322pub const SYS_eventfd2 = 356;
323pub const SYS_epoll_create1 = 357;
324pub const SYS_dup3 = 358;
325pub const SYS_pipe2 = 359;
326pub const SYS_inotify_init1 = 360;
327pub const SYS_preadv = 361;
328pub const SYS_pwritev = 362;
329pub const SYS_rt_tgsigqueueinfo = 363;
330pub const SYS_perf_event_open = 364;
331pub const SYS_recvmmsg = 365;
332pub const SYS_accept4 = 366;
333pub const SYS_fanotify_init = 367;
334pub const SYS_fanotify_mark = 368;
335pub const SYS_prlimit64 = 369;
336pub const SYS_name_to_handle_at = 370;
337pub const SYS_open_by_handle_at = 371;
338pub const SYS_clock_adjtime = 372;
339pub const SYS_syncfs = 373;
340pub const SYS_sendmmsg = 374;
341pub const SYS_setns = 375;
342pub const SYS_process_vm_readv = 376;
343pub const SYS_process_vm_writev = 377;
344pub const SYS_kcmp = 378;
345pub const SYS_finit_module = 379;
346pub const SYS_sched_setattr = 380;
347pub const SYS_sched_getattr = 381;
348pub const SYS_renameat2 = 382;
349pub const SYS_seccomp = 383;
350pub const SYS_getrandom = 384;
351pub const SYS_memfd_create = 385;
352pub const SYS_bpf = 386;
353pub const SYS_execveat = 387;
354pub const SYS_userfaultfd = 388;
355pub const SYS_membarrier = 389;
356pub const SYS_mlock2 = 390;
357pub const SYS_copy_file_range = 391;
358pub const SYS_preadv2 = 392;
359pub const SYS_pwritev2 = 393;
360pub const SYS_pkey_mprotect = 394;
361pub const SYS_pkey_alloc = 395;
362pub const SYS_pkey_free = 396;
363pub const SYS_statx = 397;
364pub const SYS_rseq = 398;
365pub const SYS_io_pgetevents = 399;
366pub const SYS_migrate_pages = 400;
367pub const SYS_kexec_file_load = 401;
368pub const SYS_clock_gettime64 = 403;
369pub const SYS_clock_settime64 = 404;
370pub const SYS_clock_adjtime64 = 405;
371pub const SYS_clock_getres_time64 = 406;
372pub const SYS_clock_nanosleep_time64 = 407;
373pub const SYS_timer_gettime64 = 408;
374pub const SYS_timer_settime64 = 409;
375pub const SYS_timerfd_gettime64 = 410;
376pub const SYS_timerfd_settime64 = 411;
377pub const SYS_utimensat_time64 = 412;
378pub const SYS_pselect6_time64 = 413;
379pub const SYS_ppoll_time64 = 414;
380pub const SYS_io_pgetevents_time64 = 416;
381pub const SYS_recvmmsg_time64 = 417;
382pub const SYS_mq_timedsend_time64 = 418;
383pub const SYS_mq_timedreceive_time64 = 419;
384pub const SYS_semtimedop_time64 = 420;
385pub const SYS_rt_sigtimedwait_time64 = 421;
386pub const SYS_futex_time64 = 422;
387pub const SYS_sched_rr_get_interval_time64 = 423;
388pub const SYS_pidfd_send_signal = 424;
389pub const SYS_io_uring_setup = 425;
390pub const SYS_io_uring_enter = 426;
391pub const SYS_io_uring_register = 427;
392
393pub const SYS_breakpoint = 0x0f0001;
394pub const SYS_cacheflush = 0x0f0002;
395pub const SYS_usr26 = 0x0f0003;
396pub const SYS_usr32 = 0x0f0004;
397pub const SYS_set_tls = 0x0f0005;
398pub const SYS_get_tls = 0x0f0006;
399
400pub const MMAP2_UNIT = 4096;
401
402pub const O_CREAT = 0o100;
403pub const O_EXCL = 0o200;
404pub const O_NOCTTY = 0o400;
405pub const O_TRUNC = 0o1000;
406pub const O_APPEND = 0o2000;
407pub const O_NONBLOCK = 0o4000;
408pub const O_DSYNC = 0o10000;
409pub const O_SYNC = 0o4010000;
410pub const O_RSYNC = 0o4010000;
411pub const O_DIRECTORY = 0o40000;
412pub const O_NOFOLLOW = 0o100000;
413pub const O_CLOEXEC = 0o2000000;
414
415pub const O_ASYNC = 0o20000;
416pub const O_DIRECT = 0o200000;
417pub const O_LARGEFILE = 0o400000;
418pub const O_NOATIME = 0o1000000;
419pub const O_PATH = 0o10000000;
420pub const O_TMPFILE = 0o20040000;
421pub const O_NDELAY = O_NONBLOCK;
422
423pub const F_DUPFD = 0;
424pub const F_GETFD = 1;
425pub const F_SETFD = 2;
426pub const F_GETFL = 3;
427pub const F_SETFL = 4;
428
429pub const F_SETOWN = 8;
430pub const F_GETOWN = 9;
431pub const F_SETSIG = 10;
432pub const F_GETSIG = 11;
433
434pub const F_GETLK = 12;
435pub const F_SETLK = 13;
436pub const F_SETLKW = 14;
437
438pub const F_SETOWN_EX = 15;
439pub const F_GETOWN_EX = 16;
440
441pub const F_GETOWNER_UIDS = 17;
442
443/// stack-like segment
444pub const MAP_GROWSDOWN = 0x0100;
445
446/// ETXTBSY
447pub const MAP_DENYWRITE = 0x0800;
448
449/// mark it as an executable
450pub const MAP_EXECUTABLE = 0x1000;
451
452/// pages are locked
453pub const MAP_LOCKED = 0x2000;
454
455/// don't check for reservations
456pub const MAP_NORESERVE = 0x4000;
457
458/// populate (prefault) pagetables
459pub const MAP_POPULATE = 0x8000;
460
461/// do not block on IO
462pub const MAP_NONBLOCK = 0x10000;
463
464/// give out an address that is best suited for process/thread stacks
465pub const MAP_STACK = 0x20000;
466
467/// create a huge page mapping
468pub const MAP_HUGETLB = 0x40000;
469
470/// perform synchronous page faults for the mapping
471pub const MAP_SYNC = 0x80000;
472
473pub const VDSO_USEFUL = true;
474pub const VDSO_CGT_SYM = "__vdso_clock_gettime";
475pub const VDSO_CGT_VER = "LINUX_2.6";
476
477pub const HWCAP_SWP = 1 << 0;
478pub const HWCAP_HALF = 1 << 1;
479pub const HWCAP_THUMB = 1 << 2;
480pub const HWCAP_26BIT = 1 << 3;
481pub const HWCAP_FAST_MULT = 1 << 4;
482pub const HWCAP_FPA = 1 << 5;
483pub const HWCAP_VFP = 1 << 6;
484pub const HWCAP_EDSP = 1 << 7;
485pub const HWCAP_JAVA = 1 << 8;
486pub const HWCAP_IWMMXT = 1 << 9;
487pub const HWCAP_CRUNCH = 1 << 10;
488pub const HWCAP_THUMBEE = 1 << 11;
489pub const HWCAP_NEON = 1 << 12;
490pub const HWCAP_VFPv3 = 1 << 13;
491pub const HWCAP_VFPv3D16 = 1 << 14;
492pub const HWCAP_TLS = 1 << 15;
493pub const HWCAP_VFPv4 = 1 << 16;
494pub const HWCAP_IDIVA = 1 << 17;
495pub const HWCAP_IDIVT = 1 << 18;
496pub const HWCAP_VFPD32 = 1 << 19;
497pub const HWCAP_IDIV = HWCAP_IDIVA | HWCAP_IDIVT;
498pub const HWCAP_LPAE = 1 << 20;
499pub const HWCAP_EVTSTRM = 1 << 21;
500
501pub const msghdr = extern struct {
502 msg_name: ?*sockaddr,
503 msg_namelen: socklen_t,
504 msg_iov: [*]iovec,
505 msg_iovlen: i32,
506 msg_control: ?*c_void,
507 msg_controllen: socklen_t,
508 msg_flags: i32,
509};
510
511pub const msghdr_const = extern struct {
512 msg_name: ?*const sockaddr,
513 msg_namelen: socklen_t,
514 msg_iov: [*]iovec_const,
515 msg_iovlen: i32,
516 msg_control: ?*c_void,
517 msg_controllen: socklen_t,
518 msg_flags: i32,
519};
520
521/// Renamed to Stat to not conflict with the stat function.
522/// atime, mtime, and ctime have functions to return `timespec`,
523/// because although this is a POSIX API, the layout and names of
524/// the structs are inconsistent across operating systems, and
525/// in C, macros are used to hide the differences. Here we use
526/// methods to accomplish this.
527pub const Stat = extern struct {
528 dev: u64,
529 __dev_padding: u32,
530 __ino_truncated: u32,
531 mode: u32,
532 nlink: u32,
533 uid: u32,
534 gid: u32,
535 rdev: u64,
536 __rdev_padding: u32,
537 size: i64,
538 blksize: i32,
539 blocks: u64,
540 atim: timespec,
541 mtim: timespec,
542 ctim: timespec,
543 ino: u64,
544
545 pub fn atime(self: Stat) timespec {
546 return self.atim;
547 }
548
549 pub fn mtime(self: Stat) timespec {
550 return self.mtim;
551 }
552
553 pub fn ctime(self: Stat) timespec {
554 return self.ctim;
555 }
556};
557
558pub const timespec = extern struct {
559 tv_sec: i32,
560 tv_nsec: i32,
561};
562
563pub const timeval = extern struct {
564 tv_sec: i32,
565 tv_usec: i32,
566};
567
568pub const timezone = extern struct {
569 tz_minuteswest: i32,
570 tz_dsttime: i32,
571};
572
573pub const Elf_Symndx = u32;
std/os/linux.zig+132-25
......@@ -17,6 +17,7 @@ pub const is_the_target = builtin.os == .linux;
1717pub usingnamespace switch (builtin.arch) {
1818 .x86_64 => @import("linux/x86_64.zig"),
1919 .aarch64 => @import("linux/arm64.zig"),
20 .arm => @import("linux/arm-eabi.zig"),
2021 .riscv64 => @import("linux/riscv64.zig"),
2122 else => struct {},
2223};
......@@ -190,7 +191,11 @@ pub fn umount2(special: [*]const u8, flags: u32) usize {
190191}
191192
192193pub fn mmap(address: ?[*]u8, length: usize, prot: usize, flags: u32, fd: i32, offset: isize) usize {
193 return syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, @bitCast(usize, isize(fd)), @bitCast(usize, offset));
194 if (@hasDecl(@This(), "SYS_mmap2")) {
195 return syscall6(SYS_mmap2, @ptrToInt(address), length, prot, flags, @bitCast(usize, isize(fd)), @bitCast(usize, @divTrunc(offset, MMAP2_UNIT)));
196 } else {
197 return syscall6(SYS_mmap, @ptrToInt(address), length, prot, flags, @bitCast(usize, isize(fd)), @bitCast(usize, offset));
198 }
194199}
195200
196201pub fn mprotect(address: [*]const u8, length: usize, protection: usize) usize {
......@@ -206,11 +211,26 @@ pub fn read(fd: i32, buf: [*]u8, count: usize) usize {
206211}
207212
208213pub fn preadv(fd: i32, iov: [*]const iovec, count: usize, offset: u64) usize {
209 return syscall4(SYS_preadv, @bitCast(usize, isize(fd)), @ptrToInt(iov), count, offset);
214 return syscall5(
215 SYS_preadv,
216 @bitCast(usize, isize(fd)),
217 @ptrToInt(iov),
218 count,
219 @truncate(usize, offset),
220 @truncate(usize, offset >> 32),
221 );
210222}
211223
212224pub fn preadv2(fd: i32, iov: [*]const iovec, count: usize, offset: u64, flags: kernel_rwf) usize {
213 return syscall5(SYS_preadv2, @bitCast(usize, isize(fd)), @ptrToInt(iov), count, offset, flags);
225 return syscall6(
226 SYS_preadv2,
227 @bitCast(usize, isize(fd)),
228 @ptrToInt(iov),
229 count,
230 @truncate(usize, offset),
231 @truncate(usize, offset >> 32),
232 flags,
233 );
214234}
215235
216236pub fn readv(fd: i32, iov: [*]const iovec, count: usize) usize {
......@@ -222,11 +242,26 @@ pub fn writev(fd: i32, iov: [*]const iovec_const, count: usize) usize {
222242}
223243
224244pub fn pwritev(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64) usize {
225 return syscall4(SYS_pwritev, @bitCast(usize, isize(fd)), @ptrToInt(iov), count, offset);
245 return syscall5(
246 SYS_pwritev,
247 @bitCast(usize, isize(fd)),
248 @ptrToInt(iov),
249 count,
250 @truncate(usize, offset),
251 @truncate(usize, offset >> 32),
252 );
226253}
227254
228255pub fn pwritev2(fd: i32, iov: [*]const iovec_const, count: usize, offset: u64, flags: kernel_rwf) usize {
229 return syscall5(SYS_pwritev2, @bitCast(usize, isize(fd)), @ptrToInt(iov), count, offset, flags);
256 return syscall6(
257 SYS_pwritev2,
258 @bitCast(usize, isize(fd)),
259 @ptrToInt(iov),
260 count,
261 @truncate(usize, offset),
262 @truncate(usize, offset >> 32),
263 flags,
264 );
230265}
231266
232267// TODO https://github.com/ziglang/zig/issues/265
......@@ -482,67 +517,123 @@ pub fn nanosleep(req: *const timespec, rem: ?*timespec) usize {
482517}
483518
484519pub fn setuid(uid: u32) usize {
485 return syscall1(SYS_setuid, uid);
520 if (@hasDecl(@This(), "SYS_setuid32")) {
521 return syscall1(SYS_setuid32, uid);
522 } else {
523 return syscall1(SYS_setuid, uid);
524 }
486525}
487526
488527pub fn setgid(gid: u32) usize {
489 return syscall1(SYS_setgid, gid);
528 if (@hasDecl(@This(), "SYS_setgid32")) {
529 return syscall1(SYS_setgid32, gid);
530 } else {
531 return syscall1(SYS_setgid, gid);
532 }
490533}
491534
492535pub fn setreuid(ruid: u32, euid: u32) usize {
493 return syscall2(SYS_setreuid, ruid, euid);
536 if (@hasDecl(@This(), "SYS_setreuid32")) {
537 return syscall2(SYS_setreuid32, ruid, euid);
538 } else {
539 return syscall2(SYS_setreuid, ruid, euid);
540 }
494541}
495542
496543pub fn setregid(rgid: u32, egid: u32) usize {
497 return syscall2(SYS_setregid, rgid, egid);
544 if (@hasDecl(@This(), "SYS_setregid32")) {
545 return syscall2(SYS_setregid32, rgid, egid);
546 } else {
547 return syscall2(SYS_setregid, rgid, egid);
548 }
498549}
499550
500551pub fn getuid() u32 {
501 return u32(syscall0(SYS_getuid));
552 if (@hasDecl(@This(), "SYS_getuid32")) {
553 return u32(syscall0(SYS_getuid32));
554 } else {
555 return u32(syscall0(SYS_getuid));
556 }
502557}
503558
504559pub fn getgid() u32 {
505 return u32(syscall0(SYS_getgid));
560 if (@hasDecl(@This(), "SYS_getgid32")) {
561 return u32(syscall0(SYS_getgid32));
562 } else {
563 return u32(syscall0(SYS_getgid));
564 }
506565}
507566
508567pub fn geteuid() u32 {
509 return u32(syscall0(SYS_geteuid));
568 if (@hasDecl(@This(), "SYS_geteuid32")) {
569 return u32(syscall0(SYS_geteuid32));
570 } else {
571 return u32(syscall0(SYS_geteuid));
572 }
510573}
511574
512575pub fn getegid() u32 {
513 return u32(syscall0(SYS_getegid));
576 if (@hasDecl(@This(), "SYS_getegid32")) {
577 return u32(syscall0(SYS_getegid32));
578 } else {
579 return u32(syscall0(SYS_getegid));
580 }
514581}
515582
516583pub fn seteuid(euid: u32) usize {
517 return syscall1(SYS_seteuid, euid);
584 return setreuid(std.math.maxInt(u32), euid);
518585}
519586
520587pub fn setegid(egid: u32) usize {
521 return syscall1(SYS_setegid, egid);
588 return setregid(std.math.maxInt(u32), egid);
522589}
523590
524591pub fn getresuid(ruid: *u32, euid: *u32, suid: *u32) usize {
525 return syscall3(SYS_getresuid, @ptrToInt(ruid), @ptrToInt(euid), @ptrToInt(suid));
592 if (@hasDecl(@This(), "SYS_getresuid32")) {
593 return syscall3(SYS_getresuid32, @ptrToInt(ruid), @ptrToInt(euid), @ptrToInt(suid));
594 } else {
595 return syscall3(SYS_getresuid, @ptrToInt(ruid), @ptrToInt(euid), @ptrToInt(suid));
596 }
526597}
527598
528599pub fn getresgid(rgid: *u32, egid: *u32, sgid: *u32) usize {
529 return syscall3(SYS_getresgid, @ptrToInt(rgid), @ptrToInt(egid), @ptrToInt(sgid));
600 if (@hasDecl(@This(), "SYS_getresgid32")) {
601 return syscall3(SYS_getresgid32, @ptrToInt(rgid), @ptrToInt(egid), @ptrToInt(sgid));
602 } else {
603 return syscall3(SYS_getresgid, @ptrToInt(rgid), @ptrToInt(egid), @ptrToInt(sgid));
604 }
530605}
531606
532607pub fn setresuid(ruid: u32, euid: u32, suid: u32) usize {
533 return syscall3(SYS_setresuid, ruid, euid, suid);
608 if (@hasDecl(@This(), "SYS_setresuid32")) {
609 return syscall3(SYS_setresuid32, ruid, euid, suid);
610 } else {
611 return syscall3(SYS_setresuid, ruid, euid, suid);
612 }
534613}
535614
536615pub fn setresgid(rgid: u32, egid: u32, sgid: u32) usize {
537 return syscall3(SYS_setresgid, rgid, egid, sgid);
616 if (@hasDecl(@This(), "SYS_setresgid32")) {
617 return syscall3(SYS_setresgid32, rgid, egid, sgid);
618 } else {
619 return syscall3(SYS_setresgid, rgid, egid, sgid);
620 }
538621}
539622
540623pub fn getgroups(size: usize, list: *u32) usize {
541 return syscall2(SYS_getgroups, size, @ptrToInt(list));
624 if (@hasDecl(@This(), "SYS_getgroups32")) {
625 return syscall2(SYS_getgroups32, size, @ptrToInt(list));
626 } else {
627 return syscall2(SYS_getgroups, size, @ptrToInt(list));
628 }
542629}
543630
544631pub fn setgroups(size: usize, list: *const u32) usize {
545 return syscall2(SYS_setgroups, size, @ptrToInt(list));
632 if (@hasDecl(@This(), "SYS_setgroups32")) {
633 return syscall2(SYS_setgroups32, size, @ptrToInt(list));
634 } else {
635 return syscall2(SYS_setgroups, size, @ptrToInt(list));
636 }
546637}
547638
548639pub fn getpid() i32 {
......@@ -709,22 +800,38 @@ pub fn accept4(fd: i32, noalias addr: *sockaddr, noalias len: *socklen_t, flags:
709800}
710801
711802pub fn fstat(fd: i32, stat_buf: *Stat) usize {
712 return syscall2(SYS_fstat, @bitCast(usize, isize(fd)), @ptrToInt(stat_buf));
803 if (@hasDecl(@This(), "SYS_fstat64")) {
804 return syscall2(SYS_fstat64, @bitCast(usize, isize(fd)), @ptrToInt(stat_buf));
805 } else {
806 return syscall2(SYS_fstat, @bitCast(usize, isize(fd)), @ptrToInt(stat_buf));
807 }
713808}
714809
715810// TODO https://github.com/ziglang/zig/issues/265
716811pub fn stat(pathname: [*]const u8, statbuf: *Stat) usize {
717 return syscall2(SYS_stat, @ptrToInt(pathname), @ptrToInt(statbuf));
812 if (@hasDecl(@This(), "SYS_stat64")) {
813 return syscall2(SYS_stat64, @ptrToInt(pathname), @ptrToInt(statbuf));
814 } else {
815 return syscall2(SYS_stat, @ptrToInt(pathname), @ptrToInt(statbuf));
816 }
718817}
719818
720819// TODO https://github.com/ziglang/zig/issues/265
721820pub fn lstat(pathname: [*]const u8, statbuf: *Stat) usize {
722 return syscall2(SYS_lstat, @ptrToInt(pathname), @ptrToInt(statbuf));
821 if (@hasDecl(@This(), "SYS_lstat64")) {
822 return syscall2(SYS_lstat64, @ptrToInt(pathname), @ptrToInt(statbuf));
823 } else {
824 return syscall2(SYS_lstat, @ptrToInt(pathname), @ptrToInt(statbuf));
825 }
723826}
724827
725828// TODO https://github.com/ziglang/zig/issues/265
726829pub fn fstatat(dirfd: i32, path: [*]const u8, stat_buf: *Stat, flags: u32) usize {
727 return syscall4(SYS_fstatat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
830 if (@hasDecl(@This(), "SYS_fstatat64")) {
831 return syscall4(SYS_fstatat64, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
832 } else {
833 return syscall4(SYS_fstatat, @bitCast(usize, isize(dirfd)), @ptrToInt(path), @ptrToInt(stat_buf), flags);
834 }
728835}
729836
730837// TODO https://github.com/ziglang/zig/issues/265
std/os/linux/arm-eabi.zig created+96
......@@ -0,0 +1,96 @@
1pub fn syscall0(number: usize) usize {
2 return asm volatile ("svc #0"
3 : [ret] "={r0}" (-> usize)
4 : [number] "{r7}" (number)
5 : "memory"
6 );
7}
8
9pub fn syscall1(number: usize, arg1: usize) usize {
10 return asm volatile ("svc #0"
11 : [ret] "={r0}" (-> usize)
12 : [number] "{r7}" (number),
13 [arg1] "{r0}" (arg1)
14 : "memory"
15 );
16}
17
18pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
19 return asm volatile ("svc #0"
20 : [ret] "={r0}" (-> usize)
21 : [number] "{r7}" (number),
22 [arg1] "{r0}" (arg1),
23 [arg2] "{r1}" (arg2)
24 : "memory"
25 );
26}
27
28pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
29 return asm volatile ("svc #0"
30 : [ret] "={r0}" (-> usize)
31 : [number] "{r7}" (number),
32 [arg1] "{r0}" (arg1),
33 [arg2] "{r1}" (arg2),
34 [arg3] "{r2}" (arg3)
35 : "memory"
36 );
37}
38
39pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize {
40 return asm volatile ("svc #0"
41 : [ret] "={r0}" (-> usize)
42 : [number] "{r7}" (number),
43 [arg1] "{r0}" (arg1),
44 [arg2] "{r1}" (arg2),
45 [arg3] "{r2}" (arg3),
46 [arg4] "{r3}" (arg4)
47 : "memory"
48 );
49}
50
51pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize {
52 return asm volatile ("svc #0"
53 : [ret] "={r0}" (-> usize)
54 : [number] "{r7}" (number),
55 [arg1] "{r0}" (arg1),
56 [arg2] "{r1}" (arg2),
57 [arg3] "{r2}" (arg3),
58 [arg4] "{r3}" (arg4),
59 [arg5] "{r4}" (arg5)
60 : "memory"
61 );
62}
63
64pub fn syscall6(
65 number: usize,
66 arg1: usize,
67 arg2: usize,
68 arg3: usize,
69 arg4: usize,
70 arg5: usize,
71 arg6: usize,
72) usize {
73 return asm volatile ("svc #0"
74 : [ret] "={r0}" (-> usize)
75 : [number] "{r7}" (number),
76 [arg1] "{r0}" (arg1),
77 [arg2] "{r1}" (arg2),
78 [arg3] "{r2}" (arg3),
79 [arg4] "{r3}" (arg4),
80 [arg5] "{r4}" (arg5),
81 [arg6] "{r5}" (arg6)
82 : "memory"
83 );
84}
85
86/// This matches the libc clone function.
87pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: u32, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize;
88
89// LLVM calls this when the read-tp-hard feature is set to false. Currently, there is no way to pass
90// that to llvm via zig, see https://github.com/ziglang/zig/issues/2883.
91// LLVM expects libc to provide this function as __aeabi_read_tp, so it is exported if needed from special/c.zig.
92pub extern fn getThreadPointer() usize {
93 return asm volatile("mrc p15, 0, %[ret], c13, c0, 3"
94 : [ret] "=r" (-> usize)
95 );
96}
\ No newline at end of file
std/os/linux/arm64.zig+7-7
......@@ -2,7 +2,7 @@ pub fn syscall0(number: usize) usize {
22 return asm volatile ("svc #0"
33 : [ret] "={x0}" (-> usize)
44 : [number] "{x8}" (number)
5 : "memory"
5 : "memory", "cc"
66 );
77}
88
......@@ -11,7 +11,7 @@ pub fn syscall1(number: usize, arg1: usize) usize {
1111 : [ret] "={x0}" (-> usize)
1212 : [number] "{x8}" (number),
1313 [arg1] "{x0}" (arg1)
14 : "memory"
14 : "memory", "cc"
1515 );
1616}
1717
......@@ -21,7 +21,7 @@ pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize {
2121 : [number] "{x8}" (number),
2222 [arg1] "{x0}" (arg1),
2323 [arg2] "{x1}" (arg2)
24 : "memory"
24 : "memory", "cc"
2525 );
2626}
2727
......@@ -32,7 +32,7 @@ pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize {
3232 [arg1] "{x0}" (arg1),
3333 [arg2] "{x1}" (arg2),
3434 [arg3] "{x2}" (arg3)
35 : "memory"
35 : "memory", "cc"
3636 );
3737}
3838
......@@ -44,7 +44,7 @@ pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz
4444 [arg2] "{x1}" (arg2),
4545 [arg3] "{x2}" (arg3),
4646 [arg4] "{x3}" (arg4)
47 : "memory"
47 : "memory", "cc"
4848 );
4949}
5050
......@@ -57,7 +57,7 @@ pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usiz
5757 [arg3] "{x2}" (arg3),
5858 [arg4] "{x3}" (arg4),
5959 [arg5] "{x4}" (arg5)
60 : "memory"
60 : "memory", "cc"
6161 );
6262}
6363
......@@ -79,7 +79,7 @@ pub fn syscall6(
7979 [arg4] "{x3}" (arg4),
8080 [arg5] "{x4}" (arg5),
8181 [arg6] "{x5}" (arg6)
82 : "memory"
82 : "memory", "cc"
8383 );
8484}
8585
std/os/linux/tls.zig+13
......@@ -118,6 +118,9 @@ pub fn setThreadPointer(addr: usize) void {
118118 : [addr] "r" (addr)
119119 );
120120 },
121 .arm => |arm| {
122 _ = std.os.linux.syscall1(std.os.linux.SYS_set_tls, addr);
123 },
121124 .riscv64 => {
122125 asm volatile (
123126 \\ mv tp, %[addr]
......@@ -137,6 +140,7 @@ pub fn initTLS() void {
137140 var at_phent: usize = undefined;
138141 var at_phnum: usize = undefined;
139142 var at_phdr: usize = undefined;
143 var at_hwcap: usize = undefined;
140144
141145 var i: usize = 0;
142146 while (auxv[i].a_type != std.elf.AT_NULL) : (i += 1) {
......@@ -144,6 +148,7 @@ pub fn initTLS() void {
144148 elf.AT_PHENT => at_phent = auxv[i].a_un.a_val,
145149 elf.AT_PHNUM => at_phnum = auxv[i].a_un.a_val,
146150 elf.AT_PHDR => at_phdr = auxv[i].a_un.a_val,
151 elf.AT_HWCAP => at_hwcap = auxv[i].a_un.a_val,
147152 else => continue,
148153 }
149154 }
......@@ -163,6 +168,14 @@ pub fn initTLS() void {
163168 }
164169
165170 if (tls_phdr) |phdr| {
171 // If the cpu is arm-based, check if it supports the TLS register
172 if (builtin.arch == builtin.Arch.arm and at_hwcap & std.os.linux.HWCAP_TLS == 0) {
173 // If the CPU does not support TLS via a coprocessor register,
174 // a kernel helper function can be used instead on certain linux kernels.
175 // See linux/arch/arm/include/asm/tls.h and musl/src/thread/arm/__set_thread_area.c.
176 @panic("TODO: Implement ARM fallback TLS functionality");
177 }
178
166179 // Offsets into the allocated TLS area
167180 var tcb_offset: usize = undefined;
168181 var dtv_offset: usize = undefined;
std/special/build_runner.zig+2
......@@ -123,6 +123,7 @@ pub fn main() !void {
123123 }
124124 }
125125
126 builder.resolveInstallPrefix();
126127 try runBuild(builder);
127128
128129 if (builder.validateUserInputDidItFail())
......@@ -151,6 +152,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: var) !void {
151152 // run the build script to collect the options
152153 if (!already_ran_build) {
153154 builder.setInstallPrefix(null);
155 builder.resolveInstallPrefix();
154156 try runBuild(builder);
155157 }
156158
std/special/c.zig+31
......@@ -31,6 +31,8 @@ comptime {
3131 @export("strlen", strlen, .Strong);
3232 } else if (is_msvc) {
3333 @export("_fltused", _fltused, .Strong);
34 } else if (builtin.arch == builtin.Arch.arm and builtin.os == .linux) {
35 @export("__aeabi_read_tp", std.os.linux.getThreadPointer, .Strong);
3436 }
3537}
3638
......@@ -249,6 +251,35 @@ nakedcc fn clone() void {
249251 \\ mov x8,#93 // SYS_exit
250252 \\ svc #0
251253 );
254 } else if (builtin.arch == builtin.Arch.arm) {
255 asm volatile (
256 \\ stmfd sp!,{r4,r5,r6,r7}
257 \\ mov r7,#120
258 \\ mov r6,r3
259 \\ mov r5,r0
260 \\ mov r0,r2
261 \\ and r1,r1,#-16
262 \\ ldr r2,[sp,#16]
263 \\ ldr r3,[sp,#20]
264 \\ ldr r4,[sp,#24]
265 \\ svc 0
266 \\ tst r0,r0
267 \\ beq 1f
268 \\ ldmfd sp!,{r4,r5,r6,r7}
269 \\ bx lr
270 \\
271 \\1: mov r0,r6
272 \\ tst r5,#1
273 \\ bne 1f
274 \\ mov lr,pc
275 \\ mov pc,r5
276 \\2: mov r7,#1
277 \\ svc 0
278 \\
279 \\1: mov lr,pc
280 \\ bx r5
281 \\ b 2b
282 );
252283 } else {
253284 @compileError("Implement clone() for this arch.");
254285 }
std/special/start.zig+1-1
......@@ -44,7 +44,7 @@ nakedcc fn _start() noreturn {
4444 : [argc] "={esp}" (-> [*]usize)
4545 );
4646 },
47 .aarch64, .aarch64_be => {
47 .aarch64, .aarch64_be, .arm => {
4848 argc_ptr = asm ("mov %[argc], sp"
4949 : [argc] "=r" (-> [*]usize)
5050 );
std/std.zig+3
......@@ -1,6 +1,7 @@
11pub const AlignedArrayList = @import("array_list.zig").AlignedArrayList;
22pub const ArrayList = @import("array_list.zig").ArrayList;
33pub const AutoHashMap = @import("hash_map.zig").AutoHashMap;
4pub const BloomFilter = @import("bloom_filter.zig").BloomFilter;
45pub const BufMap = @import("buf_map.zig").BufMap;
56pub const BufSet = @import("buf_set.zig").BufSet;
67pub const Buffer = @import("buffer.zig").Buffer;
......@@ -48,6 +49,7 @@ pub const mem = @import("mem.zig");
4849pub const meta = @import("meta.zig");
4950pub const net = @import("net.zig");
5051pub const os = @import("os.zig");
52pub const packed_int_array = @import("packed_int_array.zig");
5153pub const pdb = @import("pdb.zig");
5254pub const process = @import("process.zig");
5355pub const rand = @import("rand.zig");
......@@ -64,6 +66,7 @@ test "std" {
6466 // run tests from these
6567 _ = @import("array_list.zig");
6668 _ = @import("atomic.zig");
69 _ = @import("bloom_filter.zig");
6770 _ = @import("buf_map.zig");
6871 _ = @import("buf_set.zig");
6972 _ = @import("buffer.zig");
std/zig/parse.zig+4-2
......@@ -201,7 +201,7 @@ fn parseTopLevelComptime(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*
201201}
202202
203203/// TopLevelDecl
204/// <- (KEYWORD_export / KEYWORD_extern STRINGLITERAL? / KEYWORD_inline)? FnProto (SEMICOLON / Block)
204/// <- (KEYWORD_export / KEYWORD_extern STRINGLITERAL? / (KEYWORD_inline / KEYWORD_noinline))? FnProto (SEMICOLON / Block)
205205/// / (KEYWORD_export / KEYWORD_extern STRINGLITERAL?)? KEYWORD_threadlocal? VarDecl
206206/// / KEYWORD_usingnamespace Expr SEMICOLON
207207fn parseTopLevelDecl(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node {
......@@ -213,6 +213,7 @@ fn parseTopLevelDecl(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node
213213 break :blk token;
214214 }
215215 if (eatToken(it, .Keyword_inline)) |token| break :blk token;
216 if (eatToken(it, .Keyword_noinline)) |token| break :blk token;
216217 break :blk null;
217218 };
218219
......@@ -232,7 +233,8 @@ fn parseTopLevelDecl(arena: *Allocator, it: *TokenIterator, tree: *Tree) !?*Node
232233 }
233234
234235 if (extern_export_inline_token) |token| {
235 if (tree.tokens.at(token).id == .Keyword_inline) {
236 if (tree.tokens.at(token).id == .Keyword_inline or
237 tree.tokens.at(token).id == .Keyword_noinline) {
236238 putBackToken(it, token);
237239 return null;
238240 }
std/zig/parser_test.zig+91
......@@ -1677,14 +1677,17 @@ test "zig fmt: functions" {
16771677 \\extern "c" fn puts(s: *const u8) c_int;
16781678 \\export fn puts(s: *const u8) c_int;
16791679 \\inline fn puts(s: *const u8) c_int;
1680 \\noinline fn puts(s: *const u8) c_int;
16801681 \\pub extern fn puts(s: *const u8) c_int;
16811682 \\pub extern "c" fn puts(s: *const u8) c_int;
16821683 \\pub export fn puts(s: *const u8) c_int;
16831684 \\pub inline fn puts(s: *const u8) c_int;
1685 \\pub noinline fn puts(s: *const u8) c_int;
16841686 \\pub extern fn puts(s: *const u8) align(2 + 2) c_int;
16851687 \\pub extern "c" fn puts(s: *const u8) align(2 + 2) c_int;
16861688 \\pub export fn puts(s: *const u8) align(2 + 2) c_int;
16871689 \\pub inline fn puts(s: *const u8) align(2 + 2) c_int;
1690 \\pub noinline fn puts(s: *const u8) align(2 + 2) c_int;
16881691 \\
16891692 );
16901693}
......@@ -2419,6 +2422,94 @@ test "zig fmt: comment after empty comment" {
24192422 );
24202423}
24212424
2425test "zig fmt: line comment in array" {
2426 try testTransform(
2427 \\test "a" {
2428 \\ var arr = [_]u32{
2429 \\ 0
2430 \\ // 1,
2431 \\ // 2,
2432 \\ };
2433 \\}
2434 \\
2435 ,
2436 \\test "a" {
2437 \\ var arr = [_]u32{
2438 \\ 0, // 1,
2439 \\ // 2,
2440 \\ };
2441 \\}
2442 \\
2443 );
2444 try testCanonical(
2445 \\test "a" {
2446 \\ var arr = [_]u32{
2447 \\ 0,
2448 \\ // 1,
2449 \\ // 2,
2450 \\ };
2451 \\}
2452 \\
2453 );
2454}
2455
2456test "zig fmt: comment after params" {
2457 try testTransform(
2458 \\fn a(
2459 \\ b: u32
2460 \\ // c: u32,
2461 \\ // d: u32,
2462 \\) void {}
2463 \\
2464 ,
2465 \\fn a(
2466 \\ b: u32, // c: u32,
2467 \\ // d: u32,
2468 \\) void {}
2469 \\
2470 );
2471 try testCanonical(
2472 \\fn a(
2473 \\ b: u32,
2474 \\ // c: u32,
2475 \\ // d: u32,
2476 \\) void {}
2477 \\
2478 );
2479}
2480
2481test "zig fmt: comment in array initializer/access" {
2482 try testCanonical(
2483 \\test "a" {
2484 \\ var a = x{ //aa
2485 \\ //bb
2486 \\ };
2487 \\ var a = []x{ //aa
2488 \\ //bb
2489 \\ };
2490 \\ var b = [ //aa
2491 \\ _
2492 \\ ]x{ //aa
2493 \\ //bb
2494 \\ 9,
2495 \\ };
2496 \\ var c = b[ //aa
2497 \\ 0
2498 \\ ];
2499 \\ var d = [_
2500 \\ //aa
2501 \\ ]x{ //aa
2502 \\ //bb
2503 \\ 9,
2504 \\ };
2505 \\ var e = d[0
2506 \\ //aa
2507 \\ ];
2508 \\}
2509 \\
2510 );
2511}
2512
24222513test "zig fmt: comments at several places in struct init" {
24232514 try testTransform(
24242515 \\var bar = Bar{
std/zig/render.zig+34-9
......@@ -483,9 +483,23 @@ fn renderExpression(
483483 },
484484
485485 ast.Node.PrefixOp.Op.ArrayType => |array_index| {
486 try renderToken(tree, stream, prefix_op_node.op_token, indent, start_col, Space.None); // [
487 try renderExpression(allocator, stream, tree, indent, start_col, array_index, Space.None);
488 try renderToken(tree, stream, tree.nextToken(array_index.lastToken()), indent, start_col, Space.None); // ]
486 const lbracket = prefix_op_node.op_token;
487 const rbracket = tree.nextToken(array_index.lastToken());
488
489 try renderToken(tree, stream, lbracket, indent, start_col, Space.None); // [
490
491 const starts_with_comment = tree.tokens.at(lbracket + 1).id == .LineComment;
492 const ends_with_comment = tree.tokens.at(rbracket - 1).id == .LineComment;
493 const new_indent = if (ends_with_comment) indent + indent_delta else indent;
494 const new_space = if (ends_with_comment) Space.Newline else Space.None;
495 try renderExpression(allocator, stream, tree, new_indent, start_col, array_index, new_space);
496 if (starts_with_comment) {
497 try stream.writeByte('\n');
498 }
499 if (ends_with_comment or starts_with_comment) {
500 try stream.writeByteNTimes(' ', indent);
501 }
502 try renderToken(tree, stream, rbracket, indent, start_col, Space.None); // ]
489503 },
490504 ast.Node.PrefixOp.Op.BitNot,
491505 ast.Node.PrefixOp.Op.BoolNot,
......@@ -580,7 +594,18 @@ fn renderExpression(
580594
581595 try renderExpression(allocator, stream, tree, indent, start_col, suffix_op.lhs, Space.None);
582596 try renderToken(tree, stream, lbracket, indent, start_col, Space.None); // [
583 try renderExpression(allocator, stream, tree, indent, start_col, index_expr, Space.None);
597
598 const starts_with_comment = tree.tokens.at(lbracket + 1).id == .LineComment;
599 const ends_with_comment = tree.tokens.at(rbracket - 1).id == .LineComment;
600 const new_indent = if (ends_with_comment) indent + indent_delta else indent;
601 const new_space = if (ends_with_comment) Space.Newline else Space.None;
602 try renderExpression(allocator, stream, tree, new_indent, start_col, index_expr, new_space);
603 if (starts_with_comment) {
604 try stream.writeByte('\n');
605 }
606 if (ends_with_comment or starts_with_comment) {
607 try stream.writeByteNTimes(' ', indent);
608 }
584609 return renderToken(tree, stream, rbracket, indent, start_col, space); // ]
585610 },
586611
......@@ -615,7 +640,7 @@ fn renderExpression(
615640
616641 if (field_inits.len == 0) {
617642 try renderExpression(allocator, stream, tree, indent, start_col, suffix_op.lhs, Space.None);
618 try renderToken(tree, stream, lbrace, indent, start_col, Space.None);
643 try renderToken(tree, stream, lbrace, indent + indent_delta, start_col, Space.None);
619644 return renderToken(tree, stream, suffix_op.rtoken, indent, start_col, space);
620645 }
621646
......@@ -714,7 +739,7 @@ fn renderExpression(
714739 try renderToken(tree, stream, lbrace, indent, start_col, Space.None);
715740 return renderToken(tree, stream, suffix_op.rtoken, indent, start_col, space);
716741 }
717 if (exprs.len == 1) {
742 if (exprs.len == 1 and tree.tokens.at(exprs.at(0).*.lastToken() + 1).id == .RBrace) {
718743 const expr = exprs.at(0).*;
719744
720745 try renderExpression(allocator, stream, tree, indent, start_col, suffix_op.lhs, Space.None);
......@@ -775,7 +800,7 @@ fn renderExpression(
775800 while (it.next()) |expr| : (i += 1) {
776801 counting_stream.bytes_written = 0;
777802 var dummy_col: usize = 0;
778 try renderExpression(allocator, &counting_stream.stream, tree, 0, &dummy_col, expr.*, Space.None);
803 try renderExpression(allocator, &counting_stream.stream, tree, indent, &dummy_col, expr.*, Space.None);
779804 const width = @intCast(usize, counting_stream.bytes_written);
780805 const col = i % row_size;
781806 column_widths[col] = std.math.max(column_widths[col], width);
......@@ -1191,8 +1216,8 @@ fn renderExpression(
11911216 });
11921217
11931218 const src_params_trailing_comma = blk: {
1194 const maybe_comma = tree.prevToken(rparen);
1195 break :blk tree.tokens.at(maybe_comma).id == Token.Id.Comma;
1219 const maybe_comma = tree.tokens.at(rparen - 1).id;
1220 break :blk maybe_comma == .Comma or maybe_comma == .LineComment;
11961221 };
11971222
11981223 if (!src_params_trailing_comma) {
std/zig/tokenizer.zig+4
......@@ -38,6 +38,8 @@ pub const Token = struct {
3838 Keyword{ .bytes = "inline", .id = Id.Keyword_inline },
3939 Keyword{ .bytes = "nakedcc", .id = Id.Keyword_nakedcc },
4040 Keyword{ .bytes = "noalias", .id = Id.Keyword_noalias },
41 Keyword{ .bytes = "noasync", .id = Id.Keyword_noasync },
42 Keyword{ .bytes = "noinline", .id = Id.Keyword_noinline },
4143 Keyword{ .bytes = "null", .id = Id.Keyword_null },
4244 Keyword{ .bytes = "or", .id = Id.Keyword_or },
4345 Keyword{ .bytes = "orelse", .id = Id.Keyword_orelse },
......@@ -168,6 +170,8 @@ pub const Token = struct {
168170 Keyword_inline,
169171 Keyword_nakedcc,
170172 Keyword_noalias,
173 Keyword_noasync,
174 Keyword_noinline,
171175 Keyword_null,
172176 Keyword_or,
173177 Keyword_orelse,
test/compile_errors.zig+105
......@@ -2,6 +2,71 @@ const tests = @import("tests.zig");
22const builtin = @import("builtin");
33
44pub fn addCases(cases: *tests.CompileErrorContext) void {
5 cases.add(
6 "attempt to negate a non-integer, non-float or non-vector type",
7 \\fn foo() anyerror!u32 {
8 \\ return 1;
9 \\}
10 \\
11 \\export fn entry() void {
12 \\ const x = -foo();
13 \\}
14 ,
15 "tmp.zig:6:15: error: negation of type 'anyerror!u32'",
16 );
17
18 cases.add(
19 "attempt to create 17 bit float type",
20 \\const builtin = @import("builtin");
21 \\comptime {
22 \\ _ = @Type(builtin.TypeInfo { .Float = builtin.TypeInfo.Float { .bits = 17 } });
23 \\}
24 ,
25 "tmp.zig:3:32: error: 17-bit float unsupported",
26 );
27
28 cases.add(
29 "wrong type for @Type",
30 \\export fn entry() void {
31 \\ _ = @Type(0);
32 \\}
33 ,
34 "tmp.zig:2:15: error: expected type 'builtin.TypeInfo', found 'comptime_int'",
35 );
36
37 cases.add(
38 "@Type with non-constant expression",
39 \\const builtin = @import("builtin");
40 \\var globalTypeInfo : builtin.TypeInfo = undefined;
41 \\export fn entry() void {
42 \\ _ = @Type(globalTypeInfo);
43 \\}
44 ,
45 "tmp.zig:4:15: error: unable to evaluate constant expression",
46 );
47
48 cases.add(
49 "@Type with TypeInfo.Int",
50 \\const builtin = @import("builtin");
51 \\export fn entry() void {
52 \\ _ = @Type(builtin.TypeInfo.Int {
53 \\ .is_signed = true,
54 \\ .bits = 8,
55 \\ });
56 \\}
57 ,
58 "tmp.zig:3:36: error: expected type 'builtin.TypeInfo', found 'builtin.Int'",
59 );
60
61 cases.add(
62 "Struct unavailable for @Type",
63 \\export fn entry() void {
64 \\ _ = @Type(@typeInfo(struct { }));
65 \\}
66 ,
67 "tmp.zig:2:15: error: @Type not availble for 'TypeInfo.Struct'",
68 );
69
570 cases.add(
671 "wrong type for result ptr to @asyncCall",
772 \\export fn entry() void {
......@@ -18,6 +83,26 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1883 "tmp.zig:6:37: error: expected type '*i32', found 'bool'",
1984 );
2085
86 cases.add(
87 "shift amount has to be an integer type",
88 \\export fn entry() void {
89 \\ const x = 1 << &u8(10);
90 \\}
91 ,
92 "tmp.zig:2:23: error: shift amount has to be an integer type, but found '*u8'",
93 "tmp.zig:2:17: note: referenced here",
94 );
95
96 cases.add(
97 "bit shifting only works on integer types",
98 \\export fn entry() void {
99 \\ const x = &u8(1) << 10;
100 \\}
101 ,
102 "tmp.zig:2:18: error: bit shifting operation expected integer type, found '*u8'",
103 "tmp.zig:2:22: note: referenced here",
104 );
105
21106 cases.add(
22107 "struct depends on itself via optional field",
23108 \\const LhsExpr = struct {
......@@ -6462,4 +6547,24 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
64626547 "tmp.zig:5:30: error: expression value is ignored",
64636548 "tmp.zig:9:30: error: expression value is ignored",
64646549 );
6550
6551 cases.add(
6552 "aligned variable of zero-bit type",
6553 \\export fn f() void {
6554 \\ var s: struct {} align(4) = undefined;
6555 \\}
6556 ,
6557 "tmp.zig:2:5: error: variable 's' of zero-bit type 'struct:2:12' has no in-memory representation, it cannot be aligned",
6558 );
6559
6560 cases.add(
6561 "function returning opaque type",
6562 \\const FooType = @OpaqueType();
6563 \\export fn bar() !FooType {
6564 \\ return error.InvalidValue;
6565 \\}
6566 ,
6567 "tmp.zig:2:18: error: opaque return type 'FooType' not allowed",
6568 "tmp.zig:1:1: note: declared here",
6569 );
64656570}
test/runtime_safety.zig+15
......@@ -1,6 +1,21 @@
11const tests = @import("tests.zig");
22
33pub fn addCases(cases: *tests.CompareOutputContext) void {
4 cases.addRuntimeSafety("noasync function call, callee suspends",
5 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
6 \\ @import("std").os.exit(126);
7 \\}
8 \\pub fn main() void {
9 \\ _ = noasync add(101, 100);
10 \\}
11 \\fn add(a: i32, b: i32) i32 {
12 \\ if (a > 100) {
13 \\ suspend;
14 \\ }
15 \\ return a + b;
16 \\}
17 );
18
419 cases.addRuntimeSafety("awaiting twice",
520 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
621 \\ @import("std").os.exit(126);
test/stack_traces.zig created+355
......@@ -0,0 +1,355 @@
1const builtin = @import("builtin");
2const std = @import("std");
3const os = std.os;
4const tests = @import("tests.zig");
5
6pub fn addCases(cases: *tests.StackTracesContext) void {
7 const source_return =
8 \\const std = @import("std");
9 \\
10 \\pub fn main() !void {
11 \\ return error.TheSkyIsFalling;
12 \\}
13 ;
14 const source_try_return =
15 \\const std = @import("std");
16 \\
17 \\fn foo() !void {
18 \\ return error.TheSkyIsFalling;
19 \\}
20 \\
21 \\pub fn main() !void {
22 \\ try foo();
23 \\}
24 ;
25 const source_try_try_return_return =
26 \\const std = @import("std");
27 \\
28 \\fn foo() !void {
29 \\ try bar();
30 \\}
31 \\
32 \\fn bar() !void {
33 \\ return make_error();
34 \\}
35 \\
36 \\fn make_error() !void {
37 \\ return error.TheSkyIsFalling;
38 \\}
39 \\
40 \\pub fn main() !void {
41 \\ try foo();
42 \\}
43 ;
44 // zig fmt: off
45 switch (builtin.os) {
46 .freebsd => {
47 cases.addCase(
48 "return",
49 source_return,
50 [_][]const u8{
51 // debug
52 \\error: TheSkyIsFalling
53 \\source.zig:4:5: [address] in main (test)
54 \\
55 ,
56 // release-safe
57 \\error: TheSkyIsFalling
58 \\source.zig:4:5: [address] in std.special.main (test)
59 \\
60 ,
61 // release-fast
62 \\error: TheSkyIsFalling
63 \\
64 ,
65 // release-small
66 \\error: TheSkyIsFalling
67 \\
68 },
69 );
70 cases.addCase(
71 "try return",
72 source_try_return,
73 [_][]const u8{
74 // debug
75 \\error: TheSkyIsFalling
76 \\source.zig:4:5: [address] in foo (test)
77 \\source.zig:8:5: [address] in main (test)
78 \\
79 ,
80 // release-safe
81 \\error: TheSkyIsFalling
82 \\source.zig:4:5: [address] in std.special.main (test)
83 \\source.zig:8:5: [address] in std.special.main (test)
84 \\
85 ,
86 // release-fast
87 \\error: TheSkyIsFalling
88 \\
89 ,
90 // release-small
91 \\error: TheSkyIsFalling
92 \\
93 },
94 );
95 cases.addCase(
96 "try try return return",
97 source_try_try_return_return,
98 [_][]const u8{
99 // debug
100 \\error: TheSkyIsFalling
101 \\source.zig:12:5: [address] in make_error (test)
102 \\source.zig:8:5: [address] in bar (test)
103 \\source.zig:4:5: [address] in foo (test)
104 \\source.zig:16:5: [address] in main (test)
105 \\
106 ,
107 // release-safe
108 \\error: TheSkyIsFalling
109 \\source.zig:12:5: [address] in std.special.main (test)
110 \\source.zig:8:5: [address] in std.special.main (test)
111 \\source.zig:4:5: [address] in std.special.main (test)
112 \\source.zig:16:5: [address] in std.special.main (test)
113 \\
114 ,
115 // release-fast
116 \\error: TheSkyIsFalling
117 \\
118 ,
119 // release-small
120 \\error: TheSkyIsFalling
121 \\
122 },
123 );
124 },
125 .linux => {
126 cases.addCase(
127 "return",
128 source_return,
129 [_][]const u8{
130 // debug
131 \\error: TheSkyIsFalling
132 \\source.zig:4:5: [address] in main (test)
133 \\
134 ,
135 // release-safe
136 \\error: TheSkyIsFalling
137 \\source.zig:4:5: [address] in std.special.posixCallMainAndExit (test)
138 \\
139 ,
140 // release-fast
141 \\error: TheSkyIsFalling
142 \\
143 ,
144 // release-small
145 \\error: TheSkyIsFalling
146 \\
147 },
148 );
149 cases.addCase(
150 "try return",
151 source_try_return,
152 [_][]const u8{
153 // debug
154 \\error: TheSkyIsFalling
155 \\source.zig:4:5: [address] in foo (test)
156 \\source.zig:8:5: [address] in main (test)
157 \\
158 ,
159 // release-safe
160 \\error: TheSkyIsFalling
161 \\source.zig:4:5: [address] in std.special.posixCallMainAndExit (test)
162 \\source.zig:8:5: [address] in std.special.posixCallMainAndExit (test)
163 \\
164 ,
165 // release-fast
166 \\error: TheSkyIsFalling
167 \\
168 ,
169 // release-small
170 \\error: TheSkyIsFalling
171 \\
172 },
173 );
174 cases.addCase(
175 "try try return return",
176 source_try_try_return_return,
177 [_][]const u8{
178 // debug
179 \\error: TheSkyIsFalling
180 \\source.zig:12:5: [address] in make_error (test)
181 \\source.zig:8:5: [address] in bar (test)
182 \\source.zig:4:5: [address] in foo (test)
183 \\source.zig:16:5: [address] in main (test)
184 \\
185 ,
186 // release-safe
187 \\error: TheSkyIsFalling
188 \\source.zig:12:5: [address] in std.special.posixCallMainAndExit (test)
189 \\source.zig:8:5: [address] in std.special.posixCallMainAndExit (test)
190 \\source.zig:4:5: [address] in std.special.posixCallMainAndExit (test)
191 \\source.zig:16:5: [address] in std.special.posixCallMainAndExit (test)
192 \\
193 ,
194 // release-fast
195 \\error: TheSkyIsFalling
196 \\
197 ,
198 // release-small
199 \\error: TheSkyIsFalling
200 \\
201 },
202 );
203 },
204 .macosx => {
205 cases.addCase(
206 "return",
207 source_return,
208 [_][]const u8{
209 // debug
210 \\error: TheSkyIsFalling
211 \\source.zig:4:5: [address] in _main.0 (test.o)
212 \\
213 ,
214 // release-safe
215 \\error: TheSkyIsFalling
216 \\source.zig:4:5: [address] in _main (test.o)
217 \\
218 ,
219 // release-fast
220 \\error: TheSkyIsFalling
221 \\
222 ,
223 // release-small
224 \\error: TheSkyIsFalling
225 \\
226 },
227 );
228 cases.addCase(
229 "try return",
230 source_try_return,
231 [_][]const u8{
232 // debug
233 \\error: TheSkyIsFalling
234 \\source.zig:4:5: [address] in _foo (test.o)
235 \\source.zig:8:5: [address] in _main.0 (test.o)
236 \\
237 ,
238 // release-safe
239 \\error: TheSkyIsFalling
240 \\source.zig:4:5: [address] in _main (test.o)
241 \\source.zig:8:5: [address] in _main (test.o)
242 \\
243 ,
244 // release-fast
245 \\error: TheSkyIsFalling
246 \\
247 ,
248 // release-small
249 \\error: TheSkyIsFalling
250 \\
251 },
252 );
253 cases.addCase(
254 "try try return return",
255 source_try_try_return_return,
256 [_][]const u8{
257 // debug
258 \\error: TheSkyIsFalling
259 \\source.zig:12:5: [address] in _make_error (test.o)
260 \\source.zig:8:5: [address] in _bar (test.o)
261 \\source.zig:4:5: [address] in _foo (test.o)
262 \\source.zig:16:5: [address] in _main.0 (test.o)
263 \\
264 ,
265 // release-safe
266 \\error: TheSkyIsFalling
267 \\source.zig:12:5: [address] in _main (test.o)
268 \\source.zig:8:5: [address] in _main (test.o)
269 \\source.zig:4:5: [address] in _main (test.o)
270 \\source.zig:16:5: [address] in _main (test.o)
271 \\
272 ,
273 // release-fast
274 \\error: TheSkyIsFalling
275 \\
276 ,
277 // release-small
278 \\error: TheSkyIsFalling
279 \\
280 },
281 );
282 },
283 .windows => {
284 cases.addCase(
285 "return",
286 source_return,
287 [_][]const u8{
288 // debug
289 \\error: TheSkyIsFalling
290 \\source.zig:4:5: [address] in main (test.obj)
291 \\
292 ,
293 // release-safe
294 // --disabled-- results in segmenetation fault
295 "",
296 // release-fast
297 \\error: TheSkyIsFalling
298 \\
299 ,
300 // release-small
301 \\error: TheSkyIsFalling
302 \\
303 },
304 );
305 cases.addCase(
306 "try return",
307 source_try_return,
308 [_][]const u8{
309 // debug
310 \\error: TheSkyIsFalling
311 \\source.zig:4:5: [address] in foo (test.obj)
312 \\source.zig:8:5: [address] in main (test.obj)
313 \\
314 ,
315 // release-safe
316 // --disabled-- results in segmenetation fault
317 "",
318 // release-fast
319 \\error: TheSkyIsFalling
320 \\
321 ,
322 // release-small
323 \\error: TheSkyIsFalling
324 \\
325 },
326 );
327 cases.addCase(
328 "try try return return",
329 source_try_try_return_return,
330 [_][]const u8{
331 // debug
332 \\error: TheSkyIsFalling
333 \\source.zig:12:5: [address] in make_error (test.obj)
334 \\source.zig:8:5: [address] in bar (test.obj)
335 \\source.zig:4:5: [address] in foo (test.obj)
336 \\source.zig:16:5: [address] in main (test.obj)
337 \\
338 ,
339 // release-safe
340 // --disabled-- results in segmenetation fault
341 "",
342 // release-fast
343 \\error: TheSkyIsFalling
344 \\
345 ,
346 // release-small
347 \\error: TheSkyIsFalling
348 \\
349 },
350 );
351 },
352 else => {},
353 }
354 // zig fmt: off
355}
test/stage1/behavior.zig+1
......@@ -93,6 +93,7 @@ comptime {
9393 _ = @import("behavior/this.zig");
9494 _ = @import("behavior/truncate.zig");
9595 _ = @import("behavior/try.zig");
96 _ = @import("behavior/type.zig");
9697 _ = @import("behavior/type_info.zig");
9798 _ = @import("behavior/typename.zig");
9899 _ = @import("behavior/undefined.zig");
test/stage1/behavior/async_fn.zig+184-8
......@@ -921,12 +921,10 @@ fn recursiveAsyncFunctionTest(comptime suspending_implementation: bool) type {
921921 var sum: u32 = 0;
922922
923923 f1_awaited = true;
924 const result_f1 = await f1; // TODO https://github.com/ziglang/zig/issues/3077
925 sum += try result_f1;
924 sum += try await f1;
926925
927926 f2_awaited = true;
928 const result_f2 = await f2; // TODO https://github.com/ziglang/zig/issues/3077
929 sum += try result_f2;
927 sum += try await f2;
930928
931929 return sum;
932930 }
......@@ -943,8 +941,7 @@ fn recursiveAsyncFunctionTest(comptime suspending_implementation: bool) type {
943941
944942 fn amain(result: *u32) void {
945943 var x = async fib(std.heap.direct_allocator, 10);
946 const res = await x; // TODO https://github.com/ziglang/zig/issues/3077
947 result.* = res catch unreachable;
944 result.* = (await x) catch unreachable;
948945 }
949946 };
950947}
......@@ -1002,8 +999,7 @@ test "@asyncCall using the result location inside the frame" {
1002999 return 1234;
10031000 }
10041001 fn getAnswer(f: anyframe->i32, out: *i32) void {
1005 var res = await f; // TODO https://github.com/ziglang/zig/issues/3077
1006 out.* = res;
1002 out.* = await f;
10071003 }
10081004 };
10091005 var data: i32 = 1;
......@@ -1092,3 +1088,183 @@ test "recursive call of await @asyncCall with struct return type" {
10921088 expect(res.y == 2);
10931089 expect(res.z == 3);
10941090}
1091
1092test "noasync function call" {
1093 const S = struct {
1094 fn doTheTest() void {
1095 const result = noasync add(50, 100);
1096 expect(result == 150);
1097 }
1098 fn add(a: i32, b: i32) i32 {
1099 if (a > 100) {
1100 suspend;
1101 }
1102 return a + b;
1103 }
1104 };
1105 S.doTheTest();
1106}
1107
1108test "await used in expression and awaiting fn with no suspend but async calling convention" {
1109 const S = struct {
1110 fn atest() void {
1111 var f1 = async add(1, 2);
1112 var f2 = async add(3, 4);
1113
1114 const sum = (await f1) + (await f2);
1115 expect(sum == 10);
1116 }
1117 async fn add(a: i32, b: i32) i32 {
1118 return a + b;
1119 }
1120 };
1121 _ = async S.atest();
1122}
1123
1124test "await used in expression after a fn call" {
1125 const S = struct {
1126 fn atest() void {
1127 var f1 = async add(3, 4);
1128 var sum: i32 = 0;
1129 sum = foo() + await f1;
1130 expect(sum == 8);
1131 }
1132 async fn add(a: i32, b: i32) i32 {
1133 return a + b;
1134 }
1135 fn foo() i32 { return 1; }
1136 };
1137 _ = async S.atest();
1138}
1139
1140test "async fn call used in expression after a fn call" {
1141 const S = struct {
1142 fn atest() void {
1143 var sum: i32 = 0;
1144 sum = foo() + add(3, 4);
1145 expect(sum == 8);
1146 }
1147 async fn add(a: i32, b: i32) i32 {
1148 return a + b;
1149 }
1150 fn foo() i32 { return 1; }
1151 };
1152 _ = async S.atest();
1153}
1154
1155test "suspend in for loop" {
1156 const S = struct {
1157 var global_frame: ?anyframe = null;
1158
1159 fn doTheTest() void {
1160 _ = async atest();
1161 while (global_frame) |f| resume f;
1162 }
1163
1164 fn atest() void {
1165 expect(func([_]u8{ 1, 2, 3 }) == 6);
1166 }
1167 fn func(stuff: []const u8) u32 {
1168 global_frame = @frame();
1169 var sum: u32 = 0;
1170 for (stuff) |x| {
1171 suspend;
1172 sum += x;
1173 }
1174 global_frame = null;
1175 return sum;
1176 }
1177 };
1178 S.doTheTest();
1179}
1180
1181test "correctly spill when returning the error union result of another async fn" {
1182 const S = struct {
1183 var global_frame: anyframe = undefined;
1184
1185 fn doTheTest() void {
1186 expect((atest() catch unreachable) == 1234);
1187 }
1188
1189 fn atest() !i32 {
1190 return fallible1();
1191 }
1192
1193 fn fallible1() anyerror!i32 {
1194 suspend {
1195 global_frame = @frame();
1196 }
1197 return 1234;
1198 }
1199 };
1200 _ = async S.doTheTest();
1201 resume S.global_frame;
1202}
1203
1204
1205test "spill target expr in a for loop" {
1206 const S = struct {
1207 var global_frame: anyframe = undefined;
1208
1209 fn doTheTest() void {
1210 var foo = Foo{
1211 .slice = [_]i32{1, 2},
1212 };
1213 expect(atest(&foo) == 3);
1214 }
1215
1216 const Foo = struct {
1217 slice: []i32,
1218 };
1219
1220 fn atest(foo: *Foo) i32 {
1221 var sum: i32 = 0;
1222 for (foo.slice) |x| {
1223 suspend {
1224 global_frame = @frame();
1225 }
1226 sum += x;
1227 }
1228 return sum;
1229 }
1230 };
1231 _ = async S.doTheTest();
1232 resume S.global_frame;
1233 resume S.global_frame;
1234}
1235
1236test "spill target expr in a for loop, with a var decl in the loop body" {
1237 const S = struct {
1238 var global_frame: anyframe = undefined;
1239
1240 fn doTheTest() void {
1241 var foo = Foo{
1242 .slice = [_]i32{1, 2},
1243 };
1244 expect(atest(&foo) == 3);
1245 }
1246
1247 const Foo = struct {
1248 slice: []i32,
1249 };
1250
1251 fn atest(foo: *Foo) i32 {
1252 var sum: i32 = 0;
1253 for (foo.slice) |x| {
1254 // Previously this var decl would prevent spills. This test makes sure
1255 // the for loop spills still happen even though there is a VarDecl in scope
1256 // before the suspend.
1257 var anything = true;
1258 _ = anything;
1259 suspend {
1260 global_frame = @frame();
1261 }
1262 sum += x;
1263 }
1264 return sum;
1265 }
1266 };
1267 _ = async S.doTheTest();
1268 resume S.global_frame;
1269 resume S.global_frame;
1270}
test/stage1/behavior/enum.zig+14
......@@ -993,3 +993,17 @@ test "enum with one member and custom tag type" {
993993 };
994994 expect(@enumToInt(E2.One) == 2);
995995}
996
997test "enum literal casting to optional" {
998 var bar: ?Bar = undefined;
999 bar = .B;
1000
1001 expect(bar.? == Bar.B);
1002}
1003
1004test "enum literal casting to error union with payload enum" {
1005 var bar: error{B}!Bar = undefined;
1006 bar = .B; // should never cast to the error set
1007
1008 expect((try bar) == Bar.B);
1009}
test/stage1/behavior/if.zig+12
......@@ -74,3 +74,15 @@ test "const result loc, runtime if cond, else unreachable" {
7474 const x = if (t) Num.Two else unreachable;
7575 if (x != .Two) @compileError("bad");
7676}
77
78test "if prongs cast to expected type instead of peer type resolution" {
79 const S = struct {
80 fn doTheTest(f: bool) void {
81 var x: i32 = 0;
82 x = if (f) 1 else 2;
83 expect(x == 2);
84 }
85 };
86 S.doTheTest(false);
87 comptime S.doTheTest(false);
88}
test/stage1/behavior/sizeof_and_typeof.zig+9
......@@ -115,3 +115,12 @@ test "branching logic inside @typeOf" {
115115 comptime expect(T == i32);
116116 expect(S.data == 0);
117117}
118
119fn fn1(alpha: bool) void {
120 const n: usize = 7;
121 const v = if (alpha) n else @sizeOf(usize);
122}
123
124test "lazy @sizeOf result is checked for definedness" {
125 const f = fn1;
126}
test/stage1/behavior/struct.zig+59
......@@ -599,3 +599,62 @@ test "extern fn returns struct by value" {
599599 S.entry();
600600 comptime S.entry();
601601}
602
603test "for loop over pointers to struct, getting field from struct pointer" {
604 const S = struct {
605 const Foo = struct {
606 name: []const u8,
607 };
608
609 var ok = true;
610
611 fn eql(a: []const u8) bool {
612 return true;
613 }
614
615 const ArrayList = struct {
616 fn toSlice(self: *ArrayList) []*Foo {
617 return ([*]*Foo)(undefined)[0..0];
618 }
619 };
620
621 fn doTheTest() void {
622 var objects: ArrayList = undefined;
623
624 for (objects.toSlice()) |obj| {
625 if (eql(obj.name)) {
626 ok = false;
627 }
628 }
629
630 expect(ok);
631 }
632 };
633 S.doTheTest();
634}
635
636test "zero-bit field in packed struct" {
637 const S = packed struct {
638 x: u10,
639 y: void,
640 };
641 var x: S = undefined;
642}
643
644test "struct field init with catch" {
645 const S = struct {
646 fn doTheTest() void {
647 var x: anyerror!isize = 1;
648 var req = Foo{
649 .field = x catch undefined,
650 };
651 expect(req.field == 1);
652 }
653
654 pub const Foo = extern struct {
655 field: isize,
656 };
657 };
658 S.doTheTest();
659 comptime S.doTheTest();
660}
test/stage1/behavior/type.zig created+113
......@@ -0,0 +1,113 @@
1const builtin = @import("builtin");
2const TypeInfo = builtin.TypeInfo;
3
4const std = @import("std");
5const testing = std.testing;
6
7fn testTypes(comptime types: []const type) void {
8 inline for (types) |testType| {
9 testing.expect(testType == @Type(@typeInfo(testType)));
10 }
11}
12
13test "Type.MetaType" {
14 testing.expect(type == @Type(TypeInfo { .Type = undefined }));
15 testTypes([_]type {type});
16}
17
18test "Type.Void" {
19 testing.expect(void == @Type(TypeInfo { .Void = undefined }));
20 testTypes([_]type {void});
21}
22
23test "Type.Bool" {
24 testing.expect(bool == @Type(TypeInfo { .Bool = undefined }));
25 testTypes([_]type {bool});
26}
27
28test "Type.NoReturn" {
29 testing.expect(noreturn == @Type(TypeInfo { .NoReturn = undefined }));
30 testTypes([_]type {noreturn});
31}
32
33test "Type.Int" {
34 testing.expect(u1 == @Type(TypeInfo { .Int = TypeInfo.Int { .is_signed = false, .bits = 1 } }));
35 testing.expect(i1 == @Type(TypeInfo { .Int = TypeInfo.Int { .is_signed = true, .bits = 1 } }));
36 testing.expect(u8 == @Type(TypeInfo { .Int = TypeInfo.Int { .is_signed = false, .bits = 8 } }));
37 testing.expect(i8 == @Type(TypeInfo { .Int = TypeInfo.Int { .is_signed = true, .bits = 8 } }));
38 testing.expect(u64 == @Type(TypeInfo { .Int = TypeInfo.Int { .is_signed = false, .bits = 64 } }));
39 testing.expect(i64 == @Type(TypeInfo { .Int = TypeInfo.Int { .is_signed = true, .bits = 64 } }));
40 testTypes([_]type {u8,u32,i64});
41}
42
43test "Type.Float" {
44 testing.expect(f16 == @Type(TypeInfo { .Float = TypeInfo.Float { .bits = 16 } }));
45 testing.expect(f32 == @Type(TypeInfo { .Float = TypeInfo.Float { .bits = 32 } }));
46 testing.expect(f64 == @Type(TypeInfo { .Float = TypeInfo.Float { .bits = 64 } }));
47 testing.expect(f128 == @Type(TypeInfo { .Float = TypeInfo.Float { .bits = 128 } }));
48 testTypes([_]type {f16, f32, f64, f128});
49}
50
51test "Type.Pointer" {
52 testTypes([_]type {
53 // One Value Pointer Types
54 *u8, *const u8,
55 *volatile u8, *const volatile u8,
56 *align(4) u8, *const align(4) u8,
57 *volatile align(4) u8, *const volatile align(4) u8,
58 *align(8) u8, *const align(8) u8,
59 *volatile align(8) u8, *const volatile align(8) u8,
60 *allowzero u8, *const allowzero u8,
61 *volatile allowzero u8, *const volatile allowzero u8,
62 *align(4) allowzero u8, *const align(4) allowzero u8,
63 *volatile align(4) allowzero u8, *const volatile align(4) allowzero u8,
64 // Many Values Pointer Types
65 [*]u8, [*]const u8,
66 [*]volatile u8, [*]const volatile u8,
67 [*]align(4) u8, [*]const align(4) u8,
68 [*]volatile align(4) u8, [*]const volatile align(4) u8,
69 [*]align(8) u8, [*]const align(8) u8,
70 [*]volatile align(8) u8, [*]const volatile align(8) u8,
71 [*]allowzero u8, [*]const allowzero u8,
72 [*]volatile allowzero u8, [*]const volatile allowzero u8,
73 [*]align(4) allowzero u8, [*]const align(4) allowzero u8,
74 [*]volatile align(4) allowzero u8, [*]const volatile align(4) allowzero u8,
75 // Slice Types
76 []u8, []const u8,
77 []volatile u8, []const volatile u8,
78 []align(4) u8, []const align(4) u8,
79 []volatile align(4) u8, []const volatile align(4) u8,
80 []align(8) u8, []const align(8) u8,
81 []volatile align(8) u8, []const volatile align(8) u8,
82 []allowzero u8, []const allowzero u8,
83 []volatile allowzero u8, []const volatile allowzero u8,
84 []align(4) allowzero u8, []const align(4) allowzero u8,
85 []volatile align(4) allowzero u8, []const volatile align(4) allowzero u8,
86 // C Pointer Types
87 [*c]u8, [*c]const u8,
88 [*c]volatile u8, [*c]const volatile u8,
89 [*c]align(4) u8, [*c]const align(4) u8,
90 [*c]volatile align(4) u8, [*c]const volatile align(4) u8,
91 [*c]align(8) u8, [*c]const align(8) u8,
92 [*c]volatile align(8) u8, [*c]const volatile align(8) u8,
93 });
94}
95
96test "Type.Array" {
97 testing.expect([123]u8 == @Type(TypeInfo { .Array = TypeInfo.Array { .len = 123, .child = u8 } }));
98 testing.expect([2]u32 == @Type(TypeInfo { .Array = TypeInfo.Array { .len = 2, .child = u32 } }));
99 testTypes([_]type {[1]u8, [30]usize, [7]bool});
100}
101
102test "Type.ComptimeFloat" {
103 testTypes([_]type {comptime_float});
104}
105test "Type.ComptimeInt" {
106 testTypes([_]type {comptime_int});
107}
108test "Type.Undefined" {
109 testTypes([_]type {@typeOf(undefined)});
110}
111test "Type.Null" {
112 testTypes([_]type {@typeOf(null)});
113}
test/stage1/behavior/union.zig+37
......@@ -457,3 +457,40 @@ test "@unionInit can modify a pointer value" {
457457 value_ptr.* = @unionInit(UnionInitEnum, "Byte", 2);
458458 expect(value.Byte == 2);
459459}
460
461test "union no tag with struct member" {
462 const Struct = struct {};
463 const Union = union {
464 s: Struct,
465 pub fn foo(self: *@This()) void {}
466 };
467 var u = Union{ .s = Struct{} };
468 u.foo();
469}
470
471fn testComparison() void {
472 var x = Payload{.A = 42};
473 expect(x == .A);
474 expect(x != .B);
475 expect(x != .C);
476 expect((x == .B) == false);
477 expect((x == .C) == false);
478 expect((x != .A) == false);
479}
480
481test "comparison between union and enum literal" {
482 testComparison();
483 comptime testComparison();
484}
485
486test "packed union generates correctly aligned LLVM type" {
487 const U = packed union {
488 f1: fn () void,
489 f2: u32,
490 };
491 var foo = [_]U{
492 U{ .f1 = doTest },
493 U{ .f2 = 0 },
494 };
495 foo[0].f1();
496}
test/tests.zig+222-2
......@@ -16,13 +16,14 @@ const LibExeObjStep = build.LibExeObjStep;
1616
1717const compare_output = @import("compare_output.zig");
1818const standalone = @import("standalone.zig");
19const stack_traces = @import("stack_traces.zig");
1920const compile_errors = @import("compile_errors.zig");
2021const assemble_and_link = @import("assemble_and_link.zig");
2122const runtime_safety = @import("runtime_safety.zig");
2223const translate_c = @import("translate_c.zig");
2324const gen_h = @import("gen_h.zig");
2425
25const test_targets = [_]CrossTarget{
26const cross_targets = [_]CrossTarget{
2627 CrossTarget{
2728 .os = .linux,
2829 .arch = .x86_64,
......@@ -57,6 +58,21 @@ pub fn addCompareOutputTests(b: *build.Builder, test_filter: ?[]const u8, modes:
5758 return cases.step;
5859}
5960
61pub fn addStackTraceTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step {
62 const cases = b.allocator.create(StackTracesContext) catch unreachable;
63 cases.* = StackTracesContext{
64 .b = b,
65 .step = b.step("test-stack-traces", "Run the stack trace tests"),
66 .test_index = 0,
67 .test_filter = test_filter,
68 .modes = modes,
69 };
70
71 stack_traces.addCases(cases);
72
73 return cases.step;
74}
75
6076pub fn addRuntimeSafetyTests(b: *build.Builder, test_filter: ?[]const u8, modes: []const Mode) *build.Step {
6177 const cases = b.allocator.create(CompareOutputContext) catch unreachable;
6278 cases.* = CompareOutputContext{
......@@ -170,7 +186,17 @@ pub fn addPkgTests(
170186 skip_non_native: bool,
171187) *build.Step {
172188 const step = b.step(b.fmt("test-{}", name), desc);
173 for (test_targets) |test_target| {
189
190 var targets = std.ArrayList(*const CrossTarget).init(b.allocator);
191 defer targets.deinit();
192 const host = CrossTarget{ .os = builtin.os, .arch = builtin.arch, .abi = builtin.abi };
193 targets.append(&host) catch unreachable;
194 for (cross_targets) |*t| {
195 if (t.os == builtin.os and t.arch == builtin.arch and t.abi == builtin.abi) continue;
196 targets.append(t) catch unreachable;
197 }
198
199 for (targets.toSliceConst()) |test_target| {
174200 const is_native = (test_target.os == builtin.os and test_target.arch == builtin.arch);
175201 if (skip_non_native and !is_native)
176202 continue;
......@@ -549,6 +575,200 @@ pub const CompareOutputContext = struct {
549575 }
550576};
551577
578pub const StackTracesContext = struct {
579 b: *build.Builder,
580 step: *build.Step,
581 test_index: usize,
582 test_filter: ?[]const u8,
583 modes: []const Mode,
584
585 const Expect = [@typeInfo(Mode).Enum.fields.len][]const u8;
586
587 pub fn addCase(
588 self: *StackTracesContext,
589 name: []const u8,
590 source: []const u8,
591 expect: Expect,
592 ) void {
593 const b = self.b;
594
595 const source_pathname = fs.path.join(
596 b.allocator,
597 [_][]const u8{ b.cache_root, "source.zig" },
598 ) catch unreachable;
599
600 for (self.modes) |mode| {
601 const expect_for_mode = expect[@enumToInt(mode)];
602 if (expect_for_mode.len == 0) continue;
603
604 const annotated_case_name = fmt.allocPrint(self.b.allocator, "{} {} ({})", "stack-trace", name, @tagName(mode)) catch unreachable;
605 if (self.test_filter) |filter| {
606 if (mem.indexOf(u8, annotated_case_name, filter) == null) continue;
607 }
608
609 const exe = b.addExecutable("test", source_pathname);
610 exe.setBuildMode(mode);
611
612 const write_source = b.addWriteFile(source_pathname, source);
613 exe.step.dependOn(&write_source.step);
614
615 const run_and_compare = RunAndCompareStep.create(
616 self,
617 exe,
618 annotated_case_name,
619 mode,
620 expect_for_mode,
621 );
622
623 self.step.dependOn(&run_and_compare.step);
624 }
625 }
626
627 const RunAndCompareStep = struct {
628 step: build.Step,
629 context: *StackTracesContext,
630 exe: *LibExeObjStep,
631 name: []const u8,
632 mode: Mode,
633 expect_output: []const u8,
634 test_index: usize,
635
636 pub fn create(
637 context: *StackTracesContext,
638 exe: *LibExeObjStep,
639 name: []const u8,
640 mode: Mode,
641 expect_output: []const u8,
642 ) *RunAndCompareStep {
643 const allocator = context.b.allocator;
644 const ptr = allocator.create(RunAndCompareStep) catch unreachable;
645 ptr.* = RunAndCompareStep{
646 .step = build.Step.init("StackTraceCompareOutputStep", allocator, make),
647 .context = context,
648 .exe = exe,
649 .name = name,
650 .mode = mode,
651 .expect_output = expect_output,
652 .test_index = context.test_index,
653 };
654 ptr.step.dependOn(&exe.step);
655 context.test_index += 1;
656 return ptr;
657 }
658
659 fn make(step: *build.Step) !void {
660 const self = @fieldParentPtr(RunAndCompareStep, "step", step);
661 const b = self.context.b;
662
663 const full_exe_path = self.exe.getOutputPath();
664 var args = ArrayList([]const u8).init(b.allocator);
665 defer args.deinit();
666 args.append(full_exe_path) catch unreachable;
667
668 warn("Test {}/{} {}...", self.test_index + 1, self.context.test_index, self.name);
669
670 const child = std.ChildProcess.init(args.toSliceConst(), b.allocator) catch unreachable;
671 defer child.deinit();
672
673 child.stdin_behavior = .Ignore;
674 child.stdout_behavior = .Pipe;
675 child.stderr_behavior = .Pipe;
676 child.env_map = b.env_map;
677
678 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
679
680 var stdout = Buffer.initNull(b.allocator);
681 var stderr = Buffer.initNull(b.allocator);
682
683 var stdout_file_in_stream = child.stdout.?.inStream();
684 var stderr_file_in_stream = child.stderr.?.inStream();
685
686 stdout_file_in_stream.stream.readAllBuffer(&stdout, max_stdout_size) catch unreachable;
687 stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size) catch unreachable;
688
689 const term = child.wait() catch |err| {
690 debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
691 };
692
693 switch (term) {
694 .Exited => |code| {
695 const expect_code: u32 = 1;
696 if (code != expect_code) {
697 warn("Process {} exited with error code {} but expected code {}\n", full_exe_path, code, expect_code);
698 printInvocation(args.toSliceConst());
699 return error.TestFailed;
700 }
701 },
702 .Signal => |signum| {
703 warn("Process {} terminated on signal {}\n", full_exe_path, signum);
704 printInvocation(args.toSliceConst());
705 return error.TestFailed;
706 },
707 .Stopped => |signum| {
708 warn("Process {} stopped on signal {}\n", full_exe_path, signum);
709 printInvocation(args.toSliceConst());
710 return error.TestFailed;
711 },
712 .Unknown => |code| {
713 warn("Process {} terminated unexpectedly with error code {}\n", full_exe_path, code);
714 printInvocation(args.toSliceConst());
715 return error.TestFailed;
716 },
717 }
718
719 // process result
720 // - keep only basename of source file path
721 // - replace address with symbolic string
722 // - skip empty lines
723 const got: []const u8 = got_result: {
724 var buf = try Buffer.initSize(b.allocator, 0);
725 defer buf.deinit();
726 var bytes = stderr.toSliceConst();
727 if (bytes.len != 0 and bytes[bytes.len - 1] == '\n') bytes = bytes[0 .. bytes.len - 1];
728 var it = mem.separate(bytes, "\n");
729 process_lines: while (it.next()) |line| {
730 if (line.len == 0) continue;
731 const delims = [_][]const u8{ ":", ":", ":", " in " };
732 var marks = [_]usize{0} ** 4;
733 // offset search past `[drive]:` on windows
734 var pos: usize = if (builtin.os == .windows) 2 else 0;
735 for (delims) |delim, i| {
736 marks[i] = mem.indexOfPos(u8, line, pos, delim) orelse {
737 try buf.append(line);
738 try buf.append("\n");
739 continue :process_lines;
740 };
741 pos = marks[i] + delim.len;
742 }
743 pos = mem.lastIndexOfScalar(u8, line[0..marks[0]], fs.path.sep) orelse {
744 try buf.append(line);
745 try buf.append("\n");
746 continue :process_lines;
747 };
748 try buf.append(line[pos + 1 .. marks[2] + delims[2].len]);
749 try buf.append(" [address]");
750 try buf.append(line[marks[3]..]);
751 try buf.append("\n");
752 }
753 break :got_result buf.toOwnedSlice();
754 };
755
756 if (!mem.eql(u8, self.expect_output, got)) {
757 warn(
758 \\
759 \\========= Expected this output: =========
760 \\{}
761 \\================================================
762 \\{}
763 \\
764 , self.expect_output, got);
765 return error.TestFailed;
766 }
767 warn("OK\n");
768 }
769 };
770};
771
552772pub const CompileErrorContext = struct {
553773 b: *build.Builder,
554774 step: *build.Step,
tools/process_headers.zig+70-326
......@@ -20,6 +20,7 @@ const assert = std.debug.assert;
2020const LibCTarget = struct {
2121 name: []const u8,
2222 arch: MultiArch,
23 abi: MultiAbi,
2324};
2425
2526const MultiArch = union(enum) {
......@@ -39,396 +40,129 @@ const MultiArch = union(enum) {
3940 }
4041};
4142
43const MultiAbi = union(enum) {
44 musl,
45 specific: Abi,
46
47 fn eql(a: MultiAbi, b: MultiAbi) bool {
48 if (@enumToInt(a) != @enumToInt(b))
49 return false;
50 if (@TagType(MultiAbi)(a) != .specific)
51 return true;
52 return a.specific == b.specific;
53 }
54};
55
4256const glibc_targets = [_]LibCTarget{
4357 LibCTarget{
4458 .name = "aarch64_be-linux-gnu",
45 .zig_arch = Arch.aarch64_be,
46 .zig_abi = Abi.gnu,
59 .arch = MultiArch {.specific = Arch.aarch64_be},
60 .abi = MultiAbi {.specific = Abi.gnu},
4761 },
4862 LibCTarget{
4963 .name = "aarch64-linux-gnu",
50 .zig_arch = Arch.aarch64,
51 .zig_abi = Abi.gnu,
52 },
53 LibCTarget{
54 .name = "aarch64-linux-gnu-disable-multi-arch",
55 .zig_arch = Arch.aarch64,
56 .zig_abi = null,
57 },
58 LibCTarget{
59 .name = "alpha-linux-gnu",
60 .zig_arch = null,
61 .zig_abi = Abi.gnu,
64 .arch = MultiArch {.specific = Arch.aarch64},
65 .abi = MultiAbi {.specific = Abi.gnu},
6266 },
6367 LibCTarget{
6468 .name = "armeb-linux-gnueabi",
65 .zig_arch = Arch.armeb,
66 .zig_abi = Abi.gnueabi,
67 },
68 LibCTarget{
69 .name = "armeb-linux-gnueabi-be8",
70 .zig_arch = Arch.armeb,
71 .zig_abi = null,
69 .arch = MultiArch {.specific = Arch.armeb},
70 .abi = MultiAbi {.specific = Abi.gnueabi},
7271 },
7372 LibCTarget{
7473 .name = "armeb-linux-gnueabihf",
75 .zig_arch = Arch.armeb,
76 .zig_abi = Abi.gnueabihf,
77 },
78 LibCTarget{
79 .name = "armeb-linux-gnueabihf-be8",
80 .zig_arch = Arch.armeb,
81 .zig_abi = null,
74 .arch = MultiArch {.specific = Arch.armeb},
75 .abi = MultiAbi {.specific = Abi.gnueabihf},
8276 },
8377 LibCTarget{
8478 .name = "arm-linux-gnueabi",
85 .zig_arch = Arch.arm,
86 .zig_abi = Abi.gnueabi,
79 .arch = MultiArch {.specific = Arch.arm},
80 .abi = MultiAbi {.specific = Abi.gnueabi},
8781 },
8882 LibCTarget{
8983 .name = "arm-linux-gnueabihf",
90 .zig_arch = Arch.arm,
91 .zig_abi = Abi.gnueabihf,
92 },
93 LibCTarget{
94 .name = "arm-linux-gnueabihf-v7a",
95 .zig_arch = Arch.arm,
96 .zig_abi = null,
97 },
98 LibCTarget{
99 .name = "arm-linux-gnueabihf-v7a-disable-multi-arch",
100 .zig_arch = null,
101 .zig_abi = null,
102 },
103 LibCTarget{
104 .name = "hppa-linux-gnu",
105 .zig_arch = null,
106 .zig_abi = Abi.gnu,
107 },
108 LibCTarget{
109 .name = "i486-linux-gnu",
110 .zig_arch = null,
111 .zig_abi = Abi.gnu,
112 },
113 LibCTarget{
114 .name = "i586-linux-gnu",
115 .zig_arch = null,
116 .zig_abi = Abi.gnu,
117 },
118 LibCTarget{
119 .name = "i686-gnu",
120 .zig_arch = Arch.i386,
121 .zig_abi = Abi.gnu,
84 .arch = MultiArch {.specific = Arch.arm},
85 .abi = MultiAbi {.specific = Abi.gnueabihf},
12286 },
12387 LibCTarget{
12488 .name = "i686-linux-gnu",
125 .zig_arch = Arch.i386,
126 .zig_abi = Abi.gnu,
127 },
128 LibCTarget{
129 .name = "i686-linux-gnu-disable-multi-arch",
130 .zig_arch = null,
131 .zig_abi = null,
132 },
133 LibCTarget{
134 .name = "i686-linux-gnu-enable-obsolete",
135 .zig_arch = Arch.i386,
136 .zig_abi = null,
137 },
138 LibCTarget{
139 .name = "i686-linux-gnu-static-pie",
140 .zig_arch = Arch.i386,
141 .zig_abi = null,
142 },
143 LibCTarget{
144 .name = "ia64-linux-gnu",
145 .zig_arch = null,
146 .zig_abi = null,
147 },
148 LibCTarget{
149 .name = "m68k-linux-gnu",
150 .zig_arch = null,
151 .zig_abi = null,
152 },
153 LibCTarget{
154 .name = "m68k-linux-gnu-coldfire",
155 .zig_arch = null,
156 .zig_abi = null,
157 },
158 LibCTarget{
159 .name = "m68k-linux-gnu-coldfire-soft",
160 .zig_arch = null,
161 .zig_abi = null,
162 },
163 LibCTarget{
164 .name = "microblazeel-linux-gnu",
165 .zig_arch = null,
166 .zig_abi = null,
167 },
168 LibCTarget{
169 .name = "microblaze-linux-gnu",
170 .zig_arch = null,
171 .zig_abi = null,
89 .arch = MultiArch {.specific = Arch.i386},
90 .abi = MultiAbi {.specific = Abi.gnu},
17291 },
17392 LibCTarget{
17493 .name = "mips64el-linux-gnu-n32",
175 .zig_arch = Arch.mips64el,
176 .zig_abi = Abi.gnuabin32,
177 },
178 LibCTarget{
179 .name = "mips64el-linux-gnu-n32-nan2008",
180 .zig_arch = Arch.mips64el,
181 .zig_abi = null,
182 },
183 LibCTarget{
184 .name = "mips64el-linux-gnu-n32-nan2008-soft",
185 .zig_arch = Arch.mips64el,
186 .zig_abi = null,
187 },
188 LibCTarget{
189 .name = "mips64el-linux-gnu-n32-soft",
190 .zig_arch = Arch.mips64el,
191 .zig_abi = null,
94 .arch = MultiArch {.specific = Arch.mips64el},
95 .abi = MultiAbi {.specific = Abi.gnuabin32},
19296 },
19397 LibCTarget{
19498 .name = "mips64el-linux-gnu-n64",
195 .zig_arch = Arch.mips64el,
196 .zig_abi = Abi.gnuabi64,
197 },
198 LibCTarget{
199 .name = "mips64el-linux-gnu-n64-nan2008",
200 .zig_arch = Arch.mips64el,
201 .zig_abi = null,
202 },
203 LibCTarget{
204 .name = "mips64el-linux-gnu-n64-nan2008-soft",
205 .zig_arch = Arch.mips64el,
206 .zig_abi = null,
207 },
208 LibCTarget{
209 .name = "mips64el-linux-gnu-n64-soft",
210 .zig_arch = Arch.mips64el,
211 .zig_abi = null,
99 .arch = MultiArch {.specific = Arch.mips64el},
100 .abi = MultiAbi {.specific = Abi.gnuabi64},
212101 },
213102 LibCTarget{
214103 .name = "mips64-linux-gnu-n32",
215 .zig_arch = Arch.mips64,
216 .zig_abi = Abi.gnuabin32,
217 },
218 LibCTarget{
219 .name = "mips64-linux-gnu-n32-nan2008",
220 .zig_arch = Arch.mips64,
221 .zig_abi = null,
222 },
223 LibCTarget{
224 .name = "mips64-linux-gnu-n32-nan2008-soft",
225 .zig_arch = Arch.mips64,
226 .zig_abi = null,
227 },
228 LibCTarget{
229 .name = "mips64-linux-gnu-n32-soft",
230 .zig_arch = Arch.mips64,
231 .zig_abi = null,
104 .arch = MultiArch {.specific = Arch.mips64},
105 .abi = MultiAbi {.specific = Abi.gnuabin32},
232106 },
233107 LibCTarget{
234108 .name = "mips64-linux-gnu-n64",
235 .zig_arch = Arch.mips64,
236 .zig_abi = Abi.gnuabi64,
237 },
238 LibCTarget{
239 .name = "mips64-linux-gnu-n64-nan2008",
240 .zig_arch = Arch.mips64,
241 .zig_abi = null,
242 },
243 LibCTarget{
244 .name = "mips64-linux-gnu-n64-nan2008-soft",
245 .zig_arch = Arch.mips64,
246 .zig_abi = null,
247 },
248 LibCTarget{
249 .name = "mips64-linux-gnu-n64-soft",
250 .zig_arch = Arch.mips64,
251 .zig_abi = null,
109 .arch = MultiArch {.specific = Arch.mips64},
110 .abi = MultiAbi {.specific = Abi.gnuabi64},
252111 },
253112 LibCTarget{
254113 .name = "mipsel-linux-gnu",
255 .zig_arch = Arch.mipsel,
256 .zig_abi = Abi.gnu,
257 },
258 LibCTarget{
259 .name = "mipsel-linux-gnu-nan2008",
260 .zig_arch = Arch.mipsel,
261 .zig_abi = null,
262 },
263 LibCTarget{
264 .name = "mipsel-linux-gnu-nan2008-soft",
265 .zig_arch = Arch.mipsel,
266 .zig_abi = null,
267 },
268 LibCTarget{
269 .name = "mipsel-linux-gnu-soft",
270 .zig_arch = Arch.mipsel,
271 .zig_abi = null,
114 .arch = MultiArch {.specific = Arch.mipsel},
115 .abi = MultiAbi {.specific = Abi.gnu},
272116 },
273117 LibCTarget{
274118 .name = "mips-linux-gnu",
275 .zig_arch = Arch.mips,
276 .zig_abi = Abi.gnu,
277 },
278 LibCTarget{
279 .name = "mips-linux-gnu-nan2008",
280 .zig_arch = Arch.mips,
281 .zig_abi = null,
282 },
283 LibCTarget{
284 .name = "mips-linux-gnu-nan2008-soft",
285 .zig_arch = Arch.mips,
286 .zig_abi = null,
287 },
288 LibCTarget{
289 .name = "mips-linux-gnu-soft",
290 .zig_arch = Arch.mips,
291 .zig_abi = null,
119 .arch = MultiArch {.specific = Arch.mips},
120 .abi = MultiAbi {.specific = Abi.gnu},
292121 },
293122 LibCTarget{
294123 .name = "powerpc64le-linux-gnu",
295 .zig_arch = Arch.powerpc64le,
296 .zig_abi = Abi.gnu,
124 .arch = MultiArch {.specific = Arch.powerpc64le},
125 .abi = MultiAbi {.specific = Abi.gnu},
297126 },
298127 LibCTarget{
299128 .name = "powerpc64-linux-gnu",
300 .zig_arch = Arch.powerpc64,
301 .zig_abi = Abi.gnu,
129 .arch = MultiArch {.specific = Arch.powerpc64},
130 .abi = MultiAbi {.specific = Abi.gnu},
302131 },
303132 LibCTarget{
304133 .name = "powerpc-linux-gnu",
305 .zig_arch = Arch.powerpc,
306 .zig_abi = Abi.gnu,
307 },
308 LibCTarget{
309 .name = "powerpc-linux-gnu-power4",
310 .zig_arch = Arch.powerpc,
311 .zig_abi = null,
312 },
313 LibCTarget{
314 .name = "powerpc-linux-gnu-soft",
315 .zig_arch = Arch.powerpc,
316 .zig_abi = null,
317 },
318 LibCTarget{
319 .name = "powerpc-linux-gnuspe",
320 .zig_arch = Arch.powerpc,
321 .zig_abi = null,
322 },
323 LibCTarget{
324 .name = "powerpc-linux-gnuspe-e500v1",
325 .zig_arch = Arch.powerpc,
326 .zig_abi = null,
134 .arch = MultiArch {.specific = Arch.powerpc},
135 .abi = MultiAbi {.specific = Abi.gnu},
327136 },
328137 LibCTarget{
329138 .name = "riscv64-linux-gnu-rv64imac-lp64",
330 .zig_arch = Arch.riscv64,
331 .zig_abi = Abi.gnu,
332 },
333 LibCTarget{
334 .name = "riscv64-linux-gnu-rv64imafdc-lp64",
335 .zig_arch = Arch.riscv64,
336 .zig_abi = null,
337 },
338 LibCTarget{
339 .name = "riscv64-linux-gnu-rv64imafdc-lp64d",
340 .zig_arch = Arch.riscv64,
341 .zig_abi = null,
342 },
343 LibCTarget{
344 .name = "s390-linux-gnu",
345 .zig_arch = null,
346 .zig_abi = Abi.gnu,
139 .arch = MultiArch {.specific = Arch.riscv64},
140 .abi = MultiAbi {.specific = Abi.gnu},
347141 },
348142 LibCTarget{
349143 .name = "s390x-linux-gnu",
350 .zig_arch = Arch.s390x,
351 .zig_abi = Abi.gnu,
352 },
353 LibCTarget{
354 .name = "sh3eb-linux-gnu",
355 .zig_arch = null,
356 .zig_abi = Abi.gnu,
357 },
358 LibCTarget{
359 .name = "sh3-linux-gnu",
360 .zig_arch = null,
361 .zig_abi = Abi.gnu,
362 },
363 LibCTarget{
364 .name = "sh4eb-linux-gnu",
365 .zig_arch = null,
366 .zig_abi = Abi.gnu,
367 },
368 LibCTarget{
369 .name = "sh4eb-linux-gnu-soft",
370 .zig_arch = null,
371 .zig_abi = null,
372 },
373 LibCTarget{
374 .name = "sh4-linux-gnu",
375 .zig_arch = null,
376 .zig_abi = Abi.gnu,
377 },
378 LibCTarget{
379 .name = "sh4-linux-gnu-soft",
380 .zig_arch = null,
381 .zig_abi = null,
144 .arch = MultiArch {.specific = Arch.s390x},
145 .abi = MultiAbi {.specific = Abi.gnu},
382146 },
383147 LibCTarget{
384148 .name = "sparc64-linux-gnu",
385 .zig_arch = Arch.sparc,
386 .zig_abi = Abi.gnu,
387 },
388 LibCTarget{
389 .name = "sparc64-linux-gnu-disable-multi-arch",
390 .zig_arch = Arch.sparc,
391 .zig_abi = null,
149 .arch = MultiArch {.specific = Arch.sparc},
150 .abi = MultiAbi {.specific = Abi.gnu},
392151 },
393152 LibCTarget{
394153 .name = "sparcv9-linux-gnu",
395 .zig_arch = Arch.sparcv9,
396 .zig_abi = Abi.gnu,
397 },
398 LibCTarget{
399 .name = "sparcv9-linux-gnu-disable-multi-arch",
400 .zig_arch = Arch.sparcv9,
401 .zig_abi = null,
154 .arch = MultiArch {.specific = Arch.sparcv9},
155 .abi = MultiAbi {.specific = Abi.gnu},
402156 },
403157 LibCTarget{
404158 .name = "x86_64-linux-gnu",
405 .zig_arch = Arch.x86_64,
406 .zig_abi = Abi.gnu,
407 },
408 LibCTarget{
409 .name = "x86_64-linux-gnu-disable-multi-arch",
410 .zig_arch = Arch.x86_64,
411 .zig_abi = null,
412 },
413 LibCTarget{
414 .name = "x86_64-linux-gnu-enable-obsolete",
415 .zig_arch = Arch.x86_64,
416 .zig_abi = null,
417 },
418 LibCTarget{
419 .name = "x86_64-linux-gnu-static-pie",
420 .zig_arch = Arch.x86_64,
421 .zig_abi = null,
159 .arch = MultiArch {.specific = Arch.x86_64},
160 .abi = MultiAbi {.specific = Abi.gnu},
422161 },
423162 LibCTarget{
424163 .name = "x86_64-linux-gnu-x32",
425 .zig_arch = Arch.x86_64,
426 .zig_abi = Abi.gnux32,
427 },
428 LibCTarget{
429 .name = "x86_64-linux-gnu-x32-static-pie",
430 .zig_arch = Arch.x86_64,
431 .zig_abi = null,
164 .arch = MultiArch {.specific = Arch.x86_64},
165 .abi = MultiAbi {.specific = Abi.gnux32},
432166 },
433167};
434168
......@@ -436,42 +170,52 @@ const musl_targets = [_]LibCTarget{
436170 LibCTarget{
437171 .name = "aarch64",
438172 .arch = MultiArch.aarch64,
173 .abi = MultiAbi.musl,
439174 },
440175 LibCTarget{
441176 .name = "arm",
442177 .arch = MultiArch.arm,
178 .abi = MultiAbi.musl,
443179 },
444180 LibCTarget{
445181 .name = "i386",
446182 .arch = MultiArch{ .specific = .i386 },
183 .abi = MultiAbi.musl,
447184 },
448185 LibCTarget{
449186 .name = "mips",
450187 .arch = MultiArch.mips,
188 .abi = MultiAbi.musl,
451189 },
452190 LibCTarget{
453191 .name = "mips64",
454192 .arch = MultiArch.mips64,
193 .abi = MultiAbi.musl,
455194 },
456195 LibCTarget{
457196 .name = "powerpc",
458197 .arch = MultiArch{ .specific = .powerpc },
198 .abi = MultiAbi.musl,
459199 },
460200 LibCTarget{
461201 .name = "powerpc64",
462202 .arch = MultiArch.powerpc64,
203 .abi = MultiAbi.musl,
463204 },
464205 LibCTarget{
465206 .name = "riscv64",
466207 .arch = MultiArch{ .specific = .riscv64 },
208 .abi = MultiAbi.musl,
467209 },
468210 LibCTarget{
469211 .name = "s390x",
470212 .arch = MultiArch{ .specific = .s390x },
213 .abi = MultiAbi.musl,
471214 },
472215 LibCTarget{
473216 .name = "x86_64",
474217 .arch = MultiArch{ .specific = .x86_64 },
218 .abi = MultiAbi.musl,
475219 },
476220};
477221
......@@ -562,7 +306,7 @@ pub fn main() !void {
562306 var libc_targets: []const LibCTarget = undefined;
563307 switch (vendor) {
564308 .musl => libc_targets = musl_targets,
565 .glibc => @panic("TODO this regressed"), // glibc_targets,
309 .glibc => libc_targets = glibc_targets,
566310 }
567311
568312 var path_table = PathTable.init(allocator);
......@@ -577,7 +321,7 @@ pub fn main() !void {
577321 .arch = libc_target.arch,
578322 .abi = switch (vendor) {
579323 .musl => .musl,
580 else => @panic("TODO this regressed"),
324 .glibc => libc_target.abi.specific,
581325 },
582326 .os = .linux,
583327 };
tools/update_glibc.zig+1-1
......@@ -135,7 +135,7 @@ pub fn main() !void {
135135 const allocator = &arena.allocator;
136136 const args = try std.process.argsAlloc(allocator);
137137 const in_glibc_dir = args[1]; // path to the unzipped tarball of glibc, e.g. ~/downloads/glibc-2.25
138 const zig_src_dir = args[2]; // path to the source checkout of zig
138 const zig_src_dir = args[2]; // path to the source checkout of zig, lib dir, e.g. ~/zig-src/lib
139139
140140 const prefix = try fs.path.join(allocator, [_][]const u8{ in_glibc_dir, "sysdeps", "unix", "sysv", "linux" });
141141 const glibc_out_dir = try fs.path.join(allocator, [_][]const u8{ zig_src_dir, "libc", "glibc" });