Skip to content

Commit

Permalink
partially fixes #20787 by having a char dummy member prepended to obj…
Browse files Browse the repository at this point in the history
…s only containing an UncheckedArray (i.e. C FAM) (#21979)

partial fix for #20787
  • Loading branch information
heterodoxic committed Jun 1, 2023
1 parent 8e35b3d commit c507ced
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 9 additions & 2 deletions compiler/ccgtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -774,8 +774,15 @@ proc getRecordDesc(m: BModule; typ: PType, name: Rope,
result = structOrUnion & " " & name
result.add(getRecordDescAux(m, typ, name, baseType, check, hasField))
let desc = getRecordFields(m, typ, check)
if desc == "" and not hasField:
result.addf("char dummy;$n", [])
if not hasField:
if desc == "":
result.add("\tchar dummy;\n")
elif typ.len == 1 and typ.n[0].kind == nkSym:
let field = typ.n[0].sym
let fieldType = field.typ.skipTypes(abstractInst)
if fieldType.kind == tyUncheckedArray:
result.add("\tchar dummy;\n")
result.add(desc)
else:
result.add(desc)
result.add("};\L")
Expand Down
4 changes: 4 additions & 0 deletions tests/ccgbugs/t20787.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type
Obj = object
f: UncheckedArray[byte]
let o = new Obj

0 comments on commit c507ced

Please sign in to comment.