diff options
author | ringabout <43030857+ringabout@users.noreply.github.com> | 2024-08-29 02:59:25 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-28 20:59:25 +0200 |
commit | 1244ffbf39e6d10abfd7f92b4e8f529e469408dc (patch) | |
tree | 2bca09f7911b16e285dffb06ae3a68e2d318c995 | |
parent | 5e8cd318ef52c5043306a47b8ecb2a8d72d76805 (diff) | |
download | Nim-1244ffbf39e6d10abfd7f92b4e8f529e469408dc.tar.gz |
fixes #23923; type-aliased seq[T] get different backend C/C++ pointer type names causing invalid codegen (#23924)
… type names causing invalid codegen fixes #23923
-rw-r--r-- | compiler/ccgcalls.nim | 4 | ||||
-rw-r--r-- | compiler/types.nim | 12 |
2 files changed, 14 insertions, 2 deletions
diff --git a/compiler/ccgcalls.nim b/compiler/ccgcalls.nim index 89a6862af..ac607e3ad 100644 --- a/compiler/ccgcalls.nim +++ b/compiler/ccgcalls.nim @@ -353,9 +353,9 @@ proc genArg(p: BProc, n: PNode, param: PSym; call: PNode; result: var Rope; need addRdLoc(a, result) else: a = initLocExprSingleUse(p, n) - if param.typ.kind in abstractPtrs: + if param.typ.kind in {tyVar, tyPtr, tyRef, tySink}: let typ = skipTypes(param.typ, abstractPtrs) - if typ.sym != nil and sfImportc in typ.sym.flags: + if not sameBackendTypePickyAliases(typ, n.typ.skipTypes(abstractPtrs)): a.snippet = "(($1) ($2))" % [getTypeDesc(p.module, param.typ), rdCharLoc(a)] addRdLoc(withTmpIfNeeded(p, a, needsTmp), result) diff --git a/compiler/types.nim b/compiler/types.nim index 786fe0b0c..93da2cc9b 100644 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -984,6 +984,7 @@ type AllowCommonBase PickyCAliases # be picky about the distinction between 'cint' and 'int32' IgnoreFlags # used for borrowed functions and methods; ignores the tfVarIsPtr flag + PickyBackendAliases # be picky about different aliases TTypeCmpFlags* = set[TTypeCmpFlag] @@ -1260,6 +1261,11 @@ proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool = let symFlagsB = if b.sym != nil: b.sym.flags else: {} if (symFlagsA+symFlagsB) * {sfImportc, sfExportc} != {}: result = symFlagsA == symFlagsB + elif result and PickyBackendAliases in c.flags: + let symFlagsA = if a.sym != nil: a.sym.flags else: {} + let symFlagsB = if b.sym != nil: b.sym.flags else: {} + if (symFlagsA+symFlagsB) * {sfImportc, sfExportc} != {}: + result = a.id == b.id of tyStatic, tyFromExpr: result = exprStructuralEquivalent(a.n, b.n) and sameFlags(a, b) @@ -1346,6 +1352,12 @@ proc sameBackendType*(x, y: PType): bool = c.cmp = dcEqIgnoreDistinct result = sameTypeAux(x, y, c) +proc sameBackendTypePickyAliases*(x, y: PType): bool = + var c = initSameTypeClosure() + c.flags.incl {IgnoreTupleFields, PickyCAliases, PickyBackendAliases} + c.cmp = dcEqIgnoreDistinct + result = sameTypeAux(x, y, c) + proc compareTypes*(x, y: PType, cmp: TDistinctCompare = dcEq, flags: TTypeCmpFlags = {}): bool = |