summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2023-08-09 18:43:17 +0800
committerGitHub <noreply@github.com>2023-08-09 12:43:17 +0200
commit5334dc921fc177bf6253256dcd579baf244f1ad8 (patch)
tree10230bb0ecaefafc622a822604792dbc2ffcdf77
parent989da75b84e15a6d585e8b03d2bcd0c42a90c2fb (diff)
downloadNim-5334dc921fc177bf6253256dcd579baf244f1ad8.tar.gz
fixes #22419; async/closure environment does not align local variables (#22425)
* fixes #22419; async/closure environment does not align local variables

* Apply suggestions from code review

* Update tests/align/talign.nim

Co-authored-by: Jacek Sieka <arnetheduck@gmail.com>

* apply code review

* update tests

---------

Co-authored-by: Jacek Sieka <arnetheduck@gmail.com>
-rw-r--r--compiler/lowerings.nim3
-rw-r--r--tests/align/talign.nim16
2 files changed, 19 insertions, 0 deletions
diff --git a/compiler/lowerings.nim b/compiler/lowerings.nim
index d70c713a1..a083b9195 100644
--- a/compiler/lowerings.nim
+++ b/compiler/lowerings.nim
@@ -237,6 +237,9 @@ proc addField*(obj: PType; s: PSym; cache: IdentCache; idgen: IdGenerator): PSym
   field.itemId = ItemId(module: s.itemId.module, item: -s.itemId.item)
   let t = skipIntLit(s.typ, idgen)
   field.typ = t
+  if s.kind in {skLet, skVar, skField, skForVar}:
+    #field.bitsize = s.bitsize
+    field.alignment = s.alignment
   assert t.kind != tyTyped
   propagateToOwner(obj, t)
   field.position = obj.n.len
diff --git a/tests/align/talign.nim b/tests/align/talign.nim
index 3b8f6b4df..08373ee49 100644
--- a/tests/align/talign.nim
+++ b/tests/align/talign.nim
@@ -51,3 +51,19 @@ type Bug[T] = object
 
 var bug: Bug[int]
 doAssert sizeof(bug) == 128, "Oops my size is " & $sizeof(bug) # 16
+
+
+block: # bug #22419
+  type
+    ValidatorPubKey = object
+      blob: array[96, byte]
+
+  proc f(): auto =
+    return iterator() =
+      var pad: int8 = 0
+      var y {.align: 16.}: ValidatorPubKey
+      let value = cast[uint64](addr y)
+      doAssert value mod 16 == 0
+
+  f()()
+