diff --git a/compiler/ast.nim b/compiler/ast.nim index a342e1ea7136..02d5591b5d78 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -393,6 +393,9 @@ type tfCompleteStruct # (for importc types); type is fully specified, allowing to compute # sizeof, alignof, offsetof at CT + tfNoTypeInfo + # do not generate typeinfo for imported struct + # workaround for Atomic[T] on C++ tfExplicitCallConv tfIsConstructor tfEffectSystemWorkaround diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 5b5218a3e262..33604832e9a3 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -1402,7 +1402,8 @@ 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 + {tfCompleteStruct, tfNoTypeInfo} * typ.flags == {tfCompleteStruct}: 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/compiler/condsyms.nim b/compiler/condsyms.nim index 5043fc5d4c45..0d8689db9f94 100644 --- a/compiler/condsyms.nim +++ b/compiler/condsyms.nim @@ -169,3 +169,4 @@ proc initDefines*(symbols: StringTableRef) = defineSymbol("nimHasGenericsOpenSym2") defineSymbol("nimHasGenericsOpenSym3") defineSymbol("nimHasJsNoLambdaLifting") + defineSymbol("nimHasNoTypeInfoPragma") diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index 9a298cd90e8a..c4c845e55357 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -73,7 +73,7 @@ const wGcSafe, wCodegenDecl, wNoInit, wCompileTime} typePragmas* = declPragmas + {wMagic, wAcyclic, wPure, wHeader, wCompilerProc, wCore, wFinal, wSize, wShallow, - wIncompleteStruct, wCompleteStruct, wByCopy, wByRef, + wIncompleteStruct, wCompleteStruct, wNoTypeInfo, wByCopy, wByRef, wInheritable, wGensym, wInject, wRequiresInit, wUnchecked, wUnion, wPacked, wCppNonPod, wBorrow, wGcSafe, wPartial, wExplain, wPackage, wCodegenDecl, wSendable, wNoInit} @@ -1216,6 +1216,10 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, noVal(c, it) if sym.typ == nil: invalidPragma(c, it) else: incl(sym.typ.flags, tfCompleteStruct) + of wNoTypeInfo: + noVal(c, it) + if sym.typ == nil or sfImportc notin sym.flags: invalidPragma(c, it) + else: incl(sym.typ.flags, tfNoTypeInfo) of wUnchecked: noVal(c, it) if sym.typ == nil or sym.typ.kind notin {tyArray, tyUncheckedArray}: diff --git a/compiler/wordrecg.nim b/compiler/wordrecg.nim index 39e0b2e25a44..db61d6caa579 100644 --- a/compiler/wordrecg.nim +++ b/compiler/wordrecg.nim @@ -46,7 +46,8 @@ type wImportc = "importc", wImportJs = "importjs", wExportc = "exportc", wExportCpp = "exportcpp", wExportNims = "exportnims", wIncompleteStruct = "incompleteStruct", # deprecated - wCompleteStruct = "completeStruct", wRequiresInit = "requiresInit", wAlign = "align", + wCompleteStruct = "completeStruct", wNoTypeInfo = "notypeinfo", + wRequiresInit = "requiresInit", wAlign = "align", wNodecl = "nodecl", wPure = "pure", wSideEffect = "sideEffect", wHeader = "header", wNoSideEffect = "noSideEffect", wGcSafe = "gcsafe", wNoreturn = "noreturn", wNosinks = "nosinks", wLib = "lib", wDynlib = "dynlib", diff --git a/lib/pure/concurrency/atomics.nim b/lib/pure/concurrency/atomics.nim index c7b881bc55c1..1625e7185612 100644 --- a/lib/pure/concurrency/atomics.nim +++ b/lib/pure/concurrency/atomics.nim @@ -88,8 +88,11 @@ when defined(cpp) or defined(nimdoc): ## Also guarantees that all threads observe the same total ordering ## with other moSequentiallyConsistent operations. + when not defined(nimHasNoTypeInfoPragma): + {.pragma: noTypeInfo.} + type - Atomic*[T] {.importcpp: "std::atomic", completeStruct.} = object + Atomic*[T] {.importcpp: "std::atomic", completeStruct, noTypeInfo.} = object ## An atomic object with underlying type `T`. raw: T 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" """