authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-18 15:00:14-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-18 15:00:14-04:00
log8c77c5705f41e55a5f2d80db20270d0c644338ed
treed3316a485f7e86d99127439f6e7487a6f6df550c
parent5fd3af9dc6ef08f23e6b64dfa6d6776371f9344a
signaturelock-open Commit is signed but in an unrecognized format.

implementation for bitcasting extern enum type to c_int

closes #1036

2 files changed, 22 insertions(+), 2 deletions(-)

src/ir.cpp+5-2
...@@ -20254,6 +20254,11 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue...@@ -20254,6 +20254,11 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
20254 bigint_write_twos_complement(&val->data.x_bigint, buf, val->type->data.integral.bit_count,20254 bigint_write_twos_complement(&val->data.x_bigint, buf, val->type->data.integral.bit_count,
20255 codegen->is_big_endian);20255 codegen->is_big_endian);
20256 return;20256 return;
20257 case ZigTypeIdEnum:
20258 bigint_write_twos_complement(&val->data.x_enum_tag, buf,
20259 val->type->data.enumeration.tag_int_type->data.integral.bit_count,
20260 codegen->is_big_endian);
20261 return;
20257 case ZigTypeIdFloat:20262 case ZigTypeIdFloat:
20258 float_write_ieee597(val, buf, codegen->is_big_endian);20263 float_write_ieee597(val, buf, codegen->is_big_endian);
20259 return;20264 return;
...@@ -20285,8 +20290,6 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue...@@ -20285,8 +20290,6 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
20285 zig_panic("TODO buf_write_value_bytes error union");20290 zig_panic("TODO buf_write_value_bytes error union");
20286 case ZigTypeIdErrorSet:20291 case ZigTypeIdErrorSet:
20287 zig_panic("TODO buf_write_value_bytes pure error type");20292 zig_panic("TODO buf_write_value_bytes pure error type");
20288 case ZigTypeIdEnum:
20289 zig_panic("TODO buf_write_value_bytes enum type");
20290 case ZigTypeIdFn:20293 case ZigTypeIdFn:
20291 zig_panic("TODO buf_write_value_bytes fn type");20294 zig_panic("TODO buf_write_value_bytes fn type");
20292 case ZigTypeIdUnion:20295 case ZigTypeIdUnion:
test/cases/bitcast.zig+17
...@@ -16,3 +16,20 @@ fn conv(x: i32) u32 {...@@ -16,3 +16,20 @@ fn conv(x: i32) u32 {
16fn conv2(x: u32) i32 {16fn conv2(x: u32) i32 {
17 return @bitCast(i32, x);17 return @bitCast(i32, x);
18}18}
19
20test "@bitCast extern enum to its integer type" {
21 const SOCK = extern enum {
22 A,
23 B,
24
25 fn testBitCastExternEnum() void {
26 var SOCK_DGRAM = @This().B;
27 var sock_dgram = @bitCast(c_int, SOCK_DGRAM);
28 assert(sock_dgram == 1);
29 }
30 };
31
32 SOCK.testBitCastExternEnum();
33 comptime SOCK.testBitCastExternEnum();
34}
35