Skip to content

Commit d39c76b

Browse files
committed
fixes #24604; importc fails to generate stub type
1 parent 8ed0a63 commit d39c76b

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

compiler/ccgtypes.nim

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ proc mapReturnType(conf: ConfigRef; typ: PType): TCTypeKind =
234234
proc isImportedType(t: PType): bool =
235235
result = t.sym != nil and sfImportc in t.sym.flags
236236

237+
proc isNoDeclType(t: PType): bool =
238+
result = t.sym != nil and lfNoDecl in t.sym.loc.flags
239+
237240
proc isImportedCppType(t: PType): bool =
238241
let x = t.skipTypes(irrelevantForBackend)
239242
result = (t.sym != nil and sfInfixCall in t.sym.flags) or
@@ -390,7 +393,7 @@ proc getTypeForward(m: BModule; typ: PType; sig: SigHash): Rope =
390393
of tySequence, tyTuple, tyObject:
391394
result = getTypeName(m, typ, sig)
392395
m.forwTypeCache[sig] = result
393-
if not isImportedType(concrete):
396+
if not isNoDeclType(concrete):
394397
addForwardStructFormat(m, structOrUnion(typ), result)
395398
else:
396399
pushType(m, concrete)
@@ -1043,14 +1046,14 @@ proc getTypeDescAux(m: BModule; origTyp: PType, check: var IntSet; kind: TypeDes
10431046
if result == "":
10441047
result = getTypeName(m, origTyp, sig)
10451048
m.forwTypeCache[sig] = result
1046-
if not isImportedType(t):
1049+
if not isNoDeclType(t):
10471050
addForwardStructFormat(m, structOrUnion(t), result)
10481051
assert m.forwTypeCache[sig] == result
10491052
m.typeCache[sig] = result # always call for sideeffects:
10501053
if not incompleteType(t):
10511054
let recdesc = if t.kind != tyTuple: getRecordDesc(m, t, result, check)
10521055
else: getTupleDesc(m, t, result, check)
1053-
if not isImportedType(t):
1056+
if not isImportedType(t) and not isNoDeclType(t):
10541057
m.s[cfsTypes].add(recdesc)
10551058
elif tfIncompleteStruct notin t.flags:
10561059
discard # addAbiCheck(m, t, result) # already handled elsewhere

tests/ccgbugs/tctypes.nim

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
discard """
22
targets: "c cpp"
3-
matrix: "--gc:refc; --gc:arc"
3+
matrix: "--mm:refc; --mm:arc"
44
"""
55

66
# bug #7308
@@ -41,3 +41,8 @@ block: # bug #11797
4141
proc foo3(): int32 = 2
4242
foo(proc(): cint = foo1())
4343
foo(proc(): int32 = foo3())
44+
45+
46+
block: # bug #24604
47+
type MyType {.importc, incompleteStruct.} = object
48+
var v {.exportc.}: ptr MyType

0 commit comments

Comments
 (0)