diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 5c3e82346d25..93b8b144ec50 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -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 diff --git a/tests/ccgbugs/tatomictypeinfo.nim b/tests/ccgbugs/tatomictypeinfo.nim new file mode 100644 index 000000000000..51d34e1f3bec --- /dev/null +++ b/tests/ccgbugs/tatomictypeinfo.nim @@ -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)) diff --git a/tests/ccgbugs/tcgbug.nim b/tests/ccgbugs/tcgbug.nim index 2eddc6fddc23..946aa794d377 100644 --- a/tests/ccgbugs/tcgbug.nim +++ b/tests/ccgbugs/tcgbug.nim @@ -4,6 +4,7 @@ success M1 M2 ok ''' +targets: "c cpp" matrix: "--mm:refc;--mm:orc" """