Skip to content

Commit

Permalink
fixes #24604; importc fails to generate stub type
Browse files Browse the repository at this point in the history
  • Loading branch information
ringabout committed Jan 8, 2025
1 parent 8ed0a63 commit d39c76b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 6 additions & 3 deletions compiler/ccgtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion tests/ccgbugs/tctypes.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
discard """
targets: "c cpp"
matrix: "--gc:refc; --gc:arc"
matrix: "--mm:refc; --mm:arc"
"""

# bug #7308
Expand Down Expand Up @@ -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

0 comments on commit d39c76b

Please sign in to comment.