authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-08-30 04:54:33-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-08-30 04:54:33-04:00
log052b4ae9415596e0b6b6c32b9b4f2d3ff8c9e953
tree7a11abbcf1de240ec1dd2e9913183eca5e5ebb41
parent3f5dd08ca8010ef365b6cf203214aac353c36643

align syntax: align(4) instead of align 4

closes #37

10 files changed, 92 insertions(+), 85 deletions(-)

src/analyze.cpp+3-3
......@@ -359,10 +359,10 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type
359359 if (unaligned_bit_count == 0 && byte_alignment == abi_alignment) {
360360 buf_appendf(&entry->name, "&%s%s%s", const_str, volatile_str, buf_ptr(&child_type->name));
361361 } else if (unaligned_bit_count == 0) {
362 buf_appendf(&entry->name, "&align %" PRIu32 " %s%s%s", byte_alignment,
362 buf_appendf(&entry->name, "&align(%" PRIu32 ") %s%s%s", byte_alignment,
363363 const_str, volatile_str, buf_ptr(&child_type->name));
364364 } else {
365 buf_appendf(&entry->name, "&align %" PRIu32 ":%" PRIu32 ":%" PRIu32 " %s%s%s", byte_alignment,
365 buf_appendf(&entry->name, "&align(%" PRIu32 ":%" PRIu32 ":%" PRIu32 ") %s%s%s", byte_alignment,
366366 bit_offset, bit_offset + unaligned_bit_count, const_str, volatile_str, buf_ptr(&child_type->name));
367367 }
368368
......@@ -885,7 +885,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
885885 }
886886 buf_appendf(&fn_type->name, ")");
887887 if (fn_type_id->alignment != 0) {
888 buf_appendf(&fn_type->name, " align %" PRIu32, fn_type_id->alignment);
888 buf_appendf(&fn_type->name, " align(%" PRIu32 ")", fn_type_id->alignment);
889889 }
890890 if (fn_type_id->return_type->id != TypeTableEntryIdVoid) {
891891 buf_appendf(&fn_type->name, " -> %s", buf_ptr(&fn_type_id->return_type->name));
src/ast_render.cpp+2-3
......@@ -585,7 +585,7 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
585585 {
586586 fprintf(ar->f, "&");
587587 if (node->data.addr_of_expr.align_expr != nullptr) {
588 fprintf(ar->f, "align ");
588 fprintf(ar->f, "align(");
589589 render_node_grouped(ar, node->data.addr_of_expr.align_expr);
590590 if (node->data.addr_of_expr.bit_offset_start != nullptr) {
591591 assert(node->data.addr_of_expr.bit_offset_end != nullptr);
......@@ -599,9 +599,8 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
599599 bigint_append_buf(&offset_end_buf, node->data.addr_of_expr.bit_offset_end, 10);
600600
601601 fprintf(ar->f, ":%s:%s ", buf_ptr(&offset_start_buf), buf_ptr(&offset_end_buf));
602 } else {
603 fprintf(ar->f, " ");
604602 }
603 fprintf(ar->f, ") ");
605604 }
606605 if (node->data.addr_of_expr.is_const) {
607606 fprintf(ar->f, "const ");
src/parser.cpp+17-9
......@@ -385,7 +385,7 @@ static AstNode *ast_parse_grouped_expr(ParseContext *pc, size_t *token_index, bo
385385}
386386
387387/*
388ArrayType : "[" option(Expression) "]" option("align" PrimaryExpression)) option("const") option("volatile") PrefixOpExpression
388ArrayType : "[" option(Expression) "]" option("align" "(" Expression option(":" Integer ":" Integer) ")")) option("const") option("volatile") TypeExpr
389389*/
390390static AstNode *ast_parse_array_type_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
391391 Token *l_bracket = &pc->tokens->at(*token_index);
......@@ -407,7 +407,9 @@ static AstNode *ast_parse_array_type_expr(ParseContext *pc, size_t *token_index,
407407 Token *token = &pc->tokens->at(*token_index);
408408 if (token->id == TokenIdKeywordAlign) {
409409 *token_index += 1;
410 node->data.array_type.align_expr = ast_parse_primary_expr(pc, token_index, true);
410 ast_eat_token(pc, token_index, TokenIdLParen);
411 node->data.array_type.align_expr = ast_parse_expression(pc, token_index, true);
412 ast_eat_token(pc, token_index, TokenIdRParen);
411413
412414 token = &pc->tokens->at(*token_index);
413415 }
......@@ -984,7 +986,8 @@ static AstNode *ast_parse_addr_of(ParseContext *pc, size_t *token_index) {
984986 Token *token = &pc->tokens->at(*token_index);
985987 if (token->id == TokenIdKeywordAlign) {
986988 *token_index += 1;
987 node->data.addr_of_expr.align_expr = ast_parse_primary_expr(pc, token_index, true);
989 ast_eat_token(pc, token_index, TokenIdLParen);
990 node->data.addr_of_expr.align_expr = ast_parse_expression(pc, token_index, true);
988991
989992 token = &pc->tokens->at(*token_index);
990993 if (token->id == TokenIdColon) {
......@@ -992,11 +995,12 @@ static AstNode *ast_parse_addr_of(ParseContext *pc, size_t *token_index) {
992995 Token *bit_offset_start_tok = ast_eat_token(pc, token_index, TokenIdIntLiteral);
993996 ast_eat_token(pc, token_index, TokenIdColon);
994997 Token *bit_offset_end_tok = ast_eat_token(pc, token_index, TokenIdIntLiteral);
995 token = &pc->tokens->at(*token_index);
996998
997999 node->data.addr_of_expr.bit_offset_start = token_bigint(bit_offset_start_tok);
9981000 node->data.addr_of_expr.bit_offset_end = token_bigint(bit_offset_end_tok);
9991001 }
1002 ast_eat_token(pc, token_index, TokenIdRParen);
1003 token = &pc->tokens->at(*token_index);
10001004 }
10011005 if (token->id == TokenIdKeywordConst) {
10021006 *token_index += 1;
......@@ -1015,7 +1019,7 @@ static AstNode *ast_parse_addr_of(ParseContext *pc, size_t *token_index) {
10151019
10161020/*
10171021PrefixOpExpression : PrefixOp PrefixOpExpression | SuffixOpExpression
1018PrefixOp = "!" | "-" | "~" | "*" | ("&" option("align" PrimaryExpression option(":" Integer ":" Integer)) option("const") option("volatile")) | "?" | "%" | "%%" | "??" | "-%"
1022PrefixOp = "!" | "-" | "~" | "*" | ("&" option("align" "(" Expression option(":" Integer ":" Integer) ")" ) option("const") option("volatile")) | "?" | "%" | "%%" | "??" | "-%"
10191023*/
10201024static AstNode *ast_parse_prefix_op_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
10211025 Token *token = &pc->tokens->at(*token_index);
......@@ -1534,7 +1538,7 @@ static AstNode *ast_parse_defer_expr(ParseContext *pc, size_t *token_index) {
15341538}
15351539
15361540/*
1537VariableDeclaration = option("comptime") ("var" | "const") Symbol option(":" TypeExpr) option("align" PrimaryExpression) "=" Expression
1541VariableDeclaration = option("comptime") ("var" | "const") Symbol option(":" TypeExpr) option("align" "(" Expression ")") "=" Expression
15381542*/
15391543static AstNode *ast_parse_variable_declaration_expr(ParseContext *pc, size_t *token_index, bool mandatory,
15401544 VisibMod visib_mod)
......@@ -1594,7 +1598,9 @@ static AstNode *ast_parse_variable_declaration_expr(ParseContext *pc, size_t *to
15941598
15951599 if (next_token->id == TokenIdKeywordAlign) {
15961600 *token_index += 1;
1597 node->data.variable_declaration.align_expr = ast_parse_primary_expr(pc, token_index, true);
1601 ast_eat_token(pc, token_index, TokenIdLParen);
1602 node->data.variable_declaration.align_expr = ast_parse_expression(pc, token_index, true);
1603 ast_eat_token(pc, token_index, TokenIdRParen);
15981604 next_token = &pc->tokens->at(*token_index);
15991605 }
16001606
......@@ -2203,7 +2209,7 @@ static AstNode *ast_parse_block(ParseContext *pc, size_t *token_index, bool mand
22032209}
22042210
22052211/*
2206FnProto = option("coldcc" | "nakedcc" | "stdcallcc") "fn" option(Symbol) ParamDeclList option("align" PrimaryExpression) option("->" TypeExpr)
2212FnProto = option("coldcc" | "nakedcc" | "stdcallcc") "fn" option(Symbol) ParamDeclList option("align" "(" Expression ")") option("->" TypeExpr)
22072213*/
22082214static AstNode *ast_parse_fn_proto(ParseContext *pc, size_t *token_index, bool mandatory, VisibMod visib_mod) {
22092215 Token *first_token = &pc->tokens->at(*token_index);
......@@ -2251,8 +2257,10 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc, size_t *token_index, bool m
22512257 Token *next_token = &pc->tokens->at(*token_index);
22522258 if (next_token->id == TokenIdKeywordAlign) {
22532259 *token_index += 1;
2260 ast_eat_token(pc, token_index, TokenIdLParen);
22542261
2255 node->data.fn_proto.align_expr = ast_parse_primary_expr(pc, token_index, true);
2262 node->data.fn_proto.align_expr = ast_parse_expression(pc, token_index, true);
2263 ast_eat_token(pc, token_index, TokenIdRParen);
22562264 next_token = &pc->tokens->at(*token_index);
22572265 }
22582266 if (next_token->id == TokenIdArrow) {
std/special/compiler_rt/udivmod.zig+5-5
......@@ -54,7 +54,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
5454 if (maybe_rem) |rem| {
5555 r[high] = n[high] % d[high];
5656 r[low] = 0;
57 *rem = *@ptrCast(&align @alignOf(SingleInt) DoubleInt, &r[0]); // TODO issue #421
57 *rem = *@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]); // TODO issue #421
5858 }
5959 return n[high] / d[high];
6060 }
......@@ -66,7 +66,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
6666 if (maybe_rem) |rem| {
6767 r[low] = n[low];
6868 r[high] = n[high] & (d[high] - 1);
69 *rem = *@ptrCast(&align @alignOf(SingleInt) DoubleInt, &r[0]); // TODO issue #421
69 *rem = *@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]); // TODO issue #421
7070 }
7171 return n[high] >> Log2SingleInt(@ctz(d[high]));
7272 }
......@@ -106,7 +106,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
106106 sr = @ctz(d[low]);
107107 q[high] = n[high] >> Log2SingleInt(sr);
108108 q[low] = (n[high] << Log2SingleInt(SingleInt.bit_count - sr)) | (n[low] >> Log2SingleInt(sr));
109 return *@ptrCast(&align @alignOf(SingleInt) DoubleInt, &q[0]); // TODO issue #421
109 return *@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &q[0]); // TODO issue #421
110110 }
111111 // K X
112112 // ---
......@@ -180,13 +180,13 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
180180 // r.all -= b;
181181 // carry = 1;
182182 // }
183 r_all = *@ptrCast(&align @alignOf(SingleInt) DoubleInt, &r[0]); // TODO issue #421
183 r_all = *@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]); // TODO issue #421
184184 const s: SignedDoubleInt = SignedDoubleInt(b -% r_all -% 1) >> (DoubleInt.bit_count - 1);
185185 carry = u32(s & 1);
186186 r_all -= b & @bitCast(DoubleInt, s);
187187 r = *@ptrCast(&[2]SingleInt, &r_all); // TODO issue #421
188188 }
189 const q_all = ((*@ptrCast(&align @alignOf(SingleInt) DoubleInt, &q[0])) << 1) | carry; // TODO issue #421
189 const q_all = ((*@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &q[0])) << 1) | carry; // TODO issue #421
190190 if (maybe_rem) |rem| {
191191 *rem = r_all;
192192 }
test/cases/align.zig+49-49
......@@ -1,22 +1,22 @@
11const assert = @import("std").debug.assert;
22
3var foo: u8 align 4 = 100;
3var foo: u8 align(4) = 100;
44
55test "global variable alignment" {
66 assert(@typeOf(&foo).alignment == 4);
7 assert(@typeOf(&foo) == &align 4 u8);
7 assert(@typeOf(&foo) == &align(4) u8);
88 const slice = (&foo)[0..1];
9 assert(@typeOf(slice) == []align 4 u8);
9 assert(@typeOf(slice) == []align(4) u8);
1010}
1111
12fn derp() align (@sizeOf(usize) * 2) -> i32 { 1234 }
13fn noop1() align 1 {}
14fn noop4() align 4 {}
12fn derp() align(@sizeOf(usize) * 2) -> i32 { 1234 }
13fn noop1() align(1) {}
14fn noop4() align(4) {}
1515
1616test "function alignment" {
1717 assert(derp() == 1234);
18 assert(@typeOf(noop1) == fn() align 1);
19 assert(@typeOf(noop4) == fn() align 4);
18 assert(@typeOf(noop1) == fn() align(1));
19 assert(@typeOf(noop4) == fn() align(4));
2020 noop1();
2121 noop4();
2222}
......@@ -28,7 +28,7 @@ var baz: packed struct {
2828} = undefined;
2929
3030test "packed struct alignment" {
31 assert(@typeOf(&baz.b) == &align 1 u32);
31 assert(@typeOf(&baz.b) == &align(1) u32);
3232}
3333
3434
......@@ -39,33 +39,33 @@ const blah: packed struct {
3939} = undefined;
4040
4141test "bit field alignment" {
42 assert(@typeOf(&blah.b) == &align 1:3:6 const u3);
42 assert(@typeOf(&blah.b) == &align(1:3:6) const u3);
4343}
4444
4545test "default alignment allows unspecified in type syntax" {
46 assert(&u32 == &align @alignOf(u32) u32);
46 assert(&u32 == &align(@alignOf(u32)) u32);
4747}
4848
4949test "implicitly decreasing pointer alignment" {
50 const a: u32 align 4 = 3;
51 const b: u32 align 8 = 4;
50 const a: u32 align(4) = 3;
51 const b: u32 align(8) = 4;
5252 assert(addUnaligned(&a, &b) == 7);
5353}
5454
55fn addUnaligned(a: &align 1 const u32, b: &align 1 const u32) -> u32 { *a + *b }
55fn addUnaligned(a: &align(1) const u32, b: &align(1) const u32) -> u32 { *a + *b }
5656
5757test "implicitly decreasing slice alignment" {
58 const a: u32 align 4 = 3;
59 const b: u32 align 8 = 4;
58 const a: u32 align(4) = 3;
59 const b: u32 align(8) = 4;
6060 assert(addUnalignedSlice((&a)[0..1], (&b)[0..1]) == 7);
6161}
62fn addUnalignedSlice(a: []align 1 const u32, b: []align 1 const u32) -> u32 { a[0] + b[0] }
62fn addUnalignedSlice(a: []align(1) const u32, b: []align(1) const u32) -> u32 { a[0] + b[0] }
6363
6464test "specifying alignment allows pointer cast" {
6565 testBytesAlign(0x33);
6666}
6767fn testBytesAlign(b: u8) {
68 var bytes align 4 = []u8{b, b, b, b};
68 var bytes align(4) = []u8{b, b, b, b};
6969 const ptr = @ptrCast(&u32, &bytes[0]);
7070 assert(*ptr == 0x33333333);
7171}
......@@ -74,33 +74,33 @@ test "specifying alignment allows slice cast" {
7474 testBytesAlignSlice(0x33);
7575}
7676fn testBytesAlignSlice(b: u8) {
77 var bytes align 4 = []u8{b, b, b, b};
77 var bytes align(4) = []u8{b, b, b, b};
7878 const slice = ([]u32)(bytes[0..]);
7979 assert(slice[0] == 0x33333333);
8080}
8181
8282test "@alignCast pointers" {
83 var x: u32 align 4 = 1;
83 var x: u32 align(4) = 1;
8484 expectsOnly1(&x);
8585 assert(x == 2);
8686}
87fn expectsOnly1(x: &align 1 u32) {
87fn expectsOnly1(x: &align(1) u32) {
8888 expects4(@alignCast(4, x));
8989}
90fn expects4(x: &align 4 u32) {
90fn expects4(x: &align(4) u32) {
9191 *x += 1;
9292}
9393
9494test "@alignCast slices" {
95 var array align 4 = []u32{1, 1};
95 var array align(4) = []u32{1, 1};
9696 const slice = array[0..];
9797 sliceExpectsOnly1(slice);
9898 assert(slice[0] == 2);
9999}
100fn sliceExpectsOnly1(slice: []align 1 u32) {
100fn sliceExpectsOnly1(slice: []align(1) u32) {
101101 sliceExpects4(@alignCast(4, slice));
102102}
103fn sliceExpects4(slice: []align 4 u32) {
103fn sliceExpects4(slice: []align(4) u32) {
104104 slice[0] += 1;
105105}
106106
......@@ -110,24 +110,24 @@ test "implicitly decreasing fn alignment" {
110110 testImplicitlyDecreaseFnAlign(alignedBig, 5678);
111111}
112112
113fn testImplicitlyDecreaseFnAlign(ptr: fn () align 1 -> i32, answer: i32) {
113fn testImplicitlyDecreaseFnAlign(ptr: fn () align(1) -> i32, answer: i32) {
114114 assert(ptr() == answer);
115115}
116116
117fn alignedSmall() align 8 -> i32 { 1234 }
118fn alignedBig() align 16 -> i32 { 5678 }
117fn alignedSmall() align(8) -> i32 { 1234 }
118fn alignedBig() align(16) -> i32 { 5678 }
119119
120120
121121test "@alignCast functions" {
122122 assert(fnExpectsOnly1(simple4) == 0x19);
123123}
124fn fnExpectsOnly1(ptr: fn()align 1 -> i32) -> i32 {
124fn fnExpectsOnly1(ptr: fn()align(1) -> i32) -> i32 {
125125 fnExpects4(@alignCast(4, ptr))
126126}
127fn fnExpects4(ptr: fn()align 4 -> i32) -> i32 {
127fn fnExpects4(ptr: fn()align(4) -> i32) -> i32 {
128128 ptr()
129129}
130fn simple4() align 4 -> i32 { 0x19 }
130fn simple4() align(4) -> i32 { 0x19 }
131131
132132
133133test "generic function with align param" {
......@@ -136,37 +136,37 @@ test "generic function with align param" {
136136 assert(whyWouldYouEverDoThis(8) == 0x1);
137137}
138138
139fn whyWouldYouEverDoThis(comptime align_bytes: u8) align align_bytes -> u8 { 0x1 }
139fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) -> u8 { 0x1 }
140140
141141
142142test "@ptrCast preserves alignment of bigger source" {
143 var x: u32 align 16 = 1234;
143 var x: u32 align(16) = 1234;
144144 const ptr = @ptrCast(&u8, &x);
145 assert(@typeOf(ptr) == &align 16 u8);
145 assert(@typeOf(ptr) == &align(16) u8);
146146}
147147
148148
149149test "compile-time known array index has best alignment possible" {
150150 // take full advantage of over-alignment
151 var array align 4 = []u8 {1, 2, 3, 4};
152 assert(@typeOf(&array[0]) == &align 4 u8);
151 var array align(4) = []u8 {1, 2, 3, 4};
152 assert(@typeOf(&array[0]) == &align(4) u8);
153153 assert(@typeOf(&array[1]) == &u8);
154 assert(@typeOf(&array[2]) == &align 2 u8);
154 assert(@typeOf(&array[2]) == &align(2) u8);
155155 assert(@typeOf(&array[3]) == &u8);
156156
157157 // because align is too small but we still figure out to use 2
158 var bigger align 2 = []u64{1, 2, 3, 4};
159 assert(@typeOf(&bigger[0]) == &align 2 u64);
160 assert(@typeOf(&bigger[1]) == &align 2 u64);
161 assert(@typeOf(&bigger[2]) == &align 2 u64);
162 assert(@typeOf(&bigger[3]) == &align 2 u64);
158 var bigger align(2) = []u64{1, 2, 3, 4};
159 assert(@typeOf(&bigger[0]) == &align(2) u64);
160 assert(@typeOf(&bigger[1]) == &align(2) u64);
161 assert(@typeOf(&bigger[2]) == &align(2) u64);
162 assert(@typeOf(&bigger[3]) == &align(2) u64);
163163
164164 // because pointer is align 2 and u32 align % 2 == 0 we can assume align 2
165 var smaller align 2 = []u32{1, 2, 3, 4};
166 testIndex(&smaller[0], 0, &align 2 u32);
167 testIndex(&smaller[0], 1, &align 2 u32);
168 testIndex(&smaller[0], 2, &align 2 u32);
169 testIndex(&smaller[0], 3, &align 2 u32);
165 var smaller align(2) = []u32{1, 2, 3, 4};
166 testIndex(&smaller[0], 0, &align(2) u32);
167 testIndex(&smaller[0], 1, &align(2) u32);
168 testIndex(&smaller[0], 2, &align(2) u32);
169 testIndex(&smaller[0], 3, &align(2) u32);
170170
171171 // has to use ABI alignment because index known at runtime only
172172 testIndex2(&array[0], 0, &u8);
......@@ -174,9 +174,9 @@ test "compile-time known array index has best alignment possible" {
174174 testIndex2(&array[0], 2, &u8);
175175 testIndex2(&array[0], 3, &u8);
176176}
177fn testIndex(smaller: &align 2 u32, index: usize, comptime T: type) {
177fn testIndex(smaller: &align(2) u32, index: usize, comptime T: type) {
178178 assert(@typeOf(&smaller[index]) == T);
179179}
180fn testIndex2(ptr: &align 4 u8, index: usize, comptime T: type) {
180fn testIndex2(ptr: &align(4) u8, index: usize, comptime T: type) {
181181 assert(@typeOf(&ptr[index]) == T);
182182}
test/cases/cast.zig+1-1
......@@ -277,7 +277,7 @@ fn cast128Float(x: u128) -> f128 {
277277}
278278
279279test "const slice widen cast" {
280 const bytes align 4 = []u8{0x12, 0x12, 0x12, 0x12};
280 const bytes align(4) = []u8{0x12, 0x12, 0x12, 0x12};
281281
282282 const u32_value = ([]const u32)(bytes[0..])[0];
283283 assert(u32_value == 0x12121212);
test/cases/misc.zig+1-1
......@@ -404,7 +404,7 @@ test "cast slice to u8 slice" {
404404 bytes[6] = 0;
405405 bytes[7] = 0;
406406 assert(big_thing_slice[1] == 0);
407 const big_thing_again = ([]align 1 i32)(bytes);
407 const big_thing_again = ([]align(1) i32)(bytes);
408408 assert(big_thing_again[2] == 3);
409409 big_thing_again[2] = -1;
410410 assert(bytes[8] == @maxValue(u8));
test/compare_output.zig+2-2
......@@ -262,8 +262,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
262262 \\const c = @cImport(@cInclude("stdlib.h"));
263263 \\
264264 \\export fn compare_fn(a: ?&const c_void, b: ?&const c_void) -> c_int {
265 \\ const a_int = @ptrCast(&align 1 i32, a ?? unreachable);
266 \\ const b_int = @ptrCast(&align 1 i32, b ?? unreachable);
265 \\ const a_int = @ptrCast(&align(1) i32, a ?? unreachable);
266 \\ const b_int = @ptrCast(&align(1) i32, b ?? unreachable);
267267 \\ if (*a_int < *b_int) {
268268 \\ -1
269269 \\ } else if (*a_int > *b_int) {
test/compile_errors.zig+9-9
......@@ -1317,12 +1317,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
13171317 , ".tmp_source.zig:2:24: error: integer value 753664 cannot be implicitly casted to type 'u16'");
13181318
13191319 cases.add("global variable alignment non power of 2",
1320 \\const some_data: [100]u8 align 3 = undefined;
1320 \\const some_data: [100]u8 align(3) = undefined;
13211321 \\export fn entry() -> usize { @sizeOf(@typeOf(some_data)) }
13221322 , ".tmp_source.zig:1:32: error: alignment value 3 is not a power of 2");
13231323
13241324 cases.add("function alignment non power of 2",
1325 \\extern fn foo() align 3;
1325 \\extern fn foo() align(3);
13261326 \\export fn entry() { foo() }
13271327 , ".tmp_source.zig:1:23: error: alignment value 3 is not a power of 2");
13281328
......@@ -1359,7 +1359,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
13591359 \\}
13601360 \\
13611361 \\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
1362 , ".tmp_source.zig:8:26: error: expected type '&const u3', found '&align 1:3:6 const u3'");
1362 , ".tmp_source.zig:8:26: error: expected type '&const u3', found '&align(1:3:6) const u3'");
13631363
13641364 cases.add("referring to a struct that is invalid",
13651365 \\const UsbDeviceRequest = struct {
......@@ -1992,7 +1992,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
19921992 \\ *x += 1;
19931993 \\}
19941994 ,
1995 ".tmp_source.zig:8:13: error: expected type '&u32', found '&align 1 u32'");
1995 ".tmp_source.zig:8:13: error: expected type '&u32', found '&align(1) u32'");
19961996
19971997 cases.add("implicitly increasing slice alignment",
19981998 \\const Foo = packed struct {
......@@ -2010,7 +2010,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
20102010 \\ x[0] += 1;
20112011 \\}
20122012 ,
2013 ".tmp_source.zig:9:17: error: expected type '[]u32', found '[]align 1 u32'");
2013 ".tmp_source.zig:9:17: error: expected type '[]u32', found '[]align(1) u32'");
20142014
20152015 cases.add("increase pointer alignment in @ptrCast",
20162016 \\export fn entry() -> u32 {
......@@ -2044,17 +2044,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
20442044 \\export fn entry() {
20452045 \\ testImplicitlyDecreaseFnAlign(alignedSmall, 1234);
20462046 \\}
2047 \\fn testImplicitlyDecreaseFnAlign(ptr: fn () align 8 -> i32, answer: i32) {
2047 \\fn testImplicitlyDecreaseFnAlign(ptr: fn () align(8) -> i32, answer: i32) {
20482048 \\ if (ptr() != answer) unreachable;
20492049 \\}
2050 \\fn alignedSmall() align 4 -> i32 { 1234 }
2050 \\fn alignedSmall() align(4) -> i32 { 1234 }
20512051 ,
2052 ".tmp_source.zig:2:35: error: expected type 'fn() align 8 -> i32', found 'fn() align 4 -> i32'");
2052 ".tmp_source.zig:2:35: error: expected type 'fn() align(8) -> i32', found 'fn() align(4) -> i32'");
20532053
20542054 cases.add("passing a not-aligned-enough pointer to cmpxchg",
20552055 \\const AtomicOrder = @import("builtin").AtomicOrder;
20562056 \\export fn entry() -> bool {
2057 \\ var x: i32 align 1 = 1234;
2057 \\ var x: i32 align(1) = 1234;
20582058 \\ while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) {}
20592059 \\ return x == 5678;
20602060 \\}
test/debug_safety.zig+3-3
......@@ -200,8 +200,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
200200 \\ const x = widenSlice([]u8{1, 2, 3, 4, 5});
201201 \\ if (x.len == 0) return error.Whatever;
202202 \\}
203 \\fn widenSlice(slice: []align 1 const u8) -> []align 1 const i32 {
204 \\ ([]align 1 const i32)(slice)
203 \\fn widenSlice(slice: []align(1) const u8) -> []align(1) const i32 {
204 \\ ([]align(1) const i32)(slice)
205205 \\}
206206 );
207207
......@@ -269,7 +269,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
269269 \\}
270270 \\error Wrong;
271271 \\pub fn main() -> %void {
272 \\ var array align 4 = []u32{0x11111111, 0x11111111};
272 \\ var array align(4) = []u32{0x11111111, 0x11111111};
273273 \\ const bytes = ([]u8)(array[0..]);
274274 \\ if (foo(bytes) != 0x11111111) return error.Wrong;
275275 \\}