From 14239c9948ff9181620c90e282af06261d389478 Mon Sep 17 00:00:00 2001 From: metagn Date: Mon, 23 Sep 2024 18:05:04 +0300 Subject: [PATCH] don't trust completeStruct for typeinfo gen of imported C++ types fixes #24159, refs #23761 --- compiler/ccgtypes.nim | 5 ++++- tests/ccgbugs/tatomictypeinfo.nim | 14 ++++++++++++++ tests/ccgbugs/tcgbug.nim | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tests/ccgbugs/tatomictypeinfo.nim 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" """