Skip to content
This repository was archived by the owner on Nov 26, 2025. It is now read-only.

Commit efc6480

Browse files
steeveVexu
authored andcommitted
Fix incomplete bitCast in bit shifts
Closes #217
1 parent a8bd558 commit efc6480

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/Translator.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2681,7 +2681,7 @@ fn transShiftExpr(t: *Translator, scope: *Scope, bin: Node.Binary, op_id: ZigTag
26812681
// lhs >> @intCast(rh)
26822682
const lhs = try t.transExpr(scope, bin.lhs, .used);
26832683

2684-
const rhs = try t.transExprCoercing(scope, bin.rhs, .used);
2684+
const rhs = try t.transExpr(scope, bin.rhs, .used);
26852685
const rhs_casted = try ZigTag.int_cast.create(t.arena, rhs);
26862686

26872687
return t.createBinOpNode(op_id, lhs, rhs_casted);

test/cases/translate/bitshift.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ int foo(void) {
55
// translate
66
//
77
// pub export fn foo() c_int {
8-
// return (@as(c_int, 1) << @intCast(2)) >> @intCast(1);
8+
// return (@as(c_int, 1) << @intCast(@as(c_int, 2))) >> @intCast(@as(c_int, 1));
99
// }
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
unsigned int bit31() {
2+
return 1u << (31);
3+
}
4+
5+
// translate
6+
//
7+
// pub export fn bit31() c_uint {
8+
// return @as(c_uint, 1) << @intCast(@as(c_uint, @bitCast(@as(c_int, @as(c_int, 31)))));
9+
// }

0 commit comments

Comments
 (0)