authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-02-16 16:34:37+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-02-16 16:40:43+02:00
log9a826ccbe0b10046e5dd7c482e9e87912c0fa95c
tree4bc4ca5c768e52ce457d27e8c193b3cdd3c4b7c4
parent74e9d4ca820f9940b47ae658c41e7edb315681c8
signature Commit is signed but in an unrecognized format.

translate-c: elide some unecessary casts of literals


5 files changed, 104 insertions(+), 54 deletions(-)

src/clang.zig+4-1
...@@ -127,6 +127,9 @@ pub const APSInt = opaque {...@@ -127,6 +127,9 @@ pub const APSInt = opaque {
127127
128 pub const getNumWords = ZigClangAPSInt_getNumWords;128 pub const getNumWords = ZigClangAPSInt_getNumWords;
129 extern fn ZigClangAPSInt_getNumWords(*const APSInt) c_uint;129 extern fn ZigClangAPSInt_getNumWords(*const APSInt) c_uint;
130
131 pub const lessThanEqual = ZigClangAPSInt_lessThanEqual;
132 extern fn ZigClangAPSInt_lessThanEqual(*const APSInt, rhs: u64) bool;
130};133};
131134
132pub const ASTContext = opaque {135pub const ASTContext = opaque {
...@@ -407,7 +410,7 @@ pub const Expr = opaque {...@@ -407,7 +410,7 @@ pub const Expr = opaque {
407 pub const getBeginLoc = ZigClangExpr_getBeginLoc;410 pub const getBeginLoc = ZigClangExpr_getBeginLoc;
408 extern fn ZigClangExpr_getBeginLoc(*const Expr) SourceLocation;411 extern fn ZigClangExpr_getBeginLoc(*const Expr) SourceLocation;
409412
410 pub const EvaluateAsConstantExpr = ZigClangExpr_EvaluateAsConstantExpr;413 pub const evaluateAsConstantExpr = ZigClangExpr_EvaluateAsConstantExpr;
411 extern fn ZigClangExpr_EvaluateAsConstantExpr(*const Expr, *ExprEvalResult, Expr_ConstExprUsage, *const ASTContext) bool;414 extern fn ZigClangExpr_EvaluateAsConstantExpr(*const Expr, *ExprEvalResult, Expr_ConstExprUsage, *const ASTContext) bool;
412};415};
413416
src/translate_c.zig+47-5
...@@ -1820,11 +1820,55 @@ fn transExprCoercing(c: *Context, scope: *Scope, expr: *const clang.Expr, used:...@@ -1820,11 +1820,55 @@ fn transExprCoercing(c: *Context, scope: *Scope, expr: *const clang.Expr, used:
1820 return transExprCoercing(c, scope, un_expr.getSubExpr(), used);1820 return transExprCoercing(c, scope, un_expr.getSubExpr(), used);
1821 }1821 }
1822 },1822 },
1823 .ImplicitCastExprClass => {
1824 const cast_expr = @ptrCast(*const clang.ImplicitCastExpr, expr);
1825 const sub_expr = cast_expr.getSubExpr();
1826 switch (@ptrCast(*const clang.Stmt, sub_expr).getStmtClass()) {
1827 .IntegerLiteralClass, .CharacterLiteralClass => switch (cast_expr.getCastKind()) {
1828 .IntegralToFloating => return transExprCoercing(c, scope, sub_expr, used),
1829 .IntegralCast => {
1830 const dest_type = getExprQualType(c, expr);
1831 if (literalFitsInType(c, sub_expr, dest_type))
1832 return transExprCoercing(c, scope, sub_expr, used);
1833 },
1834 else => {},
1835 },
1836 else => {},
1837 }
1838 },
1823 else => {},1839 else => {},
1824 }1840 }
1825 return transExpr(c, scope, expr, .used);1841 return transExpr(c, scope, expr, .used);
1826}1842}
18271843
1844fn literalFitsInType(c: *Context, expr: *const clang.Expr, qt: clang.QualType) bool {
1845 var width = qualTypeIntBitWidth(c, qt) catch 8;
1846 if (width == 0) width = 8; // Byte is the smallest type.
1847 const is_signed = cIsSignedInteger(qt);
1848 const width_max_int= (@as(u64, 1) << math.lossyCast(u6, width - @boolToInt(is_signed))) - 1;
1849
1850 switch (@ptrCast(*const clang.Stmt, expr).getStmtClass()) {
1851 .CharacterLiteralClass => {
1852 const char_lit = @ptrCast(*const clang.CharacterLiteral, expr);
1853 const val = char_lit.getValue();
1854 // If the val is less than the max int then it fits.
1855 return val <= width_max_int;
1856 },
1857 .IntegerLiteralClass => {
1858 const int_lit = @ptrCast(*const clang.IntegerLiteral, expr);
1859 var eval_result: clang.ExprEvalResult = undefined;
1860 if (!int_lit.EvaluateAsInt(&eval_result, c.clang_context)) {
1861 return false;
1862 }
1863
1864 const int = eval_result.Val.getInt();
1865 return int.lessThanEqual(width_max_int);
1866 },
1867 else => unreachable,
1868 }
1869
1870}
1871
1828fn transInitListExprRecord(1872fn transInitListExprRecord(
1829 c: *Context,1873 c: *Context,
1830 scope: *Scope,1874 scope: *Scope,
...@@ -2331,7 +2375,7 @@ fn transDefault(...@@ -2331,7 +2375,7 @@ fn transDefault(
23312375
2332fn transConstantExpr(c: *Context, scope: *Scope, expr: *const clang.Expr, used: ResultUsed) TransError!Node {2376fn transConstantExpr(c: *Context, scope: *Scope, expr: *const clang.Expr, used: ResultUsed) TransError!Node {
2333 var result: clang.ExprEvalResult = undefined;2377 var result: clang.ExprEvalResult = undefined;
2334 if (!expr.EvaluateAsConstantExpr(&result, .EvaluateForCodeGen, c.clang_context))2378 if (!expr.evaluateAsConstantExpr(&result, .EvaluateForCodeGen, c.clang_context))
2335 return fail(c, error.UnsupportedTranslation, expr.getBeginLoc(), "invalid constant expression", .{});2379 return fail(c, error.UnsupportedTranslation, expr.getBeginLoc(), "invalid constant expression", .{});
23362380
2337 switch (result.Val.getKind()) {2381 switch (result.Val.getKind()) {
...@@ -3171,7 +3215,7 @@ fn qualTypeIsBoolean(qt: clang.QualType) bool {...@@ -3171,7 +3215,7 @@ fn qualTypeIsBoolean(qt: clang.QualType) bool {
3171 return qualTypeCanon(qt).isBooleanType();3215 return qualTypeCanon(qt).isBooleanType();
3172}3216}
31733217
3174fn qualTypeIntBitWidth(c: *Context, qt: clang.QualType, source_loc: clang.SourceLocation) !u32 {3218fn qualTypeIntBitWidth(c: *Context, qt: clang.QualType) !u32 {
3175 const ty = qt.getTypePtr();3219 const ty = qt.getTypePtr();
31763220
3177 switch (ty.getTypeClass()) {3221 switch (ty.getTypeClass()) {
...@@ -3211,12 +3255,10 @@ fn qualTypeIntBitWidth(c: *Context, qt: clang.QualType, source_loc: clang.Source...@@ -3211,12 +3255,10 @@ fn qualTypeIntBitWidth(c: *Context, qt: clang.QualType, source_loc: clang.Source
3211 },3255 },
3212 else => return 0,3256 else => return 0,
3213 }3257 }
3214
3215 unreachable;
3216}3258}
32173259
3218fn qualTypeToLog2IntRef(c: *Context, qt: clang.QualType, source_loc: clang.SourceLocation) !Node {3260fn qualTypeToLog2IntRef(c: *Context, qt: clang.QualType, source_loc: clang.SourceLocation) !Node {
3219 const int_bit_width = try qualTypeIntBitWidth(c, qt, source_loc);3261 const int_bit_width = try qualTypeIntBitWidth(c, qt);
32203262
3221 if (int_bit_width != 0) {3263 if (int_bit_width != 0) {
3222 // we can perform the log2 now.3264 // we can perform the log2 now.
src/zig_clang.cpp+5
...@@ -2244,6 +2244,11 @@ unsigned ZigClangAPSInt_getNumWords(const ZigClangAPSInt *self) {...@@ -2244,6 +2244,11 @@ unsigned ZigClangAPSInt_getNumWords(const ZigClangAPSInt *self) {
2244 return casted->getNumWords();2244 return casted->getNumWords();
2245}2245}
22462246
2247bool ZigClangAPSInt_lessThanEqual(const ZigClangAPSInt *self, uint64_t rhs) {
2248 auto casted = reinterpret_cast<const llvm::APSInt *>(self);
2249 return casted->ule(rhs);
2250}
2251
2247uint64_t ZigClangAPInt_getLimitedValue(const ZigClangAPInt *self, uint64_t limit) {2252uint64_t ZigClangAPInt_getLimitedValue(const ZigClangAPInt *self, uint64_t limit) {
2248 auto casted = reinterpret_cast<const llvm::APInt *>(self);2253 auto casted = reinterpret_cast<const llvm::APInt *>(self);
2249 return casted->getLimitedValue(limit);2254 return casted->getLimitedValue(limit);
src/zig_clang.h+1
...@@ -1097,6 +1097,7 @@ ZIG_EXTERN_C const struct ZigClangAPSInt *ZigClangAPSInt_negate(const struct Zig...@@ -1097,6 +1097,7 @@ ZIG_EXTERN_C const struct ZigClangAPSInt *ZigClangAPSInt_negate(const struct Zig
1097ZIG_EXTERN_C void ZigClangAPSInt_free(const struct ZigClangAPSInt *self);1097ZIG_EXTERN_C void ZigClangAPSInt_free(const struct ZigClangAPSInt *self);
1098ZIG_EXTERN_C const uint64_t *ZigClangAPSInt_getRawData(const struct ZigClangAPSInt *self);1098ZIG_EXTERN_C const uint64_t *ZigClangAPSInt_getRawData(const struct ZigClangAPSInt *self);
1099ZIG_EXTERN_C unsigned ZigClangAPSInt_getNumWords(const struct ZigClangAPSInt *self);1099ZIG_EXTERN_C unsigned ZigClangAPSInt_getNumWords(const struct ZigClangAPSInt *self);
1100ZIG_EXTERN_C bool ZigClangAPSInt_lessThanEqual(const struct ZigClangAPSInt *self, uint64_t rhs);
11001101
1101ZIG_EXTERN_C uint64_t ZigClangAPInt_getLimitedValue(const struct ZigClangAPInt *self, uint64_t limit);1102ZIG_EXTERN_C uint64_t ZigClangAPInt_getLimitedValue(const struct ZigClangAPInt *self, uint64_t limit);
11021103
test/translate_c.zig+47-48
...@@ -313,22 +313,22 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -313,22 +313,22 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
313 , &[_][]const u8{313 , &[_][]const u8{
314 \\pub const uuid_t = [16]u8;314 \\pub const uuid_t = [16]u8;
315 \\pub const UUID_NULL: uuid_t = [16]u8{315 \\pub const UUID_NULL: uuid_t = [16]u8{
316 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),316 \\ 0,
317 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),317 \\ 0,
318 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),318 \\ 0,
319 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),319 \\ 0,
320 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),320 \\ 0,
321 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),321 \\ 0,
322 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),322 \\ 0,
323 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),323 \\ 0,
324 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),324 \\ 0,
325 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),325 \\ 0,
326 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),326 \\ 0,
327 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),327 \\ 0,
328 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),328 \\ 0,
329 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),329 \\ 0,
330 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),330 \\ 0,
331 \\ @bitCast(u8, @truncate(i8, @as(c_int, 0))),331 \\ 0,
332 \\};332 \\};
333 });333 });
334334
...@@ -382,10 +382,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -382,10 +382,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
382 \\};382 \\};
383 \\pub export var ub: union_unnamed_1 = union_unnamed_1{383 \\pub export var ub: union_unnamed_1 = union_unnamed_1{
384 \\ .c = [4]u8{384 \\ .c = [4]u8{
385 \\ @bitCast(u8, @truncate(i8, @as(c_int, 'a'))),385 \\ 'a',
386 \\ @bitCast(u8, @truncate(i8, @as(c_int, 'b'))),386 \\ 'b',
387 \\ @bitCast(u8, @truncate(i8, @as(c_int, 'b'))),387 \\ 'b',
388 \\ @bitCast(u8, @truncate(i8, @as(c_int, 'a'))),388 \\ 'a',
389 \\ },389 \\ },
390 \\};390 \\};
391 });391 });
...@@ -512,7 +512,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -512,7 +512,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
512 , &[_][]const u8{512 , &[_][]const u8{
513 \\pub export fn foo() void {513 \\pub export fn foo() void {
514 \\ var a: c_int = undefined;514 \\ var a: c_int = undefined;
515 \\ var b: u8 = @bitCast(u8, @truncate(i8, @as(c_int, 123)));515 \\ var b: u8 = 123;
516 \\ const c: c_int = undefined;516 \\ const c: c_int = undefined;
517 \\ const d: c_uint = @bitCast(c_uint, @as(c_int, 440));517 \\ const d: c_uint = @bitCast(c_uint, @as(c_int, 440));
518 \\ var e: c_int = 10;518 \\ var e: c_int = 10;
...@@ -1468,7 +1468,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1468,7 +1468,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1468 , &[_][]const u8{1468 , &[_][]const u8{
1469 \\pub fn foo() callconv(.C) void {1469 \\pub fn foo() callconv(.C) void {
1470 \\ var arr: [10]u8 = [1]u8{1470 \\ var arr: [10]u8 = [1]u8{
1471 \\ @bitCast(u8, @truncate(i8, @as(c_int, 1))),1471 \\ 1,
1472 \\ } ++ [1]u8{0} ** 9;1472 \\ } ++ [1]u8{0} ** 9;
1473 \\ var arr1: [10][*c]u8 = [1][*c]u8{1473 \\ var arr1: [10][*c]u8 = [1][*c]u8{
1474 \\ null,1474 \\ null,
...@@ -1721,13 +1721,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1721,13 +1721,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1721 \\ unsigned d = 440;1721 \\ unsigned d = 440;
1722 \\}1722 \\}
1723 , &[_][]const u8{1723 , &[_][]const u8{
1724 \\pub var a: c_long = @bitCast(c_long, @as(c_long, @as(c_int, 2)));1724 \\pub var a: c_long = 2;
1725 \\pub var b: c_long = @bitCast(c_long, @as(c_long, @as(c_int, 2)));1725 \\pub var b: c_long = 2;
1726 \\pub var c: c_int = 4;1726 \\pub var c: c_int = 4;
1727 \\pub export fn foo(arg_c_1: u8) void {1727 \\pub export fn foo(arg_c_1: u8) void {
1728 \\ var c_1 = arg_c_1;1728 \\ var c_1 = arg_c_1;
1729 \\ var a_2: c_int = undefined;1729 \\ var a_2: c_int = undefined;
1730 \\ var b_3: u8 = @bitCast(u8, @truncate(i8, @as(c_int, 123)));1730 \\ var b_3: u8 = 123;
1731 \\ b_3 = @bitCast(u8, @truncate(i8, a_2));1731 \\ b_3 = @bitCast(u8, @truncate(i8, a_2));
1732 \\ {1732 \\ {
1733 \\ var d: c_int = 5;1733 \\ var d: c_int = 5;
...@@ -1838,7 +1838,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1838,7 +1838,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1838 \\ };1838 \\ };
1839 \\ }1839 \\ }
1840 \\ }1840 \\ }
1841 \\ var i: u8 = @bitCast(u8, @truncate(i8, @as(c_int, 2)));1841 \\ var i: u8 = 2;
1842 \\}1842 \\}
1843 });1843 });
18441844
...@@ -1846,7 +1846,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1846,7 +1846,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1846 \\unsigned anyerror = 2;1846 \\unsigned anyerror = 2;
1847 \\#define noreturn _Noreturn1847 \\#define noreturn _Noreturn
1848 , &[_][]const u8{1848 , &[_][]const u8{
1849 \\pub export var anyerror_1: c_uint = @bitCast(c_uint, @as(c_int, 2));1849 \\pub export var anyerror_1: c_uint = 2;
1850 ,1850 ,
1851 \\pub const noreturn_2 = @compileError("unable to translate C expr: unexpected token .Keyword_noreturn");1851 \\pub const noreturn_2 = @compileError("unable to translate C expr: unexpected token .Keyword_noreturn");
1852 });1852 });
...@@ -1860,7 +1860,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1860,7 +1860,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1860 \\pub export var a: f32 = @floatCast(f32, 3.1415);1860 \\pub export var a: f32 = @floatCast(f32, 3.1415);
1861 \\pub export var b: f64 = 3.1415;1861 \\pub export var b: f64 = 3.1415;
1862 \\pub export var c: c_int = @floatToInt(c_int, 3.1415);1862 \\pub export var c: c_int = @floatToInt(c_int, 3.1415);
1863 \\pub export var d: f64 = @intToFloat(f64, @as(c_int, 3));1863 \\pub export var d: f64 = 3;
1864 });1864 });
18651865
1866 cases.add("conditional operator",1866 cases.add("conditional operator",
...@@ -2009,7 +2009,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2009,7 +2009,6 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2009 \\}2009 \\}
2010 });2010 });
20112011
2012 // TODO translate-c should in theory be able to figure out to drop all these casts
2013 cases.add("escape sequences",2012 cases.add("escape sequences",
2014 \\const char *escapes() {2013 \\const char *escapes() {
2015 \\char a = '\'',2014 \\char a = '\'',
...@@ -2028,17 +2027,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2028,17 +2027,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2028 \\2027 \\
2029 , &[_][]const u8{2028 , &[_][]const u8{
2030 \\pub export fn escapes() [*c]const u8 {2029 \\pub export fn escapes() [*c]const u8 {
2031 \\ var a: u8 = @bitCast(u8, @truncate(i8, @as(c_int, '\'')));2030 \\ var a: u8 = '\'';
2032 \\ var b: u8 = @bitCast(u8, @truncate(i8, @as(c_int, '\\')));2031 \\ var b: u8 = '\\';
2033 \\ var c: u8 = @bitCast(u8, @truncate(i8, @as(c_int, '\x07')));2032 \\ var c: u8 = '\x07';
2034 \\ var d: u8 = @bitCast(u8, @truncate(i8, @as(c_int, '\x08')));2033 \\ var d: u8 = '\x08';
2035 \\ var e: u8 = @bitCast(u8, @truncate(i8, @as(c_int, '\x0c')));2034 \\ var e: u8 = '\x0c';
2036 \\ var f: u8 = @bitCast(u8, @truncate(i8, @as(c_int, '\n')));2035 \\ var f: u8 = '\n';
2037 \\ var g: u8 = @bitCast(u8, @truncate(i8, @as(c_int, '\r')));2036 \\ var g: u8 = '\r';
2038 \\ var h: u8 = @bitCast(u8, @truncate(i8, @as(c_int, '\t')));2037 \\ var h: u8 = '\t';
2039 \\ var i: u8 = @bitCast(u8, @truncate(i8, @as(c_int, '\x0b')));2038 \\ var i: u8 = '\x0b';
2040 \\ var j: u8 = @bitCast(u8, @truncate(i8, @as(c_int, '\x00')));2039 \\ var j: u8 = '\x00';
2041 \\ var k: u8 = @bitCast(u8, @truncate(i8, @as(c_int, '\"')));2040 \\ var k: u8 = '\"';
2042 \\ return "\'\\\x07\x08\x0c\n\r\t\x0b\x00\"";2041 \\ return "\'\\\x07\x08\x0c\n\r\t\x0b\x00\"";
2043 \\}2042 \\}
2044 });2043 });
...@@ -2308,8 +2307,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2308,8 +2307,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2308 , &[_][]const u8{2307 , &[_][]const u8{
2309 \\pub export fn foo() void {2308 \\pub export fn foo() void {
2310 \\ var a: [10]c_longlong = undefined;2309 \\ var a: [10]c_longlong = undefined;
2311 \\ var i: c_longlong = @bitCast(c_longlong, @as(c_longlong, @as(c_int, 0)));2310 \\ var i: c_longlong = 0;
2312 \\ a[@intCast(usize, i)] = @bitCast(c_longlong, @as(c_longlong, @as(c_int, 0)));2311 \\ a[@intCast(usize, i)] = 0;
2313 \\}2312 \\}
2314 });2313 });
23152314
...@@ -2321,8 +2320,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2321,8 +2320,8 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2321 , &[_][]const u8{2320 , &[_][]const u8{
2322 \\pub export fn foo() void {2321 \\pub export fn foo() void {
2323 \\ var a: [10]c_uint = undefined;2322 \\ var a: [10]c_uint = undefined;
2324 \\ var i: c_uint = @bitCast(c_uint, @as(c_int, 0));2323 \\ var i: c_uint = 0;
2325 \\ a[i] = @bitCast(c_uint, @as(c_int, 0));2324 \\ a[i] = 0;
2326 \\}2325 \\}
2327 });2326 });
23282327
...@@ -2527,7 +2526,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2527,7 +2526,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2527 , &[_][]const u8{2526 , &[_][]const u8{
2528 \\pub export fn foo() void {2527 \\pub export fn foo() void {
2529 \\ var i: c_int = 0;2528 \\ var i: c_int = 0;
2530 \\ var u: c_uint = @bitCast(c_uint, @as(c_int, 0));2529 \\ var u: c_uint = 0;
2531 \\ i += 1;2530 \\ i += 1;
2532 \\ i -= 1;2531 \\ i -= 1;
2533 \\ u +%= 1;2532 \\ u +%= 1;
...@@ -2614,7 +2613,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2614,7 +2613,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2614 , &[_][]const u8{2613 , &[_][]const u8{
2615 \\pub export fn foo() void {2614 \\pub export fn foo() void {
2616 \\ var a: c_int = 0;2615 \\ var a: c_int = 0;
2617 \\ var b: c_uint = @bitCast(c_uint, @as(c_int, 0));2616 \\ var b: c_uint = 0;
2618 \\ a += blk: {2617 \\ a += blk: {
2619 \\ const ref = &a;2618 \\ const ref = &a;
2620 \\ ref.* += @as(c_int, 1);2619 \\ ref.* += @as(c_int, 1);
...@@ -2692,7 +2691,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2692,7 +2691,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2692 \\}2691 \\}
2693 , &[_][]const u8{2692 , &[_][]const u8{
2694 \\pub export fn foo() void {2693 \\pub export fn foo() void {
2695 \\ var a: c_uint = @bitCast(c_uint, @as(c_int, 0));2694 \\ var a: c_uint = 0;
2696 \\ a +%= blk: {2695 \\ a +%= blk: {
2697 \\ const ref = &a;2696 \\ const ref = &a;
2698 \\ ref.* +%= @bitCast(c_uint, @as(c_int, 1));2697 \\ ref.* +%= @bitCast(c_uint, @as(c_int, 1));
...@@ -2752,7 +2751,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -2752,7 +2751,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2752 , &[_][]const u8{2751 , &[_][]const u8{
2753 \\pub export fn foo() void {2752 \\pub export fn foo() void {
2754 \\ var i: c_int = 0;2753 \\ var i: c_int = 0;
2755 \\ var u: c_uint = @bitCast(c_uint, @as(c_int, 0));2754 \\ var u: c_uint = 0;
2756 \\ i += 1;2755 \\ i += 1;
2757 \\ i -= 1;2756 \\ i -= 1;
2758 \\ u +%= 1;2757 \\ u +%= 1;