diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index b3e03f57490f5..67a23c0dd7280 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -234,6 +234,9 @@ proc mapReturnType(conf: ConfigRef; typ: PType): TCTypeKind = proc isImportedType(t: PType): bool = result = t.sym != nil and sfImportc in t.sym.flags +proc isNoDeclType(t: PType): bool = + result = t.sym != nil and lfNoDecl in t.sym.loc.flags + proc isImportedCppType(t: PType): bool = let x = t.skipTypes(irrelevantForBackend) result = (t.sym != nil and sfInfixCall in t.sym.flags) or @@ -390,7 +393,7 @@ proc getTypeForward(m: BModule; typ: PType; sig: SigHash): Rope = of tySequence, tyTuple, tyObject: result = getTypeName(m, typ, sig) m.forwTypeCache[sig] = result - if not isImportedType(concrete): + if not isNoDeclType(concrete): addForwardStructFormat(m, structOrUnion(typ), result) else: pushType(m, concrete) @@ -1043,14 +1046,14 @@ proc getTypeDescAux(m: BModule; origTyp: PType, check: var IntSet; kind: TypeDes if result == "": result = getTypeName(m, origTyp, sig) m.forwTypeCache[sig] = result - if not isImportedType(t): + if not isNoDeclType(t): addForwardStructFormat(m, structOrUnion(t), result) assert m.forwTypeCache[sig] == result m.typeCache[sig] = result # always call for sideeffects: if not incompleteType(t): let recdesc = if t.kind != tyTuple: getRecordDesc(m, t, result, check) else: getTupleDesc(m, t, result, check) - if not isImportedType(t): + if not isImportedType(t) and not isNoDeclType(t): m.s[cfsTypes].add(recdesc) elif tfIncompleteStruct notin t.flags: discard # addAbiCheck(m, t, result) # already handled elsewhere diff --git a/tests/ccgbugs/tctypes.nim b/tests/ccgbugs/tctypes.nim index be6009115a9d8..741b0d7e2f39c 100644 --- a/tests/ccgbugs/tctypes.nim +++ b/tests/ccgbugs/tctypes.nim @@ -1,6 +1,6 @@ discard """ targets: "c cpp" - matrix: "--gc:refc; --gc:arc" + matrix: "--mm:refc; --mm:arc" """ # bug #7308 @@ -41,3 +41,8 @@ block: # bug #11797 proc foo3(): int32 = 2 foo(proc(): cint = foo1()) foo(proc(): int32 = foo3()) + + +block: # bug #24604 + type MyType {.importc, incompleteStruct.} = object + var v {.exportc.}: ptr MyType