From 59cc7072e22d03ba40456a58eaf3b37b239b420e Mon Sep 17 00:00:00 2001 From: Vexu Date: Mon, 23 Dec 2019 09:47:31 +0200 Subject: [PATCH] translate-c-2 use `intCast` in most places --- lib/std/zig/ast.zig | 92 ++++++++++++++++----------------- src-self-hosted/translate_c.zig | 46 +++++++---------- test/translate_c.zig | 72 +++++++++++++------------- 3 files changed, 101 insertions(+), 109 deletions(-) diff --git a/lib/std/zig/ast.zig b/lib/std/zig/ast.zig index 1c9b4eb3c9..adbcef165e 100644 --- a/lib/std/zig/ast.zig +++ b/lib/std/zig/ast.zig @@ -584,7 +584,7 @@ pub const Node = struct { } pub const Root = struct { - base: Node = Node {.id = .Root}, + base: Node = Node{ .id = .Root }, decls: DeclList, eof_token: TokenIndex, @@ -607,7 +607,7 @@ pub const Node = struct { }; pub const VarDecl = struct { - base: Node = Node {.id = .VarDecl}, + base: Node = Node{ .id = .VarDecl }, doc_comments: ?*DocComment, visib_token: ?TokenIndex, thread_local_token: ?TokenIndex, @@ -664,7 +664,7 @@ pub const Node = struct { }; pub const Use = struct { - base: Node = Node {.id = .Use}, + base: Node = Node{ .id = .Use }, doc_comments: ?*DocComment, visib_token: ?TokenIndex, use_token: TokenIndex, @@ -691,7 +691,7 @@ pub const Node = struct { }; pub const ErrorSetDecl = struct { - base: Node = Node {.id = .ErrorSetDecl}, + base: Node = Node{ .id = .ErrorSetDecl }, error_token: TokenIndex, decls: DeclList, rbrace_token: TokenIndex, @@ -717,7 +717,7 @@ pub const Node = struct { }; pub const ContainerDecl = struct { - base: Node = Node {.id = .ContainerDecl}, + base: Node = Node{ .id = .ContainerDecl }, layout_token: ?TokenIndex, kind_token: TokenIndex, init_arg_expr: InitArg, @@ -804,7 +804,7 @@ pub const Node = struct { }; pub const ErrorTag = struct { - base: Node = Node {.id = .ErrorTag}, + base: Node = Node{ .id = .ErrorTag }, doc_comments: ?*DocComment, name_token: TokenIndex, @@ -829,7 +829,7 @@ pub const Node = struct { }; pub const Identifier = struct { - base: Node = Node {.id = .Identifier}, + base: Node = Node{ .id = .Identifier }, token: TokenIndex, pub fn iterate(self: *Identifier, index: usize) ?*Node { @@ -846,7 +846,7 @@ pub const Node = struct { }; pub const FnProto = struct { - base: Node = Node {.id = .FnProto}, + base: Node = Node{ .id = .FnProto }, doc_comments: ?*DocComment, visib_token: ?TokenIndex, fn_token: TokenIndex, @@ -928,7 +928,7 @@ pub const Node = struct { }; pub const AnyFrameType = struct { - base: Node = Node {.id = .AnyFrameType}, + base: Node = Node{ .id = .AnyFrameType }, anyframe_token: TokenIndex, result: ?Result, @@ -959,7 +959,7 @@ pub const Node = struct { }; pub const ParamDecl = struct { - base: Node = Node {.id = .ParamDecl}, + base: Node = Node{ .id = .ParamDecl }, doc_comments: ?*DocComment, comptime_token: ?TokenIndex, noalias_token: ?TokenIndex, @@ -992,7 +992,7 @@ pub const Node = struct { }; pub const Block = struct { - base: Node = Node {.id = .Block}, + base: Node = Node{ .id = .Block }, label: ?TokenIndex, lbrace: TokenIndex, statements: StatementList, @@ -1023,7 +1023,7 @@ pub const Node = struct { }; pub const Defer = struct { - base: Node = Node {.id = .Defer}, + base: Node = Node{ .id = .Defer }, defer_token: TokenIndex, expr: *Node, @@ -1046,7 +1046,7 @@ pub const Node = struct { }; pub const Comptime = struct { - base: Node = Node {.id = .Comptime}, + base: Node = Node{ .id = .Comptime }, doc_comments: ?*DocComment, comptime_token: TokenIndex, expr: *Node, @@ -1070,7 +1070,7 @@ pub const Node = struct { }; pub const Payload = struct { - base: Node = Node {.id = .Payload}, + base: Node = Node{ .id = .Payload }, lpipe: TokenIndex, error_symbol: *Node, rpipe: TokenIndex, @@ -1094,7 +1094,7 @@ pub const Node = struct { }; pub const PointerPayload = struct { - base: Node = Node {.id = .PointerPayload}, + base: Node = Node{ .id = .PointerPayload }, lpipe: TokenIndex, ptr_token: ?TokenIndex, value_symbol: *Node, @@ -1119,7 +1119,7 @@ pub const Node = struct { }; pub const PointerIndexPayload = struct { - base: Node = Node {.id = .PointerIndexPayload}, + base: Node = Node{ .id = .PointerIndexPayload }, lpipe: TokenIndex, ptr_token: ?TokenIndex, value_symbol: *Node, @@ -1150,7 +1150,7 @@ pub const Node = struct { }; pub const Else = struct { - base: Node = Node {.id = .Else}, + base: Node = Node{ .id = .Else }, else_token: TokenIndex, payload: ?*Node, body: *Node, @@ -1179,7 +1179,7 @@ pub const Node = struct { }; pub const Switch = struct { - base: Node = Node {.id = .Switch}, + base: Node = Node{ .id = .Switch }, switch_token: TokenIndex, expr: *Node, @@ -1211,7 +1211,7 @@ pub const Node = struct { }; pub const SwitchCase = struct { - base: Node = Node {.id = .SwitchCase}, + base: Node = Node{ .id = .SwitchCase }, items: ItemList, arrow_token: TokenIndex, payload: ?*Node, @@ -1246,7 +1246,7 @@ pub const Node = struct { }; pub const SwitchElse = struct { - base: Node = Node {.id = .SwitchElse}, + base: Node = Node{ .id = .SwitchElse }, token: TokenIndex, pub fn iterate(self: *SwitchElse, index: usize) ?*Node { @@ -1263,7 +1263,7 @@ pub const Node = struct { }; pub const While = struct { - base: Node = Node {.id = .While}, + base: Node = Node{ .id = .While }, label: ?TokenIndex, inline_token: ?TokenIndex, while_token: TokenIndex, @@ -1322,7 +1322,7 @@ pub const Node = struct { }; pub const For = struct { - base: Node = Node {.id = .For}, + base: Node = Node{ .id = .For }, label: ?TokenIndex, inline_token: ?TokenIndex, for_token: TokenIndex, @@ -1373,7 +1373,7 @@ pub const Node = struct { }; pub const If = struct { - base: Node = Node {.id = .If}, + base: Node = Node{ .id = .If }, if_token: TokenIndex, condition: *Node, payload: ?*Node, @@ -1416,7 +1416,7 @@ pub const Node = struct { }; pub const InfixOp = struct { - base: Node = Node {.id = .InfixOp}, + base: Node = Node{ .id = .InfixOp }, op_token: TokenIndex, lhs: *Node, op: Op, @@ -1649,7 +1649,7 @@ pub const Node = struct { }; pub const FieldInitializer = struct { - base: Node = Node {.id = .FieldInitializer}, + base: Node = Node{ .id = .FieldInitializer }, period_token: TokenIndex, name_token: TokenIndex, expr: *Node, @@ -1673,7 +1673,7 @@ pub const Node = struct { }; pub const SuffixOp = struct { - base: Node = Node {.id = .SuffixOp}, + base: Node = Node{ .id = .SuffixOp }, lhs: Lhs, op: Op, rtoken: TokenIndex, @@ -1774,7 +1774,7 @@ pub const Node = struct { }; pub const GroupedExpression = struct { - base: Node = Node {.id = .GroupedExpression}, + base: Node = Node{ .id = .GroupedExpression }, lparen: TokenIndex, expr: *Node, rparen: TokenIndex, @@ -1798,7 +1798,7 @@ pub const Node = struct { }; pub const ControlFlowExpression = struct { - base: Node = Node {.id = .ControlFlowExpression}, + base: Node = Node{ .id = .ControlFlowExpression }, ltoken: TokenIndex, kind: Kind, rhs: ?*Node, @@ -1864,7 +1864,7 @@ pub const Node = struct { }; pub const Suspend = struct { - base: Node = Node {.id = .Suspend}, + base: Node = Node{ .id = .Suspend }, suspend_token: TokenIndex, body: ?*Node, @@ -1893,7 +1893,7 @@ pub const Node = struct { }; pub const IntegerLiteral = struct { - base: Node = Node {.id = .IntegerLiteral}, + base: Node = Node{ .id = .IntegerLiteral }, token: TokenIndex, pub fn iterate(self: *IntegerLiteral, index: usize) ?*Node { @@ -1910,7 +1910,7 @@ pub const Node = struct { }; pub const EnumLiteral = struct { - base: Node = Node {.id = .EnumLiteral}, + base: Node = Node{ .id = .EnumLiteral }, dot: TokenIndex, name: TokenIndex, @@ -1928,7 +1928,7 @@ pub const Node = struct { }; pub const FloatLiteral = struct { - base: Node = Node {.id = .FloatLiteral}, + base: Node = Node{ .id = .FloatLiteral }, token: TokenIndex, pub fn iterate(self: *FloatLiteral, index: usize) ?*Node { @@ -1945,7 +1945,7 @@ pub const Node = struct { }; pub const BuiltinCall = struct { - base: Node = Node {.id = .BuiltinCall}, + base: Node = Node{ .id = .BuiltinCall }, builtin_token: TokenIndex, params: ParamList, rparen_token: TokenIndex, @@ -1971,7 +1971,7 @@ pub const Node = struct { }; pub const StringLiteral = struct { - base: Node = Node {.id = .StringLiteral}, + base: Node = Node{ .id = .StringLiteral }, token: TokenIndex, pub fn iterate(self: *StringLiteral, index: usize) ?*Node { @@ -1988,7 +1988,7 @@ pub const Node = struct { }; pub const MultilineStringLiteral = struct { - base: Node = Node {.id = .MultilineStringLiteral}, + base: Node = Node{ .id = .MultilineStringLiteral }, lines: LineList, pub const LineList = SegmentedList(TokenIndex, 4); @@ -2007,7 +2007,7 @@ pub const Node = struct { }; pub const CharLiteral = struct { - base: Node = Node {.id = .CharLiteral}, + base: Node = Node{ .id = .CharLiteral }, token: TokenIndex, pub fn iterate(self: *CharLiteral, index: usize) ?*Node { @@ -2024,7 +2024,7 @@ pub const Node = struct { }; pub const BoolLiteral = struct { - base: Node = Node {.id = .BoolLiteral}, + base: Node = Node{ .id = .BoolLiteral }, token: TokenIndex, pub fn iterate(self: *BoolLiteral, index: usize) ?*Node { @@ -2041,7 +2041,7 @@ pub const Node = struct { }; pub const NullLiteral = struct { - base: Node = Node {.id = .NullLiteral}, + base: Node = Node{ .id = .NullLiteral }, token: TokenIndex, pub fn iterate(self: *NullLiteral, index: usize) ?*Node { @@ -2058,7 +2058,7 @@ pub const Node = struct { }; pub const UndefinedLiteral = struct { - base: Node = Node {.id = .UndefinedLiteral}, + base: Node = Node{ .id = .UndefinedLiteral }, token: TokenIndex, pub fn iterate(self: *UndefinedLiteral, index: usize) ?*Node { @@ -2075,7 +2075,7 @@ pub const Node = struct { }; pub const AsmOutput = struct { - base: Node = Node {.id = .AsmOutput}, + base: Node = Node{ .id = .AsmOutput }, lbracket: TokenIndex, symbolic_name: *Node, constraint: *Node, @@ -2120,7 +2120,7 @@ pub const Node = struct { }; pub const AsmInput = struct { - base: Node = Node {.id = .AsmInput}, + base: Node = Node{ .id = .AsmInput }, lbracket: TokenIndex, symbolic_name: *Node, constraint: *Node, @@ -2152,7 +2152,7 @@ pub const Node = struct { }; pub const Asm = struct { - base: Node = Node {.id = .Asm}, + base: Node = Node{ .id = .Asm }, asm_token: TokenIndex, volatile_token: ?TokenIndex, template: *Node, @@ -2187,7 +2187,7 @@ pub const Node = struct { }; pub const Unreachable = struct { - base: Node = Node {.id = .Unreachable}, + base: Node = Node{ .id = .Unreachable }, token: TokenIndex, pub fn iterate(self: *Unreachable, index: usize) ?*Node { @@ -2204,7 +2204,7 @@ pub const Node = struct { }; pub const ErrorType = struct { - base: Node = Node {.id = .ErrorType}, + base: Node = Node{ .id = .ErrorType }, token: TokenIndex, pub fn iterate(self: *ErrorType, index: usize) ?*Node { @@ -2238,7 +2238,7 @@ pub const Node = struct { }; pub const DocComment = struct { - base: Node = Node {.id = .DocComment}, + base: Node = Node{ .id = .DocComment }, lines: LineList, pub const LineList = SegmentedList(TokenIndex, 4); @@ -2257,7 +2257,7 @@ pub const Node = struct { }; pub const TestDecl = struct { - base: Node = Node {.id = .TestDecl}, + base: Node = Node{ .id = .TestDecl }, doc_comments: ?*DocComment, test_token: TokenIndex, name: *Node, diff --git a/src-self-hosted/translate_c.zig b/src-self-hosted/translate_c.zig index dee4135ea1..eb3be0bfa0 100644 --- a/src-self-hosted/translate_c.zig +++ b/src-self-hosted/translate_c.zig @@ -1194,7 +1194,7 @@ fn transImplicitCastExpr( const dest_type = getExprQualType(c, @ptrCast(*const ZigClangExpr, expr)); const src_type = getExprQualType(c, sub_expr); switch (ZigClangImplicitCastExpr_getCastKind(expr)) { - .BitCast, .FloatingCast, .FloatingToIntegral, .IntegralToFloating, .IntegralCast => { + .BitCast, .FloatingCast, .FloatingToIntegral, .IntegralToFloating, .IntegralCast, .PointerToIntegral, .IntegralToPointer => { return transCCast(rp, scope, ZigClangImplicitCastExpr_getBeginLoc(expr), dest_type, src_type, sub_expr_node); }, .LValueToRValue, .NoOp, .FunctionToPointerDecay, .ArrayToPointerDecay => { @@ -1221,29 +1221,6 @@ fn transImplicitCastExpr( const rhs_node = try transCreateNodeInt(rp.c, 0); return transCreateNodeInfixOp(rp, scope, node, .BangEqual, op_token, rhs_node, result_used, false); }, - .PointerToIntegral => { - // @intCast(dest_type, @ptrToInt(val)) - const cast_node = try transCreateNodeBuiltinFnCall(rp.c, "@intCast"); - try cast_node.params.push(try transQualType(rp, dest_type, ZigClangImplicitCastExpr_getBeginLoc(expr))); - _ = try appendToken(rp.c, .Comma, ","); - - const ptr_to_int = try transCreateNodeBuiltinFnCall(rp.c, "@ptrToInt"); - try ptr_to_int.params.push(try transExpr(rp, scope, sub_expr, .used, .r_value)); - ptr_to_int.rparen_token = try appendToken(rp.c, .RParen, ")"); - try cast_node.params.push(&ptr_to_int.base); - cast_node.rparen_token = try appendToken(rp.c, .RParen, ")"); - return maybeSuppressResult(rp, scope, result_used, &cast_node.base); - }, - .IntegralToPointer => { - // @intToPtr(dest_type, val) - const int_to_ptr = try transCreateNodeBuiltinFnCall(rp.c, "@intToPtr"); - try int_to_ptr.params.push(try transQualType(rp, dest_type, ZigClangImplicitCastExpr_getBeginLoc(expr))); - _ = try appendToken(rp.c, .Comma, ","); - - try int_to_ptr.params.push(try transExpr(rp, scope, sub_expr, .used, .r_value)); - int_to_ptr.rparen_token = try appendToken(rp.c, .RParen, ")"); - return maybeSuppressResult(rp, scope, result_used, &int_to_ptr.base); - }, else => |kind| return revertAndWarn( rp, error.UnsupportedTranslation, @@ -1509,8 +1486,18 @@ fn transCCast( if (ZigClangQualType_eq(dst_type, src_type)) return expr; if (qualTypeIsPtr(dst_type) and qualTypeIsPtr(src_type)) return transCPtrCast(rp, loc, dst_type, src_type, expr); - if (cIsUnsignedInteger(dst_type) and qualTypeIsPtr(src_type)) { - const cast_node = try transCreateNodeBuiltinFnCall(rp.c, "@as"); + if (cIsInteger(dst_type) and cIsInteger(src_type)) { + // @intCast(dest_type, val) + const cast_node = try transCreateNodeBuiltinFnCall(rp.c, "@intCast"); + try cast_node.params.push(try transQualType(rp, dst_type, loc)); + _ = try appendToken(rp.c, .Comma, ","); + try cast_node.params.push(expr); + cast_node.rparen_token = try appendToken(rp.c, .RParen, ")"); + return &cast_node.base; + } + if (cIsInteger(dst_type) and qualTypeIsPtr(src_type)) { + // @intCast(dest_type, @ptrToInt(val)) + const cast_node = try transCreateNodeBuiltinFnCall(rp.c, "@intCast"); try cast_node.params.push(try transQualType(rp, dst_type, loc)); _ = try appendToken(rp.c, .Comma, ","); const builtin_node = try transCreateNodeBuiltinFnCall(rp.c, "@ptrToInt"); @@ -1520,7 +1507,8 @@ fn transCCast( cast_node.rparen_token = try appendToken(rp.c, .RParen, ")"); return &cast_node.base; } - if (cIsUnsignedInteger(src_type) and qualTypeIsPtr(dst_type)) { + if (cIsInteger(src_type) and qualTypeIsPtr(dst_type)) { + // @intToPtr(dest_type, val) const builtin_node = try transCreateNodeBuiltinFnCall(rp.c, "@intToPtr"); try builtin_node.params.push(try transQualType(rp, dst_type, loc)); _ = try appendToken(rp.c, .Comma, ","); @@ -2870,6 +2858,10 @@ fn typeIsOpaque(c: *Context, ty: *const ZigClangType, loc: ZigClangSourceLocatio } } +fn cIsInteger(qt: ZigClangQualType) bool { + return cIsSignedInteger(qt) or cIsUnsignedInteger(qt); +} + fn cIsUnsignedInteger(qt: ZigClangQualType) bool { const c_type = qualTypeCanon(qt); if (ZigClangType_getTypeClass(c_type) != .Builtin) return false; diff --git a/test/translate_c.zig b/test/translate_c.zig index 6e6ddada3a..f2404753b2 100644 --- a/test/translate_c.zig +++ b/test/translate_c.zig @@ -21,9 +21,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() void { \\ var a: c_int = undefined; - \\ var b: u8 = @as(u8, 123); + \\ var b: u8 = @intCast(u8, 123); \\ const c: c_int = undefined; - \\ const d: c_uint = @as(c_uint, 440); + \\ const d: c_uint = @intCast(c_uint, 440); \\} }); @@ -110,7 +110,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub extern fn foo() void; \\pub export fn bar() void { \\ var func_ptr: ?*c_void = @ptrCast(?*c_void, foo); - \\ var typed_func_ptr: ?extern fn () void = @intToPtr(?extern fn () void, @as(c_ulong, @ptrToInt(func_ptr))); + \\ var typed_func_ptr: ?extern fn () void = @intToPtr(?extern fn () void, @intCast(c_ulong, @ptrToInt(func_ptr))); \\} }); @@ -855,7 +855,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub fn foo() void { \\ var arr: [10]u8 = .{ - \\ @as(u8, 1), + \\ @intCast(u8, 1), \\ } ++ .{0} ** 9; \\ var arr1: [10][*c]u8 = .{ \\ null, @@ -1082,18 +1082,18 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ unsigned d = 440; \\} , &[_][]const u8{ - \\pub var a: c_long = @as(c_long, 2); - \\pub var b: c_long = @as(c_long, 2); + \\pub var a: c_long = @intCast(c_long, 2); + \\pub var b: c_long = @intCast(c_long, 2); \\pub var c: c_int = 4; \\pub export fn foo(_arg_c_1: u8) void { \\ var c_1 = _arg_c_1; \\ var a_2: c_int = undefined; - \\ var b_3: u8 = @as(u8, 123); - \\ b_3 = @as(u8, a_2); + \\ var b_3: u8 = @intCast(u8, 123); + \\ b_3 = @intCast(u8, a_2); \\ { \\ var d: c_int = 5; \\ } - \\ var d: c_uint = @as(c_uint, 440); + \\ var d: c_uint = @intCast(c_uint, 440); \\} }); @@ -1216,14 +1216,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ _ = 7; \\ } \\ } - \\ var i: u8 = @as(u8, 2); + \\ var i: u8 = @intCast(u8, 2); \\} }); cases.add("shadowing primitive types", \\unsigned anyerror = 2; , &[_][]const u8{ - \\pub export var _anyerror: c_uint = @as(c_uint, 2); + \\pub export var _anyerror: c_uint = @intCast(c_uint, 2); }); cases.add("floats", @@ -1397,17 +1397,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ , &[_][]const u8{ \\pub export fn escapes() [*c]const u8 { - \\ var a: u8 = @as(u8, '\''); - \\ var b: u8 = @as(u8, '\\'); - \\ var c: u8 = @as(u8, '\x07'); - \\ var d: u8 = @as(u8, '\x08'); - \\ var e: u8 = @as(u8, '\x0c'); - \\ var f: u8 = @as(u8, '\n'); - \\ var g: u8 = @as(u8, '\r'); - \\ var h: u8 = @as(u8, '\t'); - \\ var i: u8 = @as(u8, '\x0b'); - \\ var j: u8 = @as(u8, '\x00'); - \\ var k: u8 = @as(u8, '\"'); + \\ var a: u8 = @intCast(u8, '\''); + \\ var b: u8 = @intCast(u8, '\\'); + \\ var c: u8 = @intCast(u8, '\x07'); + \\ var d: u8 = @intCast(u8, '\x08'); + \\ var e: u8 = @intCast(u8, '\x0c'); + \\ var f: u8 = @intCast(u8, '\n'); + \\ var g: u8 = @intCast(u8, '\r'); + \\ var h: u8 = @intCast(u8, '\t'); + \\ var i: u8 = @intCast(u8, '\x0b'); + \\ var j: u8 = @intCast(u8, '\x00'); + \\ var k: u8 = @intCast(u8, '\"'); \\ return "\'\\\x07\x08\x0c\n\r\t\x0b\x00\""; \\} }); @@ -1818,7 +1818,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() void { \\ var i: c_int = 0; - \\ var u: c_uint = @as(c_uint, 0); + \\ var u: c_uint = @intCast(c_uint, 0); \\ i += 1; \\ i -= 1; \\ u +%= 1; @@ -1858,7 +1858,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub export fn log2(_arg_a: c_uint) c_int { \\ var a = _arg_a; \\ var i: c_int = 0; - \\ while (a > @as(c_uint, 0)) { + \\ while (a > @intCast(c_uint, 0)) { \\ a >>= @as(@import("std").math.Log2Int(c_int), 1); \\ } \\ return i; @@ -1878,7 +1878,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub export fn log2(_arg_a: u32) c_int { \\ var a = _arg_a; \\ var i: c_int = 0; - \\ while (a > @as(c_uint, 0)) { + \\ while (a > @intCast(c_uint, 0)) { \\ a >>= @as(@import("std").math.Log2Int(c_int), 1); \\ } \\ return i; @@ -1957,35 +1957,35 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\} , &[_][]const u8{ \\pub export fn foo() void { - \\ var a: c_uint = @as(c_uint, 0); + \\ var a: c_uint = @intCast(c_uint, 0); \\ a +%= (blk: { \\ const _ref_1 = &a; - \\ _ref_1.* = _ref_1.* +% @as(c_uint, 1); + \\ _ref_1.* = _ref_1.* +% @intCast(c_uint, 1); \\ break :blk _ref_1.*; \\ }); \\ a -%= (blk: { \\ const _ref_2 = &a; - \\ _ref_2.* = _ref_2.* -% @as(c_uint, 1); + \\ _ref_2.* = _ref_2.* -% @intCast(c_uint, 1); \\ break :blk _ref_2.*; \\ }); \\ a *%= (blk: { \\ const _ref_3 = &a; - \\ _ref_3.* = _ref_3.* *% @as(c_uint, 1); + \\ _ref_3.* = _ref_3.* *% @intCast(c_uint, 1); \\ break :blk _ref_3.*; \\ }); \\ a &= (blk: { \\ const _ref_4 = &a; - \\ _ref_4.* = _ref_4.* & @as(c_uint, 1); + \\ _ref_4.* = _ref_4.* & @intCast(c_uint, 1); \\ break :blk _ref_4.*; \\ }); \\ a |= (blk: { \\ const _ref_5 = &a; - \\ _ref_5.* = _ref_5.* | @as(c_uint, 1); + \\ _ref_5.* = _ref_5.* | @intCast(c_uint, 1); \\ break :blk _ref_5.*; \\ }); \\ a ^= (blk: { \\ const _ref_6 = &a; - \\ _ref_6.* = _ref_6.* ^ @as(c_uint, 1); + \\ _ref_6.* = _ref_6.* ^ @intCast(c_uint, 1); \\ break :blk _ref_6.*; \\ }); \\ a >>= @as(@import("std").math.Log2Int(c_uint), (blk: { @@ -2017,7 +2017,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { , &[_][]const u8{ \\pub export fn foo() void { \\ var i: c_int = 0; - \\ var u: c_uint = @as(c_uint, 0); + \\ var u: c_uint = @intCast(c_uint, 0); \\ i += 1; \\ i -= 1; \\ u +%= 1; @@ -2092,9 +2092,9 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ fn_int(1094861636); \\ fn_f32(@intToFloat(f32, 3)); \\ fn_f64(@intToFloat(f64, 3)); - \\ fn_char(@as(u8, '3')); - \\ fn_char(@as(u8, '\x01')); - \\ fn_char(@as(u8, 0)); + \\ fn_char(@intCast(u8, '3')); + \\ fn_char(@intCast(u8, '\x01')); + \\ fn_char(@intCast(u8, 0)); \\ fn_f32(3); \\ fn_f64(3); \\ fn_bool(123 != 0);