Merge pull request #17438 from Luukdegram/issue-17436

wasm - fix `@tagName` for signed enums
This commit is contained in:
Luuk de Gram 2023-10-08 21:58:35 +02:00 committed by GitHub
commit 54e7f58fcb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View File

@ -7215,12 +7215,12 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
switch (tag_value) {
.imm32 => |value| {
try writer.writeByte(std.wasm.opcode(.i32_const));
try leb.writeULEB128(writer, value);
try leb.writeILEB128(writer, @as(i32, @bitCast(value)));
try writer.writeByte(std.wasm.opcode(.i32_ne));
},
.imm64 => |value| {
try writer.writeByte(std.wasm.opcode(.i64_const));
try leb.writeULEB128(writer, value);
try leb.writeILEB128(writer, @as(i64, @bitCast(value)));
try writer.writeByte(std.wasm.opcode(.i64_ne));
},
else => unreachable,

View File

@ -1048,6 +1048,22 @@ test "@tagName on enum literals" {
try comptime expect(mem.eql(u8, @tagName(.FooBar), "FooBar"));
}
test "tag name with signed enum values" {
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
const LocalFoo = enum(isize) {
alfa = 62,
bravo = 63,
charlie = 64,
delta = 65,
};
var b = LocalFoo.bravo;
try expect(mem.eql(u8, @tagName(b), "bravo"));
}
test "enum literal casting to optional" {
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;