mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-08 04:44:20 +00:00
added missing .noalias support for object fields (#15445)
This commit is contained in:
@@ -564,19 +564,21 @@ proc genRecordFieldsAux(m: BModule, n: PNode,
|
||||
# have to recurse via 'getTypeDescAux'. And not doing so prevents problems
|
||||
# with heavily templatized C++ code:
|
||||
if not isImportedCppType(rectype):
|
||||
let noAlias = if sfNoalias in field.flags: ~" NIM_NOALIAS" else: nil
|
||||
|
||||
let fieldType = field.loc.lode.typ.skipTypes(abstractInst)
|
||||
if fieldType.kind == tyUncheckedArray:
|
||||
result.addf("$1 $2[SEQ_DECL_SIZE];$n",
|
||||
[getTypeDescAux(m, fieldType.elemType, check, skField), sname])
|
||||
elif fieldType.kind == tySequence:
|
||||
# we need to use a weak dependency here for trecursive_table.
|
||||
result.addf("$1 $2;$n", [getTypeDescWeak(m, field.loc.t, check, skField), sname])
|
||||
result.addf("$1$3 $2;$n", [getTypeDescWeak(m, field.loc.t, check, skField), sname, noAlias])
|
||||
elif field.bitsize != 0:
|
||||
result.addf("$1 $2:$3;$n", [getTypeDescAux(m, field.loc.t, check, skField), sname, rope($field.bitsize)])
|
||||
result.addf("$1$4 $2:$3;$n", [getTypeDescAux(m, field.loc.t, check, skField), sname, rope($field.bitsize), noAlias])
|
||||
else:
|
||||
# don't use fieldType here because we need the
|
||||
# tyGenericInst for C++ template support
|
||||
result.addf("$1 $2;$n", [getTypeDescAux(m, field.loc.t, check, skField), sname])
|
||||
result.addf("$1$3 $2;$n", [getTypeDescAux(m, field.loc.t, check, skField), sname, noAlias])
|
||||
else: internalError(m.config, n.info, "genRecordFieldsAux()")
|
||||
|
||||
proc getRecordFields(m: BModule, typ: PType, check: var IntSet): Rope =
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
discard """
|
||||
ccodecheck: "\\i@'NIM_CHAR* NIM_NOALIAS x,' @'void* NIM_NOALIAS q'"
|
||||
ccodecheck: "\\i@'NI* NIM_NOALIAS field;' @'NIM_CHAR* NIM_NOALIAS x,' @'void* NIM_NOALIAS q'"
|
||||
"""
|
||||
|
||||
type
|
||||
BigNum = object
|
||||
field {.noalias.}: ptr UncheckedArray[int]
|
||||
|
||||
proc p(x {.noalias.}: openArray[char]) =
|
||||
var q {.noalias.}: pointer = unsafeAddr(x[0])
|
||||
|
||||
var bn: BigNum
|
||||
p "abc"
|
||||
|
||||
Reference in New Issue
Block a user