From afb5212fe04a3e38b4582f70c544f9df6bb0994b Mon Sep 17 00:00:00 2001 From: cooldome Date: Tue, 27 Oct 2020 23:09:26 +0000 Subject: [PATCH] fix #15752 (#15754) (cherry picked from commit f8cac6bbbcfa8ddc649160945a17a6f5b7a4d9d6) --- compiler/sizealignoffsetimpl.nim | 8 ++++---- tests/enum/tenum.nim | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/compiler/sizealignoffsetimpl.nim b/compiler/sizealignoffsetimpl.nim index 3e536f5d7c..2c764fe12a 100644 --- a/compiler/sizealignoffsetimpl.nim +++ b/compiler/sizealignoffsetimpl.nim @@ -277,14 +277,14 @@ proc computeSizeAlign(conf: ConfigRef; typ: PType) = typ.size = 4 # use signed int32 typ.align = 4 else: - let length = toInt64(lastOrd(conf, typ)) # BUGFIX: use lastOrd! - if length + 1 < `shl`(1, 8): + let lastOrd = toInt64(lastOrd(conf, typ)) # BUGFIX: use lastOrd! + if lastOrd < `shl`(1, 8): typ.size = 1 typ.align = 1 - elif length + 1 < `shl`(1, 16): + elif lastOrd < `shl`(1, 16): typ.size = 2 typ.align = 2 - elif length + 1 < `shl`(BiggestInt(1), 32): + elif lastOrd < `shl`(BiggestInt(1), 32): typ.size = 4 typ.align = 4 else: diff --git a/tests/enum/tenum.nim b/tests/enum/tenum.nim index 8cc578d3cc..aa338ee2c0 100644 --- a/tests/enum/tenum.nim +++ b/tests/enum/tenum.nim @@ -154,3 +154,12 @@ block nonzero: # bug #6959 B C let slice = SomeEnum.low..SomeEnum.high + +block size_one_byte: #issue 15752 + type + Flag = enum + Disabled = 0x00 + Enabled = 0xFF + + static: + assert 1 == sizeof(Flag) \ No newline at end of file