Commit 052b4ae941
Changed files (10)
std
special
compiler_rt
src/analyze.cpp
@@ -359,10 +359,10 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type
if (unaligned_bit_count == 0 && byte_alignment == abi_alignment) {
buf_appendf(&entry->name, "&%s%s%s", const_str, volatile_str, buf_ptr(&child_type->name));
} else if (unaligned_bit_count == 0) {
- buf_appendf(&entry->name, "&align %" PRIu32 " %s%s%s", byte_alignment,
+ buf_appendf(&entry->name, "&align(%" PRIu32 ") %s%s%s", byte_alignment,
const_str, volatile_str, buf_ptr(&child_type->name));
} else {
- buf_appendf(&entry->name, "&align %" PRIu32 ":%" PRIu32 ":%" PRIu32 " %s%s%s", byte_alignment,
+ buf_appendf(&entry->name, "&align(%" PRIu32 ":%" PRIu32 ":%" PRIu32 ") %s%s%s", byte_alignment,
bit_offset, bit_offset + unaligned_bit_count, const_str, volatile_str, buf_ptr(&child_type->name));
}
@@ -885,7 +885,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
}
buf_appendf(&fn_type->name, ")");
if (fn_type_id->alignment != 0) {
- buf_appendf(&fn_type->name, " align %" PRIu32, fn_type_id->alignment);
+ buf_appendf(&fn_type->name, " align(%" PRIu32 ")", fn_type_id->alignment);
}
if (fn_type_id->return_type->id != TypeTableEntryIdVoid) {
buf_appendf(&fn_type->name, " -> %s", buf_ptr(&fn_type_id->return_type->name));
src/ast_render.cpp
@@ -585,7 +585,7 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
{
fprintf(ar->f, "&");
if (node->data.addr_of_expr.align_expr != nullptr) {
- fprintf(ar->f, "align ");
+ fprintf(ar->f, "align(");
render_node_grouped(ar, node->data.addr_of_expr.align_expr);
if (node->data.addr_of_expr.bit_offset_start != nullptr) {
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) {
bigint_append_buf(&offset_end_buf, node->data.addr_of_expr.bit_offset_end, 10);
fprintf(ar->f, ":%s:%s ", buf_ptr(&offset_start_buf), buf_ptr(&offset_end_buf));
- } else {
- fprintf(ar->f, " ");
}
+ fprintf(ar->f, ") ");
}
if (node->data.addr_of_expr.is_const) {
fprintf(ar->f, "const ");
src/parser.cpp
@@ -385,7 +385,7 @@ static AstNode *ast_parse_grouped_expr(ParseContext *pc, size_t *token_index, bo
}
/*
-ArrayType : "[" option(Expression) "]" option("align" PrimaryExpression)) option("const") option("volatile") PrefixOpExpression
+ArrayType : "[" option(Expression) "]" option("align" "(" Expression option(":" Integer ":" Integer) ")")) option("const") option("volatile") TypeExpr
*/
static AstNode *ast_parse_array_type_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
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,
Token *token = &pc->tokens->at(*token_index);
if (token->id == TokenIdKeywordAlign) {
*token_index += 1;
- node->data.array_type.align_expr = ast_parse_primary_expr(pc, token_index, true);
+ ast_eat_token(pc, token_index, TokenIdLParen);
+ node->data.array_type.align_expr = ast_parse_expression(pc, token_index, true);
+ ast_eat_token(pc, token_index, TokenIdRParen);
token = &pc->tokens->at(*token_index);
}
@@ -984,7 +986,8 @@ static AstNode *ast_parse_addr_of(ParseContext *pc, size_t *token_index) {
Token *token = &pc->tokens->at(*token_index);
if (token->id == TokenIdKeywordAlign) {
*token_index += 1;
- node->data.addr_of_expr.align_expr = ast_parse_primary_expr(pc, token_index, true);
+ ast_eat_token(pc, token_index, TokenIdLParen);
+ node->data.addr_of_expr.align_expr = ast_parse_expression(pc, token_index, true);
token = &pc->tokens->at(*token_index);
if (token->id == TokenIdColon) {
@@ -992,11 +995,12 @@ static AstNode *ast_parse_addr_of(ParseContext *pc, size_t *token_index) {
Token *bit_offset_start_tok = ast_eat_token(pc, token_index, TokenIdIntLiteral);
ast_eat_token(pc, token_index, TokenIdColon);
Token *bit_offset_end_tok = ast_eat_token(pc, token_index, TokenIdIntLiteral);
- token = &pc->tokens->at(*token_index);
node->data.addr_of_expr.bit_offset_start = token_bigint(bit_offset_start_tok);
node->data.addr_of_expr.bit_offset_end = token_bigint(bit_offset_end_tok);
}
+ ast_eat_token(pc, token_index, TokenIdRParen);
+ token = &pc->tokens->at(*token_index);
}
if (token->id == TokenIdKeywordConst) {
*token_index += 1;
@@ -1015,7 +1019,7 @@ static AstNode *ast_parse_addr_of(ParseContext *pc, size_t *token_index) {
/*
PrefixOpExpression : PrefixOp PrefixOpExpression | SuffixOpExpression
-PrefixOp = "!" | "-" | "~" | "*" | ("&" option("align" PrimaryExpression option(":" Integer ":" Integer)) option("const") option("volatile")) | "?" | "%" | "%%" | "??" | "-%"
+PrefixOp = "!" | "-" | "~" | "*" | ("&" option("align" "(" Expression option(":" Integer ":" Integer) ")" ) option("const") option("volatile")) | "?" | "%" | "%%" | "??" | "-%"
*/
static AstNode *ast_parse_prefix_op_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
Token *token = &pc->tokens->at(*token_index);
@@ -1534,7 +1538,7 @@ static AstNode *ast_parse_defer_expr(ParseContext *pc, size_t *token_index) {
}
/*
-VariableDeclaration = option("comptime") ("var" | "const") Symbol option(":" TypeExpr) option("align" PrimaryExpression) "=" Expression
+VariableDeclaration = option("comptime") ("var" | "const") Symbol option(":" TypeExpr) option("align" "(" Expression ")") "=" Expression
*/
static AstNode *ast_parse_variable_declaration_expr(ParseContext *pc, size_t *token_index, bool mandatory,
VisibMod visib_mod)
@@ -1594,7 +1598,9 @@ static AstNode *ast_parse_variable_declaration_expr(ParseContext *pc, size_t *to
if (next_token->id == TokenIdKeywordAlign) {
*token_index += 1;
- node->data.variable_declaration.align_expr = ast_parse_primary_expr(pc, token_index, true);
+ ast_eat_token(pc, token_index, TokenIdLParen);
+ node->data.variable_declaration.align_expr = ast_parse_expression(pc, token_index, true);
+ ast_eat_token(pc, token_index, TokenIdRParen);
next_token = &pc->tokens->at(*token_index);
}
@@ -2203,7 +2209,7 @@ static AstNode *ast_parse_block(ParseContext *pc, size_t *token_index, bool mand
}
/*
-FnProto = option("coldcc" | "nakedcc" | "stdcallcc") "fn" option(Symbol) ParamDeclList option("align" PrimaryExpression) option("->" TypeExpr)
+FnProto = option("coldcc" | "nakedcc" | "stdcallcc") "fn" option(Symbol) ParamDeclList option("align" "(" Expression ")") option("->" TypeExpr)
*/
static AstNode *ast_parse_fn_proto(ParseContext *pc, size_t *token_index, bool mandatory, VisibMod visib_mod) {
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
Token *next_token = &pc->tokens->at(*token_index);
if (next_token->id == TokenIdKeywordAlign) {
*token_index += 1;
+ ast_eat_token(pc, token_index, TokenIdLParen);
- node->data.fn_proto.align_expr = ast_parse_primary_expr(pc, token_index, true);
+ node->data.fn_proto.align_expr = ast_parse_expression(pc, token_index, true);
+ ast_eat_token(pc, token_index, TokenIdRParen);
next_token = &pc->tokens->at(*token_index);
}
if (next_token->id == TokenIdArrow) {
std/special/compiler_rt/udivmod.zig
@@ -54,7 +54,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
if (maybe_rem) |rem| {
r[high] = n[high] % d[high];
r[low] = 0;
- *rem = *@ptrCast(&align @alignOf(SingleInt) DoubleInt, &r[0]); // TODO issue #421
+ *rem = *@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]); // TODO issue #421
}
return n[high] / d[high];
}
@@ -66,7 +66,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
if (maybe_rem) |rem| {
r[low] = n[low];
r[high] = n[high] & (d[high] - 1);
- *rem = *@ptrCast(&align @alignOf(SingleInt) DoubleInt, &r[0]); // TODO issue #421
+ *rem = *@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]); // TODO issue #421
}
return n[high] >> Log2SingleInt(@ctz(d[high]));
}
@@ -106,7 +106,7 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
sr = @ctz(d[low]);
q[high] = n[high] >> Log2SingleInt(sr);
q[low] = (n[high] << Log2SingleInt(SingleInt.bit_count - sr)) | (n[low] >> Log2SingleInt(sr));
- return *@ptrCast(&align @alignOf(SingleInt) DoubleInt, &q[0]); // TODO issue #421
+ return *@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &q[0]); // TODO issue #421
}
// K X
// ---
@@ -180,13 +180,13 @@ pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem:
// r.all -= b;
// carry = 1;
// }
- r_all = *@ptrCast(&align @alignOf(SingleInt) DoubleInt, &r[0]); // TODO issue #421
+ r_all = *@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &r[0]); // TODO issue #421
const s: SignedDoubleInt = SignedDoubleInt(b -% r_all -% 1) >> (DoubleInt.bit_count - 1);
carry = u32(s & 1);
r_all -= b & @bitCast(DoubleInt, s);
r = *@ptrCast(&[2]SingleInt, &r_all); // TODO issue #421
}
- const q_all = ((*@ptrCast(&align @alignOf(SingleInt) DoubleInt, &q[0])) << 1) | carry; // TODO issue #421
+ const q_all = ((*@ptrCast(&align(@alignOf(SingleInt)) DoubleInt, &q[0])) << 1) | carry; // TODO issue #421
if (maybe_rem) |rem| {
*rem = r_all;
}
test/cases/align.zig
@@ -1,22 +1,22 @@
const assert = @import("std").debug.assert;
-var foo: u8 align 4 = 100;
+var foo: u8 align(4) = 100;
test "global variable alignment" {
assert(@typeOf(&foo).alignment == 4);
- assert(@typeOf(&foo) == &align 4 u8);
+ assert(@typeOf(&foo) == &align(4) u8);
const slice = (&foo)[0..1];
- assert(@typeOf(slice) == []align 4 u8);
+ assert(@typeOf(slice) == []align(4) u8);
}
-fn derp() align (@sizeOf(usize) * 2) -> i32 { 1234 }
-fn noop1() align 1 {}
-fn noop4() align 4 {}
+fn derp() align(@sizeOf(usize) * 2) -> i32 { 1234 }
+fn noop1() align(1) {}
+fn noop4() align(4) {}
test "function alignment" {
assert(derp() == 1234);
- assert(@typeOf(noop1) == fn() align 1);
- assert(@typeOf(noop4) == fn() align 4);
+ assert(@typeOf(noop1) == fn() align(1));
+ assert(@typeOf(noop4) == fn() align(4));
noop1();
noop4();
}
@@ -28,7 +28,7 @@ var baz: packed struct {
} = undefined;
test "packed struct alignment" {
- assert(@typeOf(&baz.b) == &align 1 u32);
+ assert(@typeOf(&baz.b) == &align(1) u32);
}
@@ -39,33 +39,33 @@ const blah: packed struct {
} = undefined;
test "bit field alignment" {
- assert(@typeOf(&blah.b) == &align 1:3:6 const u3);
+ assert(@typeOf(&blah.b) == &align(1:3:6) const u3);
}
test "default alignment allows unspecified in type syntax" {
- assert(&u32 == &align @alignOf(u32) u32);
+ assert(&u32 == &align(@alignOf(u32)) u32);
}
test "implicitly decreasing pointer alignment" {
- const a: u32 align 4 = 3;
- const b: u32 align 8 = 4;
+ const a: u32 align(4) = 3;
+ const b: u32 align(8) = 4;
assert(addUnaligned(&a, &b) == 7);
}
-fn addUnaligned(a: &align 1 const u32, b: &align 1 const u32) -> u32 { *a + *b }
+fn addUnaligned(a: &align(1) const u32, b: &align(1) const u32) -> u32 { *a + *b }
test "implicitly decreasing slice alignment" {
- const a: u32 align 4 = 3;
- const b: u32 align 8 = 4;
+ const a: u32 align(4) = 3;
+ const b: u32 align(8) = 4;
assert(addUnalignedSlice((&a)[0..1], (&b)[0..1]) == 7);
}
-fn addUnalignedSlice(a: []align 1 const u32, b: []align 1 const u32) -> u32 { a[0] + b[0] }
+fn addUnalignedSlice(a: []align(1) const u32, b: []align(1) const u32) -> u32 { a[0] + b[0] }
test "specifying alignment allows pointer cast" {
testBytesAlign(0x33);
}
fn testBytesAlign(b: u8) {
- var bytes align 4 = []u8{b, b, b, b};
+ var bytes align(4) = []u8{b, b, b, b};
const ptr = @ptrCast(&u32, &bytes[0]);
assert(*ptr == 0x33333333);
}
@@ -74,33 +74,33 @@ test "specifying alignment allows slice cast" {
testBytesAlignSlice(0x33);
}
fn testBytesAlignSlice(b: u8) {
- var bytes align 4 = []u8{b, b, b, b};
+ var bytes align(4) = []u8{b, b, b, b};
const slice = ([]u32)(bytes[0..]);
assert(slice[0] == 0x33333333);
}
test "@alignCast pointers" {
- var x: u32 align 4 = 1;
+ var x: u32 align(4) = 1;
expectsOnly1(&x);
assert(x == 2);
}
-fn expectsOnly1(x: &align 1 u32) {
+fn expectsOnly1(x: &align(1) u32) {
expects4(@alignCast(4, x));
}
-fn expects4(x: &align 4 u32) {
+fn expects4(x: &align(4) u32) {
*x += 1;
}
test "@alignCast slices" {
- var array align 4 = []u32{1, 1};
+ var array align(4) = []u32{1, 1};
const slice = array[0..];
sliceExpectsOnly1(slice);
assert(slice[0] == 2);
}
-fn sliceExpectsOnly1(slice: []align 1 u32) {
+fn sliceExpectsOnly1(slice: []align(1) u32) {
sliceExpects4(@alignCast(4, slice));
}
-fn sliceExpects4(slice: []align 4 u32) {
+fn sliceExpects4(slice: []align(4) u32) {
slice[0] += 1;
}
@@ -110,24 +110,24 @@ test "implicitly decreasing fn alignment" {
testImplicitlyDecreaseFnAlign(alignedBig, 5678);
}
-fn testImplicitlyDecreaseFnAlign(ptr: fn () align 1 -> i32, answer: i32) {
+fn testImplicitlyDecreaseFnAlign(ptr: fn () align(1) -> i32, answer: i32) {
assert(ptr() == answer);
}
-fn alignedSmall() align 8 -> i32 { 1234 }
-fn alignedBig() align 16 -> i32 { 5678 }
+fn alignedSmall() align(8) -> i32 { 1234 }
+fn alignedBig() align(16) -> i32 { 5678 }
test "@alignCast functions" {
assert(fnExpectsOnly1(simple4) == 0x19);
}
-fn fnExpectsOnly1(ptr: fn()align 1 -> i32) -> i32 {
+fn fnExpectsOnly1(ptr: fn()align(1) -> i32) -> i32 {
fnExpects4(@alignCast(4, ptr))
}
-fn fnExpects4(ptr: fn()align 4 -> i32) -> i32 {
+fn fnExpects4(ptr: fn()align(4) -> i32) -> i32 {
ptr()
}
-fn simple4() align 4 -> i32 { 0x19 }
+fn simple4() align(4) -> i32 { 0x19 }
test "generic function with align param" {
@@ -136,37 +136,37 @@ test "generic function with align param" {
assert(whyWouldYouEverDoThis(8) == 0x1);
}
-fn whyWouldYouEverDoThis(comptime align_bytes: u8) align align_bytes -> u8 { 0x1 }
+fn whyWouldYouEverDoThis(comptime align_bytes: u8) align(align_bytes) -> u8 { 0x1 }
test "@ptrCast preserves alignment of bigger source" {
- var x: u32 align 16 = 1234;
+ var x: u32 align(16) = 1234;
const ptr = @ptrCast(&u8, &x);
- assert(@typeOf(ptr) == &align 16 u8);
+ assert(@typeOf(ptr) == &align(16) u8);
}
test "compile-time known array index has best alignment possible" {
// take full advantage of over-alignment
- var array align 4 = []u8 {1, 2, 3, 4};
- assert(@typeOf(&array[0]) == &align 4 u8);
+ var array align(4) = []u8 {1, 2, 3, 4};
+ assert(@typeOf(&array[0]) == &align(4) u8);
assert(@typeOf(&array[1]) == &u8);
- assert(@typeOf(&array[2]) == &align 2 u8);
+ assert(@typeOf(&array[2]) == &align(2) u8);
assert(@typeOf(&array[3]) == &u8);
// because align is too small but we still figure out to use 2
- var bigger align 2 = []u64{1, 2, 3, 4};
- assert(@typeOf(&bigger[0]) == &align 2 u64);
- assert(@typeOf(&bigger[1]) == &align 2 u64);
- assert(@typeOf(&bigger[2]) == &align 2 u64);
- assert(@typeOf(&bigger[3]) == &align 2 u64);
+ var bigger align(2) = []u64{1, 2, 3, 4};
+ assert(@typeOf(&bigger[0]) == &align(2) u64);
+ assert(@typeOf(&bigger[1]) == &align(2) u64);
+ assert(@typeOf(&bigger[2]) == &align(2) u64);
+ assert(@typeOf(&bigger[3]) == &align(2) u64);
// because pointer is align 2 and u32 align % 2 == 0 we can assume align 2
- var smaller align 2 = []u32{1, 2, 3, 4};
- testIndex(&smaller[0], 0, &align 2 u32);
- testIndex(&smaller[0], 1, &align 2 u32);
- testIndex(&smaller[0], 2, &align 2 u32);
- testIndex(&smaller[0], 3, &align 2 u32);
+ var smaller align(2) = []u32{1, 2, 3, 4};
+ testIndex(&smaller[0], 0, &align(2) u32);
+ testIndex(&smaller[0], 1, &align(2) u32);
+ testIndex(&smaller[0], 2, &align(2) u32);
+ testIndex(&smaller[0], 3, &align(2) u32);
// has to use ABI alignment because index known at runtime only
testIndex2(&array[0], 0, &u8);
@@ -174,9 +174,9 @@ test "compile-time known array index has best alignment possible" {
testIndex2(&array[0], 2, &u8);
testIndex2(&array[0], 3, &u8);
}
-fn testIndex(smaller: &align 2 u32, index: usize, comptime T: type) {
+fn testIndex(smaller: &align(2) u32, index: usize, comptime T: type) {
assert(@typeOf(&smaller[index]) == T);
}
-fn testIndex2(ptr: &align 4 u8, index: usize, comptime T: type) {
+fn testIndex2(ptr: &align(4) u8, index: usize, comptime T: type) {
assert(@typeOf(&ptr[index]) == T);
}
test/cases/cast.zig
@@ -277,7 +277,7 @@ fn cast128Float(x: u128) -> f128 {
}
test "const slice widen cast" {
- const bytes align 4 = []u8{0x12, 0x12, 0x12, 0x12};
+ const bytes align(4) = []u8{0x12, 0x12, 0x12, 0x12};
const u32_value = ([]const u32)(bytes[0..])[0];
assert(u32_value == 0x12121212);
test/cases/misc.zig
@@ -404,7 +404,7 @@ test "cast slice to u8 slice" {
bytes[6] = 0;
bytes[7] = 0;
assert(big_thing_slice[1] == 0);
- const big_thing_again = ([]align 1 i32)(bytes);
+ const big_thing_again = ([]align(1) i32)(bytes);
assert(big_thing_again[2] == 3);
big_thing_again[2] = -1;
assert(bytes[8] == @maxValue(u8));
test/compare_output.zig
@@ -262,8 +262,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
\\const c = @cImport(@cInclude("stdlib.h"));
\\
\\export fn compare_fn(a: ?&const c_void, b: ?&const c_void) -> c_int {
- \\ const a_int = @ptrCast(&align 1 i32, a ?? unreachable);
- \\ const b_int = @ptrCast(&align 1 i32, b ?? unreachable);
+ \\ const a_int = @ptrCast(&align(1) i32, a ?? unreachable);
+ \\ const b_int = @ptrCast(&align(1) i32, b ?? unreachable);
\\ if (*a_int < *b_int) {
\\ -1
\\ } else if (*a_int > *b_int) {
test/compile_errors.zig
@@ -1317,12 +1317,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
, ".tmp_source.zig:2:24: error: integer value 753664 cannot be implicitly casted to type 'u16'");
cases.add("global variable alignment non power of 2",
- \\const some_data: [100]u8 align 3 = undefined;
+ \\const some_data: [100]u8 align(3) = undefined;
\\export fn entry() -> usize { @sizeOf(@typeOf(some_data)) }
, ".tmp_source.zig:1:32: error: alignment value 3 is not a power of 2");
cases.add("function alignment non power of 2",
- \\extern fn foo() align 3;
+ \\extern fn foo() align(3);
\\export fn entry() { foo() }
, ".tmp_source.zig:1:23: error: alignment value 3 is not a power of 2");
@@ -1359,7 +1359,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\}
\\
\\export fn entry() -> usize { @sizeOf(@typeOf(foo)) }
- , ".tmp_source.zig:8:26: error: expected type '&const u3', found '&align 1:3:6 const u3'");
+ , ".tmp_source.zig:8:26: error: expected type '&const u3', found '&align(1:3:6) const u3'");
cases.add("referring to a struct that is invalid",
\\const UsbDeviceRequest = struct {
@@ -1992,7 +1992,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ *x += 1;
\\}
,
- ".tmp_source.zig:8:13: error: expected type '&u32', found '&align 1 u32'");
+ ".tmp_source.zig:8:13: error: expected type '&u32', found '&align(1) u32'");
cases.add("implicitly increasing slice alignment",
\\const Foo = packed struct {
@@ -2010,7 +2010,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\ x[0] += 1;
\\}
,
- ".tmp_source.zig:9:17: error: expected type '[]u32', found '[]align 1 u32'");
+ ".tmp_source.zig:9:17: error: expected type '[]u32', found '[]align(1) u32'");
cases.add("increase pointer alignment in @ptrCast",
\\export fn entry() -> u32 {
@@ -2044,17 +2044,17 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
\\export fn entry() {
\\ testImplicitlyDecreaseFnAlign(alignedSmall, 1234);
\\}
- \\fn testImplicitlyDecreaseFnAlign(ptr: fn () align 8 -> i32, answer: i32) {
+ \\fn testImplicitlyDecreaseFnAlign(ptr: fn () align(8) -> i32, answer: i32) {
\\ if (ptr() != answer) unreachable;
\\}
- \\fn alignedSmall() align 4 -> i32 { 1234 }
+ \\fn alignedSmall() align(4) -> i32 { 1234 }
,
- ".tmp_source.zig:2:35: error: expected type 'fn() align 8 -> i32', found 'fn() align 4 -> i32'");
+ ".tmp_source.zig:2:35: error: expected type 'fn() align(8) -> i32', found 'fn() align(4) -> i32'");
cases.add("passing a not-aligned-enough pointer to cmpxchg",
\\const AtomicOrder = @import("builtin").AtomicOrder;
\\export fn entry() -> bool {
- \\ var x: i32 align 1 = 1234;
+ \\ var x: i32 align(1) = 1234;
\\ while (!@cmpxchg(&x, 1234, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) {}
\\ return x == 5678;
\\}
test/debug_safety.zig
@@ -200,8 +200,8 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
\\ const x = widenSlice([]u8{1, 2, 3, 4, 5});
\\ if (x.len == 0) return error.Whatever;
\\}
- \\fn widenSlice(slice: []align 1 const u8) -> []align 1 const i32 {
- \\ ([]align 1 const i32)(slice)
+ \\fn widenSlice(slice: []align(1) const u8) -> []align(1) const i32 {
+ \\ ([]align(1) const i32)(slice)
\\}
);
@@ -269,7 +269,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
\\}
\\error Wrong;
\\pub fn main() -> %void {
- \\ var array align 4 = []u32{0x11111111, 0x11111111};
+ \\ var array align(4) = []u32{0x11111111, 0x11111111};
\\ const bytes = ([]u8)(array[0..]);
\\ if (foo(bytes) != 0x11111111) return error.Wrong;
\\}