Skip to content

Commit

Permalink
don't trust completeStruct for typeinfo gen of imported C++ types
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Sep 23, 2024
1 parent 6f6e34e commit 14239c9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion compiler/ccgtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1474,7 +1474,10 @@ proc genObjectInfo(m: BModule; typ, origType: PType, name: Rope; info: TLineInfo
typeToString(typ))
genTypeInfoAux(m, typ, origType, name, info)
var tmp = getNimNode(m)
if (not isImportedType(typ)) or tfCompleteStruct in typ.flags:
if (not isImportedType(typ)) or
# don't trust C++ imported fields even if completeStruct to
# workaround C++ atomic implementation
(tfCompleteStruct in typ.flags and not isImportedCppType(typ)):
genObjectFields(m, typ, origType, typ.n, tmp, info)
m.s[cfsTypeInit3].addf("$1.node = &$2;$n", [tiNameForHcr(m, name), tmp])
var t = typ.baseClass
Expand Down
14 changes: 14 additions & 0 deletions tests/ccgbugs/tatomictypeinfo.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
discard """
matrix: "--mm:refc; --mm:orc"
targets: "c cpp"
"""

# issue #24159

import std/atomics

type N = object
u: ptr Atomic[int]
proc w(args: N) = discard
var e: Thread[N]
createThread(e, w, default(N))
1 change: 1 addition & 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
'''
targets: "c cpp"
matrix: "--mm:refc;--mm:orc"
"""

Expand Down

0 comments on commit 14239c9

Please sign in to comment.