| author | |
| committer | |
| log | 41d08843ffd59e0ae1396dbf958bdd11257f384a |
| tree | 43441731c1ad5a3718a5f6b725293a1e62090c03 |
| parent | 3a8097ffd4a6370e8188767c6fff409e02186f72 |
Once the switch condition is been shifted up so the minimum value is 0,
it makes sense to treat its type as the unsigned version of its original
type.
Fixes #356512 files changed, 19 insertions(+), 1 deletions(-)
src/codegen/x86_64/CodeGen.zig+1-1| ... | ... | @@ -176662,7 +176662,7 @@ fn lowerSwitchBr( |
| 176662 | 176662 | }; |
| 176663 | 176663 | const condition_index_lock = cg.register_manager.lockReg(condition_index_reg); |
| 176664 | 176664 | defer if (condition_index_lock) |lock| cg.register_manager.unlockReg(lock); |
| 176665 | try cg.truncateRegister(condition_ty, condition_index_reg); | |
| 176665 | try cg.truncateRegister(unsigned_condition_ty, condition_index_reg); | |
| 176666 | 176666 | const ptr_size = @divExact(cg.target.ptrBitWidth(), 8); |
| 176667 | 176667 | try cg.asmMemory(.{ ._mp, .j }, .{ |
| 176668 | 176668 | .base = .table, |
test/behavior/enum.zig+18| ... | ... | @@ -1313,6 +1313,24 @@ test "switch on an extern enum with negative value" { |
| 1313 | 1313 | } |
| 1314 | 1314 | } |
| 1315 | 1315 | |
| 1316 | test "switch on an enum with small signed tag type" { | |
| 1317 | const E = enum(i3) { | |
| 1318 | y = -2, | |
| 1319 | z = -1, | |
| 1320 | a = 0, | |
| 1321 | b = 1, | |
| 1322 | c = 2, | |
| 1323 | }; | |
| 1324 | ||
| 1325 | var runtime: E = .c; | |
| 1326 | _ = &runtime; | |
| 1327 | const result: u8 = switch (runtime) { | |
| 1328 | .y, .z, .a, .b => 0, | |
| 1329 | .c => 1, | |
| 1330 | }; | |
| 1331 | try expect(result == 1); | |
| 1332 | } | |
| 1333 | ||
| 1316 | 1334 | test "Non-exhaustive enum with nonstandard int size behaves correctly" { |
| 1317 | 1335 | const E = enum(u15) { _ }; |
| 1318 | 1336 | try expect(@sizeOf(E) == @sizeOf(u15)); |