authorgravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2026-10-23 08:00:41+02:00
committergravatar for squeek502@hotmail.comRyan Liptak <squeek502@hotmail.com> 2026-10-23 08:00:41+02:00
logfb255db0adc7fb39f4d33738fcf3c5831a1a7649
treea5ade7b27a5c2002ffacb7ba02d21c0dd75e9049
parent0a01fe2bc6748b5fa2b03cebdcaae0e655501ad4
parent755333971b19907375410c131433668528bb1bc0

Merge pull request 'Parser: Add error when operator precedence is undefined' (#30160) from CMDRZero/zig:ambiguous-precedence into master

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30160 Reviewed-by: Ryan Liptak <squeek502@noreply.codeberg.org>

114 files changed, 1588 insertions(+), 508 deletions(-)

doc/langref.html.in+100-7
...@@ -1894,20 +1894,77 @@ const B = error{Two};...@@ -1894,20 +1894,77 @@ const B = error{Two};
1894 </div>1894 </div>
1895 {#header_close#}1895 {#header_close#}
1896 {#header_open|Precedence#}1896 {#header_open|Precedence#}
1897 <p>
1898 Zig features partial operator precedence: not every operator has a defined precedence with
1899 every other operator. Mixing operators with ambiguous precedence is prohibited and parentheses
1900 are mandatory. Consequently, valid code is typically auto-descriptive; when reading and
1901 writing Zig code, there are very few precedence rules you'll need to remember.
1902 </p>
1903
1904 {#code|operator_precedence.zig#}
1905
1906 {#code|ambiguous_precedence_orelse.zig#}
1907
1908 <p>
1909 There is a set of operators (prefix operators, suffix operators, etc) that have unambiguously
1910 higher precedence than all other operators. That set of operators has the following precedence table:
1911 </p>
1912
1897 <pre>{#syntax#}x() x[] x.y x.* x.?1913 <pre>{#syntax#}x() x[] x.y x.* x.?
1898a!b1914a!b
1899x{}1915x{}
1900!x -x -%x ~x &x ?x try1916!x -x -%x ~x &x ?x try
1901* / % *% *| ||1917// lower precedence operators omitted{#endsyntax#}</pre>
1902+ - ++ +% -% +| -|1918
1903<< >> <<|1919 <p>
1904& ^ | orelse catch1920 For the other operators, simplified operator precedence tables are provided below, each containing only
1921 the information that you'll need to know when reading/writing code that uses that particular category of operators.
1922 The operators that have ambiguous precedence or semantic errors with the relevant operators have been omitted,
1923 as have the operators with higher precedence (those shown above).
1924 </p>
1925
1926 <p>
1927 For arithmetic operators:
1928 </p>
1929
1930 <pre>{#syntax#}* / *% *| %
1931+ - +% -% +| -|
1932== != < > <= >=
1933and or{#endsyntax#}</pre>
1934
1935 <p>
1936 For bitwise operators:
1937 </p>
1938
1939 <pre>{#syntax#}<< <<| >> & ^ |
1905== != < > <= >=1940== != < > <= >=
1906and1941and or{#endsyntax#}</pre>
1907or1942
1908= *= *%= *|= /= %= += +%= +|= -= -%= -|= <<= <<|= >>= &= ^= |={#endsyntax#}</pre>1943 <p>
1944 For null and error recovery operators:
1945 </p>
1946
1947 <pre>{#syntax#}catch orelse{#endsyntax#}</pre>
1948
1949 <p>
1950 For error set operators:
1951 </p>
1952
1953 <pre>{#syntax#}||{#endsyntax#}</pre>
1954
1955 <p>
1956 For array concatenation operators:
1957 </p>
1958
1959 <pre>{#syntax#}++{#endsyntax#}</pre>
1960
1961 <p>
1962 The full precedence rules can be found in the {#link|Grammar#}, which also includes an {#link|Operator Precedence Flowchart#}.
1963 </p>
1964
1909 {#header_close#}1965 {#header_close#}
1910 {#header_close#}1966 {#header_close#}
1967
1911 {#header_open|Arrays#}1968 {#header_open|Arrays#}
1912 {#code|test_arrays.zig#}1969 {#code|test_arrays.zig#}
19131970
...@@ -7879,6 +7936,42 @@ fn readU32Be() u32 {}...@@ -7879,6 +7936,42 @@ fn readU32Be() u32 {}
7879 {#header_open|Appendix#}7936 {#header_open|Appendix#}
7880 {#header_open|Grammar#}7937 {#header_open|Grammar#}
7881 {#grammar#}7938 {#grammar#}
7939 {#header_open|Operator Precedence Flowchart#}
7940 <p>
7941 To help understand the grammar, this flowchart is provided for the operator precedence.
7942 The bottom represents any location where an expression may occur and the topmost row represents
7943 a parenthesized expression. An operator will have a higher precedence (and therefore be the parent) to
7944 another node if it is strictly lower on the tree (having a directed path from one to another). This is inverted from classical precedence, but
7945 is closer to how a recursive descent parser views the grammar.
7946 </p>
7947 <pre><code>
7948 ┏━━━━━━━━━━━━━━━━━━━┓
7949 ┃(expr) ┃
7950 ┃x() x[] x.y x.* x.?┃
7951 ┃E!T ┃
7952 ┃x{} ┃
7953 ┃!x -x -%x ~x &x ?x ┃
7954 ┗━━━━━━━━━▲━━━━━━━━━┛
7955 ┌─────────────┬──────┴───────┬───────┬──┬──┬─┐
7956 │ │ │ │ │ │ │
7957 ┏━━━━━━┷━━━━━┓╭Non╌Chaining╮ ╭Non╌Chaining╮┏┷┓┏┷┓┏┷┓│
7958 ┃* *% *| / ||┃╎ % ╎ ╎ &lt;&lt; &lt;&lt;| >> ╎┃&┃┃^┃┃|┃│
7959 ┗━━━━━━▲━━━━━┛╰╌╌╌╌╌╌▲╌╌╌╌╌╯ ╰╌╌╌╌╌╌▲╌╌╌╌╌╯┗▲┛┗▲┛┗▲┛│
7960 ┏━━┷━━━━━━━━━━━━━┷━┓ ┌────┴───────┴──┴──┘ │
7961 ┃+ - +% -% +| -| ++┃ │ │
7962 ┗━━━━━━━━━━━▲━━━━━━┛ │ │
7963 ╭┴╌Non-Chaining╌┴╮ │
7964 ╎== != &lt; &lt;= >= >╎ │
7965 ╰╌╌╌▲╌╌╌╌▲╌╌╌╌╌╌╌╯ ┌──────┬─────┘
7966 ┏━┷━┓┏━┷━┓ ┏━━━┷━━┓┏━━┷━━┓
7967 ┃and┃┃or ┃ ┃orelse┃┃catch┃
7968 ┗━▲━┛┗━▲━┛ ┗━━━▲━━┛┗━━▲━━┛
7969 ╭╌╌┴╌╌╌╌┴╌╌╌╌╌╌╌╌╌╌╌╌╌╌┴╌╌╌╌╌╌┴╌╮
7970 ╎ Any expression location ╎
7971 ╰╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╯
7972
7973 </code></pre>
7974 {#header_close#}
7882 {#header_close#}7975 {#header_close#}
7883 {#header_open|Zen#}7976 {#header_open|Zen#}
7884 <ul>7977 <ul>
doc/langref/ambiguous_precedence_orelse.zig created+12
...@@ -0,0 +1,12 @@
1test "ambiguous precedence" {
2 const x: ?bool = true;
3 const y: bool = false;
4 const z: bool = false;
5
6 // The following expression is always considered ambiguous,
7 // and, in this particular case, `(x orelse y) == z` would
8 // produce a different result than `x orelse (y == z)`.
9 _ = x orelse y == z;
10}
11
12// obj=ambiguous operator precedence with operators ... orelse ... == ...; use parentheses to disambiguate
doc/langref/grammar.peg+44-18
...@@ -127,21 +127,34 @@ AssignExpr <- Expr (AssignOp Expr / (COMMA Expr)+ EQUAL Expr / !AssignOp !COMMA)...@@ -127,21 +127,34 @@ AssignExpr <- Expr (AssignOp Expr / (COMMA Expr)+ EQUAL Expr / !AssignOp !COMMA)
127127
128SingleAssignExpr <- Expr (AssignOp Expr / !AssignOp)128SingleAssignExpr <- Expr (AssignOp Expr / !AssignOp)
129129
130Expr <- BoolOrExpr130Expr <- PrefixExpr (OrElseExpr / CatchExpr / BoolExpr)
131131
132BoolOrExpr <- BoolAndExpr (OrOp BoolAndExpr)* !OrOp132OrElseExpr <- (OrElseOp PrefixExpr)+ !RecoveryNonmixingOp
133CatchExpr <- (CatchOp PrefixExpr)+ !RecoveryNonmixingOp
134RecoveryNonmixingOp <- ControlOp / CompareOp / BitwiseNonmixingOp
135ControlOp <- OrElseOp / CatchOp / AndOp / OrOp
133136
134BoolAndExpr <- CompareExpr (AndOp CompareExpr)* !AndOp137BoolExpr <- CompareExpr (BoolAndExpr / BoolOrExpr / !ControlOp)
138BoolAndExpr <- (AndOp PrefixExpr CompareExpr)+ !ControlOp
139BoolOrExpr <- (OrOp PrefixExpr CompareExpr)+ !ControlOp
135140
136CompareExpr <- BitwiseExpr (CompareOp BitwiseExpr)? !CompareOp141CompareExpr <- CompareOperand (CompareOp PrefixExpr CompareOperand)? !(CompareOp / OrElseOp / CatchOp)
142CompareOperand
143 <- (BitwiseOrOp PrefixExpr)+ !BitwiseNonmixingOp
144 / (BitwiseAndOp PrefixExpr)+ !BitwiseNonmixingOp
145 / (BitwiseXorOp PrefixExpr)+ !BitwiseNonmixingOp
146 / BitShiftOp PrefixExpr !BitwiseNonmixingOp
147 / !BitOp AdditionExpr
137148
138BitwiseExpr <- BitShiftExpr (BitwiseOp BitShiftExpr)* !BitwiseOp149BitOp <- BitwiseOrOp / BitwiseAndOp / BitwiseXorOp / BitShiftOp
150BitwiseNonmixingOp <- MultiplyNonmixingOp / AdditionOp
139151
140BitShiftExpr <- AdditionExpr (BitShiftOp AdditionExpr)* !BitShiftOp152AdditionExpr <- MulOrModExpr (AdditionOp PrefixExpr MulOrModExpr)* !(AdditionOp / BitOp / OrElseOp / CatchOp)
141153
142AdditionExpr <- MultiplyExpr (AdditionOp MultiplyExpr)* !AdditionOp154MulOrModExpr <- ModExpr / !ModOp MultiplyExpr
143155ModExpr <- ModOp PrefixExpr !MultiplyNonmixingOp
144MultiplyExpr <- PrefixExpr (MultiplyOp PrefixExpr)* !MultiplyOp156MultiplyExpr <- (MultiplyOp PrefixExpr)* !MultiplyNonmixingOp
157MultiplyNonmixingOp <- MultiplyOp / ModOp / BitOp / OrElseOp / CatchOp
145158
146PrefixExpr <- PrefixOp* !PrefixOp PrimaryExpr159PrefixExpr <- PrefixOp* !PrefixOp PrimaryExpr
147160
...@@ -323,15 +336,26 @@ CompareOpTok...@@ -323,15 +336,26 @@ CompareOpTok
323 / LARROWEQUAL336 / LARROWEQUAL
324 / RARROWEQUAL337 / RARROWEQUAL
325338
326BitwiseOp <- pre_op_white BitwiseOpTok post_op_white339BitwiseAndOp <- pre_op_white BitwiseAndOpTok post_op_white
327 / !pre_op_white BitwiseOpTok !post_op_white340 / !pre_op_white BitwiseAndOpTok !post_op_white
328 / pre_op_white KEYWORD_catch post_op_white Payload?341BitwiseAndOpTok
329 / !pre_op_white KEYWORD_catch !post_op_white Payload?
330BitwiseOpTok
331 <- AMPERSAND ![&]342 <- AMPERSAND ![&]
332 / CARET343
333 / PIPE344BitwiseOrOp <- pre_op_white BitwiseOrOpTok post_op_white
334 / KEYWORD_orelse345 / !pre_op_white BitwiseOrOpTok !post_op_white
346BitwiseOrOpTok
347 <- PIPE
348
349BitwiseXorOp <- pre_op_white BitwiseXorOpTok post_op_white
350 / !pre_op_white BitwiseXorOpTok !post_op_white
351BitwiseXorOpTok
352 <- CARET
353
354CatchOp <- pre_op_white KEYWORD_catch post_op_white Payload?
355 / !pre_op_white KEYWORD_catch !post_op_white Payload?
356
357OrElseOp <- pre_op_white KEYWORD_orelse post_op_white
358 / !pre_op_white KEYWORD_orelse !post_op_white
335359
336BitShiftOp <- pre_op_white BitShiftOpTok post_op_white360BitShiftOp <- pre_op_white BitShiftOpTok post_op_white
337 / !pre_op_white BitShiftOpTok !post_op_white361 / !pre_op_white BitShiftOpTok !post_op_white
...@@ -357,10 +381,12 @@ MultiplyOpTok...@@ -357,10 +381,12 @@ MultiplyOpTok
357 <- PIPE2381 <- PIPE2
358 / ASTERISK382 / ASTERISK
359 / SLASH383 / SLASH
360 / PERCENT
361 / ASTERISKPERCENT384 / ASTERISKPERCENT
362 / ASTERISKPIPE385 / ASTERISKPIPE
363386
387ModOp <- pre_op_white PERCENT post_op_white
388 / !pre_op_white PERCENT !post_op_white
389
364PrefixOp390PrefixOp
365 <- EXCLAMATIONMARK391 <- EXCLAMATIONMARK
366 / MINUS392 / MINUS
doc/langref/operator_precedence.zig created+86
...@@ -0,0 +1,86 @@
1const std = @import("std");
2
3test "operator precedence" {
4 // Arithmetic operators follow the conventional order of operations.
5 {
6 const a = 1 + 2 * 3 - 4 / 2;
7 const b = 1 + (2 * 3) - (4 / 2);
8 try std.testing.expectEqual(a, b);
9 }
10
11 // Remainder division is a special case. It still has a higher precedence than
12 // addition and subtraction, but it has ambiguous precedence with itself and
13 // other multiplication/division operators.
14 {
15 const a = 1 + 2 % 3;
16 const b = 1 + (2 % 3);
17 try std.testing.expectEqual(a, b);
18
19 // `1 % 2 % 3`, `1 % 2 / 3`, etc. would be a compile error,
20 // and parentheses would be required to disambiguate.
21 }
22
23 // Bitwise operators have ambiguous precedence with other bitwise operators.
24 // However, non-shifting bitwise operators (&, |, ^) can be chained with themselves.
25 {
26 const a = 1 ^ 2 ^ 3;
27 const b = (1 ^ 2) ^ 3;
28 try std.testing.expectEqual(a, b);
29
30 // `1 ^ 2 | 3`, `1 << 2 << 3`, etc. would be a compile error,
31 // and parentheses would be required to disambiguate.
32
33 // To mix bitwise operators, parentheses must be used.
34 try std.testing.expectEqual(0x10101, (1 << 16) | (1 << 8) | 1);
35 }
36
37 // Comparison operators have lower precedence than both arithmetic and bitwise
38 // operators. Comparisons cannot be chained.
39 {
40 const a = 1 | 4 <= 1 + 4;
41 const b = (1 | 4) <= (1 + 4);
42 try std.testing.expectEqual(a, b);
43
44 // `1 == 2 >= 3`, etc. would be a compile error,
45 // and parentheses would be required to disambiguate.
46 }
47
48 // Logical operators have lower precedence than comparison operators,
49 // and may only be chained homogeneously (`and` with `and`, but not
50 // with `or`, and vice versa).
51 {
52 const false_expr: bool = 7 < 2;
53 const true_expr: bool = 1 + 1 == 2;
54
55 const a = false_expr or false_expr or true_expr;
56 const b = 7 < 2 or 7 < 2 or 1 + 1 == 2;
57 const c = ((7 < 2) or (7 < 2)) or (1 + 1 == 2);
58 try std.testing.expect(a and b and c);
59
60 // `a or b and c`, etc. would be a compile error,
61 // and parentheses would be required to disambiguate.
62 }
63
64 // `orelse` and `catch` may be chained with themselves, but not each other.
65 {
66 const some_null: ?u8 = null;
67
68 const a = some_null orelse some_null orelse 2;
69 const b = (some_null orelse some_null) orelse 2;
70 try std.testing.expectEqual(a, b);
71
72 // `a catch b orelse c`, etc. would be a compile error,
73 // and parentheses would be required to disambiguate.
74
75 // Prefix operators like `try` have higher precedence than `orelse`/`catch`.
76 const c = try maybe() orelse 1;
77 const d = (try maybe()) orelse 1;
78 try std.testing.expectEqual(c, d);
79 }
80}
81
82fn maybe() error{Fail}!?u8 {
83 return null;
84}
85
86// test
lib/c/math.zig+2-2
...@@ -355,7 +355,7 @@ fn pow10f(x: f32) callconv(.c) f32 {...@@ -355,7 +355,7 @@ fn pow10f(x: f32) callconv(.c) f32 {
355fn rint(x: f64) callconv(.c) f64 {355fn rint(x: f64) callconv(.c) f64 {
356 const toint: f64 = 1.0 / math.floatEps(f64);356 const toint: f64 = 1.0 / math.floatEps(f64);
357 const a: u64 = @bitCast(x);357 const a: u64 = @bitCast(x);
358 const e = a >> 52 & 0x7ff;358 const e = (a >> 52) & 0x7ff;
359 const s = a >> 63;359 const s = a >> 63;
360 var y: f64 = undefined;360 var y: f64 = undefined;
361361
...@@ -376,7 +376,7 @@ fn rint(x: f64) callconv(.c) f64 {...@@ -376,7 +376,7 @@ fn rint(x: f64) callconv(.c) f64 {
376fn rintf(x: f32) callconv(.c) f32 {376fn rintf(x: f32) callconv(.c) f32 {
377 const toint: f32 = 1.0 / math.floatEps(f32);377 const toint: f32 = 1.0 / math.floatEps(f32);
378 const a: u32 = @bitCast(x);378 const a: u32 = @bitCast(x);
379 const e = a >> 23 & 0xff;379 const e = (a >> 23) & 0xff;
380 const s = a >> 31;380 const s = a >> 31;
381 var y: f32 = undefined;381 var y: f32 = undefined;
382382
lib/c/stdlib/drand48.zig+6-6
...@@ -30,7 +30,7 @@ var lcg: Lcg = .init(0, default_multiplier, default_addend);...@@ -30,7 +30,7 @@ var lcg: Lcg = .init(0, default_multiplier, default_addend);
30var seed48_xi: [3]c_ushort = undefined;30var seed48_xi: [3]c_ushort = undefined;
3131
32fn erand48(xsubi: *[3]c_ushort) callconv(.c) f64 {32fn erand48(xsubi: *[3]c_ushort) callconv(.c) f64 {
33 const xi = @as(u48, @as(u16, @truncate(xsubi[0])) | (@as(u48, @as(u16, @truncate(xsubi[1])))) << 16) | (@as(u48, @as(u16, @truncate(xsubi[2]))) << 32);33 const xi = @as(u48, @as(u16, @truncate(xsubi[0])) | ((@as(u48, @as(u16, @truncate(xsubi[1])))) << 16)) | (@as(u48, @as(u16, @truncate(xsubi[2]))) << 32);
3434
35 var separate_lcg: Lcg = .init(xi, lcg.a, lcg.c);35 var separate_lcg: Lcg = .init(xi, lcg.a, lcg.c);
36 const next_xi = separate_lcg.next();36 const next_xi = separate_lcg.next();
...@@ -40,7 +40,7 @@ fn erand48(xsubi: *[3]c_ushort) callconv(.c) f64 {...@@ -40,7 +40,7 @@ fn erand48(xsubi: *[3]c_ushort) callconv(.c) f64 {
40}40}
4141
42fn jrand48(xsubi: *[3]c_ushort) callconv(.c) c_long {42fn jrand48(xsubi: *[3]c_ushort) callconv(.c) c_long {
43 const xi = @as(u48, @as(u16, @truncate(xsubi[0])) | (@as(u48, @as(u16, @truncate(xsubi[1])))) << 16) | (@as(u48, @as(u16, @truncate(xsubi[2]))) << 32);43 const xi = @as(u48, @as(u16, @truncate(xsubi[0])) | ((@as(u48, @as(u16, @truncate(xsubi[1])))) << 16)) | (@as(u48, @as(u16, @truncate(xsubi[2]))) << 32);
4444
45 var separate_lcg: Lcg = .init(xi, lcg.a, lcg.c);45 var separate_lcg: Lcg = .init(xi, lcg.a, lcg.c);
46 const next_xi = separate_lcg.next();46 const next_xi = separate_lcg.next();
...@@ -50,7 +50,7 @@ fn jrand48(xsubi: *[3]c_ushort) callconv(.c) c_long {...@@ -50,7 +50,7 @@ fn jrand48(xsubi: *[3]c_ushort) callconv(.c) c_long {
50}50}
5151
52fn nrand48(xsubi: *[3]c_ushort) callconv(.c) c_long {52fn nrand48(xsubi: *[3]c_ushort) callconv(.c) c_long {
53 const xi = @as(u48, @as(u16, @truncate(xsubi[0])) | (@as(u48, @as(u16, @truncate(xsubi[1])))) << 16) | (@as(u48, @as(u16, @truncate(xsubi[2]))) << 32);53 const xi = @as(u48, @as(u16, @truncate(xsubi[0])) | ((@as(u48, @as(u16, @truncate(xsubi[1])))) << 16)) | (@as(u48, @as(u16, @truncate(xsubi[2]))) << 32);
5454
55 var separate_lcg: Lcg = .init(xi, lcg.a, lcg.c);55 var separate_lcg: Lcg = .init(xi, lcg.a, lcg.c);
56 const next_xi = separate_lcg.next();56 const next_xi = separate_lcg.next();
...@@ -74,14 +74,14 @@ fn mrand48() callconv(.c) c_long {...@@ -74,14 +74,14 @@ fn mrand48() callconv(.c) c_long {
74// 0..3 is `Xi`, 3..6 is `a`, 6 is `c`74// 0..3 is `Xi`, 3..6 is `a`, 6 is `c`
75// first low 16-bits, then mid, then high.75// first low 16-bits, then mid, then high.
76fn lcong48(param: *[7]c_ushort) callconv(.c) void {76fn lcong48(param: *[7]c_ushort) callconv(.c) void {
77 lcg.xi = (@as(u48, @as(u16, @truncate(param[0]))) | (@as(u48, @as(u16, @truncate(param[1])))) << 16) | (@as(u48, @as(u16, @truncate(param[2]))) << 32);77 lcg.xi = (@as(u48, @as(u16, @truncate(param[0]))) | ((@as(u48, @as(u16, @truncate(param[1])))) << 16)) | (@as(u48, @as(u16, @truncate(param[2]))) << 32);
78 lcg.a = (@as(u48, @as(u16, @truncate(param[3]))) | (@as(u48, @as(u16, @truncate(param[4])))) << 16) | (@as(u48, @as(u16, @truncate(param[5]))) << 32);78 lcg.a = (@as(u48, @as(u16, @truncate(param[3]))) | ((@as(u48, @as(u16, @truncate(param[4])))) << 16)) | (@as(u48, @as(u16, @truncate(param[5]))) << 32);
79 lcg.c = @as(u16, @truncate(param[6]));79 lcg.c = @as(u16, @truncate(param[6]));
80}80}
8181
82fn seed48(seed16v: *[3]c_ushort) callconv(.c) *[3]c_ushort {82fn seed48(seed16v: *[3]c_ushort) callconv(.c) *[3]c_ushort {
83 seed48_xi = .{ @truncate(lcg.xi & 0xFFFF), @truncate((lcg.xi >> 16) & 0xFFFF), @truncate((lcg.xi >> 32) & 0xFFFF) };83 seed48_xi = .{ @truncate(lcg.xi & 0xFFFF), @truncate((lcg.xi >> 16) & 0xFFFF), @truncate((lcg.xi >> 32) & 0xFFFF) };
84 const xi = (@as(u48, @as(u16, @truncate(seed16v[0]))) | (@as(u48, @as(u16, @truncate(seed16v[1])))) << 16) | (@as(u48, @as(u16, @truncate(seed16v[2]))) << 32);84 const xi = (@as(u48, @as(u16, @truncate(seed16v[0]))) | ((@as(u48, @as(u16, @truncate(seed16v[1])))) << 16)) | (@as(u48, @as(u16, @truncate(seed16v[2]))) << 32);
85 lcg = .init(xi, default_multiplier, default_addend);85 lcg = .init(xi, default_multiplier, default_addend);
86 return &seed48_xi;86 return &seed48_xi;
87}87}
lib/compiler/Maker/Step/Compile.zig+1-1
...@@ -45,7 +45,7 @@ pub fn make(...@@ -45,7 +45,7 @@ pub fn make(
4545
46 try lowerZigArgs(arena, compile_index, maker, progress_node, &argv, false);46 try lowerZigArgs(arena, compile_index, maker, progress_node, &argv, false);
4747
48 const incremental = conf_comp.flags4.incremental.toBool() orelse graph.incremental == true;48 const incremental = conf_comp.flags4.incremental.toBool() orelse graph.incremental orelse false;
4949
50 const opt_cache_digest = Step.evalZigProcess(50 const opt_cache_digest = Step.evalZigProcess(
51 compile_index,51 compile_index,
lib/compiler/aro/aro/Compilation.zig+3-3
...@@ -287,7 +287,7 @@ fn generateSystemDefines(comp: *Compilation, w: *Io.Writer) !void {...@@ -287,7 +287,7 @@ fn generateSystemDefines(comp: *Compilation, w: *Io.Writer) !void {
287 const gnuc_version = comp.langopts.gnuc_version orelse comp.langopts.emulate.defaultGccVersion();287 const gnuc_version = comp.langopts.gnuc_version orelse comp.langopts.emulate.defaultGccVersion();
288 if (gnuc_version > 0) {288 if (gnuc_version > 0) {
289 try w.print("#define __GNUC__ {d}\n", .{gnuc_version / 10_000});289 try w.print("#define __GNUC__ {d}\n", .{gnuc_version / 10_000});
290 try w.print("#define __GNUC_MINOR__ {d}\n", .{gnuc_version / 100 % 100});290 try w.print("#define __GNUC_MINOR__ {d}\n", .{(gnuc_version / 100) % 100});
291 try w.print("#define __GNUC_PATCHLEVEL__ {d}\n", .{gnuc_version % 100});291 try w.print("#define __GNUC_PATCHLEVEL__ {d}\n", .{gnuc_version % 100});
292 }292 }
293293
...@@ -962,7 +962,7 @@ fn generateSystemDefines(comp: *Compilation, w: *Io.Writer) !void {...@@ -962,7 +962,7 @@ fn generateSystemDefines(comp: *Compilation, w: *Io.Writer) !void {
962 try define(w, "__ARM_ARCH_EXT_IDIV__");962 try define(w, "__ARM_ARCH_EXT_IDIV__");
963 }963 }
964 var sat = false;964 var sat = false;
965 if (arm_version == 6 and !target.cpu.has(.arm, .mclass) or arm_version > 6) {965 if ((arm_version == 6 and !target.cpu.has(.arm, .mclass)) or arm_version > 6) {
966 try define(w, "__ARM_FEATURE_SAT");966 try define(w, "__ARM_FEATURE_SAT");
967 sat = true;967 sat = true;
968 }968 }
...@@ -2856,7 +2856,7 @@ test "addSourceFromBuffer - exhaustive check for carriage return elimination" {...@@ -2856,7 +2856,7 @@ test "addSourceFromBuffer - exhaustive check for carriage return elimination" {
2856 if (buf[j] == alphabet[0]) buf[j - 1] = alphabet[(idx + 1) % alen] else break;2856 if (buf[j] == alphabet[0]) buf[j - 1] = alphabet[(idx + 1) % alen] else break;
2857 }2857 }
2858 }2858 }
2859 try std.testing.expect(source_count == std.math.powi(usize, alen, alen) catch unreachable);2859 try std.testing.expect(source_count == (std.math.powi(usize, alen, alen) catch unreachable));
2860}2860}
28612861
2862test "ignore BOM at beginning of file" {2862test "ignore BOM at beginning of file" {
lib/compiler/aro/aro/Driver.zig+1-1
...@@ -1373,7 +1373,7 @@ fn getOutFileName(d: *Driver, source: Source, buf: *[std.fs.max_name_bytes]u8) !...@@ -1373,7 +1373,7 @@ fn getOutFileName(d: *Driver, source: Source, buf: *[std.fs.max_name_bytes]u8) !
1373 if (d.only_preprocess_and_compile) ".s" else d.comp.target.ofmt.fileExt(d.comp.target.cpu.arch),1373 if (d.only_preprocess_and_compile) ".s" else d.comp.target.ofmt.fileExt(d.comp.target.cpu.arch),
1374 };1374 };
1375 return d.output_name orelse1375 return d.output_name orelse
1376 mem.print(buf, fmt_template, fmt_args) catch return d.fatal("Filename too long for filesystem: " ++ fmt_template, fmt_args);1376 (mem.print(buf, fmt_template, fmt_args) catch return d.fatal("Filename too long for filesystem: " ++ fmt_template, fmt_args));
1377 }1377 }
13781378
1379 return d.getRandomFilename(buf, d.comp.target.ofmt.fileExt(d.comp.target.cpu.arch));1379 return d.getRandomFilename(buf, d.comp.target.ofmt.fileExt(d.comp.target.cpu.arch));
lib/compiler/aro/aro/Parser.zig+1-1
...@@ -7084,7 +7084,7 @@ pub const Result = struct {...@@ -7084,7 +7084,7 @@ pub const Result = struct {
7084 const b_child_qt = b.qt.get(p.comp, .pointer).?.child;7084 const b_child_qt = b.qt.get(p.comp, .pointer).?.child;
70857085
7086 if (!a_child_qt.eql(b_child_qt, p.comp)) try p.err(tok, .incompatible_pointers, .{ a.qt, b.qt });7086 if (!a_child_qt.eql(b_child_qt, p.comp)) try p.err(tok, .incompatible_pointers, .{ a.qt, b.qt });
7087 if (a.qt.childType(p.comp).sizeofOrNull(p.comp) orelse 1 == 0) try p.err(tok, .subtract_pointers_zero_elem_size, .{a.qt.childType(p.comp)});7087 if ((a.qt.childType(p.comp).sizeofOrNull(p.comp) orelse 1) == 0) try p.err(tok, .subtract_pointers_zero_elem_size, .{a.qt.childType(p.comp)});
7088 a.qt = p.comp.type_store.ptrdiff;7088 a.qt = p.comp.type_store.ptrdiff;
7089 }7089 }
70907090
lib/compiler/aro/aro/Preprocessor.zig+3-3
...@@ -310,13 +310,13 @@ pub const InitOptions = struct {...@@ -310,13 +310,13 @@ pub const InitOptions = struct {
310};310};
311311
312pub fn init(comp: *Compilation, options: InitOptions) !Preprocessor {312pub fn init(comp: *Compilation, options: InitOptions) !Preprocessor {
313 const source_epoch: SourceEpoch = options.source_epoch orelse comp.environment.sourceEpoch(comp.io) catch |er| switch (er) {313 const source_epoch: SourceEpoch = options.source_epoch orelse (comp.environment.sourceEpoch(comp.io) catch |er| switch (er) {
314 error.InvalidEpoch => blk: {314 error.InvalidEpoch => blk: {
315 const diagnostic: Diagnostic = .invalid_source_epoch;315 const diagnostic: Diagnostic = .invalid_source_epoch;
316 try comp.diagnostics.add(.{ .text = diagnostic.fmt, .kind = diagnostic.kind, .opt = diagnostic.opt, .location = null });316 try comp.diagnostics.add(.{ .text = diagnostic.fmt, .kind = diagnostic.kind, .opt = diagnostic.opt, .location = null });
317 break :blk .default;317 break :blk .default;
318 },318 },
319 };319 });
320320
321 var pp: Preprocessor = .{321 var pp: Preprocessor = .{
322 .comp = comp,322 .comp = comp,
...@@ -3882,7 +3882,7 @@ pub fn prettyPrintTokens(pp: *Preprocessor, w: *std.Io.Writer, macro_dump_mode:...@@ -3882,7 +3882,7 @@ pub fn prettyPrintTokens(pp: *Preprocessor, w: *std.Io.Writer, macro_dump_mode:
3882 },3882 },
3883 .keyword_pragma => {3883 .keyword_pragma => {
3884 const pragma_name = pp.expandedSlice(pp.tokens.get(i + 1));3884 const pragma_name = pp.expandedSlice(pp.tokens.get(i + 1));
3885 const end_idx = mem.findScalarPos(Token.Id, tok_ids, i, .nl) orelse i + 1;3885 const end_idx = mem.findScalarPos(Token.Id, tok_ids, i, .nl) orelse (i + 1);
3886 const pragma_len = @as(u32, @intCast(end_idx)) - i;3886 const pragma_len = @as(u32, @intCast(end_idx)) - i;
38873887
3888 if (pp.comp.getPragma(pragma_name)) |prag| {3888 if (pp.comp.getPragma(pragma_name)) |prag| {
lib/compiler/aro/aro/Preprocessor/Parser.zig+1-1
...@@ -323,7 +323,7 @@ fn binaryExpr(p: *Parser, min_prec: Token.Precedence, eval: bool) Error!?Value {...@@ -323,7 +323,7 @@ fn binaryExpr(p: *Parser, min_prec: Token.Precedence, eval: bool) Error!?Value {
323 const else_res = try p.binaryExpr(op_prec, eval_else) orelse return null;323 const else_res = try p.binaryExpr(op_prec, eval_else) orelse return null;
324324
325 lhs = if (lhs.toBool()) rhs else else_res;325 lhs = if (lhs.toBool()) rhs else else_res;
326 if (eval and rhs == .unsigned or else_res == .unsigned) {326 if (rhs == .unsigned or else_res == .unsigned) {
327 try lhs.toUnsigned(p, operator, "right");327 try lhs.toUnsigned(p, operator, "right");
328 }328 }
329 },329 },
lib/compiler/aro/aro/char_info.zig+2-2
...@@ -492,7 +492,7 @@ pub fn isXidStart(c: u21) bool {...@@ -492,7 +492,7 @@ pub fn isXidStart(c: u21) bool {
492 assert(c > 0x7F);492 assert(c > 0x7F);
493 const idx = c / 8 / tables.chunk;493 const idx = c / 8 / tables.chunk;
494 const chunk: usize = if (idx < tables.trie_start.len) tables.trie_start[idx] else 0;494 const chunk: usize = if (idx < tables.trie_start.len) tables.trie_start[idx] else 0;
495 const offset = chunk * tables.chunk / 2 + c / 8 % tables.chunk;495 const offset = chunk * tables.chunk / 2 + (c / 8) % tables.chunk;
496 return (tables.leaf[offset] >> (@as(u3, @intCast(c % 8)))) & 1 != 0;496 return (tables.leaf[offset] >> (@as(u3, @intCast(c % 8)))) & 1 != 0;
497}497}
498498
...@@ -500,7 +500,7 @@ pub fn isXidContinue(c: u21) bool {...@@ -500,7 +500,7 @@ pub fn isXidContinue(c: u21) bool {
500 assert(c > 0x7F);500 assert(c > 0x7F);
501 const idx = c / 8 / tables.chunk;501 const idx = c / 8 / tables.chunk;
502 const chunk: usize = if (idx < tables.trie_continue.len) tables.trie_continue[idx] else 0;502 const chunk: usize = if (idx < tables.trie_continue.len) tables.trie_continue[idx] else 0;
503 const offset = chunk * tables.chunk / 2 + c / 8 % tables.chunk;503 const offset = chunk * tables.chunk / 2 + (c / 8) % tables.chunk;
504 return (tables.leaf[offset] >> (@as(u3, @intCast(c % 8)))) & 1 != 0;504 return (tables.leaf[offset] >> (@as(u3, @intCast(c % 8)))) & 1 != 0;
505}505}
506506
lib/compiler/aro/aro/record_layout.zig+1-1
...@@ -324,7 +324,7 @@ const SysVContext = struct {...@@ -324,7 +324,7 @@ const SysVContext = struct {
324324
325 // On Clang, the alignment requested by annotations is not respected if it is325 // On Clang, the alignment requested by annotations is not respected if it is
326 // larger than the value of #pragma pack. See test case 0083.326 // larger than the value of #pragma pack. See test case 0083.
327 if (annotation_alignment <= self.max_field_align_bits orelse std.math.maxInt(u29)) {327 if (annotation_alignment <= (self.max_field_align_bits orelse std.math.maxInt(u29))) {
328 field_align_bits = @max(field_align_bits, annotation_alignment);328 field_align_bits = @max(field_align_bits, annotation_alignment);
329 }329 }
330 // On Clang, if there are no packing annotations and the field would cross a330 // On Clang, if there are no packing annotations and the field would cross a
lib/compiler_rt/absv.zig+1-1
...@@ -11,7 +11,7 @@ pub inline fn absv(comptime ST: type, a: ST) ST {...@@ -11,7 +11,7 @@ pub inline fn absv(comptime ST: type, a: ST) ST {
11 // compute the integer absolute value (abs) without branching11 // compute the integer absolute value (abs) without branching
12 var x: ST = a;12 var x: ST = a;
13 const N: UT = @bitSizeOf(ST);13 const N: UT = @bitSizeOf(ST);
14 const sign: ST = a >> N - 1;14 const sign: ST = a >> (N - 1);
15 x +%= sign;15 x +%= sign;
16 x ^= sign;16 x ^= sign;
17 if (x < 0) @panic("integer overflow");17 if (x < 0) @panic("integer overflow");
lib/compiler_rt/addf3.zig+1-1
...@@ -259,7 +259,7 @@ inline fn addf3(comptime T: type, a: T, b: T) T {...@@ -259,7 +259,7 @@ inline fn addf3(comptime T: type, a: T, b: T) T {
259 // adjust the exponent:259 // adjust the exponent:
260 if (aSignificand & (integerBit << 4) != 0) {260 if (aSignificand & (integerBit << 4) != 0) {
261 const sticky = aSignificand & 1;261 const sticky = aSignificand & 1;
262 aSignificand = aSignificand >> 1 | sticky;262 aSignificand = (aSignificand >> 1) | sticky;
263 aExponent += 1;263 aExponent += 1;
264 }264 }
265 }265 }
lib/compiler_rt/atomics.zig+1-1
...@@ -241,7 +241,7 @@ fn wideUpdate(comptime T: type, ptr: *T, val: T, update: anytype) T {...@@ -241,7 +241,7 @@ fn wideUpdate(comptime T: type, ptr: *T, val: T, update: anytype) T {
241 while (true) {241 while (true) {
242 const old = @as(T, @truncate((wide_old & mask) >> inner_shift));242 const old = @as(T, @truncate((wide_old & mask) >> inner_shift));
243 const new = update(val, old);243 const new = update(val, old);
244 const wide_new = wide_old & ~mask | (@as(WideAtomic, new) << inner_shift);244 const wide_new = (wide_old & ~mask) | (@as(WideAtomic, new) << inner_shift);
245 if (@cmpxchgWeak(WideAtomic, wide_ptr, wide_old, wide_new, .seq_cst, .seq_cst)) |new_wide_old| {245 if (@cmpxchgWeak(WideAtomic, wide_ptr, wide_old, wide_new, .seq_cst, .seq_cst)) |new_wide_old| {
246 wide_old = new_wide_old;246 wide_old = new_wide_old;
247 } else {247 } else {
lib/compiler_rt/comparef.zig+4-4
...@@ -130,13 +130,13 @@ fn __aeabi_fcmplt(a: f32, b: f32) callconv(.{ .arm_aapcs = .{} }) i32 {...@@ -130,13 +130,13 @@ fn __aeabi_fcmplt(a: f32, b: f32) callconv(.{ .arm_aapcs = .{} }) i32 {
130 return @intFromBool(cmp_f32(a, b) == .lt);130 return @intFromBool(cmp_f32(a, b) == .lt);
131}131}
132fn __aeabi_fcmple(a: f32, b: f32) callconv(.{ .arm_aapcs = .{} }) i32 {132fn __aeabi_fcmple(a: f32, b: f32) callconv(.{ .arm_aapcs = .{} }) i32 {
133 return @intFromBool(cmp_f32(a, b) orelse .gt != .gt);133 return @intFromBool((cmp_f32(a, b) orelse .gt) != .gt);
134}134}
135fn __gesf2(a: compiler_rt.f32.Abi, b: compiler_rt.f32.Abi) callconv(.c) Order {135fn __gesf2(a: compiler_rt.f32.Abi, b: compiler_rt.f32.Abi) callconv(.c) Order {
136 return cmp_f32(compiler_rt.f32.fromAbi(a), compiler_rt.f32.fromAbi(b)) orelse .lt;136 return cmp_f32(compiler_rt.f32.fromAbi(a), compiler_rt.f32.fromAbi(b)) orelse .lt;
137}137}
138fn __aeabi_fcmpge(a: f32, b: f32) callconv(.{ .arm_aapcs = .{} }) i32 {138fn __aeabi_fcmpge(a: f32, b: f32) callconv(.{ .arm_aapcs = .{} }) i32 {
139 return @intFromBool(cmp_f32(a, b) orelse .lt != .lt);139 return @intFromBool((cmp_f32(a, b) orelse .lt) != .lt);
140}140}
141fn __aeabi_fcmpgt(a: f32, b: f32) callconv(.{ .arm_aapcs = .{} }) i32 {141fn __aeabi_fcmpgt(a: f32, b: f32) callconv(.{ .arm_aapcs = .{} }) i32 {
142 return @intFromBool(cmp_f32(a, b) == .gt);142 return @intFromBool(cmp_f32(a, b) == .gt);
...@@ -164,13 +164,13 @@ fn __aeabi_dcmplt(a: f64, b: f64) callconv(.{ .arm_aapcs = .{} }) i32 {...@@ -164,13 +164,13 @@ fn __aeabi_dcmplt(a: f64, b: f64) callconv(.{ .arm_aapcs = .{} }) i32 {
164 return @intFromBool(cmp_f64(a, b) == .lt);164 return @intFromBool(cmp_f64(a, b) == .lt);
165}165}
166fn __aeabi_dcmple(a: f64, b: f64) callconv(.{ .arm_aapcs = .{} }) i32 {166fn __aeabi_dcmple(a: f64, b: f64) callconv(.{ .arm_aapcs = .{} }) i32 {
167 return @intFromBool(cmp_f64(a, b) orelse .gt != .gt);167 return @intFromBool((cmp_f64(a, b) orelse .gt) != .gt);
168}168}
169fn __gedf2(a: compiler_rt.f64.Abi, b: compiler_rt.f64.Abi) callconv(.c) Order {169fn __gedf2(a: compiler_rt.f64.Abi, b: compiler_rt.f64.Abi) callconv(.c) Order {
170 return cmp_f64(compiler_rt.f64.fromAbi(a), compiler_rt.f64.fromAbi(b)) orelse .lt;170 return cmp_f64(compiler_rt.f64.fromAbi(a), compiler_rt.f64.fromAbi(b)) orelse .lt;
171}171}
172fn __aeabi_dcmpge(a: f64, b: f64) callconv(.{ .arm_aapcs = .{} }) i32 {172fn __aeabi_dcmpge(a: f64, b: f64) callconv(.{ .arm_aapcs = .{} }) i32 {
173 return @intFromBool(cmp_f64(a, b) orelse .lt != .lt);173 return @intFromBool((cmp_f64(a, b) orelse .lt) != .lt);
174}174}
175fn __aeabi_dcmpgt(a: f64, b: f64) callconv(.{ .arm_aapcs = .{} }) i32 {175fn __aeabi_dcmpgt(a: f64, b: f64) callconv(.{ .arm_aapcs = .{} }) i32 {
176 return @intFromBool(cmp_f64(a, b) == .gt);176 return @intFromBool(cmp_f64(a, b) == .gt);
lib/compiler_rt/divdf3.zig+8-8
...@@ -119,12 +119,12 @@ pub fn div_f64(a: f64, b: f64) f64 {...@@ -119,12 +119,12 @@ pub fn div_f64(a: f64, b: f64) f64 {
119 // with each iteration, so after three iterations, we have about 28 binary119 // with each iteration, so after three iterations, we have about 28 binary
120 // digits of accuracy.120 // digits of accuracy.
121 var correction32: u32 = undefined;121 var correction32: u32 = undefined;
122 correction32 = @truncate(~(@as(u64, recip32) *% q31b >> 32) +% 1);122 correction32 = @truncate(~((@as(u64, recip32) *% q31b) >> 32) +% 1);
123 recip32 = @truncate(@as(u64, recip32) *% correction32 >> 31);123 recip32 = @truncate((@as(u64, recip32) *% correction32) >> 31);
124 correction32 = @truncate(~(@as(u64, recip32) *% q31b >> 32) +% 1);124 correction32 = @truncate(~((@as(u64, recip32) *% q31b) >> 32) +% 1);
125 recip32 = @truncate(@as(u64, recip32) *% correction32 >> 31);125 recip32 = @truncate((@as(u64, recip32) *% correction32) >> 31);
126 correction32 = @truncate(~(@as(u64, recip32) *% q31b >> 32) +% 1);126 correction32 = @truncate(~((@as(u64, recip32) *% q31b) >> 32) +% 1);
127 recip32 = @truncate(@as(u64, recip32) *% correction32 >> 31);127 recip32 = @truncate((@as(u64, recip32) *% correction32) >> 31);
128128
129 // recip32 might have overflowed to exactly zero in the preceding129 // recip32 might have overflowed to exactly zero in the preceding
130 // computation if the high word of b is exactly 1.0. This would sabotage130 // computation if the high word of b is exactly 1.0. This would sabotage
...@@ -137,10 +137,10 @@ pub fn div_f64(a: f64, b: f64) f64 {...@@ -137,10 +137,10 @@ pub fn div_f64(a: f64, b: f64) f64 {
137 const q63blo: u32 = @truncate(bSignificand << 11);137 const q63blo: u32 = @truncate(bSignificand << 11);
138 var correction: u64 = undefined;138 var correction: u64 = undefined;
139 var reciprocal: u64 = undefined;139 var reciprocal: u64 = undefined;
140 correction = ~(@as(u64, recip32) *% q31b +% (@as(u64, recip32) *% q63blo >> 32)) +% 1;140 correction = ~(@as(u64, recip32) *% q31b +% ((@as(u64, recip32) *% q63blo) >> 32)) +% 1;
141 const cHi: u32 = @truncate(correction >> 32);141 const cHi: u32 = @truncate(correction >> 32);
142 const cLo: u32 = @truncate(correction);142 const cLo: u32 = @truncate(correction);
143 reciprocal = @as(u64, recip32) *% cHi +% (@as(u64, recip32) *% cLo >> 32);143 reciprocal = @as(u64, recip32) *% cHi +% ((@as(u64, recip32) *% cLo) >> 32);
144144
145 // We already adjusted the 32-bit estimate, now we need to adjust the final145 // We already adjusted the 32-bit estimate, now we need to adjust the final
146 // 64-bit reciprocal estimate downward to ensure that it is strictly smaller146 // 64-bit reciprocal estimate downward to ensure that it is strictly smaller
lib/compiler_rt/divsf3.zig+7-7
...@@ -126,12 +126,12 @@ pub fn div_f32(a: f32, b: f32) f32 {...@@ -126,12 +126,12 @@ pub fn div_f32(a: f32, b: f32) f32 {
126 // with each iteration, so after three iterations, we have about 28 binary126 // with each iteration, so after three iterations, we have about 28 binary
127 // digits of accuracy.127 // digits of accuracy.
128 var correction: u32 = undefined;128 var correction: u32 = undefined;
129 correction = @truncate(~(@as(u64, reciprocal) *% q31b >> 32) +% 1);129 correction = @truncate(~((@as(u64, reciprocal) *% q31b) >> 32) +% 1);
130 reciprocal = @truncate(@as(u64, reciprocal) *% correction >> 31);130 reciprocal = @truncate((@as(u64, reciprocal) *% correction) >> 31);
131 correction = @truncate(~(@as(u64, reciprocal) *% q31b >> 32) +% 1);131 correction = @truncate(~((@as(u64, reciprocal) *% q31b) >> 32) +% 1);
132 reciprocal = @truncate(@as(u64, reciprocal) *% correction >> 31);132 reciprocal = @truncate((@as(u64, reciprocal) *% correction) >> 31);
133 correction = @truncate(~(@as(u64, reciprocal) *% q31b >> 32) +% 1);133 correction = @truncate(~((@as(u64, reciprocal) *% q31b) >> 32) +% 1);
134 reciprocal = @truncate(@as(u64, reciprocal) *% correction >> 31);134 reciprocal = @truncate((@as(u64, reciprocal) *% correction) >> 31);
135135
136 // Exhaustive testing shows that the error in reciprocal after three steps136 // Exhaustive testing shows that the error in reciprocal after three steps
137 // is in the interval [-0x1.f58108p-31, 0x1.d0e48cp-29], in line with our137 // is in the interval [-0x1.f58108p-31, 0x1.d0e48cp-29], in line with our
...@@ -153,7 +153,7 @@ pub fn div_f32(a: f32, b: f32) f32 {...@@ -153,7 +153,7 @@ pub fn div_f32(a: f32, b: f32) f32 {
153 // is the error in the reciprocal of b scaled by the maximum153 // is the error in the reciprocal of b scaled by the maximum
154 // possible value of a. As a consequence of this error bound,154 // possible value of a. As a consequence of this error bound,
155 // either q or nextafter(q) is the correctly rounded155 // either q or nextafter(q) is the correctly rounded
156 var quotient: Z = @truncate(@as(u64, reciprocal) *% (aSignificand << 1) >> 32);156 var quotient: Z = @truncate((@as(u64, reciprocal) *% (aSignificand << 1)) >> 32);
157157
158 // Two cases: quotient is in [0.5, 1.0) or quotient is in [1.0, 2.0).158 // Two cases: quotient is in [0.5, 1.0) or quotient is in [1.0, 2.0).
159 // In either case, we are going to compute a residual of the form159 // In either case, we are going to compute a residual of the form
lib/compiler_rt/divtf3.zig+10-10
...@@ -119,16 +119,16 @@ pub fn div_f128(a: f128, b: f128) f128 {...@@ -119,16 +119,16 @@ pub fn div_f128(a: f128, b: f128) f128 {
119 // This doubles the number of correct binary digits in the approximation119 // This doubles the number of correct binary digits in the approximation
120 // with each iteration.120 // with each iteration.
121 var correction64: u64 = undefined;121 var correction64: u64 = undefined;
122 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);122 correction64 = @truncate(~((@as(u128, recip64) *% q63b) >> 64) +% 1);
123 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);123 recip64 = @truncate((@as(u128, recip64) *% correction64) >> 63);
124 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);124 correction64 = @truncate(~((@as(u128, recip64) *% q63b) >> 64) +% 1);
125 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);125 recip64 = @truncate((@as(u128, recip64) *% correction64) >> 63);
126 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);126 correction64 = @truncate(~((@as(u128, recip64) *% q63b) >> 64) +% 1);
127 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);127 recip64 = @truncate((@as(u128, recip64) *% correction64) >> 63);
128 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);128 correction64 = @truncate(~((@as(u128, recip64) *% q63b) >> 64) +% 1);
129 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);129 recip64 = @truncate((@as(u128, recip64) *% correction64) >> 63);
130 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);130 correction64 = @truncate(~((@as(u128, recip64) *% q63b) >> 64) +% 1);
131 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);131 recip64 = @truncate((@as(u128, recip64) *% correction64) >> 63);
132132
133 // The reciprocal may have overflowed to zero if the upper half of b is133 // The reciprocal may have overflowed to zero if the upper half of b is
134 // exactly 1.0. This would sabatoge the full-width final stage of the134 // exactly 1.0. This would sabatoge the full-width final stage of the
lib/compiler_rt/divxf3.zig+10-10
...@@ -102,16 +102,16 @@ pub fn div_f80(a: f80, b: f80) f80 {...@@ -102,16 +102,16 @@ pub fn div_f80(a: f80, b: f80) f80 {
102 // This doubles the number of correct binary digits in the approximation102 // This doubles the number of correct binary digits in the approximation
103 // with each iteration.103 // with each iteration.
104 var correction64: u64 = undefined;104 var correction64: u64 = undefined;
105 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);105 correction64 = @truncate(~((@as(u128, recip64) *% q63b) >> 64) +% 1);
106 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);106 recip64 = @truncate((@as(u128, recip64) *% correction64) >> 63);
107 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);107 correction64 = @truncate(~((@as(u128, recip64) *% q63b) >> 64) +% 1);
108 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);108 recip64 = @truncate((@as(u128, recip64) *% correction64) >> 63);
109 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);109 correction64 = @truncate(~((@as(u128, recip64) *% q63b) >> 64) +% 1);
110 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);110 recip64 = @truncate((@as(u128, recip64) *% correction64) >> 63);
111 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);111 correction64 = @truncate(~((@as(u128, recip64) *% q63b) >> 64) +% 1);
112 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);112 recip64 = @truncate((@as(u128, recip64) *% correction64) >> 63);
113 correction64 = @truncate(~(@as(u128, recip64) *% q63b >> 64) +% 1);113 correction64 = @truncate(~((@as(u128, recip64) *% q63b) >> 64) +% 1);
114 recip64 = @truncate(@as(u128, recip64) *% correction64 >> 63);114 recip64 = @truncate((@as(u128, recip64) *% correction64) >> 63);
115115
116 // The reciprocal may have overflowed to zero if the upper half of b is116 // The reciprocal may have overflowed to zero if the upper half of b is
117 // exactly 1.0. This would sabatoge the full-width final stage of the117 // exactly 1.0. This would sabatoge the full-width final stage of the
lib/compiler_rt/elf/tls.zig+1-1
...@@ -251,7 +251,7 @@ fn setThreadPointer(addr: usize) void {...@@ -251,7 +251,7 @@ fn setThreadPointer(addr: usize) void {
251 // Update the %gs selector251 // Update the %gs selector
252 asm volatile ("movl %[gs_val], %%gs"252 asm volatile ("movl %[gs_val], %%gs"
253 :253 :
254 : [gs_val] "r" (gdt_entry_number << 3 | 3),254 : [gs_val] "r" ((gdt_entry_number << 3) | 3),
255 );255 );
256 },256 },
257 .x86_64 => {257 .x86_64 => {
lib/compiler_rt/extendf.zig+2-2
...@@ -165,7 +165,7 @@ pub fn f128_floatCast_f80(a: f80) f128 {...@@ -165,7 +165,7 @@ pub fn f128_floatCast_f80(a: f80) f128 {
165 }165 }
166166
167 // Apply the signbit to (dst_t)abs(a).167 // Apply the signbit to (dst_t)abs(a).
168 const result: u128 = abs_result | @as(u128, sign) << (dst_bits - 16);168 const result: u128 = abs_result | (@as(u128, sign) << (dst_bits - 16));
169 return @bitCast(result);169 return @bitCast(result);
170}170}
171171
...@@ -232,7 +232,7 @@ inline fn extendf(comptime dst_t: type, comptime src_t: type, f: src_t) dst_t {...@@ -232,7 +232,7 @@ inline fn extendf(comptime dst_t: type, comptime src_t: type, f: src_t) dst_t {
232 }232 }
233233
234 // Apply the signbit to (dst_t)abs(a).234 // Apply the signbit to (dst_t)abs(a).
235 const result: dst_rep_t = absResult | @as(dst_rep_t, sign) << (dstBits - srcBits);235 const result: dst_rep_t = absResult | (@as(dst_rep_t, sign) << (dstBits - srcBits));
236 return @bitCast(result);236 return @bitCast(result);
237}237}
238238
lib/compiler_rt/floor_ceil.zig+4-4
...@@ -141,13 +141,13 @@ inline fn impl(comptime T: type, comptime op: enum { floor, ceil }, x: T) T {...@@ -141,13 +141,13 @@ inline fn impl(comptime T: type, comptime op: enum { floor, ceil }, x: T) T {
141 const m = (@as(U, 1) << @intCast(mantissa - e)) - 1;141 const m = (@as(U, 1) << @intCast(mantissa - e)) - 1;
142 if (u & m == 0) return x;142 if (u & m == 0) return x;
143 if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1.0p120);143 if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1.0p120);
144 if (u >> bits - 1 == @intFromBool(op == .floor)) u += m;144 if (u >> (bits - 1) == @intFromBool(op == .floor)) u += m;
145 return @bitCast(u & ~m);145 return @bitCast(u & ~m);
146 } else {146 } else {
147 if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1.0p120);147 if (compiler_rt.want_float_exceptions) mem.doNotOptimizeAway(x + 0x1.0p120);
148 return switch (op) {148 return switch (op) {
149 .floor => if (u >> bits - 1 == 0) 0.0 else if (u << 1 != 0) -1.0 else x,149 .floor => if (u >> (bits - 1) == 0) 0.0 else if (u << 1 != 0) -1.0 else x,
150 .ceil => if (u >> bits - 1 != 0) -0.0 else if (u << 1 != 0) 1.0 else x,150 .ceil => if (u >> (bits - 1) != 0) -0.0 else if (u << 1 != 0) 1.0 else x,
151 };151 };
152 }152 }
153 },153 },
...@@ -155,7 +155,7 @@ inline fn impl(comptime T: type, comptime op: enum { floor, ceil }, x: T) T {...@@ -155,7 +155,7 @@ inline fn impl(comptime T: type, comptime op: enum { floor, ceil }, x: T) T {
155 const e = (u >> mantissa) & mask;155 const e = (u >> mantissa) & mask;
156 if (e >= bias + math.floatFractionalBits(T) or x == 0) return x;156 if (e >= bias + math.floatFractionalBits(T) or x == 0) return x;
157157
158 const positive = u >> @bitSizeOf(T) - 1 == 0;158 const positive = u >> (@bitSizeOf(T) - 1) == 0;
159 const y: T = if (positive)159 const y: T = if (positive)
160 x + C - C - x160 x + C - C - x
161 else161 else
lib/compiler_rt/fmod.zig+2-2
...@@ -204,8 +204,8 @@ pub fn fmod_f128(a: f128, b: f128) f128 {...@@ -204,8 +204,8 @@ pub fn fmod_f128(a: f128, b: f128) f128 {
204 }204 }
205205
206 // OR in extra non-stored mantissa digit206 // OR in extra non-stored mantissa digit
207 var highA: u64 = (aPtr_u64[high_index] & (std.math.maxInt(u64) >> 16)) | 1 << 48;207 var highA: u64 = (aPtr_u64[high_index] & (std.math.maxInt(u64) >> 16)) | (1 << 48);
208 const highB: u64 = (bPtr_u64[high_index] & (std.math.maxInt(u64) >> 16)) | 1 << 48;208 const highB: u64 = (bPtr_u64[high_index] & (std.math.maxInt(u64) >> 16)) | (1 << 48);
209 var lowA: u64 = aPtr_u64[low_index];209 var lowA: u64 = aPtr_u64[low_index];
210 const lowB: u64 = bPtr_u64[low_index];210 const lowB: u64 = bPtr_u64[low_index];
211211
lib/compiler_rt/mulf3.zig+1-1
...@@ -237,7 +237,7 @@ fn wideShrWithTruncation(comptime Z: type, hi: *Z, lo: *Z, count: u32) bool {...@@ -237,7 +237,7 @@ fn wideShrWithTruncation(comptime Z: type, hi: *Z, lo: *Z, count: u32) bool {
237 lo.* = (hi.* << @intCast(typeWidth -% count)) | (lo.* >> @intCast(count));237 lo.* = (hi.* << @intCast(typeWidth -% count)) | (lo.* >> @intCast(count));
238 hi.* = hi.* >> @intCast(count);238 hi.* = hi.* >> @intCast(count);
239 } else if (count < 2 * typeWidth) {239 } else if (count < 2 * typeWidth) {
240 inexact = (hi.* << @intCast(2 * typeWidth -% count) | lo.*) != 0;240 inexact = ((hi.* << @intCast(2 * typeWidth -% count)) | lo.*) != 0;
241 lo.* = hi.* >> @intCast(count -% typeWidth);241 lo.* = hi.* >> @intCast(count -% typeWidth);
242 hi.* = 0;242 hi.* = 0;
243 } else {243 } else {
lib/compiler_rt/rem_pio2l.zig+1-1
...@@ -37,7 +37,7 @@ pub fn rem_pio2l(comptime T: type, x: T, y: *[2]T) i32 {...@@ -37,7 +37,7 @@ pub fn rem_pio2l(comptime T: type, x: T, y: *[2]T) i32 {
37 const se = ld.signExponent(x_val);37 const se = ld.signExponent(x_val);
38 const top = ld.mantissaTop(x_val);38 const top = ld.mantissaTop(x_val);
39 const lhs = (@as(u32, se & 0x7fff) << 16) | top;39 const lhs = (@as(u32, se & 0x7fff) << 16) | top;
40 const rhs: u32 = ((0x3fff + 25) << 16) | 0x921f >> 1 | 0x8000;40 const rhs: u32 = ((0x3fff + 25) << 16) | (0x921f >> 1) | 0x8000;
41 return lhs < rhs;41 return lhs < rhs;
42 }42 }
4343
lib/compiler_rt/sqrt.zig+5-5
...@@ -523,15 +523,15 @@ const rsqrt_tab: [128]u16 = .{...@@ -523,15 +523,15 @@ const rsqrt_tab: [128]u16 = .{
523};523};
524524
525inline fn mul16(a: u16, b: u16) u16 {525inline fn mul16(a: u16, b: u16) u16 {
526 return @intCast(@as(u32, a) * b >> 16);526 return @intCast((@as(u32, a) * b) >> 16);
527}527}
528528
529inline fn mul32(a: u32, b: u32) u32 {529inline fn mul32(a: u32, b: u32) u32 {
530 return @intCast(@as(u64, a) * b >> 32);530 return @intCast((@as(u64, a) * b) >> 32);
531}531}
532532
533inline fn mul64(a: u64, b: u64) u64 {533inline fn mul64(a: u64, b: u64) u64 {
534 return @intCast(@as(u128, a) * b >> 64);534 return @intCast((@as(u128, a) * b) >> 64);
535}535}
536536
537inline fn mul80(a: u80, b: u80) u80 {537inline fn mul80(a: u80, b: u80) u80 {
...@@ -539,7 +539,7 @@ inline fn mul80(a: u80, b: u80) u80 {...@@ -539,7 +539,7 @@ inline fn mul80(a: u80, b: u80) u80 {
539 const alo = a & 0xFF_FFFF_FFFF;539 const alo = a & 0xFF_FFFF_FFFF;
540 const bhi = b >> 40;540 const bhi = b >> 40;
541 const blo = b & 0xFF_FFFF_FFFF;541 const blo = b & 0xFF_FFFF_FFFF;
542 return ahi * bhi + (ahi * blo >> 40) + (alo * bhi >> 40);542 return ahi * bhi + ((ahi * blo) >> 40) + ((alo * bhi) >> 40);
543}543}
544544
545inline fn mul128(a: u128, b: u128) u128 {545inline fn mul128(a: u128, b: u128) u128 {
...@@ -547,7 +547,7 @@ inline fn mul128(a: u128, b: u128) u128 {...@@ -547,7 +547,7 @@ inline fn mul128(a: u128, b: u128) u128 {
547 const alo = a & 0xFFFF_FFFF_FFFF_FFFF;547 const alo = a & 0xFFFF_FFFF_FFFF_FFFF;
548 const bhi = b >> 64;548 const bhi = b >> 64;
549 const blo = b & 0xFFFF_FFFF_FFFF_FFFF;549 const blo = b & 0xFFFF_FFFF_FFFF_FFFF;
550 return ahi * bhi + (ahi * blo >> 64) + (alo * bhi >> 64);550 return ahi * bhi + ((ahi * blo) >> 64) + ((alo * bhi) >> 64);
551}551}
552552
553inline fn mul80_tail(a: u80, b: u80) u80 {553inline fn mul80_tail(a: u80, b: u80) u80 {
lib/compiler_rt/truncf.zig+3-3
...@@ -279,7 +279,7 @@ inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t {...@@ -279,7 +279,7 @@ inline fn truncf(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t {
279 absResult = 0;279 absResult = 0;
280 } else {280 } else {
281 const sticky: src_rep_t = @intFromBool(significand << @intCast(srcBits - shift) != 0);281 const sticky: src_rep_t = @intFromBool(significand << @intCast(srcBits - shift) != 0);
282 const denormalizedSignificand: src_rep_t = significand >> @intCast(shift) | sticky;282 const denormalizedSignificand: src_rep_t = (significand >> @intCast(shift)) | sticky;
283 absResult = @intCast(denormalizedSignificand >> (srcSigBits - dstSigBits));283 absResult = @intCast(denormalizedSignificand >> (srcSigBits - dstSigBits));
284 const roundBits: src_rep_t = denormalizedSignificand & roundMask;284 const roundBits: src_rep_t = denormalizedSignificand & roundMask;
285 if (roundBits > halfway) {285 if (roundBits > halfway) {
...@@ -362,7 +362,7 @@ inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t {...@@ -362,7 +362,7 @@ inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t {
362 abs_result = 0;362 abs_result = 0;
363 } else {363 } else {
364 const sticky = @intFromBool(a_rep.fraction << @intCast(shift) != 0);364 const sticky = @intFromBool(a_rep.fraction << @intCast(shift) != 0);
365 const denormalized_significand = a_rep.fraction >> @intCast(shift) | sticky;365 const denormalized_significand = (a_rep.fraction >> @intCast(shift)) | sticky;
366 abs_result = @intCast(denormalized_significand >> (src_sig_bits - dst_sig_bits));366 abs_result = @intCast(denormalized_significand >> (src_sig_bits - dst_sig_bits));
367 const round_bits = denormalized_significand & round_mask;367 const round_bits = denormalized_significand & round_mask;
368 if (round_bits > halfway) {368 if (round_bits > halfway) {
...@@ -375,7 +375,7 @@ inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t {...@@ -375,7 +375,7 @@ inline fn trunc_f80(comptime dst_t: type, a: f80) dst_t {
375 }375 }
376 }376 }
377377
378 const result align(@alignOf(dst_t)) = abs_result | @as(dst_rep_t, sign) << dst_bits - 16;378 const result align(@alignOf(dst_t)) = abs_result | (@as(dst_rep_t, sign) << (dst_bits - 16));
379 return @bitCast(result);379 return @bitCast(result);
380}380}
381381
lib/std/Io/Dispatch.zig+2-2
...@@ -1931,10 +1931,10 @@ const BatchWaiter = struct {...@@ -1931,10 +1931,10 @@ const BatchWaiter = struct {
19311931
1932fn batchAwaitAsync(userdata: ?*anyopaque, batch: *Io.Batch) Io.Cancelable!void {1932fn batchAwaitAsync(userdata: ?*anyopaque, batch: *Io.Batch) Io.Cancelable!void {
1933 const ev: *Evented = @ptrCast(@alignCast(userdata));1933 const ev: *Evented = @ptrCast(@alignCast(userdata));
1934 const queue = ev.batchDrainSubmitted(batch, false) catch |err| switch (err) {1934 const queue = (ev.batchDrainSubmitted(batch, false) catch |err| switch (err) {
1935 error.ConcurrencyUnavailable => unreachable, // passed concurrency=false1935 error.ConcurrencyUnavailable => unreachable, // passed concurrency=false
1936 error.Canceled => |e| return e,1936 error.Canceled => |e| return e,
1937 } orelse return;1937 }) orelse return;
1938 if (batch.pending.head == .none) return;1938 if (batch.pending.head == .none) return;
1939 var waiter: BatchWaiter = .{1939 var waiter: BatchWaiter = .{
1940 .sleeper = .init(ev.queue, Thread.current().currentFiber()),1940 .sleeper = .init(ev.queue, Thread.current().currentFiber()),
lib/std/Io/Kqueue.zig+1-1
...@@ -164,7 +164,7 @@ pub const InitError = Allocator.Error || CreateFileDescriptorError;...@@ -164,7 +164,7 @@ pub const InitError = Allocator.Error || CreateFileDescriptorError;
164pub fn init(k: *Kqueue, gpa: Allocator, options: InitOptions) !void {164pub fn init(k: *Kqueue, gpa: Allocator, options: InitOptions) !void {
165 assert(options.n_threads != 0);165 assert(options.n_threads != 0);
166166
167 const n_threads = @max(1, options.n_threads orelse std.Thread.getCpuCount() catch 1);167 const n_threads = @max(1, options.n_threads orelse (std.Thread.getCpuCount() catch 1));
168 const threads_size = n_threads * @sizeOf(Thread);168 const threads_size = n_threads * @sizeOf(Thread);
169 const idle_stack_end_offset = std.mem.alignForward(usize, threads_size + idle_stack_size, std.heap.page_size_max);169 const idle_stack_end_offset = std.mem.alignForward(usize, threads_size + idle_stack_size, std.heap.page_size_max);
170 const allocated_slice = try gpa.alignedAlloc(u8, .of(Thread), idle_stack_end_offset);170 const allocated_slice = try gpa.alignedAlloc(u8, .of(Thread), idle_stack_end_offset);
lib/std/Io/Threaded/test.zig+1-1
...@@ -36,7 +36,7 @@ fn put(io: Io, queue: *Io.Queue(u8)) void {...@@ -36,7 +36,7 @@ fn put(io: Io, queue: *Io.Queue(u8)) void {
36}36}
3737
38fn get(io: Io, queue: *Io.Queue(u8)) void {38fn get(io: Io, queue: *Io.Queue(u8)) void {
39 assert(queue.getOneUncancelable(io) catch unreachable == 42);39 assert((queue.getOneUncancelable(io) catch unreachable) == 42);
40}40}
4141
42test "concurrent vs concurrent prevents deadlock via oversubscription" {42test "concurrent vs concurrent prevents deadlock via oversubscription" {
lib/std/Io/Writer.zig+1-1
...@@ -1827,7 +1827,7 @@ pub fn printFloatHex(w: *Writer, value: anytype, case: std.fmt.Case, opt_precisi...@@ -1827,7 +1827,7 @@ pub fn printFloatHex(w: *Writer, value: anytype, case: std.fmt.Case, opt_precisi
1827 // Restore the alignment.1827 // Restore the alignment.
1828 mantissa <<= @as(std.math.Log2Int(TU), @intCast((mantissa_digits - precision) * 4));1828 mantissa <<= @as(std.math.Log2Int(TU), @intCast((mantissa_digits - precision) * 4));
18291829
1830 const overflow = mantissa & (1 << 1 + mantissa_digits * 4) != 0;1830 const overflow = mantissa & (1 << (1 + mantissa_digits * 4)) != 0;
1831 // Prefer a normalized result in case of overflow.1831 // Prefer a normalized result in case of overflow.
1832 if (overflow) {1832 if (overflow) {
1833 mantissa >>= 1;1833 mantissa >>= 1;
lib/std/Io/net/HostName.zig+1-1
...@@ -230,7 +230,7 @@ pub fn expand(noalias packet: []const u8, start_i: usize, noalias dest_buffer: [...@@ -230,7 +230,7 @@ pub fn expand(noalias packet: []const u8, start_i: usize, noalias dest_buffer: [
230 i += 1 + label_len;230 i += 1 + label_len;
231 } else {231 } else {
232 return .{232 return .{
233 len orelse i - start_i + 1,233 len orelse (i - start_i + 1),
234 try .init(dest[0..dest_i]),234 try .init(dest[0..dest_i]),
235 };235 };
236 }236 }
lib/std/base64.zig+3-3
...@@ -148,7 +148,7 @@ pub const Base64Encoder = struct {...@@ -148,7 +148,7 @@ pub const Base64Encoder = struct {
148 if (idx + 2 < source.len) {148 if (idx + 2 < source.len) {
149 dest[out_idx] = encoder.alphabet_chars[source[idx] >> 2];149 dest[out_idx] = encoder.alphabet_chars[source[idx] >> 2];
150 dest[out_idx + 1] = encoder.alphabet_chars[((source[idx] & 0x3) << 4) | (source[idx + 1] >> 4)];150 dest[out_idx + 1] = encoder.alphabet_chars[((source[idx] & 0x3) << 4) | (source[idx + 1] >> 4)];
151 dest[out_idx + 2] = encoder.alphabet_chars[(source[idx + 1] & 0xf) << 2 | (source[idx + 2] >> 6)];151 dest[out_idx + 2] = encoder.alphabet_chars[((source[idx + 1] & 0xf) << 2) | (source[idx + 2] >> 6)];
152 dest[out_idx + 3] = encoder.alphabet_chars[source[idx + 2] & 0x3f];152 dest[out_idx + 3] = encoder.alphabet_chars[source[idx + 2] & 0x3f];
153 out_idx += 4;153 out_idx += 4;
154 } else if (idx + 1 < source.len) {154 } else if (idx + 1 < source.len) {
...@@ -282,7 +282,7 @@ pub const Base64Decoder = struct {...@@ -282,7 +282,7 @@ pub const Base64Decoder = struct {
282 dest_idx += 1;282 dest_idx += 1;
283 }283 }
284 }284 }
285 if (acc_len > 4 or (acc & (@as(u12, 1) << acc_len) - 1) != 0) {285 if (acc_len > 4 or (acc & ((@as(u12, 1) << acc_len) - 1)) != 0) {
286 return error.InvalidPadding;286 return error.InvalidPadding;
287 }287 }
288 if (leftover_idx == null) return;288 if (leftover_idx == null) return;
...@@ -357,7 +357,7 @@ pub const Base64DecoderWithIgnore = struct {...@@ -357,7 +357,7 @@ pub const Base64DecoderWithIgnore = struct {
357 dest_idx += 1;357 dest_idx += 1;
358 }358 }
359 }359 }
360 if (acc_len > 4 or (acc & (@as(u12, 1) << acc_len) - 1) != 0) {360 if (acc_len > 4 or (acc & ((@as(u12, 1) << acc_len) - 1)) != 0) {
361 return error.InvalidPadding;361 return error.InvalidPadding;
362 }362 }
363 const padding_len = acc_len / 2;363 const padding_len = acc_len / 2;
lib/std/bit_set.zig+4-4
...@@ -468,11 +468,11 @@ pub fn Array(comptime MaskIntType: type, comptime size: usize) type {...@@ -468,11 +468,11 @@ pub fn Array(comptime MaskIntType: type, comptime size: usize) type {
468468
469 if (start_mask_index == end_mask_index) {469 if (start_mask_index == end_mask_index) {
470 var mask1 = std.math.boolMask(MaskInt, true) << start_bit;470 var mask1 = std.math.boolMask(MaskInt, true) << start_bit;
471 var mask2 = std.math.boolMask(MaskInt, true) >> (mask_len - 1) - (end_bit - 1);471 var mask2 = std.math.boolMask(MaskInt, true) >> ((mask_len - 1) - (end_bit - 1));
472 self.masks[start_mask_index] &= ~(mask1 & mask2);472 self.masks[start_mask_index] &= ~(mask1 & mask2);
473473
474 mask1 = std.math.boolMask(MaskInt, value) << start_bit;474 mask1 = std.math.boolMask(MaskInt, value) << start_bit;
475 mask2 = std.math.boolMask(MaskInt, value) >> (mask_len - 1) - (end_bit - 1);475 mask2 = std.math.boolMask(MaskInt, value) >> ((mask_len - 1) - (end_bit - 1));
476 self.masks[start_mask_index] |= mask1 & mask2;476 self.masks[start_mask_index] |= mask1 & mask2;
477 } else {477 } else {
478 var bulk_mask_index: usize = undefined;478 var bulk_mask_index: usize = undefined;
...@@ -875,11 +875,11 @@ pub const Dynamic = struct {...@@ -875,11 +875,11 @@ pub const Dynamic = struct {
875875
876 if (start_mask_index == end_mask_index) {876 if (start_mask_index == end_mask_index) {
877 var mask1 = std.math.boolMask(MaskInt, true) << start_bit;877 var mask1 = std.math.boolMask(MaskInt, true) << start_bit;
878 var mask2 = std.math.boolMask(MaskInt, true) >> (@bitSizeOf(MaskInt) - 1) - (end_bit - 1);878 var mask2 = std.math.boolMask(MaskInt, true) >> ((@bitSizeOf(MaskInt) - 1) - (end_bit - 1));
879 self.masks[start_mask_index] &= ~(mask1 & mask2);879 self.masks[start_mask_index] &= ~(mask1 & mask2);
880880
881 mask1 = std.math.boolMask(MaskInt, value) << start_bit;881 mask1 = std.math.boolMask(MaskInt, value) << start_bit;
882 mask2 = std.math.boolMask(MaskInt, value) >> (@bitSizeOf(MaskInt) - 1) - (end_bit - 1);882 mask2 = std.math.boolMask(MaskInt, value) >> ((@bitSizeOf(MaskInt) - 1) - (end_bit - 1));
883 self.masks[start_mask_index] |= mask1 & mask2;883 self.masks[start_mask_index] |= mask1 & mask2;
884 } else {884 } else {
885 var bulk_mask_index: usize = undefined;885 var bulk_mask_index: usize = undefined;
lib/std/coff.zig+1-1
...@@ -2035,7 +2035,7 @@ pub const ArchiveMemberHeader = extern struct {...@@ -2035,7 +2035,7 @@ pub const ArchiveMemberHeader = extern struct {
2035 if (trim.len == 0) return error.BadName;2035 if (trim.len == 0) return error.BadName;
2036 return if (trim[0] == '/') name: {2036 return if (trim[0] == '/') name: {
2037 if (trim.len == 1 or2037 if (trim.len == 1 or
2038 trim.len == 2 and trim[1] == '/')2038 (trim.len == 2 and trim[1] == '/'))
2039 break :name trim;2039 break :name trim;
20402040
2041 const offset = std.fmt.parseUnsigned(u50, trim[1..], 10) catch2041 const offset = std.fmt.parseUnsigned(u50, trim[1..], 10) catch
lib/std/compress/flate/Compress.zig+2-2
...@@ -1333,8 +1333,8 @@ const huffman = struct {...@@ -1333,8 +1333,8 @@ const huffman = struct {
13331333
1334 const incomplete_allowed = smith.value(bool);1334 const incomplete_allowed = smith.value(bool);
1335 while (nfreqs < @as(u8, @intFromBool(!incomplete_allowed)) + 1 or1335 while (nfreqs < @as(u8, @intFromBool(!incomplete_allowed)) + 1 or
1336 nfreqs != freqs_buf.len and freqs_limit != 0 and1336 (nfreqs != freqs_buf.len and freqs_limit != 0 and
1337 smith.eosWeightedSimple(15, 1))1337 smith.eosWeightedSimple(15, 1)))
1338 {1338 {
1339 const f = smith.valueWeighted(u16, &.{1339 const f = smith.valueWeighted(u16, &.{
1340 .rangeAtMost(u16, 0, @min(31, freqs_limit), @max(freqs_limit, 1)),1340 .rangeAtMost(u16, 0, @min(31, freqs_limit), @max(freqs_limit, 1)),
lib/std/crypto/aes/soft.zig+1-1
...@@ -728,7 +728,7 @@ pub const Aes256 = struct {...@@ -728,7 +728,7 @@ pub const Aes256 = struct {
728// constants728// constants
729729
730// Rijndael's irreducible polynomial.730// Rijndael's irreducible polynomial.
731const poly: u9 = 1 << 8 | 1 << 4 | 1 << 3 | 1 << 1 | 1 << 0; // x⁸ + x⁴ + x³ + x + 1731const poly: u9 = (1 << 8) | (1 << 4) | (1 << 3) | (1 << 1) | (1 << 0); // x⁸ + x⁴ + x³ + x + 1
732732
733// Powers of x mod poly in GF(2).733// Powers of x mod poly in GF(2).
734const powx = init: {734const powx = init: {
lib/std/crypto/codecs/base64_hex_ct.zig+1-1
...@@ -29,7 +29,7 @@ pub const hex = struct {...@@ -29,7 +29,7 @@ pub const hex = struct {
29 const c: u16 = v & 0xf;29 const c: u16 = v & 0xf;
30 const off = if (case == .upper) 32 else 0;30 const off = if (case == .upper) 32 else 0;
31 const x =31 const x =
32 ((87 - off + c + (((c -% 10) >> 8) & ~@as(u16, 38 - off))) & 0xff) << 8 |32 (((87 - off + c + (((c -% 10) >> 8) & ~@as(u16, 38 - off))) & 0xff) << 8) |
33 ((87 - off + b + (((b -% 10) >> 8) & ~@as(u16, 38 - off))) & 0xff);33 ((87 - off + b + (((b -% 10) >> 8) & ~@as(u16, 38 - off))) & 0xff);
34 encoded[i * 2] = @truncate(x);34 encoded[i * 2] = @truncate(x);
35 encoded[i * 2 + 1] = @truncate(x >> 8);35 encoded[i * 2 + 1] = @truncate(x >> 8);
lib/std/crypto/ml_kem.zig+1-1
...@@ -1264,7 +1264,7 @@ const Poly = struct {...@@ -1264,7 +1264,7 @@ const Poly = struct {
1264 const b1 = @as(i16, buf[3 * i + 1]);1264 const b1 = @as(i16, buf[3 * i + 1]);
1265 const b2 = @as(i16, buf[3 * i + 2]);1265 const b2 = @as(i16, buf[3 * i + 2]);
1266 ret.cs[2 * i] = b0 | ((b1 & 0xf) << 8);1266 ret.cs[2 * i] = b0 | ((b1 & 0xf) << 8);
1267 ret.cs[2 * i + 1] = (b1 >> 4) | b2 << 4;1267 ret.cs[2 * i + 1] = (b1 >> 4) | (b2 << 4);
1268 }1268 }
1269 return ret;1269 return ret;
1270 }1270 }
lib/std/crypto/scrypt.zig+1-1
...@@ -82,7 +82,7 @@ fn blockMix(tmp: *align(16) [16]u32, in: []align(16) const u32, out: []align(16)...@@ -82,7 +82,7 @@ fn blockMix(tmp: *align(16) [16]u32, in: []align(16) const u32, out: []align(16)
8282
83fn integerify(b: []align(16) const u32, r: u30) u64 {83fn integerify(b: []align(16) const u32, r: u30) u64 {
84 const j = (2 * r - 1) * 16;84 const j = (2 * r - 1) * 16;
85 return @as(u64, b[j]) | @as(u64, b[j + 1]) << 32;85 return @as(u64, b[j]) | (@as(u64, b[j + 1]) << 32);
86}86}
8787
88fn smix(b: []align(16) u8, r: u30, n: usize, v: []align(16) u32, xy: []align(16) u32) void {88fn smix(b: []align(16) u8, r: u30, n: usize, v: []align(16) u32, xy: []align(16) u32) void {
lib/std/crypto/sha2.zig+1-1
...@@ -557,7 +557,7 @@ fn Sha2x64(comptime iv: Iv64, digest_bits: comptime_int) type {...@@ -557,7 +557,7 @@ fn Sha2x64(comptime iv: Iv64, digest_bits: comptime_int) type {
557 }557 }
558558
559 if (digest_bits % 8 != 0) @compileError("impl doesn't support non-byte digest_len");559 if (digest_bits % 8 != 0) @compileError("impl doesn't support non-byte digest_len");
560 const bytes_left = digest_bits / 8 % 8;560 const bytes_left = (digest_bits / 8) % 8;
561 if (bytes_left > 0) {561 if (bytes_left > 0) {
562 const rest = d.s[(digest_bits / 64)];562 const rest = d.s[(digest_bits / 64)];
563 var buf: [8]u8 = undefined;563 var buf: [8]u8 = undefined;
lib/std/debug.zig+1-1
...@@ -1306,7 +1306,7 @@ fn printLineInfo(...@@ -1306,7 +1306,7 @@ fn printLineInfo(
1306 try writer.print("0x{x} in {s} ({s})", .{1306 try writer.print("0x{x} in {s} ({s})", .{
1307 address,1307 address,
1308 symbol.name orelse "???",1308 symbol.name orelse "???",
1309 symbol.compile_unit_name orelse debug_info.getModuleName(io, address) catch "???",1309 symbol.compile_unit_name orelse (debug_info.getModuleName(io, address) catch "???"),
1310 });1310 });
1311 t.setColor(.reset) catch {};1311 t.setColor(.reset) catch {};
1312 try writer.writeAll("\n");1312 try writer.writeAll("\n");
lib/std/debug/SelfInfo/Elf.zig+4-4
...@@ -16,11 +16,11 @@ pub fn deinit(si: *SelfInfo, io: Io) void {...@@ -16,11 +16,11 @@ pub fn deinit(si: *SelfInfo, io: Io) void {
16 const gpa = std.debug.getDebugInfoAllocator();16 const gpa = std.debug.getDebugInfoAllocator();
17 for (si.modules.items) |*mod| {17 for (si.modules.items) |*mod| {
18 unwind: {18 unwind: {
19 const u = &(mod.unwind orelse break :unwind catch break :unwind);19 const u = &((mod.unwind orelse break :unwind) catch break :unwind);
20 for (u.buf[0..u.len]) |*unwind| unwind.deinit(gpa);20 for (u.buf[0..u.len]) |*unwind| unwind.deinit(gpa);
21 }21 }
22 loaded: {22 loaded: {
23 const l = &(mod.loaded_elf orelse break :loaded catch break :loaded);23 const l = &((mod.loaded_elf orelse break :loaded) catch break :loaded);
24 l.file.deinit(gpa);24 l.file.deinit(gpa);
25 }25 }
26 }26 }
...@@ -431,11 +431,11 @@ fn findModule(si: *SelfInfo, gpa: Allocator, io: Io, address: usize, lock: enum...@@ -431,11 +431,11 @@ fn findModule(si: *SelfInfo, gpa: Allocator, io: Io, address: usize, lock: enum
431 }431 }
432 for (si.modules.items) |*mod| {432 for (si.modules.items) |*mod| {
433 unwind: {433 unwind: {
434 const u = &(mod.unwind orelse break :unwind catch break :unwind);434 const u = &((mod.unwind orelse break :unwind) catch break :unwind);
435 for (u.buf[0..u.len]) |*unwind| unwind.deinit(gpa);435 for (u.buf[0..u.len]) |*unwind| unwind.deinit(gpa);
436 }436 }
437 loaded: {437 loaded: {
438 const l = &(mod.loaded_elf orelse break :loaded catch break :loaded);438 const l = &((mod.loaded_elf orelse break :loaded) catch break :loaded);
439 l.file.deinit(gpa);439 l.file.deinit(gpa);
440 }440 }
441 }441 }
lib/std/debug/SelfInfo/MachO.zig+2-2
...@@ -11,11 +11,11 @@ pub fn deinit(si: *SelfInfo, io: Io) void {...@@ -11,11 +11,11 @@ pub fn deinit(si: *SelfInfo, io: Io) void {
11 const gpa = std.debug.getDebugInfoAllocator();11 const gpa = std.debug.getDebugInfoAllocator();
12 for (si.modules.keys()) |*module| {12 for (si.modules.keys()) |*module| {
13 unwind: {13 unwind: {
14 const u = &(module.unwind orelse break :unwind catch break :unwind);14 const u = &((module.unwind orelse break :unwind) catch break :unwind);
15 if (u.dwarf) |*dwarf| dwarf.deinit(gpa);15 if (u.dwarf) |*dwarf| dwarf.deinit(gpa);
16 }16 }
17 file: {17 file: {
18 const f = &(module.file orelse break :file catch break :file);18 const f = &((module.file orelse break :file) catch break :file);
19 f.deinit(gpa);19 f.deinit(gpa);
20 }20 }
21 }21 }
lib/std/debug/SelfInfo/Windows.zig+4-4
...@@ -280,7 +280,7 @@ const Module = struct {...@@ -280,7 +280,7 @@ const Module = struct {
280 // we have no information to add to the address280 // we have no information to add to the address
281 break :pdb;281 break :pdb;
282 };282 };
283 const module = pdb.getModule(mod_index) catch |err| switch (err) {283 const module = (pdb.getModule(mod_index) catch |err| switch (err) {
284 error.InvalidDebugInfo,284 error.InvalidDebugInfo,
285 error.MissingDebugInfo,285 error.MissingDebugInfo,
286 error.OutOfMemory,286 error.OutOfMemory,
...@@ -289,7 +289,7 @@ const Module = struct {...@@ -289,7 +289,7 @@ const Module = struct {
289 error.ReadFailed,289 error.ReadFailed,
290 error.EndOfStream,290 error.EndOfStream,
291 => return error.InvalidDebugInfo,291 => return error.InvalidDebugInfo,
292 } orelse {292 }) orelse {
293 return error.InvalidDebugInfo; // bad module index293 return error.InvalidDebugInfo; // bad module index
294 };294 };
295295
...@@ -539,9 +539,9 @@ const Module = struct {...@@ -539,9 +539,9 @@ const Module = struct {
539 }539 }
540540
541 var opt_pdb: ?Pdb = pdb: {541 var opt_pdb: ?Pdb = pdb: {
542 const path = coff_obj.getPdbPath() catch {542 const path = (coff_obj.getPdbPath() catch {
543 return error.InvalidDebugInfo;543 return error.InvalidDebugInfo;
544 } orelse {544 }) orelse {
545 break :pdb null;545 break :pdb null;
546 };546 };
547 const pdb_file_open_result = if (fs.path.isAbsolute(path)) res: {547 const pdb_file_open_result = if (fs.path.isAbsolute(path)) res: {
lib/std/dynamic_library.zig+7-7
...@@ -13,7 +13,7 @@ const posix = std.posix;...@@ -13,7 +13,7 @@ const posix = std.posix;
13/// Platform-specific functionality is available through the `inner` field.13/// Platform-specific functionality is available through the `inner` field.
14pub const DynLib = struct {14pub const DynLib = struct {
15 const InnerType = switch (native_os) {15 const InnerType = switch (native_os) {
16 .linux => if (!builtin.link_libc or builtin.abi == .musl and builtin.link_mode == .static)16 .linux => if (!builtin.link_libc or (builtin.abi == .musl and builtin.link_mode == .static))
17 ElfDynLib17 ElfDynLib
18 else18 else
19 DlDynLib,19 DlDynLib,
...@@ -434,15 +434,15 @@ pub const ElfDynLib = struct {...@@ -434,15 +434,15 @@ pub const ElfDynLib = struct {
434 pub fn lookupAddress(self: *const ElfDynLib, vername: []const u8, name: []const u8) ?usize {434 pub fn lookupAddress(self: *const ElfDynLib, vername: []const u8, name: []const u8) ?usize {
435 const maybe_versym = if (self.verdef == null) null else self.versym;435 const maybe_versym = if (self.verdef == null) null else self.versym;
436436
437 const OK_TYPES = (1 << elf.STT_NOTYPE | 1 << elf.STT_OBJECT | 1 << elf.STT_FUNC | 1 << elf.STT_COMMON);437 const OK_TYPES = (1 << elf.STT_NOTYPE) | (1 << elf.STT_OBJECT) | (1 << elf.STT_FUNC) | (1 << elf.STT_COMMON);
438 const OK_BINDS = (1 << elf.STB_GLOBAL | 1 << elf.STB_WEAK | 1 << elf.STB_GNU_UNIQUE);438 const OK_BINDS = (1 << elf.STB_GLOBAL) | (1 << elf.STB_WEAK) | (1 << elf.STB_GNU_UNIQUE);
439439
440 switch (self.hash_table) {440 switch (self.hash_table) {
441 .dt_hash => |hashtab| {441 .dt_hash => |hashtab| {
442 var i: usize = 0;442 var i: usize = 0;
443 while (i < hashtab[1]) : (i += 1) {443 while (i < hashtab[1]) : (i += 1) {
444 if (0 == (@as(u32, 1) << @as(u5, @intCast(self.syms[i].st_info & 0xf)) & OK_TYPES)) continue;444 if (0 == (@as(u32, 1) << @as(u5, @intCast(self.syms[i].st_info & 0xf))) & OK_TYPES) continue;
445 if (0 == (@as(u32, 1) << @as(u5, @intCast(self.syms[i].st_info >> 4)) & OK_BINDS)) continue;445 if (0 == (@as(u32, 1) << @as(u5, @intCast(self.syms[i].st_info >> 4))) & OK_BINDS) continue;
446 if (0 == self.syms[i].st_shndx) continue;446 if (0 == self.syms[i].st_shndx) continue;
447 if (!mem.eql(u8, name, mem.sliceTo(self.strings + self.syms[i].st_name, 0))) continue;447 if (!mem.eql(u8, name, mem.sliceTo(self.strings + self.syms[i].st_name, 0))) continue;
448 if (maybe_versym) |versym| {448 if (maybe_versym) |versym| {
...@@ -494,8 +494,8 @@ pub const ElfDynLib = struct {...@@ -494,8 +494,8 @@ pub const ElfDynLib = struct {
494 const symbol_index = current_index + gnu_hash_header.symoffset;494 const symbol_index = current_index + gnu_hash_header.symoffset;
495 const symbol = self.syms[symbol_index];495 const symbol = self.syms[symbol_index];
496496
497 if (0 == (@as(u32, 1) << @as(u5, @intCast(symbol.st_info & 0xf)) & OK_TYPES)) continue;497 if (0 == (@as(u32, 1) << @as(u5, @intCast(symbol.st_info & 0xf))) & OK_TYPES) continue;
498 if (0 == (@as(u32, 1) << @as(u5, @intCast(symbol.st_info >> 4)) & OK_BINDS)) continue;498 if (0 == (@as(u32, 1) << @as(u5, @intCast(symbol.st_info >> 4))) & OK_BINDS) continue;
499 if (0 == symbol.st_shndx) continue;499 if (0 == symbol.st_shndx) continue;
500500
501 const symbol_name = mem.sliceTo(self.strings + symbol.st_name, 0);501 const symbol_name = mem.sliceTo(self.strings + symbol.st_name, 0);
lib/std/fmt/parse_float/common.zig+1-1
...@@ -82,7 +82,7 @@ pub fn isDigit(c: u8, comptime base: u8) bool {...@@ -82,7 +82,7 @@ pub fn isDigit(c: u8, comptime base: u8) bool {
82 return if (base == 10)82 return if (base == 10)
83 '0' <= c and c <= '9'83 '0' <= c and c <= '9'
84 else84 else
85 '0' <= c and c <= '9' or 'a' <= c and c <= 'f' or 'A' <= c and c <= 'F';85 ('0' <= c and c <= '9') or ('a' <= c and c <= 'f') or ('A' <= c and c <= 'F');
86}86}
8787
88/// Returns the underlying storage type used for the mantissa of floating-point type.88/// Returns the underlying storage type used for the mantissa of floating-point type.
lib/std/hash/cityhash.zig+1-1
...@@ -222,7 +222,7 @@ pub const CityHash64 = struct {...@@ -222,7 +222,7 @@ pub const CityHash64 = struct {
222 const c: u8 = str[str.len - 1];222 const c: u8 = str[str.len - 1];
223 const y: u32 = @as(u32, @intCast(a)) +% (@as(u32, @intCast(b)) << 8);223 const y: u32 = @as(u32, @intCast(a)) +% (@as(u32, @intCast(b)) << 8);
224 const z: u32 = @as(u32, @truncate(str.len)) +% (@as(u32, @intCast(c)) << 2);224 const z: u32 = @as(u32, @truncate(str.len)) +% (@as(u32, @intCast(c)) << 2);
225 return shiftmix(@as(u64, @intCast(y)) *% k2 ^ @as(u64, @intCast(z)) *% k0) *% k2;225 return shiftmix((@as(u64, @intCast(y)) *% k2) ^ (@as(u64, @intCast(z)) *% k0)) *% k2;
226 }226 }
227 return k2;227 return k2;
228 }228 }
lib/std/hash/xxhash.zig+1-1
...@@ -398,7 +398,7 @@ pub const XxHash32 = struct {...@@ -398,7 +398,7 @@ pub const XxHash32 = struct {
398 }398 }
399399
400 fn avalanche(value: u32) u32 {400 fn avalanche(value: u32) u32 {
401 var acc = value ^ value >> 15;401 var acc = value ^ (value >> 15);
402 acc *%= prime_2;402 acc *%= prime_2;
403 acc ^= acc >> 13;403 acc ^= acc >> 13;
404 acc *%= prime_3;404 acc *%= prime_3;
lib/std/hash_map.zig+1-1
...@@ -2019,7 +2019,7 @@ test "getOrPutAdapted" {...@@ -2019,7 +2019,7 @@ test "getOrPutAdapted" {
2019 const AdaptedContext = struct {2019 const AdaptedContext = struct {
2020 fn eql(self: @This(), adapted_key: []const u8, test_key: u64) bool {2020 fn eql(self: @This(), adapted_key: []const u8, test_key: u64) bool {
2021 _ = self;2021 _ = self;
2022 return std.fmt.parseInt(u64, adapted_key, 10) catch unreachable == test_key;2022 return (std.fmt.parseInt(u64, adapted_key, 10) catch unreachable) == test_key;
2023 }2023 }
2024 fn hash(self: @This(), adapted_key: []const u8) u64 {2024 fn hash(self: @This(), adapted_key: []const u8) u64 {
2025 _ = self;2025 _ = self;
lib/std/heap/SafeAllocator.zig+1-1
...@@ -211,7 +211,7 @@ const Bucket = struct {...@@ -211,7 +211,7 @@ const Bucket = struct {
211211
212 fn of(s: *SafeAllocator, ptr: [*]u8) *Bucket {212 fn of(s: *SafeAllocator, ptr: [*]u8) *Bucket {
213 const size_log2 = s.bucket_size_log2;213 const size_log2 = s.bucket_size_log2;
214 return @ptrFromInt(@intFromPtr(ptr) >> @intCast(size_log2) << @intCast(size_log2));214 return @ptrFromInt((@intFromPtr(ptr) >> @intCast(size_log2)) << @intCast(size_log2));
215 }215 }
216216
217 fn fillAt(s: *SafeAllocator, ptr: [*]const u8) u32 {217 fn fillAt(s: *SafeAllocator, ptr: [*]const u8) u32 {
lib/std/math.zig+14-14
...@@ -710,7 +710,7 @@ pub fn rotr(comptime T: type, x: T, r: anytype) T {...@@ -710,7 +710,7 @@ pub fn rotr(comptime T: type, x: T, r: anytype) T {
710710
711 if (comptime isPowerOfTwo(@typeInfo(T).int.bits)) {711 if (comptime isPowerOfTwo(@typeInfo(T).int.bits)) {
712 const ar: Log2Int(T) = @intCast(@mod(r, @typeInfo(T).int.bits));712 const ar: Log2Int(T) = @intCast(@mod(r, @typeInfo(T).int.bits));
713 return x >> ar | x << (1 +% ~ar);713 return (x >> ar) | (x << (1 +% ~ar));
714 } else {714 } else {
715 const ar = @mod(r, @typeInfo(T).int.bits);715 const ar = @mod(r, @typeInfo(T).int.bits);
716 return shr(T, x, ar) | shl(T, x, @typeInfo(T).int.bits - ar);716 return shr(T, x, ar) | shl(T, x, @typeInfo(T).int.bits - ar);
...@@ -753,7 +753,7 @@ pub fn rotl(comptime T: type, x: T, r: anytype) T {...@@ -753,7 +753,7 @@ pub fn rotl(comptime T: type, x: T, r: anytype) T {
753753
754 if (comptime isPowerOfTwo(@typeInfo(T).int.bits)) {754 if (comptime isPowerOfTwo(@typeInfo(T).int.bits)) {
755 const ar: Log2Int(T) = @intCast(@mod(r, @typeInfo(T).int.bits));755 const ar: Log2Int(T) = @intCast(@mod(r, @typeInfo(T).int.bits));
756 return x << ar | x >> 1 +% ~ar;756 return (x << ar) | (x >> (1 +% ~ar));
757 } else {757 } else {
758 const ar = @mod(r, @typeInfo(T).int.bits);758 const ar = @mod(r, @typeInfo(T).int.bits);
759 return shl(T, x, ar) | shr(T, x, @typeInfo(T).int.bits - ar);759 return shl(T, x, ar) | shr(T, x, @typeInfo(T).int.bits - ar);
...@@ -1542,21 +1542,21 @@ pub const Order = enum {...@@ -1542,21 +1542,21 @@ pub const Order = enum {
1542 const neg: i32 = -1;1542 const neg: i32 = -1;
1543 const zero: i32 = 0;1543 const zero: i32 = 0;
1544 const pos: i32 = 1;1544 const pos: i32 = 1;
1545 try testing.expect(order(zero, neg).differ() orelse1545 try testing.expect((order(zero, neg).differ() orelse
1546 order(pos, zero) == .gt);1546 order(pos, zero)) == .gt);
1547 try testing.expect(order(zero, zero).differ() orelse1547 try testing.expect((order(zero, zero).differ() orelse
1548 order(zero, zero) == .eq);1548 order(zero, zero)) == .eq);
1549 try testing.expect(order(pos, pos).differ() orelse1549 try testing.expect((order(pos, pos).differ() orelse
1550 order(neg, zero) == .lt);1550 order(neg, zero)) == .lt);
1551 try testing.expect(order(zero, zero).differ() orelse1551 try testing.expect((order(zero, zero).differ() orelse
1552 order(pos, neg).differ() orelse1552 order(pos, neg).differ() orelse
1553 order(neg, zero) == .gt);1553 order(neg, zero)) == .gt);
1554 try testing.expect(order(pos, pos).differ() orelse1554 try testing.expect((order(pos, pos).differ() orelse
1555 order(pos, pos).differ() orelse1555 order(pos, pos).differ() orelse
1556 order(neg, neg) == .eq);1556 order(neg, neg)) == .eq);
1557 try testing.expect(order(zero, pos).differ() orelse1557 try testing.expect((order(zero, pos).differ() orelse
1558 order(neg, pos).differ() orelse1558 order(neg, pos).differ() orelse
1559 order(pos, neg) == .lt);1559 order(pos, neg)) == .lt);
1560 }1560 }
15611561
1562 pub fn compare(self: Order, op: CompareOperator) bool {1562 pub fn compare(self: Order, op: CompareOperator) bool {
lib/std/math/acos.zig+1-1
...@@ -176,7 +176,7 @@ fn acosBinary64(x: f64) f64 {...@@ -176,7 +176,7 @@ fn acosBinary64(x: f64) f64 {
176 // |x| >= 1 or nan176 // |x| >= 1 or nan
177 if (ix >= 0x3ff0_0000) {177 if (ix >= 0x3ff0_0000) {
178 const lx: u32 = @truncate(@as(u64, @bitCast(x)));178 const lx: u32 = @truncate(@as(u64, @bitCast(x)));
179 if ((ix - 0x3ff0_0000 | lx) == 0) {179 if (((ix - 0x3ff0_0000) | lx) == 0) {
180 if (hx >> 31 != 0) {180 if (hx >> 31 != 0) {
181 return 2.0 * pio2_hi + 0x1.0p-120;181 return 2.0 * pio2_hi + 0x1.0p-120;
182 }182 }
lib/std/math/asin.zig+1-1
...@@ -156,7 +156,7 @@ fn asinBinary64(x: f64) f64 {...@@ -156,7 +156,7 @@ fn asinBinary64(x: f64) f64 {
156 if (ix >= 0x3ff0_0000) {156 if (ix >= 0x3ff0_0000) {
157 const lx: u32 = @truncate(@as(u64, @bitCast(x)));157 const lx: u32 = @truncate(@as(u64, @bitCast(x)));
158 // asin(1) = +-pi/2 with inexact158 // asin(1) = +-pi/2 with inexact
159 if ((ix - 0x3ff0_0000 | lx) == 0) {159 if (((ix - 0x3ff0_0000) | lx) == 0) {
160 return x * pio2_hi + 0x1.0p-120;160 return x * pio2_hi + 0x1.0p-120;
161 }161 }
162 return 0.0 / (x - x);162 return 0.0 / (x - x);
lib/std/math/big/int.zig+3-3
...@@ -2401,7 +2401,7 @@ pub const Const = struct {...@@ -2401,7 +2401,7 @@ pub const Const = struct {
2401 const shift: usize = @intCast(exponent - @bitSizeOf(Repr.Normalized.Fraction));2401 const shift: usize = @intCast(exponent - @bitSizeOf(Repr.Normalized.Fraction));
2402 mantissa.shiftRight(normalized_abs, shift);2402 mantissa.shiftRight(normalized_abs, shift);
2403 const final_limb_index = (shift - 1) / limb_bits;2403 const final_limb_index = (shift - 1) / limb_bits;
2404 const round_bits = normalized_abs.limbs[final_limb_index] << @truncate(-%shift) |2404 const round_bits = (normalized_abs.limbs[final_limb_index] << @truncate(-%shift)) |
2405 @intFromBool(!std.mem.allEqual(Limb, normalized_abs.limbs[0..final_limb_index], 0));2405 @intFromBool(!std.mem.allEqual(Limb, normalized_abs.limbs[0..final_limb_index], 0));
2406 if (round_bits == 0) break :exactness .exact;2406 if (round_bits == 0) break :exactness .exact;
2407 round: switch (round) {2407 round: switch (round) {
...@@ -4902,10 +4902,10 @@ test "format" {...@@ -4902,10 +4902,10 @@ test "format" {
4902 try a.set(20000000000000000000); // > maxInt(u64)4902 try a.set(20000000000000000000); // > maxInt(u64)
4903 try testFormat(a, "20000000000000000000");4903 try testFormat(a, "20000000000000000000");
49044904
4905 try a.set(1 << 64 * @sizeOf(usize) * 8);4905 try a.set(1 << (64 * @sizeOf(usize) * 8));
4906 try testFormat(a, "(BigInt)");4906 try testFormat(a, "(BigInt)");
49074907
4908 try a.set(-(1 << 64 * @sizeOf(usize) * 8));4908 try a.set(-(1 << (64 * @sizeOf(usize) * 8)));
4909 try testFormat(a, "(BigInt)");4909 try testFormat(a, "(BigInt)");
4910}4910}
49114911
lib/std/math/big/int_test.zig+16-16
...@@ -2489,14 +2489,14 @@ test "truncate to minimum signed integer" {...@@ -2489,14 +2489,14 @@ test "truncate to minimum signed integer" {
2489 .len = undefined,2489 .len = undefined,
2490 .positive = undefined,2490 .positive = undefined,
2491 };2491 };
2492 res.truncate(.{ .positive = true, .limbs = &.{1 << @bitSizeOf(Limb) - 1} }, .signed, @bitSizeOf(Limb));2492 res.truncate(.{ .positive = true, .limbs = &.{1 << (@bitSizeOf(Limb) - 1)} }, .signed, @bitSizeOf(Limb));
2493 try testing.expect(res.toConst().orderAgainstScalar(-1 << @bitSizeOf(Limb) - 1).compare(.eq));2493 try testing.expect(res.toConst().orderAgainstScalar(-1 << (@bitSizeOf(Limb) - 1)).compare(.eq));
2494 res.truncate(.{ .positive = false, .limbs = &.{1 << @bitSizeOf(Limb) - 1} }, .signed, @bitSizeOf(Limb));2494 res.truncate(.{ .positive = false, .limbs = &.{1 << (@bitSizeOf(Limb) - 1)} }, .signed, @bitSizeOf(Limb));
2495 try testing.expect(res.toConst().orderAgainstScalar(-1 << @bitSizeOf(Limb) - 1).compare(.eq));2495 try testing.expect(res.toConst().orderAgainstScalar(-1 << (@bitSizeOf(Limb) - 1)).compare(.eq));
2496 res.truncate(.{ .positive = true, .limbs = &.{1 << @bitSizeOf(Limb) - 1} }, .unsigned, @bitSizeOf(Limb));2496 res.truncate(.{ .positive = true, .limbs = &.{1 << (@bitSizeOf(Limb) - 1)} }, .unsigned, @bitSizeOf(Limb));
2497 try testing.expect(res.toConst().orderAgainstScalar(1 << @bitSizeOf(Limb) - 1).compare(.eq));2497 try testing.expect(res.toConst().orderAgainstScalar(1 << (@bitSizeOf(Limb) - 1)).compare(.eq));
2498 res.truncate(.{ .positive = false, .limbs = &.{1 << @bitSizeOf(Limb) - 1} }, .unsigned, @bitSizeOf(Limb));2498 res.truncate(.{ .positive = false, .limbs = &.{1 << (@bitSizeOf(Limb) - 1)} }, .unsigned, @bitSizeOf(Limb));
2499 try testing.expect(res.toConst().orderAgainstScalar(1 << @bitSizeOf(Limb) - 1).compare(.eq));2499 try testing.expect(res.toConst().orderAgainstScalar(1 << (@bitSizeOf(Limb) - 1)).compare(.eq));
2500}2500}
25012501
2502test "saturate single signed positive" {2502test "saturate single signed positive" {
...@@ -3880,7 +3880,7 @@ test "clz" {...@@ -3880,7 +3880,7 @@ test "clz" {
3880 try testing.expectEqual(0, neg_limb_max_squared_plus_one.clz(@bitSizeOf(Limb) * 2 + 1));3880 try testing.expectEqual(0, neg_limb_max_squared_plus_one.clz(@bitSizeOf(Limb) * 2 + 1));
38813881
3882 const neg_limb_msb_squared: std.math.big.int.Const = .{3882 const neg_limb_msb_squared: std.math.big.int.Const = .{
3883 .limbs = &.{ 0, 1 << @bitSizeOf(Limb) - 2 },3883 .limbs = &.{ 0, 1 << (@bitSizeOf(Limb) - 2) },
3884 .positive = false,3884 .positive = false,
3885 };3885 };
3886 try testing.expectEqual(0, neg_limb_msb_squared.clz(@bitSizeOf(Limb) * 2));3886 try testing.expectEqual(0, neg_limb_msb_squared.clz(@bitSizeOf(Limb) * 2));
...@@ -3896,7 +3896,7 @@ test "clz" {...@@ -3896,7 +3896,7 @@ test "clz" {
3896 try testing.expectEqual(0, neg_limb_max.clz(@bitSizeOf(Limb) * 2 + 1));3896 try testing.expectEqual(0, neg_limb_max.clz(@bitSizeOf(Limb) * 2 + 1));
38973897
3898 const neg_limb_msb: std.math.big.int.Const = .{3898 const neg_limb_msb: std.math.big.int.Const = .{
3899 .limbs = &.{1 << @bitSizeOf(Limb) - 1},3899 .limbs = &.{1 << (@bitSizeOf(Limb) - 1)},
3900 .positive = false,3900 .positive = false,
3901 };3901 };
3902 try testing.expectEqual(0, neg_limb_msb.clz(@bitSizeOf(Limb)));3902 try testing.expectEqual(0, neg_limb_msb.clz(@bitSizeOf(Limb)));
...@@ -3936,7 +3936,7 @@ test "clz" {...@@ -3936,7 +3936,7 @@ test "clz" {
3936 try testing.expectEqual(@bitSizeOf(Limb) * 2, one.clz(@bitSizeOf(Limb) * 2 + 1));3936 try testing.expectEqual(@bitSizeOf(Limb) * 2, one.clz(@bitSizeOf(Limb) * 2 + 1));
39373937
3938 const limb_msb: std.math.big.int.Const = .{3938 const limb_msb: std.math.big.int.Const = .{
3939 .limbs = &.{1 << @bitSizeOf(Limb) - 1},3939 .limbs = &.{1 << (@bitSizeOf(Limb) - 1)},
3940 .positive = true,3940 .positive = true,
3941 };3941 };
3942 try testing.expectEqual(0, limb_msb.clz(@bitSizeOf(Limb)));3942 try testing.expectEqual(0, limb_msb.clz(@bitSizeOf(Limb)));
...@@ -3956,7 +3956,7 @@ test "clz" {...@@ -3956,7 +3956,7 @@ test "clz" {
3956 try testing.expectEqual(@bitSizeOf(Limb) + 1, limb_max.clz(@bitSizeOf(Limb) * 2 + 1));3956 try testing.expectEqual(@bitSizeOf(Limb) + 1, limb_max.clz(@bitSizeOf(Limb) * 2 + 1));
39573957
3958 const limb_msb_squared: std.math.big.int.Const = .{3958 const limb_msb_squared: std.math.big.int.Const = .{
3959 .limbs = &.{ 0, 1 << @bitSizeOf(Limb) - 2 },3959 .limbs = &.{ 0, 1 << (@bitSizeOf(Limb) - 2) },
3960 .positive = true,3960 .positive = true,
3961 };3961 };
3962 try testing.expectEqual(0, limb_msb_squared.clz(@bitSizeOf(Limb) * 2 - 1));3962 try testing.expectEqual(0, limb_msb_squared.clz(@bitSizeOf(Limb) * 2 - 1));
...@@ -3992,7 +3992,7 @@ test "ctz" {...@@ -3992,7 +3992,7 @@ test "ctz" {
3992 try testing.expectEqual(@bitSizeOf(Limb) + 1, neg_limb_max_squared_plus_one.ctz(@bitSizeOf(Limb) * 2 + 1));3992 try testing.expectEqual(@bitSizeOf(Limb) + 1, neg_limb_max_squared_plus_one.ctz(@bitSizeOf(Limb) * 2 + 1));
39933993
3994 const neg_limb_msb_squared: std.math.big.int.Const = .{3994 const neg_limb_msb_squared: std.math.big.int.Const = .{
3995 .limbs = &.{ 0, 1 << @bitSizeOf(Limb) - 2 },3995 .limbs = &.{ 0, 1 << (@bitSizeOf(Limb) - 2) },
3996 .positive = false,3996 .positive = false,
3997 };3997 };
3998 try testing.expectEqual(@bitSizeOf(Limb) * 2 - 2, neg_limb_msb_squared.ctz(@bitSizeOf(Limb) * 2));3998 try testing.expectEqual(@bitSizeOf(Limb) * 2 - 2, neg_limb_msb_squared.ctz(@bitSizeOf(Limb) * 2));
...@@ -4008,7 +4008,7 @@ test "ctz" {...@@ -4008,7 +4008,7 @@ test "ctz" {
4008 try testing.expectEqual(0, neg_limb_max.ctz(@bitSizeOf(Limb) * 2 + 1));4008 try testing.expectEqual(0, neg_limb_max.ctz(@bitSizeOf(Limb) * 2 + 1));
40094009
4010 const neg_limb_msb: std.math.big.int.Const = .{4010 const neg_limb_msb: std.math.big.int.Const = .{
4011 .limbs = &.{1 << @bitSizeOf(Limb) - 1},4011 .limbs = &.{1 << (@bitSizeOf(Limb) - 1)},
4012 .positive = false,4012 .positive = false,
4013 };4013 };
4014 try testing.expectEqual(@bitSizeOf(Limb) - 1, neg_limb_msb.ctz(@bitSizeOf(Limb)));4014 try testing.expectEqual(@bitSizeOf(Limb) - 1, neg_limb_msb.ctz(@bitSizeOf(Limb)));
...@@ -4048,7 +4048,7 @@ test "ctz" {...@@ -4048,7 +4048,7 @@ test "ctz" {
4048 try testing.expectEqual(0, one.ctz(@bitSizeOf(Limb) * 2 + 1));4048 try testing.expectEqual(0, one.ctz(@bitSizeOf(Limb) * 2 + 1));
40494049
4050 const limb_msb: std.math.big.int.Const = .{4050 const limb_msb: std.math.big.int.Const = .{
4051 .limbs = &.{1 << @bitSizeOf(Limb) - 1},4051 .limbs = &.{1 << (@bitSizeOf(Limb) - 1)},
4052 .positive = true,4052 .positive = true,
4053 };4053 };
4054 try testing.expectEqual(@bitSizeOf(Limb) - 1, limb_msb.ctz(@bitSizeOf(Limb)));4054 try testing.expectEqual(@bitSizeOf(Limb) - 1, limb_msb.ctz(@bitSizeOf(Limb)));
...@@ -4068,7 +4068,7 @@ test "ctz" {...@@ -4068,7 +4068,7 @@ test "ctz" {
4068 try testing.expectEqual(0, limb_max.ctz(@bitSizeOf(Limb) * 2 + 1));4068 try testing.expectEqual(0, limb_max.ctz(@bitSizeOf(Limb) * 2 + 1));
40694069
4070 const limb_msb_squared: std.math.big.int.Const = .{4070 const limb_msb_squared: std.math.big.int.Const = .{
4071 .limbs = &.{ 0, 1 << @bitSizeOf(Limb) - 2 },4071 .limbs = &.{ 0, 1 << (@bitSizeOf(Limb) - 2) },
4072 .positive = true,4072 .positive = true,
4073 };4073 };
4074 try testing.expectEqual(@bitSizeOf(Limb) * 2 - 2, limb_msb_squared.ctz(@bitSizeOf(Limb) * 2 - 1));4074 try testing.expectEqual(@bitSizeOf(Limb) * 2 - 2, limb_msb_squared.ctz(@bitSizeOf(Limb) * 2 - 1));
lib/std/math/float.zig+2-2
...@@ -281,7 +281,7 @@ pub inline fn nan(comptime Type: type) Type {...@@ -281,7 +281,7 @@ pub inline fn nan(comptime Type: type) Type {
281 return reconstructFloat(281 return reconstructFloat(
282 RuntimeType,282 RuntimeType,
283 floatExponentMax(RuntimeType) + 1,283 floatExponentMax(RuntimeType) + 1,
284 mantissaOne(RuntimeType) | 1 << (floatFractionalBits(RuntimeType) - 1),284 mantissaOne(RuntimeType) | (1 << (floatFractionalBits(RuntimeType) - 1)),
285 );285 );
286}286}
287287
...@@ -297,7 +297,7 @@ pub inline fn snan(comptime Type: type) Type {...@@ -297,7 +297,7 @@ pub inline fn snan(comptime Type: type) Type {
297 return reconstructFloat(297 return reconstructFloat(
298 RuntimeType,298 RuntimeType,
299 floatExponentMax(RuntimeType) + 1,299 floatExponentMax(RuntimeType) + 1,
300 mantissaOne(RuntimeType) | 1 << (floatFractionalBits(RuntimeType) - 2),300 mantissaOne(RuntimeType) | (1 << (floatFractionalBits(RuntimeType) - 2)),
301 );301 );
302}302}
303303
lib/std/mem.zig+1-1
...@@ -4354,7 +4354,7 @@ pub fn alignPointerOffset(ptr: anytype, align_to: usize) ?usize {...@@ -4354,7 +4354,7 @@ pub fn alignPointerOffset(ptr: anytype, align_to: usize) ?usize {
4354 @compileError("expected many item pointer, got " ++ @typeName(T));4354 @compileError("expected many item pointer, got " ++ @typeName(T));
43554355
4356 // Do nothing if the pointer is already well-aligned.4356 // Do nothing if the pointer is already well-aligned.
4357 if (align_to <= info.pointer.attrs.@"align" orelse @alignOf(info.pointer.child))4357 if (align_to <= (info.pointer.attrs.@"align" orelse @alignOf(info.pointer.child)))
4358 return 0;4358 return 0;
43594359
4360 // Calculate the aligned base address with an eye out for overflow.4360 // Calculate the aligned base address with an eye out for overflow.
lib/std/os/linux/vdso.zig+4-4
...@@ -62,13 +62,13 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {...@@ -62,13 +62,13 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
62 const hashtab = maybe_hashtab orelse return 0;62 const hashtab = maybe_hashtab orelse return 0;
63 if (maybe_verdef == null) maybe_versym = null;63 if (maybe_verdef == null) maybe_versym = null;
6464
65 const OK_TYPES = (1 << elf.STT_NOTYPE | 1 << elf.STT_OBJECT | 1 << elf.STT_FUNC | 1 << elf.STT_COMMON);65 const OK_TYPES = (1 << elf.STT_NOTYPE) | (1 << elf.STT_OBJECT) | (1 << elf.STT_FUNC) | (1 << elf.STT_COMMON);
66 const OK_BINDS = (1 << elf.STB_GLOBAL | 1 << elf.STB_WEAK | 1 << elf.STB_GNU_UNIQUE);66 const OK_BINDS = (1 << elf.STB_GLOBAL) | (1 << elf.STB_WEAK) | (1 << elf.STB_GNU_UNIQUE);
6767
68 var i: usize = 0;68 var i: usize = 0;
69 while (i < hashtab[1]) : (i += 1) {69 while (i < hashtab[1]) : (i += 1) {
70 if (0 == (@as(u32, 1) << @as(u5, @intCast(syms[i].st_info & 0xf)) & OK_TYPES)) continue;70 if (0 == (@as(u32, 1) << @as(u5, @intCast(syms[i].st_info & 0xf))) & OK_TYPES) continue;
71 if (0 == (@as(u32, 1) << @as(u5, @intCast(syms[i].st_info >> 4)) & OK_BINDS)) continue;71 if (0 == (@as(u32, 1) << @as(u5, @intCast(syms[i].st_info >> 4))) & OK_BINDS) continue;
72 if (0 == syms[i].st_shndx) continue;72 if (0 == syms[i].st_shndx) continue;
73 const sym_name = @as([*:0]u8, @ptrCast(strings + syms[i].st_name));73 const sym_name = @as([*:0]u8, @ptrCast(strings + syms[i].st_name));
74 if (!mem.eql(u8, name, mem.sliceTo(sym_name, 0))) continue;74 if (!mem.eql(u8, name, mem.sliceTo(sym_name, 0))) continue;
lib/std/os/uefi/status.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const testing = @import("std").testing;1const testing = @import("std").testing;
22
3const high_bit = 1 << @typeInfo(usize).int.bits - 1;3const high_bit = 1 << (@typeInfo(usize).int.bits - 1);
44
5pub const Status = enum(usize) {5pub const Status = enum(usize) {
6 /// The operation completed successfully.6 /// The operation completed successfully.
lib/std/unicode.zig+1-1
...@@ -485,7 +485,7 @@ pub fn utf16DecodeSurrogatePair(surrogate_pair: []const u16) !u21 {...@@ -485,7 +485,7 @@ pub fn utf16DecodeSurrogatePair(surrogate_pair: []const u16) !u21 {
485 const high_half: u21 = surrogate_pair[0];485 const high_half: u21 = surrogate_pair[0];
486 const low_half = surrogate_pair[1];486 const low_half = surrogate_pair[1];
487 if (!utf16IsLowSurrogate(low_half)) return error.ExpectedSecondSurrogateHalf;487 if (!utf16IsLowSurrogate(low_half)) return error.ExpectedSecondSurrogateHalf;
488 return 0x10000 + ((high_half & 0x03ff) << 10) | (low_half & 0x03ff);488 return (0x10000 + ((high_half & 0x03ff) << 10)) | (low_half & 0x03ff);
489}489}
490490
491pub const Utf16LeIterator = struct {491pub const Utf16LeIterator = struct {
lib/std/zig/Ast.zig+32
...@@ -555,6 +555,33 @@ pub fn renderError(tree: Ast, parse_error: Error, w: *Writer) Writer.Error!void...@@ -555,6 +555,33 @@ pub fn renderError(tree: Ast, parse_error: Error, w: *Writer) Writer.Error!void
555 .var_const_decl => {555 .var_const_decl => {
556 return w.writeAll("use 'var' or 'const' to declare variable");556 return w.writeAll("use 'var' or 'const' to declare variable");
557 },557 },
558 .ambiguous_operator_precedence => {
559 return w.print("ambiguous operator precedence with operators ... {s} ... {s} ...; use parentheses to disambiguate", .{
560 tree.tokenTag(parse_error.token - @as(u32, @intCast(parse_error.extra.offset))).lexeme().?,
561 tree.tokenTag(parse_error.token).lexeme().?,
562 });
563 },
564 .previous_ambiguous_operator => {
565 return w.writeAll("previous ambiguous operator here");
566 },
567 .illegal_chained_operators => {
568 return w.print("repetition of non-chainable operators ... {s} ... {s} ...; use parentheses to disambiguate", .{
569 tree.tokenTag(parse_error.token - @as(u32, @intCast(parse_error.extra.offset))).lexeme().?,
570 tree.tokenTag(parse_error.token).lexeme().?,
571 });
572 },
573 .hint_operator_precedence_left => {
574 return w.print("in zig 0.17.x, this was evaluated as (... {s} ...) {s} ...", .{
575 tree.tokenTag(parse_error.token - @as(u32, @intCast(parse_error.extra.offset))).lexeme().?,
576 tree.tokenTag(parse_error.token).lexeme().?,
577 });
578 },
579 .hint_operator_precedence_right => {
580 return w.print("in zig 0.17.x, this was evaluated as ... {s} (... {s} ...)", .{
581 tree.tokenTag(parse_error.token - @as(u32, @intCast(parse_error.extra.offset))).lexeme().?,
582 tree.tokenTag(parse_error.token).lexeme().?,
583 });
584 },
558585
559 .invalid_byte => {586 .invalid_byte => {
560 const tok_slice = tree.source[tree.tokens.items(.start)[parse_error.token]..];587 const tok_slice = tree.source[tree.tokens.items(.start)[parse_error.token]..];
...@@ -2893,6 +2920,11 @@ pub const Error = struct {...@@ -2893,6 +2920,11 @@ pub const Error = struct {
2893 expected_var_const,2920 expected_var_const,
2894 wrong_equal_var_decl,2921 wrong_equal_var_decl,
2895 var_const_decl,2922 var_const_decl,
2923 ambiguous_operator_precedence,
2924 previous_ambiguous_operator,
2925 hint_operator_precedence_left,
2926 hint_operator_precedence_right,
2927 illegal_chained_operators,
28962928
2897 zig_style_container,2929 zig_style_container,
2898 previous_field,2930 previous_field,
lib/std/zig/Ast/Render.zig+34-5
...@@ -45,6 +45,8 @@ pub const Fixups = struct {...@@ -45,6 +45,8 @@ pub const Fixups = struct {
45 replace_nodes_with_node: std.AutoHashMapUnmanaged(Ast.Node.Index, Ast.Node.Index) = .empty,45 replace_nodes_with_node: std.AutoHashMapUnmanaged(Ast.Node.Index, Ast.Node.Index) = .empty,
46 /// Change all identifier names matching the key to be value instead.46 /// Change all identifier names matching the key to be value instead.
47 rename_identifiers: std.array_hash_map.String([]const u8) = .empty,47 rename_identifiers: std.array_hash_map.String([]const u8) = .empty,
48 /// Add parentheses surrounding the node.
49 insert_parentheses: std.AutoHashMapUnmanaged(Ast.Node.Index, void) = .empty,
4850
49 /// All `@import` builtin calls which refer to a file path will be prefixed51 /// All `@import` builtin calls which refer to a file path will be prefixed
50 /// with this path.52 /// with this path.
...@@ -58,6 +60,7 @@ pub const Fixups = struct {...@@ -58,6 +60,7 @@ pub const Fixups = struct {
58 f.append_string_after_node.count() +60 f.append_string_after_node.count() +
59 f.replace_nodes_with_node.count() +61 f.replace_nodes_with_node.count() +
60 f.rename_identifiers.count() +62 f.rename_identifiers.count() +
63 f.insert_parentheses.count() +
61 @intFromBool(f.rebase_imported_paths != null);64 @intFromBool(f.rebase_imported_paths != null);
62 }65 }
6366
...@@ -69,6 +72,7 @@ pub const Fixups = struct {...@@ -69,6 +72,7 @@ pub const Fixups = struct {
69 f.append_string_after_node.clearRetainingCapacity();72 f.append_string_after_node.clearRetainingCapacity();
70 f.replace_nodes_with_node.clearRetainingCapacity();73 f.replace_nodes_with_node.clearRetainingCapacity();
71 f.rename_identifiers.clearRetainingCapacity();74 f.rename_identifiers.clearRetainingCapacity();
75 f.insert_parentheses.clearRetainingCapacity();
7276
73 f.rebase_imported_paths = null;77 f.rebase_imported_paths = null;
74 }78 }
...@@ -81,6 +85,7 @@ pub const Fixups = struct {...@@ -81,6 +85,7 @@ pub const Fixups = struct {
81 f.append_string_after_node.deinit(gpa);85 f.append_string_after_node.deinit(gpa);
82 f.replace_nodes_with_node.deinit(gpa);86 f.replace_nodes_with_node.deinit(gpa);
83 f.rename_identifiers.deinit(gpa);87 f.rename_identifiers.deinit(gpa);
88 f.insert_parentheses.deinit(gpa);
84 f.* = undefined;89 f.* = undefined;
85 }90 }
86};91};
...@@ -420,6 +425,9 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {...@@ -420,6 +425,9 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
420 tree.tokenTag(fallback_first) == .multiline_string_literal_line;425 tree.tokenTag(fallback_first) == .multiline_string_literal_line;
421 const after_op_space: Space = if (seperate_line) .newline else .space;426 const after_op_space: Space = if (seperate_line) .newline else .space;
422427
428 if (r.fixups.insert_parentheses.contains(node)) {
429 try ais.writeByte('(');
430 }
423 try renderExpression(r, lhs, .space); // target431 try renderExpression(r, lhs, .space); // target
424432
425 try ais.pushIndent(.normal);433 try ais.pushIndent(.normal);
...@@ -432,7 +440,16 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {...@@ -432,7 +440,16 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
432 assert(tree.tokenTag(fallback_first - 1) == .keyword_catch);440 assert(tree.tokenTag(fallback_first - 1) == .keyword_catch);
433 try renderToken(r, main_token, after_op_space); // catch keyword441 try renderToken(r, main_token, after_op_space); // catch keyword
434 }442 }
435 try renderExpression(r, rhs, space); // fallback443 if (r.fixups.insert_parentheses.contains(node)) {
444 try renderExpression(r, rhs, .none);
445 try ais.writeByte(')');
446 const right_most_token = tree.lastToken(rhs);
447 const lexeme = tokenSliceForRender(tree, right_most_token);
448 // If our space is .none, then the above code functions is normal and below shouldn't run
449 if (space != .none) try renderSpace(r, right_most_token, lexeme.len, space);
450 } else {
451 try renderExpression(r, rhs, space); // fallback
452 }
436 ais.popIndent();453 ais.popIndent();
437 },454 },
438455
...@@ -539,13 +556,25 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {...@@ -539,13 +556,25 @@ fn renderExpression(r: *Render, node: Ast.Node.Index, space: Space) Error!void {
539 .@"orelse",556 .@"orelse",
540 => {557 => {
541 const lhs, const rhs = tree.nodeData(node).node_and_node;558 const lhs, const rhs = tree.nodeData(node).node_and_node;
559 if (r.fixups.insert_parentheses.contains(node)) {
560 try ais.writeByte('(');
561 }
542 try renderExpression(r, lhs, .space);562 try renderExpression(r, lhs, .space);
543 const op_token = tree.nodeMainToken(node);563 const op_token = tree.nodeMainToken(node);
544 try ais.pushIndent(.binop);564 try ais.pushIndent(.binop);
545 const rhs_seperate_line = !tree.tokensOnSameLine(op_token, op_token + 1) or565 const rhs_seperate_line = !tree.tokensOnSameLine(op_token, op_token + 1) or
546 tree.tokenTag(op_token + 1) == .multiline_string_literal_line;566 tree.tokenTag(op_token + 1) == .multiline_string_literal_line;
547 try renderToken(r, op_token, if (rhs_seperate_line) .newline else .space);567 try renderToken(r, op_token, if (rhs_seperate_line) .newline else .space);
548 try renderExpression(r, rhs, space);568 if (r.fixups.insert_parentheses.contains(node)) {
569 try renderExpression(r, rhs, .none);
570 try ais.writeByte(')');
571 const right_most_token = tree.lastToken(rhs);
572 const lexeme = tokenSliceForRender(tree, right_most_token);
573 // If our space was already .none, then the line below will be redundent as above handles it.
574 if (space != .none) try renderSpace(r, right_most_token, lexeme.len, space);
575 } else {
576 try renderExpression(r, rhs, space);
577 }
549 ais.popIndent();578 ais.popIndent();
550 },579 },
551580
...@@ -1483,9 +1512,9 @@ fn renderThenElse(...@@ -1483,9 +1512,9 @@ fn renderThenElse(
1483 last_else_token = error_token + 1; // |1512 last_else_token = error_token + 1; // |
1484 }1513 }
14851514
1486 const indent_else_expr = indent_then_expr and1515 const indent_else_expr = (indent_then_expr and
1487 !nodeIsBlock(tree.nodeTag(else_expr)) and1516 !nodeIsBlock(tree.nodeTag(else_expr)) and
1488 !nodeIsIfForWhileSwitch(tree.nodeTag(else_expr)) or1517 !nodeIsIfForWhileSwitch(tree.nodeTag(else_expr))) or
1489 tree.tokenTag(tree.firstToken(else_expr)) ==1518 tree.tokenTag(tree.firstToken(else_expr)) ==
1490 .multiline_string_literal_line;1519 .multiline_string_literal_line;
1491 if (indent_else_expr) {1520 if (indent_else_expr) {
...@@ -3195,7 +3224,7 @@ fn renderComments(r: *Render, start: usize, end: usize) Error!bool {...@@ -3195,7 +3224,7 @@ fn renderComments(r: *Render, start: usize, end: usize) Error!bool {
3195 }3224 }
3196 }3225 }
31973226
3198 index = 1 + (newline orelse end - 1);3227 index = 1 + (newline orelse (end - 1));
31993228
3200 const comment_content = mem.trimStart(u8, trimmed_comment["//".len..], &std.ascii.whitespace);3229 const comment_content = mem.trimStart(u8, trimmed_comment["//".len..], &std.ascii.whitespace);
3201 if (ais.disabled_offset != null and mem.eql(u8, comment_content, "zig fmt: on")) {3230 if (ais.disabled_offset != null and mem.eql(u8, comment_content, "zig fmt: on")) {
lib/std/zig/Parse.zig+319-55
...@@ -1512,7 +1512,7 @@ fn expectAssignExpr(p: *Parse) !Node.Index {...@@ -1512,7 +1512,7 @@ fn expectAssignExpr(p: *Parse) !Node.Index {
1512}1512}
15131513
1514fn parseExpr(p: *Parse) Error!?Node.Index {1514fn parseExpr(p: *Parse) Error!?Node.Index {
1515 return p.parseExprPrecedence(0);1515 return p.parseExprPrecedence(.start, p.tok_i);
1516}1516}
15171517
1518fn expectExpr(p: *Parse) Error!Node.Index {1518fn expectExpr(p: *Parse) Error!Node.Index {
...@@ -1524,67 +1524,335 @@ const Assoc = enum {...@@ -1524,67 +1524,335 @@ const Assoc = enum {
1524 none,1524 none,
1525};1525};
15261526
1527const PrecClass = struct {
1528 group: Group,
1529 assoc: Assoc = Assoc.left,
1530
1531 const Group = enum {
1532 const num_distinct = std.meta.fieldNames(Group).len;
1533
1534 top,
1535
1536 arithmetic_product_chainable,
1537 arithmetic_mod_nonchainable,
1538 arithmetic_sum,
1539
1540 bitwise_shift,
1541 bitwise_and,
1542 bitwise_xor,
1543 bitwise_or,
1544
1545 comparison,
1546
1547 bool_and,
1548 bool_or,
1549
1550 recovery_orelse,
1551 recovery_catch,
1552
1553 root,
1554
1555 const Major = enum {
1556 top,
1557 arithmetic,
1558 bitwise,
1559 comparison,
1560 bool,
1561 recovery,
1562 root,
1563 };
1564
1565 fn getMajor(group: Group) Major {
1566 return switch (group) {
1567 .top,
1568 => .top,
1569
1570 .arithmetic_product_chainable,
1571 .arithmetic_mod_nonchainable,
1572 .arithmetic_sum,
1573 => .arithmetic,
1574
1575 .bitwise_shift,
1576 .bitwise_and,
1577 .bitwise_xor,
1578 .bitwise_or,
1579 => .bitwise,
1580
1581 .comparison,
1582 => .comparison,
1583
1584 .bool_and,
1585 .bool_or,
1586 => .bool,
1587
1588 .recovery_orelse,
1589 .recovery_catch,
1590 => .recovery,
1591
1592 .root,
1593 => .root,
1594 };
1595 }
1596 };
1597
1598 pub const start: PrecClass = .{ .group = .root };
1599
1600 pub const Rel = enum(i2) {
1601 lt = -1,
1602 eq = 0,
1603 gt = 1,
1604
1605 fn inverted(self: Rel) Rel {
1606 return @fromBackingInt(@intCast(-@backingInt(self)));
1607 }
1608 };
1609
1610 const PrecedenceArray = [Group.num_distinct][Group.num_distinct]?Rel;
1611
1612 fn setMajorRelation(prec_array: *PrecedenceArray, major_a: Group.Major, rel: Rel, major_b: Group.Major) void {
1613 for (std.meta.fieldNames(Group), 0..) |fieldname_i, i| {
1614 if (@field(Group, fieldname_i).getMajor() != major_a) continue;
1615
1616 for (std.meta.fieldNames(Group), 0..) |fieldname_j, j| {
1617 if (@field(Group, fieldname_j).getMajor() != major_b) continue;
1618
1619 prec_array[i][j] = rel;
1620 prec_array[j][i] = rel.inverted();
1621 }
1622 }
1623 }
1624
1625 fn setMinorRelation(prec_array: *PrecedenceArray, minor_a: Group, rel: Rel, minor_b: Group) void {
1626 prec_array[@backingInt(minor_a)][@backingInt(minor_b)] = rel;
1627 prec_array[@backingInt(minor_b)][@backingInt(minor_a)] = rel.inverted();
1628 }
1629
1630 /// order[y][x] --> y cmp x
1631 const precedence_ordering = b: {
1632 @setEvalBranchQuota(20_000);
1633 const major_greater_than_relations = [_][2]Group.Major{
1634 // zig fmt: off
1635 .{ .top, .arithmetic },
1636 .{ .top, .bitwise },
1637 .{ .top, .recovery },
1638 .{ .arithmetic, .comparison },
1639 .{ .bitwise, .comparison },
1640 .{ .comparison, .bool },
1641 .{ .bool, .root },
1642 .{ .recovery, .root },
1643 // zig fmt: on
1644 };
1645
1646 var order: PrecedenceArray = @splat(@splat(null));
1647
1648 for (major_greater_than_relations) |relation| {
1649 setMajorRelation(&order, relation[0], .gt, relation[1]);
1650 }
1651
1652 setMinorRelation(&order, .arithmetic_mod_nonchainable, .gt, .arithmetic_sum);
1653 setMinorRelation(&order, .arithmetic_product_chainable, .gt, .arithmetic_sum);
1654
1655 computeTransitiveOrdering(&order);
1656 break :b order;
1657 };
1658
1659 /// Uses the table from Zig-0.17.0
1660 /// * / % *% *| ||
1661 /// + - ++ +% -% +| -|
1662 /// << >> <<|
1663 /// & ^ | orelse catch
1664 /// == != < > <= >=
1665 /// and
1666 /// or
1667 const v0_17_precedence_ordering = b: {
1668 @setEvalBranchQuota(20_000);
1669
1670 var order: PrecedenceArray = @splat(@splat(null));
1671
1672 setMinorRelation(&order, .top, .gt, .arithmetic_product_chainable);
1673
1674 setMinorRelation(&order, .arithmetic_product_chainable, .eq, .arithmetic_mod_nonchainable);
1675 setMinorRelation(&order, .arithmetic_mod_nonchainable, .gt, .arithmetic_sum);
1676
1677 setMinorRelation(&order, .arithmetic_sum, .gt, .bitwise_shift);
1678
1679 setMinorRelation(&order, .bitwise_shift, .gt, .bitwise_and);
1680
1681 setMinorRelation(&order, .bitwise_and, .eq, .bitwise_xor);
1682 setMinorRelation(&order, .bitwise_and, .eq, .bitwise_or);
1683 setMinorRelation(&order, .bitwise_and, .eq, .recovery_catch);
1684 setMinorRelation(&order, .bitwise_and, .eq, .recovery_orelse);
1685
1686 setMinorRelation(&order, .bitwise_and, .gt, .comparison);
1687
1688 setMinorRelation(&order, .comparison, .gt, .bool_and);
1689
1690 setMinorRelation(&order, .bool_and, .gt, .bool_or);
1691
1692 setMinorRelation(&order, .bool_or, .gt, .root);
1693
1694 computeTransitiveOrdering(&order);
1695 for (order) |row| {
1696 for (row) |item| {
1697 if (item == null) @compileError("Null entry in old precedence ordering which had none.");
1698 }
1699 }
1700 break :b order;
1701 };
1702
1703 pub fn cmp(lhs: PrecClass, rhs: PrecClass) ?Rel {
1704 return PrecClass.precedence_ordering[@backingInt(lhs.group)][@backingInt(rhs.group)];
1705 }
1706
1707 pub fn v0_17_cmp(lhs: PrecClass, rhs: PrecClass) Rel {
1708 return PrecClass.v0_17_precedence_ordering[@backingInt(lhs.group)][@backingInt(rhs.group)].?;
1709 }
1710
1711 fn computeTransitiveOrdering(order: *PrecedenceArray) void {
1712 for (0..Group.num_distinct) |i| for (0..Group.num_distinct) |j| for (0..Group.num_distinct) |k| {
1713 if (order[i][j] == null or order[j][k] == null) continue;
1714 // X < Y < Z ==> X < Z X > Y > Z ==> X > Z
1715 if (order[i][j] == order[j][k]) order[i][k] = order[i][j];
1716 // X = Y < Z ==> X < Z X = Y > Z ==> X > Z
1717 if (order[i][j] == .eq) order[i][k] = order[j][k];
1718 // X < Y = Z ==> X < Z X > Y = Z ==> X > Z
1719 if (order[j][k] == .eq) order[i][k] = order[i][j];
1720 };
1721 for (0..Group.num_distinct) |i| for (0..Group.num_distinct) |j| {
1722 if (i == j) order[i][j] = .eq;
1723 if (order[i][j] == null and order[j][i] != null) order[i][j] = order[j][i].?.inverted();
1724 };
1725 }
1726};
1727
1527const OperInfo = struct {1728const OperInfo = struct {
1528 prec: i8,1729 prec: PrecClass,
1529 tag: Node.Tag,1730 tag: Node.Tag,
1530 assoc: Assoc = Assoc.left,
1531};1731};
15321732
1533// A table of binary operator information. Higher precedence numbers are1733const operTable = std.enums.directEnumArrayDefault(Token.Tag, OperInfo, .{ .prec = .start, .tag = Node.Tag.root }, 0, .{
1534// stickier. All operators at the same precedence level should have the same1734 // zig fmt: off
1535// associativity.1735 .keyword_or = .{ .prec = .{ .group = .bool_or }, .tag = .bool_or },
1536const operTable = std.enums.directEnumArrayDefault(Token.Tag, OperInfo, .{ .prec = -1, .tag = Node.Tag.root }, 0, .{1736
1537 .keyword_or = .{ .prec = 10, .tag = .bool_or },1737 .keyword_and = .{ .prec = .{ .group = .bool_and }, .tag = .bool_and },
15381738
1539 .keyword_and = .{ .prec = 20, .tag = .bool_and },1739 .equal_equal = .{ .prec = .{ .group = .comparison, .assoc = Assoc.none }, .tag = .equal_equal },
15401740 .bang_equal = .{ .prec = .{ .group = .comparison, .assoc = Assoc.none }, .tag = .bang_equal },
1541 .equal_equal = .{ .prec = 30, .tag = .equal_equal, .assoc = Assoc.none },1741 .angle_bracket_left = .{ .prec = .{ .group = .comparison, .assoc = Assoc.none }, .tag = .less_than },
1542 .bang_equal = .{ .prec = 30, .tag = .bang_equal, .assoc = Assoc.none },1742 .angle_bracket_right = .{ .prec = .{ .group = .comparison, .assoc = Assoc.none }, .tag = .greater_than },
1543 .angle_bracket_left = .{ .prec = 30, .tag = .less_than, .assoc = Assoc.none },1743 .angle_bracket_left_equal = .{ .prec = .{ .group = .comparison, .assoc = Assoc.none }, .tag = .less_or_equal },
1544 .angle_bracket_right = .{ .prec = 30, .tag = .greater_than, .assoc = Assoc.none },1744 .angle_bracket_right_equal = .{ .prec = .{ .group = .comparison, .assoc = Assoc.none }, .tag = .greater_or_equal },
1545 .angle_bracket_left_equal = .{ .prec = 30, .tag = .less_or_equal, .assoc = Assoc.none },1745
1546 .angle_bracket_right_equal = .{ .prec = 30, .tag = .greater_or_equal, .assoc = Assoc.none },1746 .ampersand = .{ .prec = .{ .group = .bitwise_and }, .tag = .bit_and },
15471747 .caret = .{ .prec = .{ .group = .bitwise_xor }, .tag = .bit_xor },
1548 .ampersand = .{ .prec = 40, .tag = .bit_and },1748 .pipe = .{ .prec = .{ .group = .bitwise_or }, .tag = .bit_or },
1549 .caret = .{ .prec = 40, .tag = .bit_xor },1749
1550 .pipe = .{ .prec = 40, .tag = .bit_or },1750 .keyword_orelse = .{ .prec = .{ .group = .recovery_orelse }, .tag = .@"orelse" },
1551 .keyword_orelse = .{ .prec = 40, .tag = .@"orelse" },1751 .keyword_catch = .{ .prec = .{ .group = .recovery_catch }, .tag = .@"catch" },
1552 .keyword_catch = .{ .prec = 40, .tag = .@"catch" },1752
15531753 .angle_bracket_angle_bracket_left = .{ .prec = .{ .group = .bitwise_shift, .assoc = Assoc.none }, .tag = .shl },
1554 .angle_bracket_angle_bracket_left = .{ .prec = 50, .tag = .shl },1754 .angle_bracket_angle_bracket_left_pipe = .{ .prec = .{ .group = .bitwise_shift, .assoc = Assoc.none }, .tag = .shl_sat },
1555 .angle_bracket_angle_bracket_left_pipe = .{ .prec = 50, .tag = .shl_sat },1755 .angle_bracket_angle_bracket_right = .{ .prec = .{ .group = .bitwise_shift, .assoc = Assoc.none }, .tag = .shr },
1556 .angle_bracket_angle_bracket_right = .{ .prec = 50, .tag = .shr },1756
15571757 .plus = .{ .prec = .{ .group = .arithmetic_sum }, .tag = .add },
1558 .plus = .{ .prec = 60, .tag = .add },1758 .minus = .{ .prec = .{ .group = .arithmetic_sum }, .tag = .sub },
1559 .minus = .{ .prec = 60, .tag = .sub },1759 .plus_plus = .{ .prec = .{ .group = .arithmetic_sum }, .tag = .array_cat },
1560 .plus_plus = .{ .prec = 60, .tag = .array_cat },1760 .plus_percent = .{ .prec = .{ .group = .arithmetic_sum }, .tag = .add_wrap },
1561 .plus_percent = .{ .prec = 60, .tag = .add_wrap },1761 .minus_percent = .{ .prec = .{ .group = .arithmetic_sum }, .tag = .sub_wrap },
1562 .minus_percent = .{ .prec = 60, .tag = .sub_wrap },1762 .plus_pipe = .{ .prec = .{ .group = .arithmetic_sum }, .tag = .add_sat },
1563 .plus_pipe = .{ .prec = 60, .tag = .add_sat },1763 .minus_pipe = .{ .prec = .{ .group = .arithmetic_sum }, .tag = .sub_sat },
1564 .minus_pipe = .{ .prec = 60, .tag = .sub_sat },1764
15651765 .pipe_pipe = .{ .prec = .{ .group = .arithmetic_product_chainable }, .tag = .merge_error_sets },
1566 .pipe_pipe = .{ .prec = 70, .tag = .merge_error_sets },1766 .asterisk = .{ .prec = .{ .group = .arithmetic_product_chainable }, .tag = .mul },
1567 .asterisk = .{ .prec = 70, .tag = .mul },1767 .slash = .{ .prec = .{ .group = .arithmetic_product_chainable }, .tag = .div },
1568 .slash = .{ .prec = 70, .tag = .div },1768 .asterisk_percent = .{ .prec = .{ .group = .arithmetic_product_chainable }, .tag = .mul_wrap },
1569 .percent = .{ .prec = 70, .tag = .mod },1769 .asterisk_pipe = .{ .prec = .{ .group = .arithmetic_product_chainable }, .tag = .mul_sat },
1570 .asterisk_percent = .{ .prec = 70, .tag = .mul_wrap },1770
1571 .asterisk_pipe = .{ .prec = 70, .tag = .mul_sat },1771 .percent = .{ .prec = .{ .group = .arithmetic_mod_nonchainable, .assoc = Assoc.none }, .tag = .mod },
1772 // zig fmt: on
1572});1773});
15731774
1574fn parseExprPrecedence(p: *Parse, min_prec: i32) Error!?Node.Index {1775fn parseExprPrecedence(p: *Parse, min_exc_prec: PrecClass, prev_operator_token: u32) Error!?Node.Index {
1575 assert(min_prec >= 0);
1576 var node = try p.parsePrefixExpr() orelse return null;1776 var node = try p.parsePrefixExpr() orelse return null;
15771777
1578 var banned_prec: i8 = -1;
1579
1580 while (true) {1778 while (true) {
1581 const tok_tag = p.tokenTag(p.tok_i);1779 const tok_tag = p.tokenTag(p.tok_i);
1582 const info = operTable[@as(usize, @intCast(@backingInt(tok_tag)))];1780 const info = operTable[@backingInt(tok_tag)];
1583 if (info.prec < min_prec) {1781
1782 const rel = info.prec.cmp(min_exc_prec) orelse b: {
1783 const prev_op_tok_tag = p.tokenTag(prev_operator_token);
1784 const prev_op_info = operTable[@backingInt(prev_op_tok_tag)];
1785 const v0_17_rel = prev_op_info.prec.v0_17_cmp(info.prec);
1786 try p.warnMsg(.{
1787 .tag = .ambiguous_operator_precedence,
1788 .is_note = false,
1789 .token = p.tok_i,
1790 .extra = .{
1791 .offset = p.tok_i - prev_operator_token,
1792 },
1793 });
1794 try p.warnMsg(.{
1795 .tag = .previous_ambiguous_operator,
1796 .is_note = true,
1797 .token = prev_operator_token,
1798 });
1799 if (v0_17_rel == .gt or v0_17_rel == .eq) {
1800 try p.warnMsg(.{
1801 .tag = .hint_operator_precedence_left,
1802 .is_note = true,
1803 .token = p.tok_i,
1804 .extra = .{
1805 .offset = p.tok_i - prev_operator_token,
1806 },
1807 });
1808 } else {
1809 try p.warnMsg(.{
1810 .tag = .hint_operator_precedence_right,
1811 .is_note = true,
1812 .token = p.tok_i,
1813 .extra = .{
1814 .offset = p.tok_i - prev_operator_token,
1815 },
1816 });
1817 }
1818 // Use the old precedence rules to construct the tree to ease automatic fixups
1819 break :b info.prec.v0_17_cmp(min_exc_prec);
1820 };
1821
1822 if (rel == .lt) {
1584 break;1823 break;
1585 }1824 }
1586 if (info.prec == banned_prec) {1825
1587 return p.fail(.chained_comparison_operators);1826 if (min_exc_prec.group == info.prec.group and min_exc_prec.assoc == .none and info.prec.assoc == .none) {
1827 if (info.prec.group == .comparison) {
1828 try p.warn(.chained_comparison_operators);
1829 } else {
1830 try p.warnMsg(.{
1831 .tag = .illegal_chained_operators,
1832 .is_note = false,
1833 .token = p.tok_i,
1834 .extra = .{
1835 .offset = p.tok_i - prev_operator_token,
1836 },
1837 });
1838 try p.warnMsg(.{
1839 .tag = .previous_ambiguous_operator,
1840 .is_note = true,
1841 .token = prev_operator_token,
1842 });
1843 try p.warnMsg(.{
1844 .tag = .hint_operator_precedence_left,
1845 .is_note = true,
1846 .token = p.tok_i,
1847 .extra = .{
1848 .offset = p.tok_i - prev_operator_token,
1849 },
1850 });
1851 }
1852 }
1853
1854 if (rel == .eq) {
1855 break;
1588 }1856 }
15891857
1590 const oper_token = p.nextToken();1858 const oper_token = p.nextToken();
...@@ -1614,7 +1882,7 @@ fn parseExprPrecedence(p: *Parse, min_prec: i32) Error!?Node.Index {...@@ -1614,7 +1882,7 @@ fn parseExprPrecedence(p: *Parse, min_prec: i32) Error!?Node.Index {
1614 }1882 }
1615 }1883 }
16161884
1617 const rhs = try p.parseExprPrecedence(info.prec + 1) orelse {1885 const rhs = try p.parseExprPrecedence(info.prec, oper_token) orelse {
1618 try p.warn(.expected_expr);1886 try p.warn(.expected_expr);
1619 return node;1887 return node;
1620 };1888 };
...@@ -1624,10 +1892,6 @@ fn parseExprPrecedence(p: *Parse, min_prec: i32) Error!?Node.Index {...@@ -1624,10 +1892,6 @@ fn parseExprPrecedence(p: *Parse, min_prec: i32) Error!?Node.Index {
1624 .main_token = oper_token,1892 .main_token = oper_token,
1625 .data = .{ .node_and_node = .{ node, rhs } },1893 .data = .{ .node_and_node = .{ node, rhs } },
1626 });1894 });
1627
1628 if (info.assoc == Assoc.none) {
1629 banned_prec = info.prec;
1630 }
1631 }1895 }
16321896
1633 return node;1897 return node;
lib/std/zig/TokenSmith.zig+1-1
...@@ -160,7 +160,7 @@ pub fn gen(smith: *Smith) TokenSmith {...@@ -160,7 +160,7 @@ pub fn gen(smith: *Smith) TokenSmith {
160 var no_period = false;160 var no_period = false;
161 var not_exponent = true;161 var not_exponent = true;
162 for (t.source_buf[t.source_len..][0..len], 0..) |*c, i| {162 for (t.source_buf[t.source_len..][0..len], 0..) |*c, i| {
163 const invalid_period = no_period and c.* == '.' or i + 1 == len;163 const invalid_period = (no_period and c.* == '.') or i + 1 == len;
164 const is_exponent = c.* == '-' or c.* == '+';164 const is_exponent = c.* == '-' or c.* == '+';
165 const invalid_exponent = not_exponent and is_exponent;165 const invalid_exponent = not_exponent and is_exponent;
166 const valid_exponent = !not_exponent and is_exponent;166 const valid_exponent = !not_exponent and is_exponent;
lib/std/zig/llvm/BitcodeReader.zig+1-1
...@@ -404,7 +404,7 @@ fn readFixed(bc: *BitcodeReader, comptime T: type, bits: u7) !T {...@@ -404,7 +404,7 @@ fn readFixed(bc: *BitcodeReader, comptime T: type, bits: u7) !T {
404 if (bc.bit_offset == 0) bc.bit_buffer = try bc.read32Bits();404 if (bc.bit_offset == 0) bc.bit_buffer = try bc.read32Bits();
405 const chunk_len = @min(@as(u6, 32) - bc.bit_offset, remaining);405 const chunk_len = @min(@as(u6, 32) - bc.bit_offset, remaining);
406 const chunk_mask = @as(u32, std.math.maxInt(u32)) >> @intCast(32 - chunk_len);406 const chunk_mask = @as(u32, std.math.maxInt(u32)) >> @intCast(32 - chunk_len);
407 result |= @as(T, @intCast(bc.bit_buffer >> bc.bit_offset & chunk_mask)) << @intCast(shift);407 result |= @as(T, @intCast((bc.bit_buffer >> bc.bit_offset) & chunk_mask)) << @intCast(shift);
408 shift += @intCast(chunk_len);408 shift += @intCast(chunk_len);
409 remaining -= chunk_len;409 remaining -= chunk_len;
410 bc.bit_offset = @truncate(bc.bit_offset + chunk_len);410 bc.bit_offset = @truncate(bc.bit_offset + chunk_len);
lib/std/zig/llvm/Builder.zig+26-26
...@@ -1076,7 +1076,7 @@ pub const Type = enum(u32) {...@@ -1076,7 +1076,7 @@ pub const Type = enum(u32) {
1076 child: Type,1076 child: Type,
10771077
1078 fn length(self: Array) u64 {1078 fn length(self: Array) u64 {
1079 return @as(u64, self.len_hi) << 32 | self.len_lo;1079 return (@as(u64, self.len_hi) << 32) | self.len_lo;
1080 }1080 }
1081 };1081 };
10821082
...@@ -9520,7 +9520,7 @@ pub const Metadata = packed struct(u32) {...@@ -9520,7 +9520,7 @@ pub const Metadata = packed struct(u32) {
9520 size_in_bits_hi: u32,9520 size_in_bits_hi: u32,
95219521
9522 pub fn bitSize(self: BasicType) u64 {9522 pub fn bitSize(self: BasicType) u64 {
9523 return @as(u64, self.size_in_bits_hi) << 32 | self.size_in_bits_lo;9523 return (@as(u64, self.size_in_bits_hi) << 32) | self.size_in_bits_lo;
9524 }9524 }
9525 };9525 };
95269526
...@@ -9537,10 +9537,10 @@ pub const Metadata = packed struct(u32) {...@@ -9537,10 +9537,10 @@ pub const Metadata = packed struct(u32) {
9537 fields_tuple: Metadata.Optional,9537 fields_tuple: Metadata.Optional,
95389538
9539 pub fn bitSize(self: CompositeType) u64 {9539 pub fn bitSize(self: CompositeType) u64 {
9540 return @as(u64, self.size_in_bits_hi) << 32 | self.size_in_bits_lo;9540 return (@as(u64, self.size_in_bits_hi) << 32) | self.size_in_bits_lo;
9541 }9541 }
9542 pub fn bitAlign(self: CompositeType) u64 {9542 pub fn bitAlign(self: CompositeType) u64 {
9543 return @as(u64, self.align_in_bits_hi) << 32 | self.align_in_bits_lo;9543 return (@as(u64, self.align_in_bits_hi) << 32) | self.align_in_bits_lo;
9544 }9544 }
9545 };9545 };
95469546
...@@ -9558,13 +9558,13 @@ pub const Metadata = packed struct(u32) {...@@ -9558,13 +9558,13 @@ pub const Metadata = packed struct(u32) {
9558 offset_in_bits_hi: u32,9558 offset_in_bits_hi: u32,
95599559
9560 pub fn bitSize(self: DerivedType) u64 {9560 pub fn bitSize(self: DerivedType) u64 {
9561 return @as(u64, self.size_in_bits_hi) << 32 | self.size_in_bits_lo;9561 return (@as(u64, self.size_in_bits_hi) << 32) | self.size_in_bits_lo;
9562 }9562 }
9563 pub fn bitAlign(self: DerivedType) u64 {9563 pub fn bitAlign(self: DerivedType) u64 {
9564 return @as(u64, self.align_in_bits_hi) << 32 | self.align_in_bits_lo;9564 return (@as(u64, self.align_in_bits_hi) << 32) | self.align_in_bits_lo;
9565 }9565 }
9566 pub fn bitOffset(self: DerivedType) u64 {9566 pub fn bitOffset(self: DerivedType) u64 {
9567 return @as(u64, self.offset_in_bits_hi) << 32 | self.offset_in_bits_lo;9567 return (@as(u64, self.offset_in_bits_hi) << 32) | self.offset_in_bits_lo;
9568 }9568 }
9569 };9569 };
95709570
...@@ -12457,7 +12457,7 @@ fn doubleConstAssumeCapacity(self: *Builder, val: f64) Constant {...@@ -12457,7 +12457,7 @@ fn doubleConstAssumeCapacity(self: *Builder, val: f64) Constant {
12457 if (ctx.builder.constant_items.items(.tag)[rhs_index] != .double) return false;12457 if (ctx.builder.constant_items.items(.tag)[rhs_index] != .double) return false;
12458 const rhs_data = ctx.builder.constant_items.items(.data)[rhs_index];12458 const rhs_data = ctx.builder.constant_items.items(.data)[rhs_index];
12459 const rhs_extra = ctx.builder.constantExtraData(Constant.Double, rhs_data);12459 const rhs_extra = ctx.builder.constantExtraData(Constant.Double, rhs_data);
12460 return @as(u64, @bitCast(lhs_key)) == @as(u64, rhs_extra.hi) << 32 | rhs_extra.lo;12460 return @as(u64, @bitCast(lhs_key)) == (@as(u64, rhs_extra.hi) << 32) | rhs_extra.lo;
12461 }12461 }
12462 };12462 };
12463 const gop = self.constant_map.getOrPutAssumeCapacityAdapted(val, Adapter{ .builder = self });12463 const gop = self.constant_map.getOrPutAssumeCapacityAdapted(val, Adapter{ .builder = self });
...@@ -12488,8 +12488,8 @@ fn fp128ConstAssumeCapacity(self: *Builder, val: f128) Constant {...@@ -12488,8 +12488,8 @@ fn fp128ConstAssumeCapacity(self: *Builder, val: f128) Constant {
12488 if (ctx.builder.constant_items.items(.tag)[rhs_index] != .fp128) return false;12488 if (ctx.builder.constant_items.items(.tag)[rhs_index] != .fp128) return false;
12489 const rhs_data = ctx.builder.constant_items.items(.data)[rhs_index];12489 const rhs_data = ctx.builder.constant_items.items(.data)[rhs_index];
12490 const rhs_extra = ctx.builder.constantExtraData(Constant.Fp128, rhs_data);12490 const rhs_extra = ctx.builder.constantExtraData(Constant.Fp128, rhs_data);
12491 return @as(u128, @bitCast(lhs_key)) == @as(u128, rhs_extra.hi_hi) << 96 |12491 return @as(u128, @bitCast(lhs_key)) == (@as(u128, rhs_extra.hi_hi) << 96) |
12492 @as(u128, rhs_extra.hi_lo) << 64 | @as(u128, rhs_extra.lo_hi) << 32 | rhs_extra.lo_lo;12492 (@as(u128, rhs_extra.hi_lo) << 64) | (@as(u128, rhs_extra.lo_hi) << 32) | rhs_extra.lo_lo;
12493 }12493 }
12494 };12494 };
12495 const gop = self.constant_map.getOrPutAssumeCapacityAdapted(val, Adapter{ .builder = self });12495 const gop = self.constant_map.getOrPutAssumeCapacityAdapted(val, Adapter{ .builder = self });
...@@ -12522,8 +12522,8 @@ fn x86_fp80ConstAssumeCapacity(self: *Builder, val: f80) Constant {...@@ -12522,8 +12522,8 @@ fn x86_fp80ConstAssumeCapacity(self: *Builder, val: f80) Constant {
12522 if (ctx.builder.constant_items.items(.tag)[rhs_index] != .x86_fp80) return false;12522 if (ctx.builder.constant_items.items(.tag)[rhs_index] != .x86_fp80) return false;
12523 const rhs_data = ctx.builder.constant_items.items(.data)[rhs_index];12523 const rhs_data = ctx.builder.constant_items.items(.data)[rhs_index];
12524 const rhs_extra = ctx.builder.constantExtraData(Constant.Fp80, rhs_data);12524 const rhs_extra = ctx.builder.constantExtraData(Constant.Fp80, rhs_data);
12525 return @as(u80, @bitCast(lhs_key)) == @as(u80, rhs_extra.hi) << 64 |12525 return @as(u80, @bitCast(lhs_key)) == (@as(u80, rhs_extra.hi) << 64) |
12526 @as(u80, rhs_extra.lo_hi) << 32 | rhs_extra.lo_lo;12526 (@as(u80, rhs_extra.lo_hi) << 32) | rhs_extra.lo_lo;
12527 }12527 }
12528 };12528 };
12529 const gop = self.constant_map.getOrPutAssumeCapacityAdapted(val, Adapter{ .builder = self });12529 const gop = self.constant_map.getOrPutAssumeCapacityAdapted(val, Adapter{ .builder = self });
...@@ -12555,8 +12555,8 @@ fn ppc_fp128ConstAssumeCapacity(self: *Builder, val: [2]f64) Constant {...@@ -12555,8 +12555,8 @@ fn ppc_fp128ConstAssumeCapacity(self: *Builder, val: [2]f64) Constant {
12555 if (ctx.builder.constant_items.items(.tag)[rhs_index] != .ppc_fp128) return false;12555 if (ctx.builder.constant_items.items(.tag)[rhs_index] != .ppc_fp128) return false;
12556 const rhs_data = ctx.builder.constant_items.items(.data)[rhs_index];12556 const rhs_data = ctx.builder.constant_items.items(.data)[rhs_index];
12557 const rhs_extra = ctx.builder.constantExtraData(Constant.Fp128, rhs_data);12557 const rhs_extra = ctx.builder.constantExtraData(Constant.Fp128, rhs_data);
12558 return @as(u64, @bitCast(lhs_key[0])) == @as(u64, rhs_extra.lo_hi) << 32 | rhs_extra.lo_lo and12558 return @as(u64, @bitCast(lhs_key[0])) == (@as(u64, rhs_extra.lo_hi) << 32) | rhs_extra.lo_lo and
12559 @as(u64, @bitCast(lhs_key[1])) == @as(u64, rhs_extra.hi_hi) << 32 | rhs_extra.hi_lo;12559 @as(u64, @bitCast(lhs_key[1])) == (@as(u64, rhs_extra.hi_hi) << 32) | rhs_extra.hi_lo;
12560 }12560 }
12561 };12561 };
12562 const gop = self.constant_map.getOrPutAssumeCapacityAdapted(val, Adapter{ .builder = self });12562 const gop = self.constant_map.getOrPutAssumeCapacityAdapted(val, Adapter{ .builder = self });
...@@ -15225,18 +15225,18 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -15225,18 +15225,18 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
15225 for (limbs) |*limb| {15225 for (limbs) |*limb| {
15226 const val = std.mem.littleToNative(i64, @bitCast(limb.*));15226 const val = std.mem.littleToNative(i64, @bitCast(limb.*));
15227 limb.* = @bitCast(if (val >= 0)15227 limb.* = @bitCast(if (val >= 0)
15228 val << 1 | 015228 (val << 1) | 0
15229 else15229 else
15230 -%val << 1 | 1);15230 (-%val << 1) | 1);
15231 }15231 }
15232 try constants_block.writeUnabbrev(5, record.items);15232 try constants_block.writeUnabbrev(5, record.items);
15233 continue;15233 continue;
15234 };15234 };
15235 try constants_block.writeAbbrev(ConstantsBlock.Integer{15235 try constants_block.writeAbbrev(ConstantsBlock.Integer{
15236 .value = @bitCast(if (val >= 0)15236 .value = @bitCast(if (val >= 0)
15237 val << 1 | 015237 (val << 1) | 0
15238 else15238 else
15239 -%val << 1 | 1),15239 (-%val << 1) | 1),
15240 });15240 });
15241 },15241 },
15242 .half,15242 .half,
...@@ -15252,8 +15252,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -15252,8 +15252,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
15252 .x86_fp80 => {15252 .x86_fp80 => {
15253 const extra = self.constantExtraData(Constant.Fp80, data);15253 const extra = self.constantExtraData(Constant.Fp80, data);
15254 try constants_block.writeAbbrev(ConstantsBlock.Fp80{15254 try constants_block.writeAbbrev(ConstantsBlock.Fp80{
15255 .hi = @as(u64, extra.hi) << 48 | @as(u64, extra.lo_hi) << 16 |15255 .hi = (@as(u64, extra.hi) << 48) | (@as(u64, extra.lo_hi) << 16) |
15256 extra.lo_lo >> 16,15256 (extra.lo_lo >> 16),
15257 .lo = @truncate(extra.lo_lo),15257 .lo = @truncate(extra.lo_lo),
15258 });15258 });
15259 },15259 },
...@@ -15262,8 +15262,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -15262,8 +15262,8 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
15262 => {15262 => {
15263 const extra = self.constantExtraData(Constant.Fp128, data);15263 const extra = self.constantExtraData(Constant.Fp128, data);
15264 try constants_block.writeAbbrev(ConstantsBlock.Fp128{15264 try constants_block.writeAbbrev(ConstantsBlock.Fp128{
15265 .lo = @as(u64, extra.lo_hi) << 32 | @as(u64, extra.lo_lo),15265 .lo = (@as(u64, extra.lo_hi) << 32) | @as(u64, extra.lo_lo),
15266 .hi = @as(u64, extra.hi_hi) << 32 | @as(u64, extra.hi_lo),15266 .hi = (@as(u64, extra.hi_hi) << 32) | @as(u64, extra.hi_lo),
15267 });15267 });
15268 },15268 },
15269 .array,15269 .array,
...@@ -15724,9 +15724,9 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -15724,9 +15724,9 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
15724 for (limbs) |*limb| {15724 for (limbs) |*limb| {
15725 const val = std.mem.littleToNative(i64, @bitCast(limb.*));15725 const val = std.mem.littleToNative(i64, @bitCast(limb.*));
15726 limb.* = @bitCast(if (val >= 0)15726 limb.* = @bitCast(if (val >= 0)
15727 val << 1 | 015727 (val << 1) | 0
15728 else15728 else
15729 -%val << 1 | 1);15729 (-%val << 1) | 1);
15730 }15730 }
15731 try metadata_block.writeUnabbrev(@backingInt(MetadataBlock.Code.ENUMERATOR), record.items);15731 try metadata_block.writeUnabbrev(@backingInt(MetadataBlock.Code.ENUMERATOR), record.items);
15732 continue;15732 continue;
...@@ -15736,9 +15736,9 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco...@@ -15736,9 +15736,9 @@ pub fn toBitcode(self: *Builder, allocator: Allocator, producer: Producer) bitco
15736 .bit_width = extra.bit_width,15736 .bit_width = extra.bit_width,
15737 .name = extra.name,15737 .name = extra.name,
15738 .value = @bitCast(if (val >= 0)15738 .value = @bitCast(if (val >= 0)
15739 val << 1 | 015739 (val << 1) | 0
15740 else15740 else
15741 -%val << 1 | 1),15741 (-%val << 1) | 1),
15742 }, metadata_adapter);15742 }, metadata_adapter);
15743 },15743 },
15744 .subrange => {15744 .subrange => {
lib/std/zig/llvm/bitcode_writer.zig+1-1
...@@ -102,7 +102,7 @@ pub fn BitcodeWriter(comptime types: []const type) type {...@@ -102,7 +102,7 @@ pub fn BitcodeWriter(comptime types: []const type) type {
102 // If input is larger than one VBR block can store102 // If input is larger than one VBR block can store
103 // then store vbr_bits - 1 bits and a continue bit103 // then store vbr_bits - 1 bits and a continue bit
104 while (in_buffer > mask) {104 while (in_buffer > mask) {
105 try self.writeBits(in_buffer & mask | continue_bit, vbr_bits);105 try self.writeBits((in_buffer & mask) | continue_bit, vbr_bits);
106 in_buffer >>= @intCast(vbr_bits - 1);106 in_buffer >>= @intCast(vbr_bits - 1);
107 }107 }
108108
lib/std/zig/parser_generated_oracle.zig+477-67
...@@ -42,13 +42,22 @@ const Def = enum {...@@ -42,13 +42,22 @@ const Def = enum {
42 defAssignExpr,42 defAssignExpr,
43 defSingleAssignExpr,43 defSingleAssignExpr,
44 defExpr,44 defExpr,
45 defBoolOrExpr,45 defOrElseExpr,
46 defCatchExpr,
47 defRecoveryNonmixingOp,
48 defControlOp,
49 defBoolExpr,
46 defBoolAndExpr,50 defBoolAndExpr,
51 defBoolOrExpr,
47 defCompareExpr,52 defCompareExpr,
48 defBitwiseExpr,53 defCompareOperand,
49 defBitShiftExpr,54 defBitOp,
55 defBitwiseNonmixingOp,
50 defAdditionExpr,56 defAdditionExpr,
57 defMulOrModExpr,
58 defModExpr,
51 defMultiplyExpr,59 defMultiplyExpr,
60 defMultiplyNonmixingOp,
52 defPrefixExpr,61 defPrefixExpr,
53 defPrimaryExpr,62 defPrimaryExpr,
54 defIfExpr,63 defIfExpr,
...@@ -103,14 +112,21 @@ const Def = enum {...@@ -103,14 +112,21 @@ const Def = enum {
103 defAndOp,112 defAndOp,
104 defCompareOp,113 defCompareOp,
105 defCompareOpTok,114 defCompareOpTok,
106 defBitwiseOp,115 defBitwiseAndOp,
107 defBitwiseOpTok,116 defBitwiseAndOpTok,
117 defBitwiseOrOp,
118 defBitwiseOrOpTok,
119 defBitwiseXorOp,
120 defBitwiseXorOpTok,
121 defCatchOp,
122 defOrElseOp,
108 defBitShiftOp,123 defBitShiftOp,
109 defBitShiftOpTok,124 defBitShiftOpTok,
110 defAdditionOp,125 defAdditionOp,
111 defAdditionOpTok,126 defAdditionOpTok,
112 defMultiplyOp,127 defMultiplyOp,
113 defMultiplyOpTok,128 defMultiplyOpTok,
129 defModOp,
114 defPrefixOp,130 defPrefixOp,
115 defPrefixTypeOp,131 defPrefixTypeOp,
116 defPtrMods,132 defPtrMods,
...@@ -290,7 +306,7 @@ const Def = enum {...@@ -290,7 +306,7 @@ const Def = enum {
290const Parser = struct {306const Parser = struct {
291 source: []const u8,307 source: []const u8,
292 i: usize,308 i: usize,
293 depths: [272]u8,309 depths: [288]u8,
294 pub fn parseRoot(p: *Parser) Error!bool {310 pub fn parseRoot(p: *Parser) Error!bool {
295 const def_index = @backingInt(Def.defRoot);311 const def_index = @backingInt(Def.defRoot);
296 if (p.depths[def_index] > max_depth) return error.MaxDepth;312 if (p.depths[def_index] > max_depth) return error.MaxDepth;
...@@ -964,33 +980,44 @@ const Parser = struct {...@@ -964,33 +980,44 @@ const Parser = struct {
964 defer p.depths[def_index] -= 1;980 defer p.depths[def_index] -= 1;
965 return blk_0: {981 return blk_0: {
966 const pos_0 = p.i;982 const pos_0 = p.i;
967 if (try p.parseBoolOrExpr()) break :blk_0 true;983 if (try p.parsePrefixExpr() and blk_2: {
984 const pos_2 = p.i;
985 if (try p.parseOrElseExpr()) break :blk_2 true;
986 p.i = pos_2;
987 if (try p.parseCatchExpr()) break :blk_2 true;
988 p.i = pos_2;
989 if (try p.parseBoolExpr()) break :blk_2 true;
990 p.i = pos_2;
991 break :blk_2 false;
992 }) break :blk_0 true;
968 p.i = pos_0;993 p.i = pos_0;
969 break :blk_0 false;994 break :blk_0 false;
970 };995 };
971 }996 }
972 pub fn parseBoolOrExpr(p: *Parser) Error!bool {997 pub fn parseOrElseExpr(p: *Parser) Error!bool {
973 const def_index = @backingInt(Def.defBoolOrExpr);998 const def_index = @backingInt(Def.defOrElseExpr);
974 if (p.depths[def_index] > max_depth) return error.MaxDepth;999 if (p.depths[def_index] > max_depth) return error.MaxDepth;
975 p.depths[def_index] += 1;1000 p.depths[def_index] += 1;
976 defer p.depths[def_index] -= 1;1001 defer p.depths[def_index] -= 1;
977 return blk_0: {1002 return blk_0: {
978 const pos_0 = p.i;1003 const pos_0 = p.i;
979 if (try p.parseBoolAndExpr() and blk_1: {1004 if (blk_1: {
1005 var match_1 = false;
980 var i_1: usize = 0;1006 var i_1: usize = 0;
981 while (blk_3: {1007 while (blk_3: {
982 const pos_3 = p.i;1008 const pos_3 = p.i;
983 if (try p.parseOrOp() and try p.parseBoolAndExpr()) break :blk_3 true;1009 if (try p.parseOrElseOp() and try p.parsePrefixExpr()) break :blk_3 true;
984 p.i = pos_3;1010 p.i = pos_3;
985 break :blk_3 false;1011 break :blk_3 false;
986 }) {1012 }) {
1013 match_1 = true;
987 if (i_1 > max_depth) return error.MaxDepth;1014 if (i_1 > max_depth) return error.MaxDepth;
988 i_1 += 1;1015 i_1 += 1;
989 }1016 }
990 break :blk_1 true;1017 break :blk_1 match_1;
991 } and blk_1: {1018 } and blk_1: {
992 const pos_1 = p.i;1019 const pos_1 = p.i;
993 const match_1 = try p.parseOrOp();1020 const match_1 = try p.parseRecoveryNonmixingOp();
994 p.i = pos_1;1021 p.i = pos_1;
995 break :blk_1 !match_1;1022 break :blk_1 !match_1;
996 }) break :blk_0 true;1023 }) break :blk_0 true;
...@@ -998,28 +1025,30 @@ const Parser = struct {...@@ -998,28 +1025,30 @@ const Parser = struct {
998 break :blk_0 false;1025 break :blk_0 false;
999 };1026 };
1000 }1027 }
1001 pub fn parseBoolAndExpr(p: *Parser) Error!bool {1028 pub fn parseCatchExpr(p: *Parser) Error!bool {
1002 const def_index = @backingInt(Def.defBoolAndExpr);1029 const def_index = @backingInt(Def.defCatchExpr);
1003 if (p.depths[def_index] > max_depth) return error.MaxDepth;1030 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1004 p.depths[def_index] += 1;1031 p.depths[def_index] += 1;
1005 defer p.depths[def_index] -= 1;1032 defer p.depths[def_index] -= 1;
1006 return blk_0: {1033 return blk_0: {
1007 const pos_0 = p.i;1034 const pos_0 = p.i;
1008 if (try p.parseCompareExpr() and blk_1: {1035 if (blk_1: {
1036 var match_1 = false;
1009 var i_1: usize = 0;1037 var i_1: usize = 0;
1010 while (blk_3: {1038 while (blk_3: {
1011 const pos_3 = p.i;1039 const pos_3 = p.i;
1012 if (try p.parseAndOp() and try p.parseCompareExpr()) break :blk_3 true;1040 if (try p.parseCatchOp() and try p.parsePrefixExpr()) break :blk_3 true;
1013 p.i = pos_3;1041 p.i = pos_3;
1014 break :blk_3 false;1042 break :blk_3 false;
1015 }) {1043 }) {
1044 match_1 = true;
1016 if (i_1 > max_depth) return error.MaxDepth;1045 if (i_1 > max_depth) return error.MaxDepth;
1017 i_1 += 1;1046 i_1 += 1;
1018 }1047 }
1019 break :blk_1 true;1048 break :blk_1 match_1;
1020 } and blk_1: {1049 } and blk_1: {
1021 const pos_1 = p.i;1050 const pos_1 = p.i;
1022 const match_1 = try p.parseAndOp();1051 const match_1 = try p.parseRecoveryNonmixingOp();
1023 p.i = pos_1;1052 p.i = pos_1;
1024 break :blk_1 !match_1;1053 break :blk_1 !match_1;
1025 }) break :blk_0 true;1054 }) break :blk_0 true;
...@@ -1027,21 +1056,90 @@ const Parser = struct {...@@ -1027,21 +1056,90 @@ const Parser = struct {
1027 break :blk_0 false;1056 break :blk_0 false;
1028 };1057 };
1029 }1058 }
1030 pub fn parseCompareExpr(p: *Parser) Error!bool {1059 pub fn parseRecoveryNonmixingOp(p: *Parser) Error!bool {
1031 const def_index = @backingInt(Def.defCompareExpr);1060 const def_index = @backingInt(Def.defRecoveryNonmixingOp);
1032 if (p.depths[def_index] > max_depth) return error.MaxDepth;1061 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1033 p.depths[def_index] += 1;1062 p.depths[def_index] += 1;
1034 defer p.depths[def_index] -= 1;1063 defer p.depths[def_index] -= 1;
1035 return blk_0: {1064 return blk_0: {
1036 const pos_0 = p.i;1065 const pos_0 = p.i;
1037 if (try p.parseBitwiseExpr() and (blk_3: {1066 if (try p.parseControlOp()) break :blk_0 true;
1038 const pos_3 = p.i;1067 p.i = pos_0;
1039 if (try p.parseCompareOp() and try p.parseBitwiseExpr()) break :blk_3 true;1068 if (try p.parseCompareOp()) break :blk_0 true;
1040 p.i = pos_3;1069 p.i = pos_0;
1041 break :blk_3 false;1070 if (try p.parseBitwiseNonmixingOp()) break :blk_0 true;
1042 } or true) and blk_1: {1071 p.i = pos_0;
1072 break :blk_0 false;
1073 };
1074 }
1075 pub fn parseControlOp(p: *Parser) Error!bool {
1076 const def_index = @backingInt(Def.defControlOp);
1077 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1078 p.depths[def_index] += 1;
1079 defer p.depths[def_index] -= 1;
1080 return blk_0: {
1081 const pos_0 = p.i;
1082 if (try p.parseOrElseOp()) break :blk_0 true;
1083 p.i = pos_0;
1084 if (try p.parseCatchOp()) break :blk_0 true;
1085 p.i = pos_0;
1086 if (try p.parseAndOp()) break :blk_0 true;
1087 p.i = pos_0;
1088 if (try p.parseOrOp()) break :blk_0 true;
1089 p.i = pos_0;
1090 break :blk_0 false;
1091 };
1092 }
1093 pub fn parseBoolExpr(p: *Parser) Error!bool {
1094 const def_index = @backingInt(Def.defBoolExpr);
1095 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1096 p.depths[def_index] += 1;
1097 defer p.depths[def_index] -= 1;
1098 return blk_0: {
1099 const pos_0 = p.i;
1100 if (try p.parseCompareExpr() and blk_2: {
1101 const pos_2 = p.i;
1102 if (try p.parseBoolAndExpr()) break :blk_2 true;
1103 p.i = pos_2;
1104 if (try p.parseBoolOrExpr()) break :blk_2 true;
1105 p.i = pos_2;
1106 if (blk_3: {
1107 const pos_3 = p.i;
1108 const match_3 = try p.parseControlOp();
1109 p.i = pos_3;
1110 break :blk_3 !match_3;
1111 }) break :blk_2 true;
1112 p.i = pos_2;
1113 break :blk_2 false;
1114 }) break :blk_0 true;
1115 p.i = pos_0;
1116 break :blk_0 false;
1117 };
1118 }
1119 pub fn parseBoolAndExpr(p: *Parser) Error!bool {
1120 const def_index = @backingInt(Def.defBoolAndExpr);
1121 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1122 p.depths[def_index] += 1;
1123 defer p.depths[def_index] -= 1;
1124 return blk_0: {
1125 const pos_0 = p.i;
1126 if (blk_1: {
1127 var match_1 = false;
1128 var i_1: usize = 0;
1129 while (blk_3: {
1130 const pos_3 = p.i;
1131 if (try p.parseAndOp() and try p.parsePrefixExpr() and try p.parseCompareExpr()) break :blk_3 true;
1132 p.i = pos_3;
1133 break :blk_3 false;
1134 }) {
1135 match_1 = true;
1136 if (i_1 > max_depth) return error.MaxDepth;
1137 i_1 += 1;
1138 }
1139 break :blk_1 match_1;
1140 } and blk_1: {
1043 const pos_1 = p.i;1141 const pos_1 = p.i;
1044 const match_1 = try p.parseCompareOp();1142 const match_1 = try p.parseControlOp();
1045 p.i = pos_1;1143 p.i = pos_1;
1046 break :blk_1 !match_1;1144 break :blk_1 !match_1;
1047 }) break :blk_0 true;1145 }) break :blk_0 true;
...@@ -1049,28 +1147,30 @@ const Parser = struct {...@@ -1049,28 +1147,30 @@ const Parser = struct {
1049 break :blk_0 false;1147 break :blk_0 false;
1050 };1148 };
1051 }1149 }
1052 pub fn parseBitwiseExpr(p: *Parser) Error!bool {1150 pub fn parseBoolOrExpr(p: *Parser) Error!bool {
1053 const def_index = @backingInt(Def.defBitwiseExpr);1151 const def_index = @backingInt(Def.defBoolOrExpr);
1054 if (p.depths[def_index] > max_depth) return error.MaxDepth;1152 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1055 p.depths[def_index] += 1;1153 p.depths[def_index] += 1;
1056 defer p.depths[def_index] -= 1;1154 defer p.depths[def_index] -= 1;
1057 return blk_0: {1155 return blk_0: {
1058 const pos_0 = p.i;1156 const pos_0 = p.i;
1059 if (try p.parseBitShiftExpr() and blk_1: {1157 if (blk_1: {
1158 var match_1 = false;
1060 var i_1: usize = 0;1159 var i_1: usize = 0;
1061 while (blk_3: {1160 while (blk_3: {
1062 const pos_3 = p.i;1161 const pos_3 = p.i;
1063 if (try p.parseBitwiseOp() and try p.parseBitShiftExpr()) break :blk_3 true;1162 if (try p.parseOrOp() and try p.parsePrefixExpr() and try p.parseCompareExpr()) break :blk_3 true;
1064 p.i = pos_3;1163 p.i = pos_3;
1065 break :blk_3 false;1164 break :blk_3 false;
1066 }) {1165 }) {
1166 match_1 = true;
1067 if (i_1 > max_depth) return error.MaxDepth;1167 if (i_1 > max_depth) return error.MaxDepth;
1068 i_1 += 1;1168 i_1 += 1;
1069 }1169 }
1070 break :blk_1 true;1170 break :blk_1 match_1;
1071 } and blk_1: {1171 } and blk_1: {
1072 const pos_1 = p.i;1172 const pos_1 = p.i;
1073 const match_1 = try p.parseBitwiseOp();1173 const match_1 = try p.parseControlOp();
1074 p.i = pos_1;1174 p.i = pos_1;
1075 break :blk_1 !match_1;1175 break :blk_1 !match_1;
1076 }) break :blk_0 true;1176 }) break :blk_0 true;
...@@ -1078,32 +1178,153 @@ const Parser = struct {...@@ -1078,32 +1178,153 @@ const Parser = struct {
1078 break :blk_0 false;1178 break :blk_0 false;
1079 };1179 };
1080 }1180 }
1081 pub fn parseBitShiftExpr(p: *Parser) Error!bool {1181 pub fn parseCompareExpr(p: *Parser) Error!bool {
1082 const def_index = @backingInt(Def.defBitShiftExpr);1182 const def_index = @backingInt(Def.defCompareExpr);
1083 if (p.depths[def_index] > max_depth) return error.MaxDepth;1183 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1084 p.depths[def_index] += 1;1184 p.depths[def_index] += 1;
1085 defer p.depths[def_index] -= 1;1185 defer p.depths[def_index] -= 1;
1086 return blk_0: {1186 return blk_0: {
1087 const pos_0 = p.i;1187 const pos_0 = p.i;
1088 if (try p.parseAdditionExpr() and blk_1: {1188 if (try p.parseCompareOperand() and (blk_3: {
1189 const pos_3 = p.i;
1190 if (try p.parseCompareOp() and try p.parsePrefixExpr() and try p.parseCompareOperand()) break :blk_3 true;
1191 p.i = pos_3;
1192 break :blk_3 false;
1193 } or true) and blk_1: {
1194 const pos_1 = p.i;
1195 const match_1 = blk_3: {
1196 const pos_3 = p.i;
1197 if (try p.parseCompareOp()) break :blk_3 true;
1198 p.i = pos_3;
1199 if (try p.parseOrElseOp()) break :blk_3 true;
1200 p.i = pos_3;
1201 if (try p.parseCatchOp()) break :blk_3 true;
1202 p.i = pos_3;
1203 break :blk_3 false;
1204 };
1205 p.i = pos_1;
1206 break :blk_1 !match_1;
1207 }) break :blk_0 true;
1208 p.i = pos_0;
1209 break :blk_0 false;
1210 };
1211 }
1212 pub fn parseCompareOperand(p: *Parser) Error!bool {
1213 const def_index = @backingInt(Def.defCompareOperand);
1214 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1215 p.depths[def_index] += 1;
1216 defer p.depths[def_index] -= 1;
1217 return blk_0: {
1218 const pos_0 = p.i;
1219 if (blk_1: {
1220 var match_1 = false;
1089 var i_1: usize = 0;1221 var i_1: usize = 0;
1090 while (blk_3: {1222 while (blk_3: {
1091 const pos_3 = p.i;1223 const pos_3 = p.i;
1092 if (try p.parseBitShiftOp() and try p.parseAdditionExpr()) break :blk_3 true;1224 if (try p.parseBitwiseOrOp() and try p.parsePrefixExpr()) break :blk_3 true;
1093 p.i = pos_3;1225 p.i = pos_3;
1094 break :blk_3 false;1226 break :blk_3 false;
1095 }) {1227 }) {
1228 match_1 = true;
1096 if (i_1 > max_depth) return error.MaxDepth;1229 if (i_1 > max_depth) return error.MaxDepth;
1097 i_1 += 1;1230 i_1 += 1;
1098 }1231 }
1099 break :blk_1 true;1232 break :blk_1 match_1;
1233 } and blk_1: {
1234 const pos_1 = p.i;
1235 const match_1 = try p.parseBitwiseNonmixingOp();
1236 p.i = pos_1;
1237 break :blk_1 !match_1;
1238 }) break :blk_0 true;
1239 p.i = pos_0;
1240 if (blk_1: {
1241 var match_1 = false;
1242 var i_1: usize = 0;
1243 while (blk_3: {
1244 const pos_3 = p.i;
1245 if (try p.parseBitwiseAndOp() and try p.parsePrefixExpr()) break :blk_3 true;
1246 p.i = pos_3;
1247 break :blk_3 false;
1248 }) {
1249 match_1 = true;
1250 if (i_1 > max_depth) return error.MaxDepth;
1251 i_1 += 1;
1252 }
1253 break :blk_1 match_1;
1254 } and blk_1: {
1255 const pos_1 = p.i;
1256 const match_1 = try p.parseBitwiseNonmixingOp();
1257 p.i = pos_1;
1258 break :blk_1 !match_1;
1259 }) break :blk_0 true;
1260 p.i = pos_0;
1261 if (blk_1: {
1262 var match_1 = false;
1263 var i_1: usize = 0;
1264 while (blk_3: {
1265 const pos_3 = p.i;
1266 if (try p.parseBitwiseXorOp() and try p.parsePrefixExpr()) break :blk_3 true;
1267 p.i = pos_3;
1268 break :blk_3 false;
1269 }) {
1270 match_1 = true;
1271 if (i_1 > max_depth) return error.MaxDepth;
1272 i_1 += 1;
1273 }
1274 break :blk_1 match_1;
1100 } and blk_1: {1275 } and blk_1: {
1101 const pos_1 = p.i;1276 const pos_1 = p.i;
1102 const match_1 = try p.parseBitShiftOp();1277 const match_1 = try p.parseBitwiseNonmixingOp();
1103 p.i = pos_1;1278 p.i = pos_1;
1104 break :blk_1 !match_1;1279 break :blk_1 !match_1;
1105 }) break :blk_0 true;1280 }) break :blk_0 true;
1106 p.i = pos_0;1281 p.i = pos_0;
1282 if (try p.parseBitShiftOp() and try p.parsePrefixExpr() and blk_1: {
1283 const pos_1 = p.i;
1284 const match_1 = try p.parseBitwiseNonmixingOp();
1285 p.i = pos_1;
1286 break :blk_1 !match_1;
1287 }) break :blk_0 true;
1288 p.i = pos_0;
1289 if (blk_1: {
1290 const pos_1 = p.i;
1291 const match_1 = try p.parseBitOp();
1292 p.i = pos_1;
1293 break :blk_1 !match_1;
1294 } and try p.parseAdditionExpr()) break :blk_0 true;
1295 p.i = pos_0;
1296 break :blk_0 false;
1297 };
1298 }
1299 pub fn parseBitOp(p: *Parser) Error!bool {
1300 const def_index = @backingInt(Def.defBitOp);
1301 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1302 p.depths[def_index] += 1;
1303 defer p.depths[def_index] -= 1;
1304 return blk_0: {
1305 const pos_0 = p.i;
1306 if (try p.parseBitwiseOrOp()) break :blk_0 true;
1307 p.i = pos_0;
1308 if (try p.parseBitwiseAndOp()) break :blk_0 true;
1309 p.i = pos_0;
1310 if (try p.parseBitwiseXorOp()) break :blk_0 true;
1311 p.i = pos_0;
1312 if (try p.parseBitShiftOp()) break :blk_0 true;
1313 p.i = pos_0;
1314 break :blk_0 false;
1315 };
1316 }
1317 pub fn parseBitwiseNonmixingOp(p: *Parser) Error!bool {
1318 const def_index = @backingInt(Def.defBitwiseNonmixingOp);
1319 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1320 p.depths[def_index] += 1;
1321 defer p.depths[def_index] -= 1;
1322 return blk_0: {
1323 const pos_0 = p.i;
1324 if (try p.parseMultiplyNonmixingOp()) break :blk_0 true;
1325 p.i = pos_0;
1326 if (try p.parseAdditionOp()) break :blk_0 true;
1327 p.i = pos_0;
1107 break :blk_0 false;1328 break :blk_0 false;
1108 };1329 };
1109 }1330 }
...@@ -1114,11 +1335,11 @@ const Parser = struct {...@@ -1114,11 +1335,11 @@ const Parser = struct {
1114 defer p.depths[def_index] -= 1;1335 defer p.depths[def_index] -= 1;
1115 return blk_0: {1336 return blk_0: {
1116 const pos_0 = p.i;1337 const pos_0 = p.i;
1117 if (try p.parseMultiplyExpr() and blk_1: {1338 if (try p.parseMulOrModExpr() and blk_1: {
1118 var i_1: usize = 0;1339 var i_1: usize = 0;
1119 while (blk_3: {1340 while (blk_3: {
1120 const pos_3 = p.i;1341 const pos_3 = p.i;
1121 if (try p.parseAdditionOp() and try p.parseMultiplyExpr()) break :blk_3 true;1342 if (try p.parseAdditionOp() and try p.parsePrefixExpr() and try p.parseMulOrModExpr()) break :blk_3 true;
1122 p.i = pos_3;1343 p.i = pos_3;
1123 break :blk_3 false;1344 break :blk_3 false;
1124 }) {1345 }) {
...@@ -1128,7 +1349,54 @@ const Parser = struct {...@@ -1128,7 +1349,54 @@ const Parser = struct {
1128 break :blk_1 true;1349 break :blk_1 true;
1129 } and blk_1: {1350 } and blk_1: {
1130 const pos_1 = p.i;1351 const pos_1 = p.i;
1131 const match_1 = try p.parseAdditionOp();1352 const match_1 = blk_3: {
1353 const pos_3 = p.i;
1354 if (try p.parseAdditionOp()) break :blk_3 true;
1355 p.i = pos_3;
1356 if (try p.parseBitOp()) break :blk_3 true;
1357 p.i = pos_3;
1358 if (try p.parseOrElseOp()) break :blk_3 true;
1359 p.i = pos_3;
1360 if (try p.parseCatchOp()) break :blk_3 true;
1361 p.i = pos_3;
1362 break :blk_3 false;
1363 };
1364 p.i = pos_1;
1365 break :blk_1 !match_1;
1366 }) break :blk_0 true;
1367 p.i = pos_0;
1368 break :blk_0 false;
1369 };
1370 }
1371 pub fn parseMulOrModExpr(p: *Parser) Error!bool {
1372 const def_index = @backingInt(Def.defMulOrModExpr);
1373 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1374 p.depths[def_index] += 1;
1375 defer p.depths[def_index] -= 1;
1376 return blk_0: {
1377 const pos_0 = p.i;
1378 if (try p.parseModExpr()) break :blk_0 true;
1379 p.i = pos_0;
1380 if (blk_1: {
1381 const pos_1 = p.i;
1382 const match_1 = try p.parseModOp();
1383 p.i = pos_1;
1384 break :blk_1 !match_1;
1385 } and try p.parseMultiplyExpr()) break :blk_0 true;
1386 p.i = pos_0;
1387 break :blk_0 false;
1388 };
1389 }
1390 pub fn parseModExpr(p: *Parser) Error!bool {
1391 const def_index = @backingInt(Def.defModExpr);
1392 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1393 p.depths[def_index] += 1;
1394 defer p.depths[def_index] -= 1;
1395 return blk_0: {
1396 const pos_0 = p.i;
1397 if (try p.parseModOp() and try p.parsePrefixExpr() and blk_1: {
1398 const pos_1 = p.i;
1399 const match_1 = try p.parseMultiplyNonmixingOp();
1132 p.i = pos_1;1400 p.i = pos_1;
1133 break :blk_1 !match_1;1401 break :blk_1 !match_1;
1134 }) break :blk_0 true;1402 }) break :blk_0 true;
...@@ -1143,7 +1411,7 @@ const Parser = struct {...@@ -1143,7 +1411,7 @@ const Parser = struct {
1143 defer p.depths[def_index] -= 1;1411 defer p.depths[def_index] -= 1;
1144 return blk_0: {1412 return blk_0: {
1145 const pos_0 = p.i;1413 const pos_0 = p.i;
1146 if (try p.parsePrefixExpr() and blk_1: {1414 if (blk_1: {
1147 var i_1: usize = 0;1415 var i_1: usize = 0;
1148 while (blk_3: {1416 while (blk_3: {
1149 const pos_3 = p.i;1417 const pos_3 = p.i;
...@@ -1157,7 +1425,7 @@ const Parser = struct {...@@ -1157,7 +1425,7 @@ const Parser = struct {
1157 break :blk_1 true;1425 break :blk_1 true;
1158 } and blk_1: {1426 } and blk_1: {
1159 const pos_1 = p.i;1427 const pos_1 = p.i;
1160 const match_1 = try p.parseMultiplyOp();1428 const match_1 = try p.parseMultiplyNonmixingOp();
1161 p.i = pos_1;1429 p.i = pos_1;
1162 break :blk_1 !match_1;1430 break :blk_1 !match_1;
1163 }) break :blk_0 true;1431 }) break :blk_0 true;
...@@ -1165,6 +1433,26 @@ const Parser = struct {...@@ -1165,6 +1433,26 @@ const Parser = struct {
1165 break :blk_0 false;1433 break :blk_0 false;
1166 };1434 };
1167 }1435 }
1436 pub fn parseMultiplyNonmixingOp(p: *Parser) Error!bool {
1437 const def_index = @backingInt(Def.defMultiplyNonmixingOp);
1438 if (p.depths[def_index] > max_depth) return error.MaxDepth;
1439 p.depths[def_index] += 1;
1440 defer p.depths[def_index] -= 1;
1441 return blk_0: {
1442 const pos_0 = p.i;
1443 if (try p.parseMultiplyOp()) break :blk_0 true;
1444 p.i = pos_0;
1445 if (try p.parseModOp()) break :blk_0 true;
1446 p.i = pos_0;
1447 if (try p.parseBitOp()) break :blk_0 true;
1448 p.i = pos_0;
1449 if (try p.parseOrElseOp()) break :blk_0 true;
1450 p.i = pos_0;
1451 if (try p.parseCatchOp()) break :blk_0 true;
1452 p.i = pos_0;
1453 break :blk_0 false;
1454 };
1455 }
1168 pub fn parsePrefixExpr(p: *Parser) Error!bool {1456 pub fn parsePrefixExpr(p: *Parser) Error!bool {
1169 const def_index = @backingInt(Def.defPrefixExpr);1457 const def_index = @backingInt(Def.defPrefixExpr);
1170 if (p.depths[def_index] > max_depth) return error.MaxDepth;1458 if (p.depths[def_index] > max_depth) return error.MaxDepth;
...@@ -2259,70 +2547,170 @@ const Parser = struct {...@@ -2259,70 +2547,170 @@ const Parser = struct {
2259 break :blk_0 false;2547 break :blk_0 false;
2260 };2548 };
2261 }2549 }
2262 pub fn parseBitwiseOp(p: *Parser) Error!bool {2550 pub fn parseBitwiseAndOp(p: *Parser) Error!bool {
2263 const def_index = @backingInt(Def.defBitwiseOp);2551 const def_index = @backingInt(Def.defBitwiseAndOp);
2264 if (p.depths[def_index] > max_depth) return error.MaxDepth;2552 if (p.depths[def_index] > max_depth) return error.MaxDepth;
2265 p.depths[def_index] += 1;2553 p.depths[def_index] += 1;
2266 defer p.depths[def_index] -= 1;2554 defer p.depths[def_index] -= 1;
2267 return blk_0: {2555 return blk_0: {
2268 const pos_0 = p.i;2556 const pos_0 = p.i;
2269 if (try p.parsepre_op_white() and try p.parseBitwiseOpTok() and try p.parsepost_op_white()) break :blk_0 true;2557 if (try p.parsepre_op_white() and try p.parseBitwiseAndOpTok() and try p.parsepost_op_white()) break :blk_0 true;
2270 p.i = pos_0;2558 p.i = pos_0;
2271 if (blk_1: {2559 if (blk_1: {
2272 const pos_1 = p.i;2560 const pos_1 = p.i;
2273 const match_1 = try p.parsepre_op_white();2561 const match_1 = try p.parsepre_op_white();
2274 p.i = pos_1;2562 p.i = pos_1;
2275 break :blk_1 !match_1;2563 break :blk_1 !match_1;
2276 } and try p.parseBitwiseOpTok() and blk_1: {2564 } and try p.parseBitwiseAndOpTok() and blk_1: {
2277 const pos_1 = p.i;2565 const pos_1 = p.i;
2278 const match_1 = try p.parsepost_op_white();2566 const match_1 = try p.parsepost_op_white();
2279 p.i = pos_1;2567 p.i = pos_1;
2280 break :blk_1 !match_1;2568 break :blk_1 !match_1;
2281 }) break :blk_0 true;2569 }) break :blk_0 true;
2282 p.i = pos_0;2570 p.i = pos_0;
2283 if (try p.parsepre_op_white() and try p.parseKEYWORD_catch() and try p.parsepost_op_white() and (try p.parsePayload() or true)) break :blk_0 true;2571 break :blk_0 false;
2572 };
2573 }
2574 pub fn parseBitwiseAndOpTok(p: *Parser) Error!bool {
2575 const def_index = @backingInt(Def.defBitwiseAndOpTok);
2576 if (p.depths[def_index] > max_depth) return error.MaxDepth;
2577 p.depths[def_index] += 1;
2578 defer p.depths[def_index] -= 1;
2579 return blk_0: {
2580 const pos_0 = p.i;
2581 if (try p.parseAMPERSAND() and blk_1: {
2582 const pos_1 = p.i;
2583 const match_1 = (p.i < p.source.len and switch (p.source[p.i]) {
2584 '&'...'&',
2585 => blk_2: {
2586 p.i += 1;
2587 break :blk_2 true;
2588 },
2589 else => false,
2590 });
2591 p.i = pos_1;
2592 break :blk_1 !match_1;
2593 }) break :blk_0 true;
2594 p.i = pos_0;
2595 break :blk_0 false;
2596 };
2597 }
2598 pub fn parseBitwiseOrOp(p: *Parser) Error!bool {
2599 const def_index = @backingInt(Def.defBitwiseOrOp);
2600 if (p.depths[def_index] > max_depth) return error.MaxDepth;
2601 p.depths[def_index] += 1;
2602 defer p.depths[def_index] -= 1;
2603 return blk_0: {
2604 const pos_0 = p.i;
2605 if (try p.parsepre_op_white() and try p.parseBitwiseOrOpTok() and try p.parsepost_op_white()) break :blk_0 true;
2284 p.i = pos_0;2606 p.i = pos_0;
2285 if (blk_1: {2607 if (blk_1: {
2286 const pos_1 = p.i;2608 const pos_1 = p.i;
2287 const match_1 = try p.parsepre_op_white();2609 const match_1 = try p.parsepre_op_white();
2288 p.i = pos_1;2610 p.i = pos_1;
2289 break :blk_1 !match_1;2611 break :blk_1 !match_1;
2290 } and try p.parseKEYWORD_catch() and blk_1: {2612 } and try p.parseBitwiseOrOpTok() and blk_1: {
2291 const pos_1 = p.i;2613 const pos_1 = p.i;
2292 const match_1 = try p.parsepost_op_white();2614 const match_1 = try p.parsepost_op_white();
2293 p.i = pos_1;2615 p.i = pos_1;
2294 break :blk_1 !match_1;2616 break :blk_1 !match_1;
2295 } and (try p.parsePayload() or true)) break :blk_0 true;2617 }) break :blk_0 true;
2296 p.i = pos_0;2618 p.i = pos_0;
2297 break :blk_0 false;2619 break :blk_0 false;
2298 };2620 };
2299 }2621 }
2300 pub fn parseBitwiseOpTok(p: *Parser) Error!bool {2622 pub fn parseBitwiseOrOpTok(p: *Parser) Error!bool {
2301 const def_index = @backingInt(Def.defBitwiseOpTok);2623 const def_index = @backingInt(Def.defBitwiseOrOpTok);
2302 if (p.depths[def_index] > max_depth) return error.MaxDepth;2624 if (p.depths[def_index] > max_depth) return error.MaxDepth;
2303 p.depths[def_index] += 1;2625 p.depths[def_index] += 1;
2304 defer p.depths[def_index] -= 1;2626 defer p.depths[def_index] -= 1;
2305 return blk_0: {2627 return blk_0: {
2306 const pos_0 = p.i;2628 const pos_0 = p.i;
2307 if (try p.parseAMPERSAND() and blk_1: {2629 if (try p.parsePIPE()) break :blk_0 true;
2630 p.i = pos_0;
2631 break :blk_0 false;
2632 };
2633 }
2634 pub fn parseBitwiseXorOp(p: *Parser) Error!bool {
2635 const def_index = @backingInt(Def.defBitwiseXorOp);
2636 if (p.depths[def_index] > max_depth) return error.MaxDepth;
2637 p.depths[def_index] += 1;
2638 defer p.depths[def_index] -= 1;
2639 return blk_0: {
2640 const pos_0 = p.i;
2641 if (try p.parsepre_op_white() and try p.parseBitwiseXorOpTok() and try p.parsepost_op_white()) break :blk_0 true;
2642 p.i = pos_0;
2643 if (blk_1: {
2308 const pos_1 = p.i;2644 const pos_1 = p.i;
2309 const match_1 = (p.i < p.source.len and switch (p.source[p.i]) {2645 const match_1 = try p.parsepre_op_white();
2310 '&'...'&',2646 p.i = pos_1;
2311 => blk_2: {2647 break :blk_1 !match_1;
2312 p.i += 1;2648 } and try p.parseBitwiseXorOpTok() and blk_1: {
2313 break :blk_2 true;2649 const pos_1 = p.i;
2314 },2650 const match_1 = try p.parsepost_op_white();
2315 else => false,
2316 });
2317 p.i = pos_1;2651 p.i = pos_1;
2318 break :blk_1 !match_1;2652 break :blk_1 !match_1;
2319 }) break :blk_0 true;2653 }) break :blk_0 true;
2320 p.i = pos_0;2654 p.i = pos_0;
2655 break :blk_0 false;
2656 };
2657 }
2658 pub fn parseBitwiseXorOpTok(p: *Parser) Error!bool {
2659 const def_index = @backingInt(Def.defBitwiseXorOpTok);
2660 if (p.depths[def_index] > max_depth) return error.MaxDepth;
2661 p.depths[def_index] += 1;
2662 defer p.depths[def_index] -= 1;
2663 return blk_0: {
2664 const pos_0 = p.i;
2321 if (try p.parseCARET()) break :blk_0 true;2665 if (try p.parseCARET()) break :blk_0 true;
2322 p.i = pos_0;2666 p.i = pos_0;
2323 if (try p.parsePIPE()) break :blk_0 true;2667 break :blk_0 false;
2668 };
2669 }
2670 pub fn parseCatchOp(p: *Parser) Error!bool {
2671 const def_index = @backingInt(Def.defCatchOp);
2672 if (p.depths[def_index] > max_depth) return error.MaxDepth;
2673 p.depths[def_index] += 1;
2674 defer p.depths[def_index] -= 1;
2675 return blk_0: {
2676 const pos_0 = p.i;
2677 if (try p.parsepre_op_white() and try p.parseKEYWORD_catch() and try p.parsepost_op_white() and (try p.parsePayload() or true)) break :blk_0 true;
2324 p.i = pos_0;2678 p.i = pos_0;
2325 if (try p.parseKEYWORD_orelse()) break :blk_0 true;2679 if (blk_1: {
2680 const pos_1 = p.i;
2681 const match_1 = try p.parsepre_op_white();
2682 p.i = pos_1;
2683 break :blk_1 !match_1;
2684 } and try p.parseKEYWORD_catch() and blk_1: {
2685 const pos_1 = p.i;
2686 const match_1 = try p.parsepost_op_white();
2687 p.i = pos_1;
2688 break :blk_1 !match_1;
2689 } and (try p.parsePayload() or true)) break :blk_0 true;
2690 p.i = pos_0;
2691 break :blk_0 false;
2692 };
2693 }
2694 pub fn parseOrElseOp(p: *Parser) Error!bool {
2695 const def_index = @backingInt(Def.defOrElseOp);
2696 if (p.depths[def_index] > max_depth) return error.MaxDepth;
2697 p.depths[def_index] += 1;
2698 defer p.depths[def_index] -= 1;
2699 return blk_0: {
2700 const pos_0 = p.i;
2701 if (try p.parsepre_op_white() and try p.parseKEYWORD_orelse() and try p.parsepost_op_white()) break :blk_0 true;
2702 p.i = pos_0;
2703 if (blk_1: {
2704 const pos_1 = p.i;
2705 const match_1 = try p.parsepre_op_white();
2706 p.i = pos_1;
2707 break :blk_1 !match_1;
2708 } and try p.parseKEYWORD_orelse() and blk_1: {
2709 const pos_1 = p.i;
2710 const match_1 = try p.parsepost_op_white();
2711 p.i = pos_1;
2712 break :blk_1 !match_1;
2713 }) break :blk_0 true;
2326 p.i = pos_0;2714 p.i = pos_0;
2327 break :blk_0 false;2715 break :blk_0 false;
2328 };2716 };
...@@ -2452,8 +2840,6 @@ const Parser = struct {...@@ -2452,8 +2840,6 @@ const Parser = struct {
2452 p.i = pos_0;2840 p.i = pos_0;
2453 if (try p.parseSLASH()) break :blk_0 true;2841 if (try p.parseSLASH()) break :blk_0 true;
2454 p.i = pos_0;2842 p.i = pos_0;
2455 if (try p.parsePERCENT()) break :blk_0 true;
2456 p.i = pos_0;
2457 if (try p.parseASTERISKPERCENT()) break :blk_0 true;2843 if (try p.parseASTERISKPERCENT()) break :blk_0 true;
2458 p.i = pos_0;2844 p.i = pos_0;
2459 if (try p.parseASTERISKPIPE()) break :blk_0 true;2845 if (try p.parseASTERISKPIPE()) break :blk_0 true;
...@@ -2461,6 +2847,30 @@ const Parser = struct {...@@ -2461,6 +2847,30 @@ const Parser = struct {
2461 break :blk_0 false;2847 break :blk_0 false;
2462 };2848 };
2463 }2849 }
2850 pub fn parseModOp(p: *Parser) Error!bool {
2851 const def_index = @backingInt(Def.defModOp);
2852 if (p.depths[def_index] > max_depth) return error.MaxDepth;
2853 p.depths[def_index] += 1;
2854 defer p.depths[def_index] -= 1;
2855 return blk_0: {
2856 const pos_0 = p.i;
2857 if (try p.parsepre_op_white() and try p.parsePERCENT() and try p.parsepost_op_white()) break :blk_0 true;
2858 p.i = pos_0;
2859 if (blk_1: {
2860 const pos_1 = p.i;
2861 const match_1 = try p.parsepre_op_white();
2862 p.i = pos_1;
2863 break :blk_1 !match_1;
2864 } and try p.parsePERCENT() and blk_1: {
2865 const pos_1 = p.i;
2866 const match_1 = try p.parsepost_op_white();
2867 p.i = pos_1;
2868 break :blk_1 !match_1;
2869 }) break :blk_0 true;
2870 p.i = pos_0;
2871 break :blk_0 false;
2872 };
2873 }
2464 pub fn parsePrefixOp(p: *Parser) Error!bool {2874 pub fn parsePrefixOp(p: *Parser) Error!bool {
2465 const def_index = @backingInt(Def.defPrefixOp);2875 const def_index = @backingInt(Def.defPrefixOp);
2466 if (p.depths[def_index] > max_depth) return error.MaxDepth;2876 if (p.depths[def_index] > max_depth) return error.MaxDepth;
lib/std/zig/parser_test.zig+42-6
...@@ -3046,19 +3046,14 @@ test "zig fmt: precedence" {...@@ -3046,19 +3046,14 @@ test "zig fmt: precedence" {
3046 \\ !(a{});3046 \\ !(a{});
3047 \\ a + b{};3047 \\ a + b{};
3048 \\ (a + b){};3048 \\ (a + b){};
3049 \\ a << b + c;
3050 \\ (a << b) + c;3049 \\ (a << b) + c;
3051 \\ a & b << c;
3052 \\ (a & b) << c;3050 \\ (a & b) << c;
3053 \\ a ^ b & c;
3054 \\ (a ^ b) & c;3051 \\ (a ^ b) & c;
3055 \\ a | b ^ c;
3056 \\ (a | b) ^ c;3052 \\ (a | b) ^ c;
3057 \\ a == b | c;3053 \\ a == b | c;
3058 \\ (a == b) | c;3054 \\ (a == b) | c;
3059 \\ a and b == c;3055 \\ a and b == c;
3060 \\ (a and b) == c;3056 \\ (a and b) == c;
3061 \\ a or b and c;
3062 \\ (a or b) and c;3057 \\ (a or b) and c;
3063 \\ (a or b) and c;3058 \\ (a or b) and c;
3064 \\ a == b and c == d;3059 \\ a == b and c == d;
...@@ -3067,6 +3062,47 @@ test "zig fmt: precedence" {...@@ -3067,6 +3062,47 @@ test "zig fmt: precedence" {
3067 );3062 );
3068}3063}
30693064
3065test "zig fmt: ambiguous precedence" {
3066 try testError(
3067 \\test "ambiguous precedence" {
3068 \\ a & b << c;
3069 \\ a << b + c;
3070 \\ a << b | c;
3071 \\ a ^ b & c;
3072 \\ a | b ^ c;
3073 \\ a or b and c;
3074 \\ a orelse b catch c;
3075 \\ a % b % c;
3076 \\}
3077 \\
3078 , &[_]Error{
3079 .ambiguous_operator_precedence,
3080 .previous_ambiguous_operator,
3081 .hint_operator_precedence_right,
3082 .ambiguous_operator_precedence,
3083 .previous_ambiguous_operator,
3084 .hint_operator_precedence_right,
3085 .ambiguous_operator_precedence,
3086 .previous_ambiguous_operator,
3087 .hint_operator_precedence_left,
3088 .ambiguous_operator_precedence,
3089 .previous_ambiguous_operator,
3090 .hint_operator_precedence_left,
3091 .ambiguous_operator_precedence,
3092 .previous_ambiguous_operator,
3093 .hint_operator_precedence_left,
3094 .ambiguous_operator_precedence,
3095 .previous_ambiguous_operator,
3096 .hint_operator_precedence_right,
3097 .ambiguous_operator_precedence,
3098 .previous_ambiguous_operator,
3099 .hint_operator_precedence_left,
3100 .illegal_chained_operators,
3101 .previous_ambiguous_operator,
3102 .hint_operator_precedence_left,
3103 });
3104}
3105
3070test "zig fmt: prefix operators" {3106test "zig fmt: prefix operators" {
3071 try testCanonical(3107 try testCanonical(
3072 \\test "prefix operators" {3108 \\test "prefix operators" {
...@@ -7205,7 +7241,7 @@ test "recovery: missing comma" {...@@ -7205,7 +7241,7 @@ test "recovery: missing comma" {
7205 \\ 2 => {}7241 \\ 2 => {}
7206 \\ 3 => {}7242 \\ 3 => {}
7207 \\ else => {7243 \\ else => {
7208 \\ foo & bar +;7244 \\ foo & bar &;
7209 \\ }7245 \\ }
7210 \\ }7246 \\ }
7211 \\}7247 \\}
lib/std/zig/system.zig+5-5
...@@ -266,8 +266,8 @@ pub fn resolveTargetQuery(io: Io, query: Target.Query) DetectError!Target {...@@ -266,8 +266,8 @@ pub fn resolveTargetQuery(io: Io, query: Target.Query) DetectError!Target {
266 // Minor * 1(0),000 summed has been convention since FreeBSD 2.2 (1997)266 // Minor * 1(0),000 summed has been convention since FreeBSD 2.2 (1997)
267 // e.g. 492101 = 4.11-STABLE = 4.(9+2)267 // e.g. 492101 = 4.11-STABLE = 4.(9+2)
268 const major = value / 100_000;268 const major = value / 100_000;
269 const minor1 = value % 100_000 / 10_000; // usually 0 since 5.1269 const minor1 = (value % 100_000) / 10_000; // usually 0 since 5.1
270 const minor2 = value % 10_000 / 1_000; // 0 before 5.1, minor version since270 const minor2 = (value % 10_000) / 1_000; // 0 before 5.1, minor version since
271 const patch = value % 1_000;271 const patch = value % 1_000;
272 os.version_range.semver.min = .{ .major = major, .minor = minor1 + minor2, .patch = patch };272 os.version_range.semver.min = .{ .major = major, .minor = minor1 + minor2, .patch = patch };
273 os.version_range.semver.max = os.version_range.semver.min;273 os.version_range.semver.max = os.version_range.semver.min;
...@@ -280,8 +280,8 @@ pub fn resolveTargetQuery(io: Io, query: Target.Query) DetectError!Target {...@@ -280,8 +280,8 @@ pub fn resolveTargetQuery(io: Io, query: Target.Query) DetectError!Target {
280 // r = 0 (*)280 // r = 0 (*)
281 // p = patchlevel281 // p = patchlevel
282 const major = value / 100_000_000;282 const major = value / 100_000_000;
283 const minor = value % 100_000_000 / 1_000_000;283 const minor = (value % 100_000_000) / 1_000_000;
284 const patch = value % 10_000 / 100;284 const patch = (value % 10_000) / 100;
285 os.version_range.semver.min = .{ .major = major, .minor = minor, .patch = patch };285 os.version_range.semver.min = .{ .major = major, .minor = minor, .patch = patch };
286 os.version_range.semver.max = os.version_range.semver.min;286 os.version_range.semver.max = os.version_range.semver.min;
287 },287 },
...@@ -292,7 +292,7 @@ pub fn resolveTargetQuery(io: Io, query: Target.Query) DetectError!Target {...@@ -292,7 +292,7 @@ pub fn resolveTargetQuery(io: Io, query: Target.Query) DetectError!Target {
292 // m = minor; odd-numbers indicate current dev branch292 // m = minor; odd-numbers indicate current dev branch
293 // p = patch293 // p = patch
294 const major = value / 100_000;294 const major = value / 100_000;
295 const minor = value % 100_000 / 100;295 const minor = (value % 100_000) / 100;
296 const patch = value % 100;296 const patch = value % 100;
297 os.version_range.semver.min = .{ .major = major, .minor = minor, .patch = patch };297 os.version_range.semver.min = .{ .major = major, .minor = minor, .patch = patch };
298 os.version_range.semver.max = os.version_range.semver.min;298 os.version_range.semver.max = os.version_range.semver.min;
lib/std/zig/system/windows.zig+2-2
...@@ -25,7 +25,7 @@ pub fn detectRuntimeVersion() WindowsVersion {...@@ -25,7 +25,7 @@ pub fn detectRuntimeVersion() WindowsVersion {
25 // `---` `` ``--> Sub-version (Starting from Windows 10 onwards)25 // `---` `` ``--> Sub-version (Starting from Windows 10 onwards)
26 // \ `--> Service pack (Always zero in the constants defined)26 // \ `--> Service pack (Always zero in the constants defined)
27 // `--> OS version (Major & minor)27 // `--> OS version (Major & minor)
28 const os_ver: u16 = @as(u16, @intCast(version_info.dwMajorVersion & 0xff)) << 8 |28 const os_ver: u16 = (@as(u16, @intCast(version_info.dwMajorVersion & 0xff)) << 8) |
29 @as(u16, @intCast(version_info.dwMinorVersion & 0xff));29 @as(u16, @intCast(version_info.dwMinorVersion & 0xff));
30 const sp_ver: u8 = 0;30 const sp_ver: u8 = 0;
31 const sub_ver: u8 = if (os_ver >= 0x0A00) subver: {31 const sub_ver: u8 = if (os_ver >= 0x0A00) subver: {
...@@ -40,7 +40,7 @@ pub fn detectRuntimeVersion() WindowsVersion {...@@ -40,7 +40,7 @@ pub fn detectRuntimeVersion() WindowsVersion {
40 break :subver @as(u8, @truncate(last_idx));40 break :subver @as(u8, @truncate(last_idx));
41 } else 0;41 } else 0;
4242
43 const version: u32 = @as(u32, os_ver) << 16 | @as(u16, sp_ver) << 8 | sub_ver;43 const version: u32 = (@as(u32, os_ver) << 16) | (@as(u16, sp_ver) << 8) | sub_ver;
4444
45 return @as(WindowsVersion, @fromBackingInt(@intCast(version)));45 return @as(WindowsVersion, @fromBackingInt(@intCast(version)));
46}46}
src/Air.zig+1-1
...@@ -1505,7 +1505,7 @@ pub const ShuffleTwoMask = enum(u32) {...@@ -1505,7 +1505,7 @@ pub const ShuffleTwoMask = enum(u32) {
1505 return @fromBackingInt(@intCast(idx << 1));1505 return @fromBackingInt(@intCast(idx << 1));
1506 }1506 }
1507 pub fn bElem(idx: u32) ShuffleTwoMask {1507 pub fn bElem(idx: u32) ShuffleTwoMask {
1508 return @fromBackingInt(@intCast(idx << 1 | 1));1508 return @fromBackingInt(@intCast((idx << 1) | 1));
1509 }1509 }
1510 pub const Unwrapped = union(enum) {1510 pub const Unwrapped = union(enum) {
1511 /// The resulting element is this index into the first runtime vector.1511 /// The resulting element is this index into the first runtime vector.
src/Compilation.zig+2-2
...@@ -1990,7 +1990,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,...@@ -1990,7 +1990,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
1990 .path = try options.dirs.global_cache.join(arena, &.{zir_sub_dir}),1990 .path = try options.dirs.global_cache.join(arena, &.{zir_sub_dir}),
1991 };1991 };
19921992
1993 const std_mod = options.std_mod orelse Module.create(arena, .{1993 const std_mod = options.std_mod orelse (Module.create(arena, .{
1994 .paths = .{1994 .paths = .{
1995 .root = try .fromRoot(arena, options.dirs, .zig_lib, "std"),1995 .root = try .fromRoot(arena, options.dirs, .zig_lib, "std"),
1996 .root_src_path = "std.zig",1996 .root_src_path = "std.zig",
...@@ -2015,7 +2015,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,...@@ -2015,7 +2015,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
2015 error.StackProtectorUnsupportedByTarget => unreachable,2015 error.StackProtectorUnsupportedByTarget => unreachable,
2016 error.StackProtectorUnavailableWithoutLibC => unreachable,2016 error.StackProtectorUnavailableWithoutLibC => unreachable,
2017 error.PatchableFunctionEntryUnsupportedByBackend => unreachable,2017 error.PatchableFunctionEntryUnsupportedByBackend => unreachable,
2018 };2018 });
20192019
2020 const zcu = try arena.create(Zcu);2020 const zcu = try arena.create(Zcu);
2021 zcu.* = .{2021 zcu.* = .{
src/IncrementalDebugServer.zig+2-2
...@@ -243,7 +243,7 @@ fn handleCommand(zcu: *Zcu, w: *Io.Writer, cmd_str: []const u8, arg_str: []const...@@ -243,7 +243,7 @@ fn handleCommand(zcu: *Zcu, w: *Io.Writer, cmd_str: []const u8, arg_str: []const
243 for (zcu.incremental_debug_state.types.keys()) |type_ip_index| {243 for (zcu.incremental_debug_state.types.keys()) |type_ip_index| {
244 const ty: Type = .fromInterned(type_ip_index);244 const ty: Type = .fromInterned(type_ip_index);
245 const ty_name = ty.containerTypeName(ip).fqn.toSlice(ip);245 const ty_name = ty.containerTypeName(ip).fqn.toSlice(ip);
246 const success = switch (@as(u2, @intFromBool(anchor_start)) << 1 | @intFromBool(anchor_end)) {246 const success = switch ((@as(u2, @intFromBool(anchor_start)) << 1) | @intFromBool(anchor_end)) {
247 0b00 => std.mem.find(u8, ty_name, query) != null,247 0b00 => std.mem.find(u8, ty_name, query) != null,
248 0b01 => std.mem.endsWith(u8, ty_name, query),248 0b01 => std.mem.endsWith(u8, ty_name, query),
249 0b10 => std.mem.startsWith(u8, ty_name, query),249 0b10 => std.mem.startsWith(u8, ty_name, query),
...@@ -264,7 +264,7 @@ fn handleCommand(zcu: *Zcu, w: *Io.Writer, cmd_str: []const u8, arg_str: []const...@@ -264,7 +264,7 @@ fn handleCommand(zcu: *Zcu, w: *Io.Writer, cmd_str: []const u8, arg_str: []const
264 for (zcu.incremental_debug_state.navs.keys()) |nav_index| {264 for (zcu.incremental_debug_state.navs.keys()) |nav_index| {
265 const nav = ip.getNav(nav_index);265 const nav = ip.getNav(nav_index);
266 const nav_fqn = nav.fqn.toSlice(ip);266 const nav_fqn = nav.fqn.toSlice(ip);
267 const success = switch (@as(u2, @intFromBool(anchor_start)) << 1 | @intFromBool(anchor_end)) {267 const success = switch ((@as(u2, @intFromBool(anchor_start)) << 1) | @intFromBool(anchor_end)) {
268 0b00 => std.mem.find(u8, nav_fqn, query) != null,268 0b00 => std.mem.find(u8, nav_fqn, query) != null,
269 0b01 => std.mem.endsWith(u8, nav_fqn, query),269 0b01 => std.mem.endsWith(u8, nav_fqn, query),
270 0b10 => std.mem.startsWith(u8, nav_fqn, query),270 0b10 => std.mem.startsWith(u8, nav_fqn, query),
src/InternPool.zig+18-18
...@@ -215,7 +215,7 @@ pub const TrackedInst = extern struct {...@@ -215,7 +215,7 @@ pub const TrackedInst = extern struct {
215 };215 };
216 pub fn unwrap(tracked_inst_index: TrackedInst.Index, ip: *const InternPool) Unwrapped {216 pub fn unwrap(tracked_inst_index: TrackedInst.Index, ip: *const InternPool) Unwrapped {
217 return .{217 return .{
218 .tid = @fromBackingInt(@intCast(@backingInt(tracked_inst_index) >> ip.tid_shift_32 & ip.getTidMask())),218 .tid = @fromBackingInt(@intCast((@backingInt(tracked_inst_index) >> ip.tid_shift_32) & ip.getTidMask())),
219 .index = @backingInt(tracked_inst_index) & ip.getIndexMask(u32),219 .index = @backingInt(tracked_inst_index) & ip.getIndexMask(u32),
220 };220 };
221 }221 }
...@@ -517,7 +517,7 @@ pub const ComptimeUnit = extern struct {...@@ -517,7 +517,7 @@ pub const ComptimeUnit = extern struct {
517 };517 };
518 fn unwrap(id: Id, ip: *const InternPool) Unwrapped {518 fn unwrap(id: Id, ip: *const InternPool) Unwrapped {
519 return .{519 return .{
520 .tid = @fromBackingInt(@intCast(@backingInt(id) >> ip.tid_shift_32 & ip.getTidMask())),520 .tid = @fromBackingInt(@intCast((@backingInt(id) >> ip.tid_shift_32) & ip.getTidMask())),
521 .index = @backingInt(id) & ip.getIndexMask(u31),521 .index = @backingInt(id) & ip.getIndexMask(u31),
522 };522 };
523 }523 }
...@@ -655,7 +655,7 @@ pub const Nav = struct {...@@ -655,7 +655,7 @@ pub const Nav = struct {
655 };655 };
656 fn unwrap(nav_index: Nav.Index, ip: *const InternPool) Unwrapped {656 fn unwrap(nav_index: Nav.Index, ip: *const InternPool) Unwrapped {
657 return .{657 return .{
658 .tid = @fromBackingInt(@intCast(@backingInt(nav_index) >> ip.tid_shift_30 & ip.getTidMask())),658 .tid = @fromBackingInt(@intCast((@backingInt(nav_index) >> ip.tid_shift_30) & ip.getTidMask())),
659 .index = @backingInt(nav_index) & ip.getIndexMask(u30),659 .index = @backingInt(nav_index) & ip.getIndexMask(u30),
660 };660 };
661 }661 }
...@@ -1627,7 +1627,7 @@ pub const MapIndex = enum(u32) {...@@ -1627,7 +1627,7 @@ pub const MapIndex = enum(u32) {
1627 };1627 };
1628 fn unwrap(map_index: MapIndex, ip: *const InternPool) Unwrapped {1628 fn unwrap(map_index: MapIndex, ip: *const InternPool) Unwrapped {
1629 return .{1629 return .{
1630 .tid = @fromBackingInt(@intCast(@backingInt(map_index) >> ip.tid_shift_32 & ip.getTidMask())),1630 .tid = @fromBackingInt(@intCast((@backingInt(map_index) >> ip.tid_shift_32) & ip.getTidMask())),
1631 .index = @backingInt(map_index) & ip.getIndexMask(u32),1631 .index = @backingInt(map_index) & ip.getIndexMask(u32),
1632 };1632 };
1633 }1633 }
...@@ -1648,14 +1648,14 @@ pub const NamespaceIndex = enum(u32) {...@@ -1648,14 +1648,14 @@ pub const NamespaceIndex = enum(u32) {
1648 assert(unwrapped.bucket_index <= ip.getIndexMask(u32) >> Local.namespaces_bucket_width);1648 assert(unwrapped.bucket_index <= ip.getIndexMask(u32) >> Local.namespaces_bucket_width);
1649 assert(unwrapped.index <= Local.namespaces_bucket_mask);1649 assert(unwrapped.index <= Local.namespaces_bucket_mask);
1650 return @fromBackingInt(@intCast(@shlExact(@as(u32, @backingInt(unwrapped.tid)), ip.tid_shift_32) |1650 return @fromBackingInt(@intCast(@shlExact(@as(u32, @backingInt(unwrapped.tid)), ip.tid_shift_32) |
1651 unwrapped.bucket_index << Local.namespaces_bucket_width |1651 (unwrapped.bucket_index << Local.namespaces_bucket_width) |
1652 unwrapped.index));1652 unwrapped.index));
1653 }1653 }
1654 };1654 };
1655 fn unwrap(namespace_index: NamespaceIndex, ip: *const InternPool) Unwrapped {1655 fn unwrap(namespace_index: NamespaceIndex, ip: *const InternPool) Unwrapped {
1656 const index = @backingInt(namespace_index) & ip.getIndexMask(u32);1656 const index = @backingInt(namespace_index) & ip.getIndexMask(u32);
1657 return .{1657 return .{
1658 .tid = @fromBackingInt(@intCast(@backingInt(namespace_index) >> ip.tid_shift_32 & ip.getTidMask())),1658 .tid = @fromBackingInt(@intCast((@backingInt(namespace_index) >> ip.tid_shift_32) & ip.getTidMask())),
1659 .bucket_index = index >> Local.namespaces_bucket_width,1659 .bucket_index = index >> Local.namespaces_bucket_width,
1660 .index = index & Local.namespaces_bucket_mask,1660 .index = index & Local.namespaces_bucket_mask,
1661 };1661 };
...@@ -1696,7 +1696,7 @@ pub const FileIndex = enum(u32) {...@@ -1696,7 +1696,7 @@ pub const FileIndex = enum(u32) {
1696 };1696 };
1697 pub fn unwrap(file_index: FileIndex, ip: *const InternPool) Unwrapped {1697 pub fn unwrap(file_index: FileIndex, ip: *const InternPool) Unwrapped {
1698 return .{1698 return .{
1699 .tid = @fromBackingInt(@intCast(@backingInt(file_index) >> ip.tid_shift_32 & ip.getTidMask())),1699 .tid = @fromBackingInt(@intCast((@backingInt(file_index) >> ip.tid_shift_32) & ip.getTidMask())),
1700 .index = @backingInt(file_index) & ip.getIndexMask(u32),1700 .index = @backingInt(file_index) & ip.getIndexMask(u32),
1701 };1701 };
1702 }1702 }
...@@ -1755,7 +1755,7 @@ pub const String = enum(u32) {...@@ -1755,7 +1755,7 @@ pub const String = enum(u32) {
1755 };1755 };
1756 fn unwrap(string: String, ip: *const InternPool) Unwrapped {1756 fn unwrap(string: String, ip: *const InternPool) Unwrapped {
1757 return .{1757 return .{
1758 .tid = @fromBackingInt(@intCast(@backingInt(string) >> ip.tid_shift_32 & ip.getTidMask())),1758 .tid = @fromBackingInt(@intCast((@backingInt(string) >> ip.tid_shift_32) & ip.getTidMask())),
1759 .index = @backingInt(string) & ip.getIndexMask(u32),1759 .index = @backingInt(string) & ip.getIndexMask(u32),
1760 };1760 };
1761 }1761 }
...@@ -4199,7 +4199,7 @@ pub const Index = enum(u32) {...@@ -4199,7 +4199,7 @@ pub const Index = enum(u32) {
4199 };4199 };
4200 pub fn unwrap(index: Index, ip: *const InternPool) Unwrapped {4200 pub fn unwrap(index: Index, ip: *const InternPool) Unwrapped {
4201 return .{4201 return .{
4202 .tid = @fromBackingInt(@intCast(@backingInt(index) >> ip.tid_shift_30 & ip.getTidMask())),4202 .tid = @fromBackingInt(@intCast((@backingInt(index) >> ip.tid_shift_30) & ip.getTidMask())),
4203 .index = @backingInt(index) & ip.getIndexMask(u30),4203 .index = @backingInt(index) & ip.getIndexMask(u30),
4204 };4204 };
4205 }4205 }
...@@ -6062,7 +6062,7 @@ pub const PtrNav = struct {...@@ -6062,7 +6062,7 @@ pub const PtrNav = struct {
6062 };6062 };
6063 }6063 }
6064 fn byteOffset(data: @This()) u64 {6064 fn byteOffset(data: @This()) u64 {
6065 return @as(u64, data.byte_offset_a) << 32 | data.byte_offset_b;6065 return (@as(u64, data.byte_offset_a) << 32) | data.byte_offset_b;
6066 }6066 }
6067};6067};
60686068
...@@ -6080,7 +6080,7 @@ pub const PtrUav = struct {...@@ -6080,7 +6080,7 @@ pub const PtrUav = struct {
6080 };6080 };
6081 }6081 }
6082 fn byteOffset(data: @This()) u64 {6082 fn byteOffset(data: @This()) u64 {
6083 return @as(u64, data.byte_offset_a) << 32 | data.byte_offset_b;6083 return (@as(u64, data.byte_offset_a) << 32) | data.byte_offset_b;
6084 }6084 }
6085};6085};
60866086
...@@ -6101,7 +6101,7 @@ pub const PtrUavAligned = struct {...@@ -6101,7 +6101,7 @@ pub const PtrUavAligned = struct {
6101 };6101 };
6102 }6102 }
6103 fn byteOffset(data: @This()) u64 {6103 fn byteOffset(data: @This()) u64 {
6104 return @as(u64, data.byte_offset_a) << 32 | data.byte_offset_b;6104 return (@as(u64, data.byte_offset_a) << 32) | data.byte_offset_b;
6105 }6105 }
6106};6106};
61076107
...@@ -6119,7 +6119,7 @@ pub const PtrComptimeAlloc = struct {...@@ -6119,7 +6119,7 @@ pub const PtrComptimeAlloc = struct {
6119 };6119 };
6120 }6120 }
6121 fn byteOffset(data: @This()) u64 {6121 fn byteOffset(data: @This()) u64 {
6122 return @as(u64, data.byte_offset_a) << 32 | data.byte_offset_b;6122 return (@as(u64, data.byte_offset_a) << 32) | data.byte_offset_b;
6123 }6123 }
6124};6124};
61256125
...@@ -6137,7 +6137,7 @@ pub const PtrComptimeField = struct {...@@ -6137,7 +6137,7 @@ pub const PtrComptimeField = struct {
6137 };6137 };
6138 }6138 }
6139 fn byteOffset(data: @This()) u64 {6139 fn byteOffset(data: @This()) u64 {
6140 return @as(u64, data.byte_offset_a) << 32 | data.byte_offset_b;6140 return (@as(u64, data.byte_offset_a) << 32) | data.byte_offset_b;
6141 }6141 }
6142};6142};
61436143
...@@ -6155,7 +6155,7 @@ pub const PtrBase = struct {...@@ -6155,7 +6155,7 @@ pub const PtrBase = struct {
6155 };6155 };
6156 }6156 }
6157 fn byteOffset(data: @This()) u64 {6157 fn byteOffset(data: @This()) u64 {
6158 return @as(u64, data.byte_offset_a) << 32 | data.byte_offset_b;6158 return (@as(u64, data.byte_offset_a) << 32) | data.byte_offset_b;
6159 }6159 }
6160};6160};
61616161
...@@ -6175,7 +6175,7 @@ pub const PtrBaseIndex = struct {...@@ -6175,7 +6175,7 @@ pub const PtrBaseIndex = struct {
6175 };6175 };
6176 }6176 }
6177 fn byteOffset(data: @This()) u64 {6177 fn byteOffset(data: @This()) u64 {
6178 return @as(u64, data.byte_offset_a) << 32 | data.byte_offset_b;6178 return (@as(u64, data.byte_offset_a) << 32) | data.byte_offset_b;
6179 }6179 }
6180};6180};
61816181
...@@ -6191,7 +6191,7 @@ pub const PtrInt = struct {...@@ -6191,7 +6191,7 @@ pub const PtrInt = struct {
6191 };6191 };
6192 }6192 }
6193 fn byteOffset(data: @This()) u64 {6193 fn byteOffset(data: @This()) u64 {
6194 return @as(u64, data.byte_offset_a) << 32 | data.byte_offset_b;6194 return (@as(u64, data.byte_offset_a) << 32) | data.byte_offset_b;
6195 }6195 }
6196};6196};
61976197
...@@ -12634,7 +12634,7 @@ const PackedCallingConvention = packed struct(u18) {...@@ -12634,7 +12634,7 @@ const PackedCallingConvention = packed struct(u18) {
12634 std.lang.CallingConvention.SpirvFragmentOptions => .{12634 std.lang.CallingConvention.SpirvFragmentOptions => .{
12635 .tag = tag,12635 .tag = tag,
12636 .incoming_stack_alignment = .none,12636 .incoming_stack_alignment = .none,
12637 .extra = @as(u4, @backingInt(pl.depth_assumption)) << 1 | @intFromBool(pl.pixel_centered_integer),12637 .extra = (@as(u4, @backingInt(pl.depth_assumption)) << 1) | @intFromBool(pl.pixel_centered_integer),
12638 },12638 },
12639 std.lang.CallingConvention.SpirvMeshOptions => .{12639 std.lang.CallingConvention.SpirvMeshOptions => .{
12640 .tag = tag,12640 .tag = tag,
src/Sema.zig+2-2
...@@ -29956,10 +29956,10 @@ fn coerceVarArgParam(...@@ -29956,10 +29956,10 @@ fn coerceVarArgParam(
29956 if (!uncasted_ty.validateExtern(.param_ty, zcu)) break :int inst;29956 if (!uncasted_ty.validateExtern(.param_ty, zcu)) break :int inst;
29957 const target = zcu.getTarget();29957 const target = zcu.getTarget();
29958 const uncasted_info = uncasted_ty.intInfo(zcu);29958 const uncasted_info = uncasted_ty.intInfo(zcu);
29959 if (uncasted_info.bits <= target.cTypeBitSize(switch (uncasted_info.signedness) {29959 if (uncasted_info.bits <= (target.cTypeBitSize(switch (uncasted_info.signedness) {
29960 .signed => .int,29960 .signed => .int,
29961 .unsigned => .uint,29961 .unsigned => .uint,
29962 }) orelse break :int inst) break :int try sema.coerce(block, switch (uncasted_info.signedness) {29962 }) orelse break :int inst)) break :int try sema.coerce(block, switch (uncasted_info.signedness) {
29963 .signed => .c_int,29963 .signed => .c_int,
29964 .unsigned => .c_uint,29964 .unsigned => .c_uint,
29965 }, inst, inst_src);29965 }, inst, inst_src);
src/codegen/aarch64/Assemble.zig+2-2
...@@ -164,7 +164,7 @@ const matchers = matchers: {...@@ -164,7 +164,7 @@ const matchers = matchers: {
164 return @call(.auto, encode, args);164 return @call(.auto, encode, args);
165 } else if (pattern_token[0] == '<') {165 } else if (pattern_token[0] == '<') {
166 const symbol_name = comptime pattern_token[1 .. std.mem.findScalarPos(u8, pattern_token, 1, '|') orelse166 const symbol_name = comptime pattern_token[1 .. std.mem.findScalarPos(u8, pattern_token, 1, '|') orelse
167 pattern_token.len - 1];167 (pattern_token.len - 1)];
168 const symbol = @field(Symbol, symbol_name);168 const symbol = @field(Symbol, symbol_name);
169 const symbol_ptr = &@field(symbols, symbol_name);169 const symbol_ptr = &@field(symbols, symbol_name);
170 const symbol_value = zonCast(SymbolSpec, @field(instruction.symbols, symbol_name), .{}).parse(source_token) orelse {170 const symbol_value = zonCast(SymbolSpec, @field(instruction.symbols, symbol_name), .{}).parse(source_token) orelse {
...@@ -453,7 +453,7 @@ const SymbolSpec = union(enum) {...@@ -453,7 +453,7 @@ const SymbolSpec = union(enum) {
453 } else {453 } else {
454 const Repr = std.math.FloatRepr(f16);454 const Repr = std.math.FloatRepr(f16);
455 const repr: Repr = @bitCast(fimm);455 const repr: Repr = @bitCast(fimm);
456 if (repr.mantissa & std.math.maxInt(Repr.Mantissa) >> 5 != 0 or switch (repr.exponent) {456 if ((repr.mantissa & (std.math.maxInt(Repr.Mantissa) >> 5)) != 0 or switch (repr.exponent) {
457 .denormal, .infinite => true,457 .denormal, .infinite => true,
458 else => std.math.cast(i3, repr.exponent.unbias() - 1) == null,458 else => std.math.cast(i3, repr.exponent.unbias() - 1) == null,
459 }) {459 }) {
src/codegen/aarch64/Disassemble.zig+4-4
...@@ -31,7 +31,7 @@ pub fn printInstruction(dis: Disassemble, inst: aarch64.encoding.Instruction, wr...@@ -31,7 +31,7 @@ pub fn printInstruction(dis: Disassemble, inst: aarch64.encoding.Instruction, wr
31 .unallocated => break :unallocated,31 .unallocated => break :unallocated,
32 .pc_relative_addressing => |pc_relative_addressing| {32 .pc_relative_addressing => |pc_relative_addressing| {
33 const group = pc_relative_addressing.group;33 const group = pc_relative_addressing.group;
34 const imm = (@as(i33, group.immhi) << 2 | @as(i33, group.immlo) << 0) + @as(i33, switch (group.op) {34 const imm = ((@as(i33, group.immhi) << 2) | (@as(i33, group.immlo) << 0)) + @as(i33, switch (group.op) {
35 .adr => aarch64.encoding.Instruction.size,35 .adr => aarch64.encoding.Instruction.size,
36 .adrp => 0,36 .adrp => 0,
37 });37 });
...@@ -311,7 +311,7 @@ pub fn printInstruction(dis: Disassemble, inst: aarch64.encoding.Instruction, wr...@@ -311,7 +311,7 @@ pub fn printInstruction(dis: Disassemble, inst: aarch64.encoding.Instruction, wr
311 .hint => |hint| return writer.print("{f}{s}#0x{x}", .{311 .hint => |hint| return writer.print("{f}{s}#0x{x}", .{
312 fmtCase(.hint, dis.case),312 fmtCase(.hint, dis.case),
313 dis.mnemonic_operands_separator,313 dis.mnemonic_operands_separator,
314 @as(u7, hint.CRm) << 3 | @as(u7, hint.op2) << 0,314 (@as(u7, hint.CRm) << 3) | (@as(u7, hint.op2) << 0),
315 }),315 }),
316 else => |decoded| return writer.print("{f}", .{fmtCase(decoded, dis.case)}),316 else => |decoded| return writer.print("{f}", .{fmtCase(decoded, dis.case)}),
317 },317 },
...@@ -365,8 +365,8 @@ pub fn printInstruction(dis: Disassemble, inst: aarch64.encoding.Instruction, wr...@@ -365,8 +365,8 @@ pub fn printInstruction(dis: Disassemble, inst: aarch64.encoding.Instruction, wr
365 dis.mnemonic_operands_separator,365 dis.mnemonic_operands_separator,
366 group.Rt.decode(.{}).general(@fromBackingInt(@intCast(group.b5))).fmtCase(dis.case),366 group.Rt.decode(.{}).general(@fromBackingInt(@intCast(group.b5))).fmtCase(dis.case),
367 dis.operands_separator,367 dis.operands_separator,
368 @as(u6, group.b5) << 5 |368 (@as(u6, group.b5) << 5) |
369 @as(u6, group.b40) << 0,369 (@as(u6, group.b40) << 0),
370 dis.operands_separator,370 dis.operands_separator,
371 @as(u8, if (imm < 0) '-' else '+'),371 @as(u8, if (imm < 0) '-' else '+'),
372 @abs(imm) << 2,372 @abs(imm) << 2,
src/codegen/aarch64/Mir.zig+3-3
...@@ -208,7 +208,7 @@ fn emitReloc(...@@ -208,7 +208,7 @@ fn emitReloc(
208 };208 };
209 try atom.addReloc(gpa, .{209 try atom.addReloc(gpa, .{
210 .r_offset = offset,210 .r_offset = offset,
211 .r_info = @as(u64, @backingInt(sym_index)) << 32 | @backingInt(r_type),211 .r_info = (@as(u64, @backingInt(sym_index)) << 32) | @backingInt(r_type),
212 .r_addend = @bitCast(addend),212 .r_addend = @bitCast(addend),
213 }, zo);213 }, zo);
214 } else if (lf.cast(.macho)) |mf| {214 } else if (lf.cast(.macho)) |mf| {
...@@ -265,7 +265,7 @@ fn emitReloc(...@@ -265,7 +265,7 @@ fn emitReloc(
265 };265 };
266 try atom.addReloc(gpa, .{266 try atom.addReloc(gpa, .{
267 .r_offset = offset,267 .r_offset = offset,
268 .r_info = @as(u64, @backingInt(sym_index)) << 32 | @backingInt(r_type),268 .r_info = (@as(u64, @backingInt(sym_index)) << 32) | @backingInt(r_type),
269 .r_addend = @bitCast(addend),269 .r_addend = @bitCast(addend),
270 }, zo);270 }, zo);
271 } else if (lf.cast(.macho)) |mf| {271 } else if (lf.cast(.macho)) |mf| {
...@@ -328,7 +328,7 @@ fn emitReloc(...@@ -328,7 +328,7 @@ fn emitReloc(
328 };328 };
329 try atom.addReloc(gpa, .{329 try atom.addReloc(gpa, .{
330 .r_offset = offset,330 .r_offset = offset,
331 .r_info = @as(u64, @backingInt(sym_index)) << 32 | @backingInt(r_type),331 .r_info = (@as(u64, @backingInt(sym_index)) << 32) | @backingInt(r_type),
332 .r_addend = @bitCast(addend),332 .r_addend = @bitCast(addend),
333 }, zo);333 }, zo);
334 } else if (lf.cast(.macho)) |mf| {334 } else if (lf.cast(.macho)) |mf| {
src/codegen/aarch64/Select.zig+4-4
...@@ -8099,7 +8099,7 @@ fn movImmediate(isel: *Select, dst_reg: Register, src_imm: u64) !void {...@@ -8099,7 +8099,7 @@ fn movImmediate(isel: *Select, dst_reg: Register, src_imm: u64) !void {
8099 .{ .immediate = .{8099 .{ .immediate = .{
8100 .N = @fromBackingInt(@intCast(elem_width >> 6)),8100 .N = @fromBackingInt(@intCast(elem_width >> 6)),
8101 .immr = hi + mid_masked,8101 .immr = hi + mid_masked,
8102 .imms = ((((lo + hi) & smask) | mid_masked) - 1) | -%@as(u6, @truncate(elem_width)) << 1,8102 .imms = ((((lo + hi) & smask) | mid_masked) - 1) | (-%@as(u6, @truncate(elem_width)) << 1),
8103 } },8103 } },
8104 ));8104 ));
8105 }8105 }
...@@ -10831,7 +10831,7 @@ pub const Value = struct {...@@ -10831,7 +10831,7 @@ pub const Value = struct {
10831 if (feat_fp16) {10831 if (feat_fp16) {
10832 const Repr = std.math.FloatRepr(f16);10832 const Repr = std.math.FloatRepr(f16);
10833 const repr: Repr = @bitCast(imm);10833 const repr: Repr = @bitCast(imm);
10834 if (repr.mantissa & std.math.maxInt(Repr.Mantissa) >> 5 == 0 and switch (repr.exponent) {10834 if (repr.mantissa & (std.math.maxInt(Repr.Mantissa) >> 5) == 0 and switch (repr.exponent) {
10835 .denormal, .infinite => false,10835 .denormal, .infinite => false,
10836 else => std.math.cast(i3, repr.exponent.unbias() - 1) != null,10836 else => std.math.cast(i3, repr.exponent.unbias() - 1) != null,
10837 }) break :free try isel.emit(.fmov(mat.ra.h(), .{ .immediate = imm }));10837 }) break :free try isel.emit(.fmov(mat.ra.h(), .{ .immediate = imm }));
...@@ -10855,7 +10855,7 @@ pub const Value = struct {...@@ -10855,7 +10855,7 @@ pub const Value = struct {
10855 } };10855 } };
10856 const Repr = std.math.FloatRepr(f32);10856 const Repr = std.math.FloatRepr(f32);
10857 const repr: Repr = @bitCast(imm);10857 const repr: Repr = @bitCast(imm);
10858 if (repr.mantissa & std.math.maxInt(Repr.Mantissa) >> 5 == 0 and switch (repr.exponent) {10858 if (repr.mantissa & (std.math.maxInt(Repr.Mantissa) >> 5) == 0 and switch (repr.exponent) {
10859 .denormal, .infinite => false,10859 .denormal, .infinite => false,
10860 else => std.math.cast(i3, repr.exponent.unbias() - 1) != null,10860 else => std.math.cast(i3, repr.exponent.unbias() - 1) != null,
10861 }) break :free try isel.emit(.fmov(mat.ra.s(), .{ .immediate = @floatCast(imm) }));10861 }) break :free try isel.emit(.fmov(mat.ra.s(), .{ .immediate = @floatCast(imm) }));
...@@ -10878,7 +10878,7 @@ pub const Value = struct {...@@ -10878,7 +10878,7 @@ pub const Value = struct {
10878 } };10878 } };
10879 const Repr = std.math.FloatRepr(f64);10879 const Repr = std.math.FloatRepr(f64);
10880 const repr: Repr = @bitCast(imm);10880 const repr: Repr = @bitCast(imm);
10881 if (repr.mantissa & std.math.maxInt(Repr.Mantissa) >> 5 == 0 and switch (repr.exponent) {10881 if (repr.mantissa & (std.math.maxInt(Repr.Mantissa) >> 5) == 0 and switch (repr.exponent) {
10882 .denormal, .infinite => false,10882 .denormal, .infinite => false,
10883 else => std.math.cast(i3, repr.exponent.unbias() - 1) != null,10883 else => std.math.cast(i3, repr.exponent.unbias() - 1) != null,
10884 }) break :free try isel.emit(.fmov(mat.ra.d(), .{ .immediate = @floatCast(imm) }));10884 }) break :free try isel.emit(.fmov(mat.ra.d(), .{ .immediate = @floatCast(imm) }));
src/codegen/aarch64/encoding.zig+19-19
...@@ -11886,9 +11886,9 @@ pub const Instruction = packed union {...@@ -11886,9 +11886,9 @@ pub const Instruction = packed union {
11886 .cmode = switch (arrangement) {11886 .cmode = switch (arrangement) {
11887 else => unreachable,11887 else => unreachable,
11888 .@"4h", .@"8h" => @as(u3, 0b100) |11888 .@"4h", .@"8h" => @as(u3, 0b100) |
11889 @as(u3, @as(u1, @intCast(@shrExact(shifted_immediate.lsl, 3)))) << 0,11889 (@as(u3, @as(u1, @intCast(@shrExact(shifted_immediate.lsl, 3)))) << 0),
11890 .@"2s", .@"4s" => @as(u3, 0b000) |11890 .@"2s", .@"4s" => @as(u3, 0b000) |
11891 @as(u3, @as(u2, @intCast(@shrExact(shifted_immediate.lsl, 3)))) << 0,11891 (@as(u3, @as(u2, @intCast(@shrExact(shifted_immediate.lsl, 3)))) << 0),
11892 },11892 },
11893 .imm3 = @intCast(shifted_immediate.immediate >> 5),11893 .imm3 = @intCast(shifted_immediate.immediate >> 5),
11894 .Q = arrangement.size(),11894 .Q = arrangement.size(),
...@@ -12384,7 +12384,7 @@ pub const Instruction = packed union {...@@ -12384,7 +12384,7 @@ pub const Instruction = packed union {
12384 .dup = .{12384 .dup = .{
12385 .Rd = d.alias.encode(.{ .V = true }),12385 .Rd = d.alias.encode(.{ .V = true }),
12386 .Rn = n.alias.encode(.{ .V = true }),12386 .Rn = n.alias.encode(.{ .V = true }),
12387 .imm5 = @shlExact(@as(u5, n.format.element.index) << 1 | @as(u5, 0b1), @backingInt(elem_size)),12387 .imm5 = @shlExact((@as(u5, n.format.element.index) << 1) | @as(u5, 0b1), @backingInt(elem_size)),
12388 },12388 },
12389 } } };12389 } } };
12390 },12390 },
...@@ -12400,7 +12400,7 @@ pub const Instruction = packed union {...@@ -12400,7 +12400,7 @@ pub const Instruction = packed union {
12400 .Rd = d.alias.encode(.{ .V = true }),12400 .Rd = d.alias.encode(.{ .V = true }),
12401 .Rn = n.alias.encode(.{ .V = true }),12401 .Rn = n.alias.encode(.{ .V = true }),
12402 .imm4 = .element,12402 .imm4 = .element,
12403 .imm5 = @shlExact(@as(u5, element.index) << 1 | @as(u5, 0b1), @backingInt(elem_size)),12403 .imm5 = @shlExact((@as(u5, element.index) << 1) | @as(u5, 0b1), @backingInt(elem_size)),
12404 .Q = arrangement.size(),12404 .Q = arrangement.size(),
12405 },12405 },
12406 } } };12406 } } };
...@@ -14195,7 +14195,7 @@ pub const Instruction = packed union {...@@ -14195,7 +14195,7 @@ pub const Instruction = packed union {
14195 .Rd = d.alias.encode(.{ .V = true }),14195 .Rd = d.alias.encode(.{ .V = true }),
14196 .Rn = n.alias.encode(.{ .V = true }),14196 .Rn = n.alias.encode(.{ .V = true }),
14197 .imm4 = .{ .element = element.index << @intCast(@backingInt(elem_size)) },14197 .imm4 = .{ .element = element.index << @intCast(@backingInt(elem_size)) },
14198 .imm5 = (@as(u5, d.format.element.index) << 1 | @as(u5, 0b1) << 0) << @backingInt(elem_size),14198 .imm5 = ((@as(u5, d.format.element.index) << 1) | (@as(u5, 0b1) << 0)) << @backingInt(elem_size),
14199 .op = .element,14199 .op = .element,
14200 },14200 },
14201 } } };14201 } } };
...@@ -14211,7 +14211,7 @@ pub const Instruction = packed union {...@@ -14211,7 +14211,7 @@ pub const Instruction = packed union {
14211 .Rd = d.alias.encode(.{ .V = true }),14211 .Rd = d.alias.encode(.{ .V = true }),
14212 .Rn = n.alias.encode(.{}),14212 .Rn = n.alias.encode(.{}),
14213 .imm4 = .{ .general = .general },14213 .imm4 = .{ .general = .general },
14214 .imm5 = (@as(u5, d.format.element.index) << 1 | @as(u5, 0b1) << 0) << @backingInt(elem_size),14214 .imm5 = ((@as(u5, d.format.element.index) << 1) | (@as(u5, 0b1) << 0)) << @backingInt(elem_size),
14215 .op = .general,14215 .op = .general,
14216 },14216 },
14217 } } };14217 } } };
...@@ -15072,16 +15072,16 @@ pub const Instruction = packed union {...@@ -15072,16 +15072,16 @@ pub const Instruction = packed union {
15072 .lsl => |amount| switch (arrangement) {15072 .lsl => |amount| switch (arrangement) {
15073 else => unreachable,15073 else => unreachable,
15074 .@"8b", .@"16b" => @as(u4, 0b1110) |15074 .@"8b", .@"16b" => @as(u4, 0b1110) |
15075 @as(u4, @as(u0, @intCast(@shrExact(amount, 3)))) << 1,15075 (@as(u4, @as(u0, @intCast(@shrExact(amount, 3)))) << 1),
15076 .@"4h", .@"8h" => @as(u4, 0b1000) |15076 .@"4h", .@"8h" => @as(u4, 0b1000) |
15077 @as(u4, @as(u1, @intCast(@shrExact(amount, 3)))) << 1,15077 (@as(u4, @as(u1, @intCast(@shrExact(amount, 3)))) << 1),
15078 .@"2s", .@"4s" => @as(u4, 0b0000) |15078 .@"2s", .@"4s" => @as(u4, 0b0000) |
15079 @as(u4, @as(u2, @intCast(@shrExact(amount, 3)))) << 1,15079 (@as(u4, @as(u2, @intCast(@shrExact(amount, 3)))) << 1),
15080 },15080 },
15081 .msl => |amount| switch (arrangement) {15081 .msl => |amount| switch (arrangement) {
15082 else => unreachable,15082 else => unreachable,
15083 .@"2s", .@"4s" => @as(u4, 0b1100) |15083 .@"2s", .@"4s" => @as(u4, 0b1100) |
15084 @as(u4, @as(u1, @intCast(@shrExact(amount, 3) - 1))) << 0,15084 (@as(u4, @as(u1, @intCast(@shrExact(amount, 3) - 1))) << 0),
15085 },15085 },
15086 .replicate => switch (arrangement) {15086 .replicate => switch (arrangement) {
15087 else => unreachable,15087 else => unreachable,
...@@ -15345,9 +15345,9 @@ pub const Instruction = packed union {...@@ -15345,9 +15345,9 @@ pub const Instruction = packed union {
15345 .cmode = switch (arrangement) {15345 .cmode = switch (arrangement) {
15346 else => unreachable,15346 else => unreachable,
15347 .@"4h", .@"8h" => @as(u3, 0b100) |15347 .@"4h", .@"8h" => @as(u3, 0b100) |
15348 @as(u3, @as(u1, @intCast(@shrExact(shifted_immediate.lsl, 3)))) << 0,15348 (@as(u3, @as(u1, @intCast(@shrExact(shifted_immediate.lsl, 3)))) << 0),
15349 .@"2s", .@"4s" => @as(u3, 0b000) |15349 .@"2s", .@"4s" => @as(u3, 0b000) |
15350 @as(u3, @as(u2, @intCast(@shrExact(shifted_immediate.lsl, 3)))) << 0,15350 (@as(u3, @as(u2, @intCast(@shrExact(shifted_immediate.lsl, 3)))) << 0),
15351 },15351 },
15352 .imm3 = @intCast(shifted_immediate.immediate >> 5),15352 .imm3 = @intCast(shifted_immediate.immediate >> 5),
15353 .Q = arrangement.size(),15353 .Q = arrangement.size(),
...@@ -15660,9 +15660,9 @@ pub const Instruction = packed union {...@@ -15660,9 +15660,9 @@ pub const Instruction = packed union {
15660 .Rn = n.alias.encode(.{ .V = true }),15660 .Rn = n.alias.encode(.{ .V = true }),
15661 .imm5 = switch (vs) {15661 .imm5 = switch (vs) {
15662 else => unreachable,15662 else => unreachable,
15663 .byte => @as(u5, @as(u4, @intCast(n.format.element.index))) << 1 | @as(u5, 0b1) << 0,15663 .byte => (@as(u5, @as(u4, @intCast(n.format.element.index))) << 1) | (@as(u5, 0b1) << 0),
15664 .half => @as(u5, @as(u3, @intCast(n.format.element.index))) << 2 | @as(u5, 0b10) << 0,15664 .half => (@as(u5, @as(u3, @intCast(n.format.element.index))) << 2) | (@as(u5, 0b10) << 0),
15665 .single => @as(u5, @as(u2, @intCast(n.format.element.index))) << 3 | @as(u5, 0b100) << 0,15665 .single => (@as(u5, @as(u2, @intCast(n.format.element.index))) << 3) | (@as(u5, 0b100) << 0),
15666 },15666 },
15667 .Q = sf,15667 .Q = sf,
15668 },15668 },
...@@ -16492,10 +16492,10 @@ pub const Instruction = packed union {...@@ -16492,10 +16492,10 @@ pub const Instruction = packed union {
16492 .Rn = n.alias.encode(.{ .V = true }),16492 .Rn = n.alias.encode(.{ .V = true }),
16493 .imm5 = switch (vs) {16493 .imm5 = switch (vs) {
16494 else => unreachable,16494 else => unreachable,
16495 .byte => @as(u5, @as(u4, @intCast(n.format.element.index))) << 1 | @as(u5, 0b1) << 0,16495 .byte => (@as(u5, @as(u4, @intCast(n.format.element.index))) << 1) | (@as(u5, 0b1) << 0),
16496 .half => @as(u5, @as(u3, @intCast(n.format.element.index))) << 2 | @as(u5, 0b10) << 0,16496 .half => (@as(u5, @as(u3, @intCast(n.format.element.index))) << 2) | (@as(u5, 0b10) << 0),
16497 .single => @as(u5, @as(u2, @intCast(n.format.element.index))) << 3 | @as(u5, 0b100) << 0,16497 .single => (@as(u5, @as(u2, @intCast(n.format.element.index))) << 3) | (@as(u5, 0b100) << 0),
16498 .double => @as(u5, @as(u1, @intCast(n.format.element.index))) << 4 | @as(u5, 0b1000) << 0,16498 .double => (@as(u5, @as(u1, @intCast(n.format.element.index))) << 4) | (@as(u5, 0b1000) << 0),
16499 },16499 },
16500 .Q = sf,16500 .Q = sf,
16501 },16501 },
src/codegen/loongarch/Mir.zig+1-1
...@@ -181,7 +181,7 @@ fn emitReloc(...@@ -181,7 +181,7 @@ fn emitReloc(
181 const atom = zo.symbol(@backingInt(atom_index)).atom(ef).?;181 const atom = zo.symbol(@backingInt(atom_index)).atom(ef).?;
182 try atom.addReloc(zcu.gpa, .{182 try atom.addReloc(zcu.gpa, .{
183 .r_offset = offset,183 .r_offset = offset,
184 .r_info = @as(u64, @backingInt(sym_index)) << 32 | @backingInt(reloc_type),184 .r_info = (@as(u64, @backingInt(sym_index)) << 32) | @backingInt(reloc_type),
185 .r_addend = @bitCast(addend),185 .r_addend = @bitCast(addend),
186 }, zo);186 }, zo);
187 } else unreachable;187 } else unreachable;
src/codegen/riscv64/CodeGen.zig+2-2
...@@ -1764,7 +1764,7 @@ fn finishAir(...@@ -1764,7 +1764,7 @@ fn finishAir(
1764) !void {1764) !void {
1765 const tomb_bits = func.liveness.getTombBits(inst);1765 const tomb_bits = func.liveness.getTombBits(inst);
1766 for (0.., operands) |op_index, op| {1766 for (0.., operands) |op_index, op| {
1767 if (tomb_bits & @as(Air.Liveness.Bpi, 1) << @intCast(op_index) == 0) continue;1767 if (tomb_bits & (@as(Air.Liveness.Bpi, 1) << @intCast(op_index)) == 0) continue;
1768 if (func.reused_operands.isSet(op_index)) continue;1768 if (func.reused_operands.isSet(op_index)) continue;
1769 try func.processDeath(op.toIndexAllowNone() orelse continue);1769 try func.processDeath(op.toIndexAllowNone() orelse continue);
1770 }1770 }
...@@ -6272,7 +6272,7 @@ fn airAsm(func: *Func, inst: Air.Inst.Index) !void {...@@ -6272,7 +6272,7 @@ fn airAsm(func: *Func, inst: Air.Inst.Index) !void {
6272 "";6272 "";
62736273
6274 op.* = switch (args.items[6274 op.* = switch (args.items[
6275 arg_map.get(op_str["%[".len .. mod_index orelse op_str.len - "]".len]) orelse6275 arg_map.get(op_str["%[".len .. mod_index orelse (op_str.len - "]".len)]) orelse
6276 return func.fail("no matching constraint: '{s}'", .{op_str})6276 return func.fail("no matching constraint: '{s}'", .{op_str})
6277 ]) {6277 ]) {
6278 .lea_symbol => |sym_off| if (mem.eql(u8, modifier, "plt")) blk: {6278 .lea_symbol => |sym_off| if (mem.eql(u8, modifier, "plt")) blk: {
src/codegen/riscv64/encoding.zig+2-2
...@@ -582,8 +582,8 @@ pub const Instruction = union(Lir.Format) {...@@ -582,8 +582,8 @@ pub const Instruction = union(Lir.Format) {
582582
583 .opcode = opcode,583 .opcode = opcode,
584 .funct3 = @backingInt(amo.width),584 .funct3 = @backingInt(amo.width),
585 .funct7 = @as(u7, amo.funct5) << 2 |585 .funct7 = (@as(u7, amo.funct5) << 2) |
586 @as(u7, @intFromBool(ops[3].barrier == .rl)) << 1 |586 (@as(u7, @intFromBool(ops[3].barrier == .rl)) << 1) |
587 @as(u7, @intFromBool(ops[4].barrier == .aq)),587 @as(u7, @intFromBool(ops[4].barrier == .aq)),
588 },588 },
589 else => unreachable,589 else => unreachable,
src/codegen/sparc64/CodeGen.zig+2-2
...@@ -3475,11 +3475,11 @@ fn finishAirBookkeeping(self: *Self) void {...@@ -3475,11 +3475,11 @@ fn finishAirBookkeeping(self: *Self) void {
3475fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Air.Liveness.bpi - 1]Air.Inst.Ref) void {3475fn finishAir(self: *Self, inst: Air.Inst.Index, result: MCValue, operands: [Air.Liveness.bpi - 1]Air.Inst.Ref) void {
3476 const tomb_bits = self.liveness.getTombBits(inst);3476 const tomb_bits = self.liveness.getTombBits(inst);
3477 for (0.., operands) |op_index, op| {3477 for (0.., operands) |op_index, op| {
3478 if (tomb_bits & @as(Air.Liveness.Bpi, 1) << @intCast(op_index) == 0) continue;3478 if (tomb_bits & (@as(Air.Liveness.Bpi, 1) << @intCast(op_index)) == 0) continue;
3479 if (self.reused_operands.isSet(op_index)) continue;3479 if (self.reused_operands.isSet(op_index)) continue;
3480 self.processDeath(op.toIndexAllowNone() orelse continue);3480 self.processDeath(op.toIndexAllowNone() orelse continue);
3481 }3481 }
3482 if (tomb_bits & 1 << (Air.Liveness.bpi - 1) == 0) {3482 if (tomb_bits & (1 << (Air.Liveness.bpi - 1)) == 0) {
3483 log.debug("%{d} => {}", .{ inst, result });3483 log.debug("%{d} => {}", .{ inst, result });
3484 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];3484 const branch = &self.branch_stack.items[self.branch_stack.items.len - 1];
3485 branch.inst_table.putAssumeCapacityNoClobber(inst, result);3485 branch.inst_table.putAssumeCapacityNoClobber(inst, result);
src/codegen/spirv/CodeGen.zig+1-1
...@@ -1191,7 +1191,7 @@ fn constInt(cg: *CodeGen, ty: Type, value: anytype) !Id {...@@ -1191,7 +1191,7 @@ fn constInt(cg: *CodeGen, ty: Type, value: anytype) !Id {
1191 const truncated_value = if (backing_bits == 64)1191 const truncated_value = if (backing_bits == 64)
1192 value641192 value64
1193 else1193 else
1194 value64 & (@as(u64, 1) << @intCast(backing_bits)) - 1;1194 value64 & ((@as(u64, 1) << @intCast(backing_bits)) - 1);
11951195
1196 break :blk switch (backing_bits) {1196 break :blk switch (backing_bits) {
1197 1...32 => .{ .uint32 = @truncate(truncated_value) },1197 1...32 => .{ .uint32 = @truncate(truncated_value) },
src/codegen/x86_64/CodeGen.zig+17-17
...@@ -173255,7 +173255,7 @@ fn finishAir(...@@ -173255,7 +173255,7 @@ fn finishAir(
173255) !void {173255) !void {
173256 const tomb_bits = self.liveness.getTombBits(inst);173256 const tomb_bits = self.liveness.getTombBits(inst);
173257 for (0.., operands) |op_index, op| {173257 for (0.., operands) |op_index, op| {
173258 if (tomb_bits & @as(Air.Liveness.Bpi, 1) << @intCast(op_index) == 0) continue;173258 if (tomb_bits & (@as(Air.Liveness.Bpi, 1) << @intCast(op_index)) == 0) continue;
173259 if (self.reused_operands.isSet(op_index)) continue;173259 if (self.reused_operands.isSet(op_index)) continue;
173260 try self.processDeath(op.toIndexAllowNone() orelse continue, .{});173260 try self.processDeath(op.toIndexAllowNone() orelse continue, .{});
173261 }173261 }
...@@ -176321,7 +176321,7 @@ fn lowerSwitchBr(...@@ -176321,7 +176321,7 @@ fn lowerSwitchBr(
176321 const unsigned_condition_ty = try cg.pt.intType(.unsigned, cg.intInfo(condition_ty).?.bits);176321 const unsigned_condition_ty = try cg.pt.intType(.unsigned, cg.intInfo(condition_ty).?.bits);
176322176322
176323 const ExpectedContents = extern struct {176323 const ExpectedContents = extern struct {
176324 liveness_deaths: [1 << 8 | 1]Air.Inst.Index,176324 liveness_deaths: [(1 << 8) | 1]Air.Inst.Index,
176325 bigint_limbs: [std.math.big.int.calcTwosCompLimbCount(1 << 10)]std.math.big.Limb,176325 bigint_limbs: [std.math.big.int.calcTwosCompLimbCount(1 << 10)]std.math.big.Limb,
176326 relocs: [1 << 6]Mir.Inst.Index,176326 relocs: [1 << 6]Mir.Inst.Index,
176327 };176327 };
...@@ -177310,7 +177310,7 @@ fn airAsm(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -177310,7 +177310,7 @@ fn airAsm(self: *CodeGen, inst: Air.Inst.Index) !void {
177310 else177310 else
177311 "";177311 "";
177312 op.* = switch (args[177312 op.* = switch (args[
177313 arg_map.get(op_str["%[".len .. colon orelse op_str.len - "]".len]) orelse177313 arg_map.get(op_str["%[".len .. colon orelse (op_str.len - "]".len)]) orelse
177314 return self.fail("no matching constraint: '{s}'", .{op_str})177314 return self.fail("no matching constraint: '{s}'", .{op_str})
177315 ]) {177315 ]) {
177316 .immediate => |imm| if (std.mem.eql(u8, modifier, "") or177316 .immediate => |imm| if (std.mem.eql(u8, modifier, "") or
...@@ -177454,7 +177454,7 @@ fn airAsm(self: *CodeGen, inst: Air.Inst.Index) !void {...@@ -177454,7 +177454,7 @@ fn airAsm(self: *CodeGen, inst: Air.Inst.Index) !void {
177454 else177454 else
177455 "";177455 "";
177456 break :disp switch (args[177456 break :disp switch (args[
177457 arg_map.get(op_str["%[".len .. colon orelse open - "]".len]) orelse177457 arg_map.get(op_str["%[".len .. colon orelse (open - "]".len)]) orelse
177458 return self.fail("no matching constraint: '{s}'", .{op_str})177458 return self.fail("no matching constraint: '{s}'", .{op_str})
177459 ]) {177459 ]) {
177460 .immediate => |imm| if (std.mem.eql(u8, modifier, "") or177460 .immediate => |imm| if (std.mem.eql(u8, modifier, "") or
...@@ -179566,7 +179566,7 @@ fn atomicOp(...@@ -179566,7 +179566,7 @@ fn atomicOp(
179566 };179566 };
179567 defer if (mem_lock) |lock| self.register_manager.unlockReg(lock);179567 defer if (mem_lock) |lock| self.register_manager.unlockReg(lock);
179568179568
179569 const use_sse = rmw_op orelse .Xchg != .Xchg and val_ty.isRuntimeFloat();179569 const use_sse = (rmw_op orelse .Xchg) != .Xchg and val_ty.isRuntimeFloat();
179570 const strat: enum { lock, loop, libcall } = if (use_sse) .loop else switch (rmw_op orelse .Xchg) {179570 const strat: enum { lock, loop, libcall } = if (use_sse) .loop else switch (rmw_op orelse .Xchg) {
179571 .Xchg,179571 .Xchg,
179572 .Add,179572 .Add,
...@@ -179626,7 +179626,7 @@ fn atomicOp(...@@ -179626,7 +179626,7 @@ fn atomicOp(
179626179626
179627 try self.asmRegisterMemory(.{ ._, .mov }, registerAlias(.rax, val_abi_size), ptr_mem);179627 try self.asmRegisterMemory(.{ ._, .mov }, registerAlias(.rax, val_abi_size), ptr_mem);
179628 const loop: Mir.Inst.Index = @intCast(self.mir_instructions.len);179628 const loop: Mir.Inst.Index = @intCast(self.mir_instructions.len);
179629 if (!use_sse and rmw_op orelse .Xchg != .Xchg) {179629 if (!use_sse and (rmw_op orelse .Xchg) != .Xchg) {
179630 try self.genSetReg(tmp_reg, val_ty, .{ .register = .rax }, .{});179630 try self.genSetReg(tmp_reg, val_ty, .{ .register = .rax }, .{});
179631 }179631 }
179632 if (rmw_op) |op| if (use_sse) {179632 if (rmw_op) |op| if (use_sse) {
...@@ -188852,7 +188852,7 @@ const Temp = struct {...@@ -188852,7 +188852,7 @@ const Temp = struct {
188852 for (0.., op_refs, op_temps) |op_index, op_ref, op_temp| {188852 for (0.., op_refs, op_temps) |op_index, op_ref, op_temp| {
188853 if (op_temp.index == temp.index) continue;188853 if (op_temp.index == temp.index) continue;
188854 if (op_temp.tracking(cg).short != .dead) try op_temp.die(cg);188854 if (op_temp.tracking(cg).short != .dead) try op_temp.die(cg);
188855 if (tomb_bits & @as(Air.Liveness.Bpi, 1) << @intCast(op_index) == 0) continue;188855 if (tomb_bits & (@as(Air.Liveness.Bpi, 1) << @intCast(op_index)) == 0) continue;
188856 if (cg.reused_operands.isSet(op_index)) continue;188856 if (cg.reused_operands.isSet(op_index)) continue;
188857 try cg.processDeath(op_ref.toIndexAllowNone() orelse continue, .{});188857 try cg.processDeath(op_ref.toIndexAllowNone() orelse continue, .{});
188858 }188858 }
...@@ -188914,7 +188914,7 @@ const Temp = struct {...@@ -188914,7 +188914,7 @@ const Temp = struct {
188914 }188914 }
188915 for (0.., op_refs, op_temps) |op_index, op_ref, op_temp| {188915 for (0.., op_refs, op_temps) |op_index, op_ref, op_temp| {
188916 if (op_temp.index != temp.index) continue;188916 if (op_temp.index != temp.index) continue;
188917 if (tomb_bits & @as(Air.Liveness.Bpi, 1) << @intCast(op_index) == 0) continue;188917 if (tomb_bits & (@as(Air.Liveness.Bpi, 1) << @intCast(op_index)) == 0) continue;
188918 if (cg.reused_operands.isSet(op_index)) continue;188918 if (cg.reused_operands.isSet(op_index)) continue;
188919 try cg.processDeath(op_ref.toIndexAllowNone() orelse continue, .{});188919 try cg.processDeath(op_ref.toIndexAllowNone() orelse continue, .{});
188920 }188920 }
...@@ -190115,9 +190115,9 @@ const Select = struct {...@@ -190115,9 +190115,9 @@ const Select = struct {
190115 (@as(u64, std.math.maxInt(u64)) >> @intCast(res_scalar_info.bits - scalar_info.bits))),190115 (@as(u64, std.math.maxInt(u64)) >> @intCast(res_scalar_info.bits - scalar_info.bits))),
190116 .@"0x1p63_mem" => switch (res_scalar_info.bits) {190116 .@"0x1p63_mem" => switch (res_scalar_info.bits) {
190117 else => unreachable,190117 else => unreachable,
190118 16 => @as(i64, @as(i16, @bitCast(@as(f16, 0x1p63)))) << 64 - 16,190118 16 => @as(i64, @as(i16, @bitCast(@as(f16, 0x1p63)))) << (64 - 16),
190119 32 => @as(i64, @as(i32, @bitCast(@as(f32, 0x1p63)))) << 64 - 32,190119 32 => @as(i64, @as(i32, @bitCast(@as(f32, 0x1p63)))) << (64 - 32),
190120 64 => @as(i64, @as(i64, @bitCast(@as(f64, 0x1p63)))) << 64 - 64,190120 64 => @as(i64, @as(i64, @bitCast(@as(f64, 0x1p63)))) << (64 - 64),
190121 },190121 },
190122 };190122 };
190123 const shift: u6 = @intCast(64 - res_scalar_info.bits);190123 const shift: u6 = @intCast(64 - res_scalar_info.bits);
...@@ -191516,8 +191516,8 @@ const Select = struct {...@@ -191516,8 +191516,8 @@ const Select = struct {
191516 @as(SignedImm, @intCast(s.cg.nonBoolScalarBitSize(op.flags.base.ref.typeOf(s)))),191516 @as(SignedImm, @intCast(s.cg.nonBoolScalarBitSize(op.flags.base.ref.typeOf(s)))),
191517 .log2_src0_elem_size => @intCast(std.math.log2(Select.Operand.Ref.src0.typeOf(s).indexableElem(s.cg.pt.zcu).abiSize(s.cg.pt.zcu))),191517 .log2_src0_elem_size => @intCast(std.math.log2(Select.Operand.Ref.src0.typeOf(s).indexableElem(s.cg.pt.zcu).abiSize(s.cg.pt.zcu))),
191518 .elem_mask => @as(u8, std.math.maxInt(u8)) >> @intCast(191518 .elem_mask => @as(u8, std.math.maxInt(u8)) >> @intCast(
191519 8 - ((s.cg.unalignedSize(op.flags.base.ref.typeOf(s)) - 1) %191519 8 - (((s.cg.unalignedSize(op.flags.base.ref.typeOf(s)) - 1) %
191520 @divExact(op.flags.base.size.bitSize(s.cg.target), 8) + 1 >>191520 @divExact(op.flags.base.size.bitSize(s.cg.target), 8) + 1) >>
191521 op.flags.index.scale.toLog2()),191521 op.flags.index.scale.toLog2()),
191522 ),191522 ),
191523 inline .smin, .smax, .umax, .smin_shr_src1, .smax_shr_src1, .umax_shr_src1 => |adjust| switch (op.flags.base.size) {191523 inline .smin, .smax, .umax, .smin_shr_src1, .smax_shr_src1, .umax_shr_src1 => |adjust| switch (op.flags.base.size) {
...@@ -191546,7 +191546,7 @@ const Select = struct {...@@ -191546,7 +191546,7 @@ const Select = struct {
191546 },191546 },
191547 .repeat => switch (SignedImm) {191547 .repeat => switch (SignedImm) {
191548 else => unreachable,191548 else => unreachable,
191549 i64 => return @as(i64, op.imm) << 32 | @as(u32, @bitCast(op.imm)),191549 i64 => return (@as(i64, op.imm) << 32) | @as(u32, @bitCast(op.imm)),
191550 },191550 },
191551 };191551 };
191552 const rhs = op.flags.adjust.rhs.toLog2();191552 const rhs = op.flags.adjust.rhs.toLog2();
...@@ -191557,10 +191557,10 @@ const Select = struct {...@@ -191557,10 +191557,10 @@ const Select = struct {
191557 break :op_res op_res[0];191557 break :op_res op_res[0];
191558 },191558 },
191559 .div => @shrExact(lhs, rhs),191559 .div => @shrExact(lhs, rhs),
191560 .div_8_down => lhs >> 3 & @as(SignedImm, -1) << rhs,191560 .div_8_down => (lhs >> 3) & (@as(SignedImm, -1) << rhs),
191561 .rem_8_mul => lhs & ((@as(SignedImm, 8) << rhs) - 1),191561 .rem_8_mul => lhs & ((@as(SignedImm, 8) << rhs) - 1),
191562 .up_2_mul => ((lhs - 1) & @as(SignedImm, -2) << rhs) + (@as(SignedImm, 2) << rhs),191562 .up_2_mul => ((lhs - 1) & (@as(SignedImm, -2) << rhs)) + (@as(SignedImm, 2) << rhs),
191563 .up_32_mul => ((lhs - 1) & @as(SignedImm, -32) << rhs) + (@as(SignedImm, 32) << rhs),191563 .up_32_mul => ((lhs - 1) & (@as(SignedImm, -32) << rhs)) + (@as(SignedImm, 32) << rhs),
191564 };191564 };
191565 const disp: SignedImm = @bitCast(@as(UnsignedImm, @as(u32, @bitCast(op.imm))));191565 const disp: SignedImm = @bitCast(@as(UnsignedImm, @as(u32, @bitCast(op.imm))));
191566 return switch (op.flags.adjust.sign) {191566 return switch (op.flags.adjust.sign) {
src/codegen/x86_64/Disassembler.zig+1-1
...@@ -378,7 +378,7 @@ fn parseEncoding(dis: *Disassembler, prefixes: Prefixes) !?Encoding {...@@ -378,7 +378,7 @@ fn parseEncoding(dis: *Disassembler, prefixes: Prefixes) !?Encoding {
378}378}
379379
380fn parseGpRegister(low_enc: u3, is_extended: bool, rex: Rex, bit_size: u64) Register {380fn parseGpRegister(low_enc: u3, is_extended: bool, rex: Rex, bit_size: u64) Register {
381 const reg_id: u4 = @as(u4, @intCast(@intFromBool(is_extended))) << 3 | low_enc;381 const reg_id: u4 = (@as(u4, @intCast(@intFromBool(is_extended))) << 3) | low_enc;
382 const reg = @as(Register, @fromBackingInt(@intCast(reg_id))).toBitSize(bit_size);382 const reg = @as(Register, @fromBackingInt(@intCast(reg_id))).toBitSize(bit_size);
383 return switch (reg) {383 return switch (reg) {
384 .spl => if (rex.present or rex.isSet()) .spl else .ah,384 .spl => if (rex.present or rex.isSet()) .spl else .ah,
src/codegen/x86_64/Emit.zig+6-6
...@@ -694,13 +694,13 @@ pub fn emitMir(emit: *Emit) Error!void {...@@ -694,13 +694,13 @@ pub fn emitMir(emit: *Emit) Error!void {
694694
695 for (emit.table_relocs.items) |table_reloc| try atom.addReloc(gpa, .{695 for (emit.table_relocs.items) |table_reloc| try atom.addReloc(gpa, .{
696 .r_offset = table_reloc.source_offset,696 .r_offset = table_reloc.source_offset,
697 .r_info = @as(u64, @backingInt(emit.atom_id)) << 32 | @backingInt(std.elf.R_X86_64.@"32S"),697 .r_info = (@as(u64, @backingInt(emit.atom_id)) << 32) | @backingInt(std.elf.R_X86_64.@"32S"),
698 .r_addend = @as(i64, table_offset) + table_reloc.target_offset,698 .r_addend = @as(i64, table_offset) + table_reloc.target_offset,
699 }, zo);699 }, zo);
700 for (emit.lower.mir.table) |entry| {700 for (emit.lower.mir.table) |entry| {
701 try atom.addReloc(gpa, .{701 try atom.addReloc(gpa, .{
702 .r_offset = table_offset,702 .r_offset = table_offset,
703 .r_info = @as(u64, @backingInt(emit.atom_id)) << 32 | @backingInt(std.elf.R_X86_64.@"64"),703 .r_info = (@as(u64, @backingInt(emit.atom_id)) << 32) | @backingInt(std.elf.R_X86_64.@"64"),
704 .r_addend = emit.code_offset_mapping.items[entry],704 .r_addend = emit.code_offset_mapping.items[entry],
705 }, zo);705 }, zo);
706 table_offset += ptr_size;706 table_offset += ptr_size;
...@@ -812,7 +812,7 @@ fn encodeInst(emit: *Emit, lowered_inst: Instruction, reloc_info: []const RelocI...@@ -812,7 +812,7 @@ fn encodeInst(emit: *Emit, lowered_inst: Instruction, reloc_info: []const RelocI
812 .PC32;812 .PC32;
813 try atom.addReloc(gpa, .{813 try atom.addReloc(gpa, .{
814 .r_offset = end_offset - 4,814 .r_offset = end_offset - 4,
815 .r_info = @as(u64, @backingInt(target.symbol)) << 32 | @backingInt(r_type),815 .r_info = (@as(u64, @backingInt(target.symbol)) << 32) | @backingInt(r_type),
816 .r_addend = if (emit.pic) reloc.off - 4 else reloc.off,816 .r_addend = if (emit.pic) reloc.off - 4 else reloc.off,
817 }, zo);817 }, zo);
818 } else if (emit.bin_file.cast(.macho)) |macho_file| {818 } else if (emit.bin_file.cast(.macho)) |macho_file| {
...@@ -854,7 +854,7 @@ fn encodeInst(emit: *Emit, lowered_inst: Instruction, reloc_info: []const RelocI...@@ -854,7 +854,7 @@ fn encodeInst(emit: *Emit, lowered_inst: Instruction, reloc_info: []const RelocI
854 const r_type: std.elf.R_X86_64 = .PLT32;854 const r_type: std.elf.R_X86_64 = .PLT32;
855 try atom.addReloc(gpa, .{855 try atom.addReloc(gpa, .{
856 .r_offset = end_offset - 4,856 .r_offset = end_offset - 4,
857 .r_info = @as(u64, @backingInt(target.symbol)) << 32 | @backingInt(r_type),857 .r_info = (@as(u64, @backingInt(target.symbol)) << 32) | @backingInt(r_type),
858 .r_addend = reloc.off - 4,858 .r_addend = reloc.off - 4,
859 }, zo);859 }, zo);
860 } else if (emit.bin_file.cast(.elf2)) |elf| try elf.addReloc(860 } else if (emit.bin_file.cast(.elf2)) |elf| try elf.addReloc(
...@@ -894,7 +894,7 @@ fn encodeInst(emit: *Emit, lowered_inst: Instruction, reloc_info: []const RelocI...@@ -894,7 +894,7 @@ fn encodeInst(emit: *Emit, lowered_inst: Instruction, reloc_info: []const RelocI
894 const r_type: std.elf.R_X86_64 = if (emit.pic) .TLSLD else unreachable;894 const r_type: std.elf.R_X86_64 = if (emit.pic) .TLSLD else unreachable;
895 try atom.addReloc(gpa, .{895 try atom.addReloc(gpa, .{
896 .r_offset = end_offset - 4,896 .r_offset = end_offset - 4,
897 .r_info = @as(u64, @backingInt(target_symbol)) << 32 | @backingInt(r_type),897 .r_info = (@as(u64, @backingInt(target_symbol)) << 32) | @backingInt(r_type),
898 .r_addend = reloc.off - 4,898 .r_addend = reloc.off - 4,
899 }, zo);899 }, zo);
900 } else if (emit.bin_file.cast(.elf2)) |elf| try elf.addReloc(900 } else if (emit.bin_file.cast(.elf2)) |elf| try elf.addReloc(
...@@ -912,7 +912,7 @@ fn encodeInst(emit: *Emit, lowered_inst: Instruction, reloc_info: []const RelocI...@@ -912,7 +912,7 @@ fn encodeInst(emit: *Emit, lowered_inst: Instruction, reloc_info: []const RelocI
912 const r_type: std.elf.R_X86_64 = if (emit.pic) .DTPOFF32 else .TPOFF32;912 const r_type: std.elf.R_X86_64 = if (emit.pic) .DTPOFF32 else .TPOFF32;
913 try atom.addReloc(gpa, .{913 try atom.addReloc(gpa, .{
914 .r_offset = end_offset - 4,914 .r_offset = end_offset - 4,
915 .r_info = @as(u64, @backingInt(target.symbol)) << 32 | @backingInt(r_type),915 .r_info = (@as(u64, @backingInt(target.symbol)) << 32) | @backingInt(r_type),
916 .r_addend = reloc.off,916 .r_addend = reloc.off,
917 }, zo);917 }, zo);
918 } else if (emit.bin_file.cast(.elf2)) |elf| try elf.addReloc(918 } else if (emit.bin_file.cast(.elf2)) |elf| try elf.addReloc(
src/codegen/x86_64/Mir.zig+1-1
...@@ -1949,7 +1949,7 @@ pub const Memory = struct {...@@ -1949,7 +1949,7 @@ pub const Memory = struct {
1949 assert(mem.info.base == .reg);1949 assert(mem.info.base == .reg);
1950 return encoder.Instruction.Memory.initMoffs(1950 return encoder.Instruction.Memory.initMoffs(
1951 @fromBackingInt(@intCast(mem.base)),1951 @fromBackingInt(@intCast(mem.base)),
1952 @as(u64, mem.extra) << 32 | mem.off,1952 (@as(u64, mem.extra) << 32) | mem.off,
1953 );1953 );
1954 },1954 },
1955 }1955 }
src/codegen/x86_64/bits.zig+1-1
...@@ -664,7 +664,7 @@ pub const Register = enum(u8) {...@@ -664,7 +664,7 @@ pub const Register = enum(u8) {
664 .general_purpose, .gphi => if (reg.isExtended())664 .general_purpose, .gphi => if (reg.isExtended())
665 reg.enc()665 reg.enc()
666 else666 else
667 @as(u3, @truncate(@as(u24, 0o54673120) >> @as(u5, reg.enc()) * 3)),667 @as(u3, @truncate(@as(u24, 0o54673120) >> (@as(u5, reg.enc()) * 3))),
668 .sse => 17 + @as(u6, reg.enc()),668 .sse => 17 + @as(u6, reg.enc()),
669 .x87 => 33 + @as(u6, reg.enc()),669 .x87 => 33 + @as(u6, reg.enc()),
670 .mmx => 41 + @as(u6, reg.enc()),670 .mmx => 41 + @as(u6, reg.enc()),
src/codegen/x86_64/encoder.zig+14-14
...@@ -844,25 +844,25 @@ fn Encoder(comptime opts: Options) type {...@@ -844,25 +844,25 @@ fn Encoder(comptime opts: Options) type {
844 try self.w.writeByte(0b1100_0100);844 try self.w.writeByte(0b1100_0100);
845845
846 try self.w.writeByte(846 try self.w.writeByte(
847 @as(u8, ~@intFromBool(fields.r)) << 7 |847 (@as(u8, ~@intFromBool(fields.r)) << 7) |
848 @as(u8, ~@intFromBool(fields.x)) << 6 |848 (@as(u8, ~@intFromBool(fields.x)) << 6) |
849 @as(u8, ~@intFromBool(fields.b)) << 5 |849 (@as(u8, ~@intFromBool(fields.b)) << 5) |
850 @as(u8, @backingInt(fields.m)) << 0,850 (@as(u8, @backingInt(fields.m)) << 0),
851 );851 );
852852
853 try self.w.writeByte(853 try self.w.writeByte(
854 @as(u8, @intFromBool(fields.w)) << 7 |854 (@as(u8, @intFromBool(fields.w)) << 7) |
855 @as(u8, ~@as(u4, @intCast(fields.v.enc()))) << 3 |855 (@as(u8, ~@as(u4, @intCast(fields.v.enc()))) << 3) |
856 @as(u8, @intFromBool(fields.l)) << 2 |856 (@as(u8, @intFromBool(fields.l)) << 2) |
857 @as(u8, @backingInt(fields.p)) << 0,857 (@as(u8, @backingInt(fields.p)) << 0),
858 );858 );
859 } else {859 } else {
860 try self.w.writeByte(0b1100_0101);860 try self.w.writeByte(0b1100_0101);
861 try self.w.writeByte(861 try self.w.writeByte(
862 @as(u8, ~@intFromBool(fields.r)) << 7 |862 (@as(u8, ~@intFromBool(fields.r)) << 7) |
863 @as(u8, ~@as(u4, @intCast(fields.v.enc()))) << 3 |863 (@as(u8, ~@as(u4, @intCast(fields.v.enc()))) << 3) |
864 @as(u8, @intFromBool(fields.l)) << 2 |864 (@as(u8, @intFromBool(fields.l)) << 2) |
865 @as(u8, @backingInt(fields.p)) << 0,865 (@as(u8, @backingInt(fields.p)) << 0),
866 );866 );
867 }867 }
868 }868 }
...@@ -910,7 +910,7 @@ fn Encoder(comptime opts: Options) type {...@@ -910,7 +910,7 @@ fn Encoder(comptime opts: Options) type {
910 ///910 ///
911 /// Remember to add a REX prefix byte if reg or rm are extended!911 /// Remember to add a REX prefix byte if reg or rm are extended!
912 pub fn modRm(self: Self, mod: u2, reg_or_opx: u3, rm: u3) !void {912 pub fn modRm(self: Self, mod: u2, reg_or_opx: u3, rm: u3) !void {
913 try self.w.writeByte(@as(u8, mod) << 6 | @as(u8, reg_or_opx) << 3 | rm);913 try self.w.writeByte((@as(u8, mod) << 6) | (@as(u8, reg_or_opx) << 3) | rm);
914 }914 }
915915
916 /// Construct a ModR/M byte using direct r/m addressing916 /// Construct a ModR/M byte using direct r/m addressing
...@@ -996,7 +996,7 @@ fn Encoder(comptime opts: Options) type {...@@ -996,7 +996,7 @@ fn Encoder(comptime opts: Options) type {
996 ///996 ///
997 /// Remember to add a REX prefix byte if index or base are extended!997 /// Remember to add a REX prefix byte if index or base are extended!
998 pub fn sib(self: Self, scale: u2, index: u3, base: u3) !void {998 pub fn sib(self: Self, scale: u2, index: u3, base: u3) !void {
999 try self.w.writeByte(@as(u8, scale) << 6 | @as(u8, index) << 3 | base);999 try self.w.writeByte((@as(u8, scale) << 6) | (@as(u8, index) << 3) | base);
1000 }1000 }
10011001
1002 /// Construct a SIB byte with scale * index + base, no frills.1002 /// Construct a SIB byte with scale * index + base, no frills.
src/fmt.zig+94-2
...@@ -41,6 +41,7 @@ const Fmt = struct {...@@ -41,6 +41,7 @@ const Fmt = struct {
41 out_buffer: std.Io.Writer.Allocating,41 out_buffer: std.Io.Writer.Allocating,
42 stdout_writer: *Io.File.Writer,42 stdout_writer: *Io.File.Writer,
43 stats: ?*Stats,43 stats: ?*Stats,
44 fix_precedence: bool,
4445
45 const SeenMap = std.AutoHashMap(Io.File.INode, void);46 const SeenMap = std.AutoHashMap(Io.File.INode, void);
46};47};
...@@ -66,6 +67,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !...@@ -66,6 +67,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
66 var check_ast_flag = false;67 var check_ast_flag = false;
67 var force_zon = false;68 var force_zon = false;
68 var enable_stats = false;69 var enable_stats = false;
70 var fix_precedence = false;
6971
70 var input_files = std.array_list.Managed([]const u8).init(gpa);72 var input_files = std.array_list.Managed([]const u8).init(gpa);
71 defer input_files.deinit();73 defer input_files.deinit();
...@@ -107,6 +109,8 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !...@@ -107,6 +109,8 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
107 try excluded_files.append(next_arg);109 try excluded_files.append(next_arg);
108 } else if (mem.eql(u8, arg, "--zon")) {110 } else if (mem.eql(u8, arg, "--zon")) {
109 force_zon = true;111 force_zon = true;
112 } else if (mem.eql(u8, arg, "--upgrade")) {
113 fix_precedence = true;
110 } else {114 } else {
111 fatal("unrecognized parameter: {q}", .{arg});115 fatal("unrecognized parameter: {q}", .{arg});
112 }116 }
...@@ -198,6 +202,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !...@@ -198,6 +202,7 @@ pub fn run(gpa: Allocator, arena: Allocator, io: Io, args: []const []const u8) !
198 .out_buffer = .init(gpa),202 .out_buffer = .init(gpa),
199 .stdout_writer = &stdout_writer,203 .stdout_writer = &stdout_writer,
200 .stats = null,204 .stats = null,
205 .fix_precedence = fix_precedence,
201 };206 };
202 defer fmt.seen.deinit();207 defer fmt.seen.deinit();
203 defer fmt.out_buffer.deinit();208 defer fmt.out_buffer.deinit();
...@@ -323,7 +328,8 @@ fn fmtPathDir(...@@ -323,7 +328,8 @@ fn fmtPathDir(
323328
324 if (mem.startsWith(u8, entry.name, ".")) continue;329 if (mem.startsWith(u8, entry.name, ".")) continue;
325330
326 if (is_dir or entry.kind == .file and (mem.endsWith(u8, entry.name, ".zig") or mem.endsWith(u8, entry.name, ".zon"))) {331 const is_zig_or_zon = entry.kind == .file and (mem.endsWith(u8, entry.name, ".zig") or mem.endsWith(u8, entry.name, ".zon"));
332 if (is_dir or is_zig_or_zon) {
327 const full_path = try fs.path.join(fmt.gpa, &[_][]const u8{ file_path, entry.name });333 const full_path = try fs.path.join(fmt.gpa, &[_][]const u8{ file_path, entry.name });
328 defer fmt.gpa.free(full_path);334 defer fmt.gpa.free(full_path);
329335
...@@ -384,6 +390,92 @@ fn fmtPathFile(...@@ -384,6 +390,92 @@ fn fmtPathFile(
384 var tree = try std.zig.Ast.parse(gpa, source_code, .{ .mode = mode });390 var tree = try std.zig.Ast.parse(gpa, source_code, .{ .mode = mode });
385 defer tree.deinit(gpa);391 defer tree.deinit(gpa);
386392
393 var fixups: std.zig.Ast.Render.Fixups = .{};
394 defer fixups.deinit(gpa);
395
396 fix: {
397 if (!fmt.fix_precedence) break :fix;
398
399 var operators_to_fix: std.AutoHashMapUnmanaged(std.zig.Ast.TokenIndex, void) = .empty;
400 defer operators_to_fix.deinit(gpa);
401
402 // Gather ambiguous operator precedence error tokens for quick lookup later
403 var remaining_errors: usize = tree.errors.len;
404 for (tree.errors) |err| {
405 switch (err.tag) {
406 .hint_operator_precedence_left => {
407 try operators_to_fix.put(gpa, err.token - @as(u32, @intCast(err.extra.offset)), {});
408 remaining_errors -= 1;
409 },
410 .hint_operator_precedence_right => {
411 try operators_to_fix.put(gpa, err.token, {});
412 remaining_errors -= 1;
413 },
414 .ambiguous_operator_precedence,
415 .illegal_chained_operators,
416 .previous_ambiguous_operator,
417 => remaining_errors -= 1,
418 else => continue,
419 }
420 }
421
422 if (operators_to_fix.count() == 0) break :fix;
423
424 // Build a new error list without the ambiguous operator precedence errors/notes
425 var fixed_errors: std.ArrayList(std.zig.Ast.Error) = try .initCapacity(gpa, remaining_errors);
426 for (tree.errors) |err| {
427 switch (err.tag) {
428 .ambiguous_operator_precedence,
429 .illegal_chained_operators,
430 .previous_ambiguous_operator,
431 .hint_operator_precedence_left,
432 .hint_operator_precedence_right,
433 => continue,
434 else => {
435 fixed_errors.appendAssumeCapacity(err);
436 },
437 }
438 }
439 gpa.free(tree.errors);
440 tree.errors = fixed_errors.toOwnedSliceAssert();
441
442 // Find the nodes we need to add parens to and add them to the list
443 for (tree.nodes.items(.tag), 0..) |tag, i| {
444 switch (tag) {
445 .merge_error_sets,
446 .mul,
447 .div,
448 .mod,
449 .mul_wrap,
450 .mul_sat,
451 .add,
452 .sub,
453 .array_cat,
454 .add_wrap,
455 .sub_wrap,
456 .add_sat,
457 .sub_sat,
458 .shl,
459 .shl_sat,
460 .shr,
461 .bit_and,
462 .bit_xor,
463 .bit_or,
464 .@"orelse",
465 .@"catch",
466 .bool_and,
467 .bool_or,
468 => {
469 const main_tok = tree.nodes.get(i).main_token;
470 if (operators_to_fix.contains(main_tok)) {
471 try fixups.insert_parentheses.put(gpa, @fromBackingInt(@intCast(i)), {});
472 }
473 },
474 else => {},
475 }
476 }
477 }
478
387 if (tree.errors.len != 0) {479 if (tree.errors.len != 0) {
388 try std.zig.printAstErrorsToStderr(gpa, io, tree, file_path, fmt.color);480 try std.zig.printAstErrorsToStderr(gpa, io, tree, file_path, fmt.color);
389 fmt.any_error = true;481 fmt.any_error = true;
...@@ -491,7 +583,7 @@ fn fmtPathFile(...@@ -491,7 +583,7 @@ fn fmtPathFile(
491 fmt.out_buffer.clearRetainingCapacity();583 fmt.out_buffer.clearRetainingCapacity();
492 try fmt.out_buffer.ensureTotalCapacity(source_code.len);584 try fmt.out_buffer.ensureTotalCapacity(source_code.len);
493585
494 tree.render(gpa, &fmt.out_buffer.writer, .{}) catch |err| switch (err) {586 tree.render(gpa, &fmt.out_buffer.writer, fixups) catch |err| switch (err) {
495 error.WriteFailed, error.OutOfMemory => return error.OutOfMemory,587 error.WriteFailed, error.OutOfMemory => return error.OutOfMemory,
496 };588 };
497 if (!mem.eql(u8, fmt.out_buffer.written(), source_code)) {589 if (!mem.eql(u8, fmt.out_buffer.written(), source_code)) {
src/link/Dwarf.zig+3-3
...@@ -697,7 +697,7 @@ const Unit = struct {...@@ -697,7 +697,7 @@ const Unit = struct {
697 fw.writeByte(DW.LNS.extended_op) catch unreachable;697 fw.writeByte(DW.LNS.extended_op) catch unreachable;
698 const extended_op_bytes = fw.end;698 const extended_op_bytes = fw.end;
699 var op_len_bytes: u5 = 1;699 var op_len_bytes: u5 = 1;
700 while (true) switch (std.math.order(len - extended_op_bytes - op_len_bytes, @as(u32, 1) << 7 * op_len_bytes)) {700 while (true) switch (std.math.order(len - extended_op_bytes - op_len_bytes, @as(u32, 1) << (7 * op_len_bytes))) {
701 .lt => break fw.writeUleb128(len - extended_op_bytes - op_len_bytes) catch unreachable,701 .lt => break fw.writeUleb128(len - extended_op_bytes - op_len_bytes) catch unreachable,
702 .eq => {702 .eq => {
703 // no length will ever work, so undercount and futz with the leb encoding to make up the missing byte703 // no length will ever work, so undercount and futz with the leb encoding to make up the missing byte
...@@ -893,7 +893,7 @@ const Entry = struct {...@@ -893,7 +893,7 @@ const Entry = struct {
893 fw.writeUleb128(try dwarf.refAbbrevCode(.pad_n)) catch unreachable;893 fw.writeUleb128(try dwarf.refAbbrevCode(.pad_n)) catch unreachable;
894 const abbrev_code_bytes = fw.end;894 const abbrev_code_bytes = fw.end;
895 var block_len_bytes: u5 = 1;895 var block_len_bytes: u5 = 1;
896 while (true) switch (std.math.order(len - abbrev_code_bytes - block_len_bytes, @as(u32, 1) << 7 * block_len_bytes)) {896 while (true) switch (std.math.order(len - abbrev_code_bytes - block_len_bytes, @as(u32, 1) << (7 * block_len_bytes))) {
897 .lt => break fw.writeUleb128(len - abbrev_code_bytes - block_len_bytes) catch unreachable,897 .lt => break fw.writeUleb128(len - abbrev_code_bytes - block_len_bytes) catch unreachable,
898 .eq => {898 .eq => {
899 // no length will ever work, so undercount and futz with the leb encoding to make up the missing byte899 // no length will ever work, so undercount and futz with the leb encoding to make up the missing byte
...@@ -915,7 +915,7 @@ const Entry = struct {...@@ -915,7 +915,7 @@ const Entry = struct {
915 fw.writeByte(DW.LNS.extended_op) catch unreachable;915 fw.writeByte(DW.LNS.extended_op) catch unreachable;
916 const extended_op_bytes = fw.end;916 const extended_op_bytes = fw.end;
917 var op_len_bytes: u5 = 1;917 var op_len_bytes: u5 = 1;
918 while (true) switch (std.math.order(len - extended_op_bytes - op_len_bytes, @as(u32, 1) << 7 * op_len_bytes)) {918 while (true) switch (std.math.order(len - extended_op_bytes - op_len_bytes, @as(u32, 1) << (7 * op_len_bytes))) {
919 .lt => break fw.writeUleb128(len - extended_op_bytes - op_len_bytes) catch unreachable,919 .lt => break fw.writeUleb128(len - extended_op_bytes - op_len_bytes) catch unreachable,
920 .eq => {920 .eq => {
921 // no length will ever work, so undercount and futz with the leb encoding to make up the missing byte921 // no length will ever work, so undercount and futz with the leb encoding to make up the missing byte
src/link/Dwarf2.zig+2-2
...@@ -1891,7 +1891,7 @@ pub fn genDebugInfoPadding(dwarf: *Dwarf, di_w: *std.Io.Writer, size: u64) std.I...@@ -1891,7 +1891,7 @@ pub fn genDebugInfoPadding(dwarf: *Dwarf, di_w: *std.Io.Writer, size: u64) std.I
1891 var block_len_size: u5 = 1;1891 var block_len_size: u5 = 1;
1892 while (true) switch (std.math.order(1892 while (true) switch (std.math.order(
1893 size - abbrev_code_size - block_len_size,1893 size - abbrev_code_size - block_len_size,
1894 @as(u64, 1) << 7 * block_len_size,1894 @as(u64, 1) << (7 * block_len_size),
1895 )) {1895 )) {
1896 .lt => break try di_w.writeUleb128(size - abbrev_code_size - block_len_size),1896 .lt => break try di_w.writeUleb128(size - abbrev_code_size - block_len_size),
1897 .eq => {1897 .eq => {
...@@ -2023,7 +2023,7 @@ pub fn genDebugLinePadding(dl_w: *std.Io.Writer, size: u64) std.Io.Writer.Error!...@@ -2023,7 +2023,7 @@ pub fn genDebugLinePadding(dl_w: *std.Io.Writer, size: u64) std.Io.Writer.Error!
2023 var op_len_size: u5 = 1;2023 var op_len_size: u5 = 1;
2024 while (true) switch (std.math.order(2024 while (true) switch (std.math.order(
2025 size - extended_op_size - op_len_size,2025 size - extended_op_size - op_len_size,
2026 @as(u64, 1) << 7 * op_len_size,2026 @as(u64, 1) << (7 * op_len_size),
2027 )) {2027 )) {
2028 .lt => break try dl_w.writeUleb128(size - extended_op_size - op_len_size),2028 .lt => break try dl_w.writeUleb128(size - extended_op_size - op_len_size),
2029 .eq => {2029 .eq => {
src/link/Elf2.zig+4-4
...@@ -7694,11 +7694,11 @@ fn loadArchive(elf: *Elf, path: std.Build.Cache.Path, fr: *Io.File.Reader) (Load...@@ -7694,11 +7694,11 @@ fn loadArchive(elf: *Elf, path: std.Build.Cache.Path, fr: *Io.File.Reader) (Load
7694 {7694 {
7695 break :load_object;7695 break :load_object;
7696 }7696 }
7697 const member = header.name() orelse member: {7697 const member = header.name() orelse (member: {
7698 const strtab_offset = header.nameOffset() catch |err| switch (err) {7698 const strtab_offset = (header.nameOffset() catch |err| switch (err) {
7699 error.Overflow => break :member error.Overflow,7699 error.Overflow => break :member error.Overflow,
7700 error.InvalidCharacter => break :load_object,7700 error.InvalidCharacter => break :load_object,
7701 } orelse break :load_object;7701 }) orelse break :load_object;
7702 const strtab_written = strtab.written();7702 const strtab_written = strtab.written();
7703 if (strtab_offset > strtab_written.len) break :member error.Overflow;7703 if (strtab_offset > strtab_written.len) break :member error.Overflow;
7704 const member = std.mem.sliceTo(strtab_written[strtab_offset..], '\n');7704 const member = std.mem.sliceTo(strtab_written[strtab_offset..], '\n');
...@@ -7708,7 +7708,7 @@ fn loadArchive(elf: *Elf, path: std.Build.Cache.Path, fr: *Io.File.Reader) (Load...@@ -7708,7 +7708,7 @@ fn loadArchive(elf: *Elf, path: std.Build.Cache.Path, fr: *Io.File.Reader) (Load
7708 member;7708 member;
7709 } catch |err| switch (err) {7709 } catch |err| switch (err) {
7710 error.Overflow => return diags.failParse(path, "bad member name offset", .{}),7710 error.Overflow => return diags.failParse(path, "bad member name offset", .{}),
7711 };7711 });
7712 try elf.loadObject(path, member, fr, .{ .offset = offset, .size = size });7712 try elf.loadObject(path, member, fr, .{ .offset = offset, .size = size });
7713 }7713 }
7714 try fr.seekTo(std.mem.alignForward(u64, offset + size, 2));7714 try fr.seekTo(std.mem.alignForward(u64, offset + size, 2));
src/link/MachO/UnwindInfo.zig+1-1
...@@ -228,7 +228,7 @@ pub fn generate(info: *UnwindInfo, macho_file: *MachO) !void {...@@ -228,7 +228,7 @@ pub fn generate(info: *UnwindInfo, macho_file: *MachO) !void {
228 if (next.getAtomAddress(macho_file) >= range_start_max) {228 if (next.getAtomAddress(macho_file) >= range_start_max) {
229 break;229 break;
230 } else if (info.getCommonEncoding(next.enc) != null or230 } else if (info.getCommonEncoding(next.enc) != null or
231 page.getPageEncoding(next.enc) != null and !is_dwarf)231 (page.getPageEncoding(next.enc) != null and !is_dwarf))
232 {232 {
233 i += 1;233 i += 1;
234 space_left -= 1;234 space_left -= 1;
src/link/MachO/load_commands.zig+2-2
...@@ -266,8 +266,8 @@ pub fn writeDylibIdLC(macho_file: *MachO, writer: *Writer) !void {...@@ -266,8 +266,8 @@ pub fn writeDylibIdLC(macho_file: *MachO, writer: *Writer) !void {
266 try writeDylibLC(.{266 try writeDylibLC(.{
267 .cmd = .ID_DYLIB,267 .cmd = .ID_DYLIB,
268 .name = install_name,268 .name = install_name,
269 .current_version = @as(u32, @intCast(curr.major << 16 | curr.minor << 8 | curr.patch)),269 .current_version = @as(u32, @intCast((curr.major << 16) | (curr.minor << 8) | curr.patch)),
270 .compatibility_version = @as(u32, @intCast(compat.major << 16 | compat.minor << 8 | compat.patch)),270 .compatibility_version = @as(u32, @intCast((compat.major << 16) | (compat.minor << 8) | compat.patch)),
271 }, writer);271 }, writer);
272}272}
273273
src/link/Wasm/Flush.zig+1-1
...@@ -1128,7 +1128,7 @@ pub fn finish(f: *Flush, wasm: *Wasm) !void {...@@ -1128,7 +1128,7 @@ pub fn finish(f: *Flush, wasm: *Wasm) !void {
1128 // indirect function table elements1128 // indirect function table elements
1129 const table_index: u32 = @intCast(1129 const table_index: u32 = @intCast(
1130 wasm.table_imports.getIndex(wasm.preloaded_strings.__indirect_function_table) orelse1130 wasm.table_imports.getIndex(wasm.preloaded_strings.__indirect_function_table) orelse
1131 wasm.table_imports.entries.len + wasm.tables.getIndex(.__indirect_function_table).?,1131 (wasm.table_imports.entries.len + wasm.tables.getIndex(.__indirect_function_table).?),
1132 );1132 );
1133 // passive with implicit 0-index table or set table index manually1133 // passive with implicit 0-index table or set table index manually
1134 const flags: u32 = if (table_index == 0) 0x0 else 0x02;1134 const flags: u32 = if (table_index == 0) 0x0 else 0x02;
src/link/riscv.zig+2-2
...@@ -90,8 +90,8 @@ fn bitSlice(...@@ -90,8 +90,8 @@ fn bitSlice(
90 value: anytype,90 value: anytype,
91 comptime high: comptime_int,91 comptime high: comptime_int,
92 comptime low: comptime_int,92 comptime low: comptime_int,
93) std.math.IntFittingRange(0, 1 << high - low) {93) std.math.IntFittingRange(0, 1 << (high - low)) {
94 return @truncate((value >> low) & (1 << (high - low + 1)) - 1);94 return @truncate((value >> low) & ((1 << (high - low + 1)) - 1));
95}95}
9696
97pub const Eflags = packed struct(u32) {97pub const Eflags = packed struct(u32) {
src/main.zig+1-1
...@@ -3524,7 +3524,7 @@ fn buildOutputType(...@@ -3524,7 +3524,7 @@ fn buildOutputType(
3524 };3524 };
35253525
3526 const thread_limit = @min(3526 const thread_limit = @min(
3527 @max(n_jobs orelse std.Thread.getCpuCount() catch 1, 1),3527 @max(n_jobs orelse (std.Thread.getCpuCount() catch 1), 1),
3528 std.math.maxInt(Zcu.PerThread.IdBacking),3528 std.math.maxInt(Zcu.PerThread.IdBacking),
3529 );3529 );
3530 try setThreadLimit(arena, thread_limit);3530 try setThreadLimit(arena, thread_limit);
test/Runner.zig+4-4
...@@ -811,7 +811,7 @@ pub const DelimitedReader = struct {...@@ -811,7 +811,7 @@ pub const DelimitedReader = struct {
811 const d: *DelimitedReader = @fieldParentPtr("interface", r);811 const d: *DelimitedReader = @fieldParentPtr("interface", r);
812 const block = try d.unlimited.peekGreedy(d.delimiter.len);812 const block = try d.unlimited.peekGreedy(d.delimiter.len);
813 d.remaining = .limited(std.mem.findPos(u8, block, d.remaining.toInt().?, d.delimiter) orelse813 d.remaining = .limited(std.mem.findPos(u8, block, d.remaining.toInt().?, d.delimiter) orelse
814 block.len - d.delimiter.len + 1);814 (block.len - d.delimiter.len + 1));
815 if (d.remaining == .nothing) return error.EndOfStream;815 if (d.remaining == .nothing) return error.EndOfStream;
816 const n = try d.unlimited.stream(w, limit.min(d.remaining));816 const n = try d.unlimited.stream(w, limit.min(d.remaining));
817 d.remaining = d.remaining.subtract(n).?;817 d.remaining = d.remaining.subtract(n).?;
...@@ -821,7 +821,7 @@ pub const DelimitedReader = struct {...@@ -821,7 +821,7 @@ pub const DelimitedReader = struct {
821 const d: *DelimitedReader = @fieldParentPtr("interface", r);821 const d: *DelimitedReader = @fieldParentPtr("interface", r);
822 const block = try d.unlimited.peekGreedy(d.delimiter.len);822 const block = try d.unlimited.peekGreedy(d.delimiter.len);
823 d.remaining = .limited(std.mem.findPos(u8, block, d.remaining.toInt().?, d.delimiter) orelse823 d.remaining = .limited(std.mem.findPos(u8, block, d.remaining.toInt().?, d.delimiter) orelse
824 block.len - d.delimiter.len + 1);824 (block.len - d.delimiter.len + 1));
825 if (d.remaining == .nothing) return error.EndOfStream;825 if (d.remaining == .nothing) return error.EndOfStream;
826 const n = try d.unlimited.discard(limit.min(d.remaining));826 const n = try d.unlimited.discard(limit.min(d.remaining));
827 d.remaining = d.remaining.subtract(n).?;827 d.remaining = d.remaining.subtract(n).?;
...@@ -1397,9 +1397,9 @@ fn handleCommand(...@@ -1397,9 +1397,9 @@ fn handleCommand(
1397 return update.fail("compiler failed to send terminating error_bundle", .{});1397 return update.fail("compiler failed to send terminating error_bundle", .{});
1398 },1398 },
1399 }1399 }
1400 assert(contents_r.discardRemaining() catch |err| switch (err) {1400 assert((contents_r.discardRemaining() catch |err| switch (err) {
1401 error.ReadFailed => return error.ContentsReadFailed,1401 error.ReadFailed => return error.ContentsReadFailed,
1402 } == 0);1402 }) == 0);
1403 switch (cmd) {1403 switch (cmd) {
1404 .todo, .skip => {},1404 .todo, .skip => {},
1405 else => update.allow_skip = false,1405 else => update.allow_skip = false,
test/behavior/bitcast.zig+1-1
...@@ -470,7 +470,7 @@ test "@bitCast of packed struct with void field and multiple integers" {...@@ -470,7 +470,7 @@ test "@bitCast of packed struct with void field and multiple integers" {
470 fn doTheTest(x: u8, y: u8) !void {470 fn doTheTest(x: u8, y: u8) !void {
471 const foo = @as(@This(), .{ .x = x, .v = {}, .y = y });471 const foo = @as(@This(), .{ .x = x, .v = {}, .y = y });
472 const as_int: u16 = @bitCast(foo);472 const as_int: u16 = @bitCast(foo);
473 try expect(as_int == @as(u16, y) << 8 | x);473 try expect(as_int == (@as(u16, y) << 8) | x);
474 }474 }
475 };475 };
476 try S.doTheTest(123, 45);476 try S.doTheTest(123, 45);
test/behavior/error.zig+1-1
...@@ -209,7 +209,7 @@ fn testErrorSetType() !void {...@@ -209,7 +209,7 @@ fn testErrorSetType() !void {
209209
210 const a: MyErrSet!i32 = 5678;210 const a: MyErrSet!i32 = 5678;
211 const b: MyErrSet!i32 = MyErrSet.OutOfMemory;211 const b: MyErrSet!i32 = MyErrSet.OutOfMemory;
212 try expect(b catch error.OutOfMemory == error.OutOfMemory);212 try expect((b catch error.OutOfMemory) == error.OutOfMemory);
213213
214 if (a) |value| try expect(value == 5678) else |err| switch (err) {214 if (a) |value| try expect(value == 5678) else |err| switch (err) {
215 error.OutOfMemory => unreachable,215 error.OutOfMemory => unreachable,
test/behavior/math.zig+3-3
...@@ -49,10 +49,10 @@ fn testThreeExprInARow(f: bool, t: bool) !void {...@@ -49,10 +49,10 @@ fn testThreeExprInARow(f: bool, t: bool) !void {
49 try assertFalse(1 | 2 | 4 != 7);49 try assertFalse(1 | 2 | 4 != 7);
50 try assertFalse(3 ^ 6 ^ 8 != 13);50 try assertFalse(3 ^ 6 ^ 8 != 13);
51 try assertFalse(7 & 14 & 28 != 4);51 try assertFalse(7 & 14 & 28 != 4);
52 try assertFalse(9 << 1 << 2 != 9 << 3);52 try assertFalse((9 << 1) << 2 != 9 << 3);
53 try assertFalse(90 >> 1 >> 2 != 90 >> 3);53 try assertFalse((90 >> 1) >> 2 != 90 >> 3);
54 try assertFalse(100 - 1 + 1000 != 1099);54 try assertFalse(100 - 1 + 1000 != 1099);
55 try assertFalse(5 * 4 / 2 % 3 != 1);55 try assertFalse((5 * 4 / 2) % 3 != 1);
56 try assertFalse(@as(i32, @as(i32, 5)) != 5);56 try assertFalse(@as(i32, @as(i32, 5)) != 5);
57 try assertFalse(!!false);57 try assertFalse(!!false);
58 try assertFalse(@as(i32, 7) != --(@as(i32, 7)));58 try assertFalse(@as(i32, 7) != --(@as(i32, 7)));
test/behavior/try.zig+3-3
...@@ -186,9 +186,9 @@ test "try ptr propagation mutate" {...@@ -186,9 +186,9 @@ test "try ptr propagation mutate" {
186 res1.* += 1;186 res1.* += 1;
187 res2.* += 1;187 res2.* += 1;
188188
189 try expect(f0 catch unreachable == 1);189 try expect((f0 catch unreachable) == 1);
190 try expect(f1 catch unreachable == 2);190 try expect((f1 catch unreachable) == 2);
191 try expect(f2 catch unreachable == 3);191 try expect((f2 catch unreachable) == 3);
192192
193 try expect(res0.* == 1);193 try expect(res0.* == 1);
194 try expect(res1.* == 2);194 try expect(res1.* == 2);
test/behavior/x86_64/binary.zig+2-2
...@@ -5503,7 +5503,7 @@ inline fn shrExact(comptime Type: type, lhs: Type, rhs: Type) Type {...@@ -5503,7 +5503,7 @@ inline fn shrExact(comptime Type: type, lhs: Type, rhs: Type) Type {
5503 const bit_cast_rhs: AsSignedness(Type, .unsigned) = @bitCast(rhs);5503 const bit_cast_rhs: AsSignedness(Type, .unsigned) = @bitCast(rhs);
5504 const truncate_rhs: Log2Int(Type) = @truncate(bit_cast_rhs);5504 const truncate_rhs: Log2Int(Type) = @truncate(bit_cast_rhs);
5505 const final_rhs = if (comptime cast(Log2Int(Scalar(Type)), @bitSizeOf(Scalar(Type)))) |bits| truncate_rhs % @as(Log2Int(Type), @splat(bits)) else truncate_rhs;5505 const final_rhs = if (comptime cast(Log2Int(Scalar(Type)), @bitSizeOf(Scalar(Type)))) |bits| truncate_rhs % @as(Log2Int(Type), @splat(bits)) else truncate_rhs;
5506 return @shrExact(lhs >> final_rhs << final_rhs, final_rhs);5506 return @shrExact((lhs >> final_rhs) << final_rhs, final_rhs);
5507}5507}
5508test shrExact {5508test shrExact {
5509 const test_shr_exact = binary(shrExact, .{});5509 const test_shr_exact = binary(shrExact, .{});
...@@ -5527,7 +5527,7 @@ inline fn shlExactUnsafe(comptime Type: type, lhs: Type, rhs: Type) Type {...@@ -5527,7 +5527,7 @@ inline fn shlExactUnsafe(comptime Type: type, lhs: Type, rhs: Type) Type {
5527 const bit_cast_rhs: AsSignedness(Type, .unsigned) = @bitCast(rhs);5527 const bit_cast_rhs: AsSignedness(Type, .unsigned) = @bitCast(rhs);
5528 const truncate_rhs: Log2Int(Type) = @truncate(bit_cast_rhs);5528 const truncate_rhs: Log2Int(Type) = @truncate(bit_cast_rhs);
5529 const final_rhs = if (comptime cast(Log2Int(Scalar(Type)), @bitSizeOf(Scalar(Type)))) |bits| truncate_rhs % @as(Log2Int(Type), @splat(bits)) else truncate_rhs;5529 const final_rhs = if (comptime cast(Log2Int(Scalar(Type)), @bitSizeOf(Scalar(Type)))) |bits| truncate_rhs % @as(Log2Int(Type), @splat(bits)) else truncate_rhs;
5530 return @shlExact(lhs << final_rhs >> final_rhs, final_rhs);5530 return @shlExact((lhs << final_rhs) >> final_rhs, final_rhs);
5531}5531}
5532test shlExactUnsafe {5532test shlExactUnsafe {
5533 const test_shl_exact_unsafe = binary(shlExactUnsafe, .{});5533 const test_shl_exact_unsafe = binary(shlExactUnsafe, .{});
test/behavior/x86_64/cast.zig+4-4
...@@ -14502,15 +14502,15 @@ inline fn intCast(comptime Result: type, comptime Type: type, rhs: Type, comptim...@@ -14502,15 +14502,15 @@ inline fn intCast(comptime Result: type, comptime Type: type, rhs: Type, comptim
14502 // TODO: if (bits == 0) rhs else rhs >> bits,14502 // TODO: if (bits == 0) rhs else rhs >> bits,
14503 .shift => |bits| if (bits == 0) rhs else switch (@typeInfo(Type)) {14503 .shift => |bits| if (bits == 0) rhs else switch (@typeInfo(Type)) {
14504 .int => if (ct_rhs < 0)14504 .int => if (ct_rhs < 0)
14505 rhs | imin(Type) >> bits14505 rhs | (imin(Type) >> bits)
14506 else14506 else
14507 rhs & imax(Type) >> bits,14507 rhs & (imax(Type) >> bits),
14508 .vector => rhs | @select(14508 .vector => (rhs | @select(
14509 Scalar(Type),14509 Scalar(Type),
14510 ct_rhs < @as(Type, @splat(0)),14510 ct_rhs < @as(Type, @splat(0)),
14511 @as(Type, @splat(imin(Scalar(Type)) >> bits)),14511 @as(Type, @splat(imin(Scalar(Type)) >> bits)),
14512 @as(Type, @splat(0)),14512 @as(Type, @splat(0)),
14513 ) & ~@select(14513 )) & ~@select(
14514 Scalar(Type),14514 Scalar(Type),
14515 ct_rhs >= @as(Type, @splat(0)),14515 ct_rhs >= @as(Type, @splat(0)),
14516 @as(Type, @splat(imin(Scalar(Type)) >> bits)),14516 @as(Type, @splat(imin(Scalar(Type)) >> bits)),
tools/doctest.zig+1-1
...@@ -225,7 +225,7 @@ fn printOutput(...@@ -225,7 +225,7 @@ fn printOutput(
225 if (mem.startsWith(u8, triple, "wasm32") or225 if (mem.startsWith(u8, triple, "wasm32") or
226 mem.startsWith(u8, triple, "riscv64-linux") or226 mem.startsWith(u8, triple, "riscv64-linux") or
227 (mem.startsWith(u8, triple, "x86_64-linux") and227 (mem.startsWith(u8, triple, "x86_64-linux") and
228 builtin.os.tag != .linux or builtin.cpu.arch != .x86_64))228 (builtin.os.tag != .linux or builtin.cpu.arch != .x86_64)))
229 {229 {
230 // skip execution230 // skip execution
231 break :code_block;231 break :code_block;
tools/loongarch/OpcodeDesc.zig+2-2
...@@ -95,10 +95,10 @@ pub const Format = struct {...@@ -95,10 +95,10 @@ pub const Format = struct {
95 const index: Slot.Index = try .parse(&reader);95 const index: Slot.Index = try .parse(&reader);
96 const length = try takeInteger(u5, &reader);96 const length = try takeInteger(u5, &reader);
97 const post_proc = post_proc: {97 const post_proc = post_proc: {
98 if ('p' == reader.peekByte() catch |err| switch (err) {98 if ('p' == (reader.peekByte() catch |err| switch (err) {
99 error.EndOfStream => ' ',99 error.EndOfStream => ' ',
100 else => return err,100 else => return err,
101 }) {101 })) {
102 reader.toss(1);102 reader.toss(1);
103 break :post_proc try Slot.PostProcess.parse(&reader);103 break :post_proc try Slot.PostProcess.parse(&reader);
104 } else break :post_proc Slot.PostProcess.none;104 } else break :post_proc Slot.PostProcess.none;