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
This commit is contained in:
ringabout
2024-08-29 02:59:25 +08:00
committed by GitHub
parent 5e8cd318ef
commit 1244ffbf39
2 changed files with 14 additions and 2 deletions

View File

@@ -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 =