Skip to content

Commit

Permalink
fixes #9940; genericAssign does not take care of the importC variable…
Browse files Browse the repository at this point in the history
…s in refc [backport] (#23761)

fixes #9940

(cherry picked from commit 828cd58)
  • Loading branch information
ringabout authored and narimiran committed Jun 26, 2024
1 parent 16bbffc commit 915cd5b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion compiler/ccgtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,7 @@ proc genObjectInfo(m: BModule; typ, origType: PType, name: Rope; info: TLineInfo
else:
genTypeInfoAuxBase(m, typ, origType, name, rope("0"), info)
var tmp = getNimNode(m)
if not isImportedType(typ):
if (not isImportedType(typ)) or tfCompleteStruct in typ.flags:
genObjectFields(m, typ, origType, typ.n, tmp, info)
m.s[cfsTypeInit3].addf("$1.node = &$2;$n", [tiNameForHcr(m, name), tmp])
var t = typ[0]
Expand Down
7 changes: 5 additions & 2 deletions tests/ccgbugs/t13062.nim
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ type
fulfilled: Atomic[bool]

var x: Pledge
when defined(gcRefc):
when defined(cpp):
# TODO: fixme
discard "it doesn't work for refc/orc because of contrived `Atomic` in cpp"
elif defined(gcRefc):
doAssert x.repr == "[p = nil]"
elif not defined(cpp): # fixme # bug #20081
else: # fixme # bug #20081
doAssert x.repr == "Pledge(p: nil)"
28 changes: 28 additions & 0 deletions tests/ccgbugs/tcgbug.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ success
M1 M2
ok
'''
matrix: "--mm:refc;--mm:orc"
"""

type
Expand Down Expand Up @@ -133,3 +134,30 @@ proc foo = # bug #23280
doAssert L mod 6 == 0

foo()

block: # bug #9940
{.emit:"""/*TYPESECTION*/
typedef struct { int base; } S;
""".}

type S {.importc: "S", completeStruct.} = object
base: cint
proc init(x:ptr S) =
x.base = 1

type
Foo = object
a: seq[float]
b: seq[float]
c: seq[float]
d: seq[float]
s: S

proc newT(): Foo =
var t: Foo
t.s.addr.init
doAssert t.s.base == 1
t

var t = newT()
doAssert t.s.base == 1

0 comments on commit 915cd5b

Please sign in to comment.