summary refs log tree commit diff stats
path: root/tests/ccgbugs
ModeNameSize
-rw-r--r--mymodule.nim245log stats plain blame
d---------pkg861680log stats plain
-rw-r--r--t5296.nim187log stats plain blame
-rw-r--r--t5345.nim135log stats plain blame
-rw-r--r--t5701.nim340log stats plain blame
-rw-r--r--t6279.nim231log stats plain blame
-rw-r--r--t6756.nim258log stats plain blame
-rw-r--r--t7079.nim151log stats plain blame
-rw-r--r--t8616.nim56log stats plain blame
-rw-r--r--t8781.nim555log stats plain blame
-rw-r--r--t8964.nim176log stats plain blame
-rw-r--r--t8967.nim153log stats plain blame
-rw-r--r--taddhigh.nim217log stats plain blame
-rw-r--r--tarray_equality.nim159log stats plain blame
-rw-r--r--tborrowmagic.nim177log stats plain blame
-rw-r--r--tbug1081.nim741log stats plain blame
-rw-r--r--tcapture_static.nim168log stats plain blame
-rw-r--r--tccgen1.nim1646log stats plain blame
-rw-r--r--tcgbug.nim435log stats plain blame
-rw-r--r--tclosureeq.nim263log stats plain blame
-rw-r--r--tcodegenbug1.nim3072log stats plain blame
-rw-r--r--tcodegendecllambda.nim257log stats plain blame
-rw-r--r--tconstobj.nim274log stats plain blame
-rw-r--r--tcvarargs.nim414log stats plain blame
-rw-r--r--tdeepcopy_addr_rval.nim175log stats plain blame
-rw-r--r--tescaping_temps.nim641log stats plain blame
-rw-r--r--tforward_decl_only.nim614log stats plain blame
-rw-r--r--tgeneric_closure.nim456log stats plain blame
-rw-r--r--tgeneric_smallobj_asgn_opt.nim512log stats plain blame
-rw-r--r--thtiobj.nim95log stats plain blame
-rw-r--r--tinefficient_const_table.nim494log stats plain blame
-rw-r--r--tmangle_field.nim235log stats plain blame
-rw-r--r--tmarkerproc_regression.nim1036log stats plain blame
-rw-r--r--tmissing_ccgtrav_unique_type.nim173log stats plain blame
-rw-r--r--tmissingbracket.nim993log stats plain blame
-rw-r--r--tmissingderef.nim662log stats plain blame
-rw-r--r--tmissingderef2.nim362log stats plain blame
-rw-r--r--tmissinginit.nim363log stats plain blame
-rw-r--r--tmissingvolatile.nim283log stats plain blame
-rw-r--r--tnocodegen_for_compiletime.nim204log stats plain blame
-rw-r--r--tobjconstr_bad_aliasing.nim520log stats plain blame
-rw-r--r--tobjconstr_outoforder.nim597log stats plain blame
-rw-r--r--tobjconstr_regression.nim467log stats plain blame
-rw-r--r--topenarraycast.nim158log stats plain blame
-rw-r--r--tpartialcs.nim194log stats plain blame
-rw-r--r--trecursive_closure.nim272log stats plain blame
-rw-r--r--trecursive_table.nim193log stats plain blame
-rw-r--r--trefseqsort.nim423log stats plain blame
-rw-r--r--tresult_of_array.nim584log stats plain blame
-rw-r--r--tret_arg_init.nim300log stats plain blame
-rw-r--r--tsighash_typename_regression.nim128log stats plain blame
-rw-r--r--tstringslice.nim338log stats plain blame
-rw-r--r--tunsafeaddr.nim455log stats plain blame
-rw-r--r--tuple_canon.nim2838log stats plain blame
-rw-r--r--tuplecast.nim119log stats plain blame
-rw-r--r--tweakopenarray.nim147log stats plain blame
-rw-r--r--twrong_discriminant_check.nim405log stats plain blame
-rw-r--r--twrong_method.nim539log stats plain blame
-rw-r--r--twrong_rc_for_refarray.nim398log stats plain blame
-rw-r--r--twrong_setconstr.nim7437log stats plain blame
-rw-r--r--twrong_string_asgn.nim239log stats plain blame
-rw-r--r--twrong_tupleconv.nim433log stats plain blame
-rw-r--r--twrongrefcounting.nim414log stats plain blame
al.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#
#
#            Nim's Runtime Library
#        (c) Copyright 2017 Nim contributors
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#


# import typetraits
# strs already imported allocators for us.

proc supportsCopyMem(t: typedesc): bool {.magic: "TypeTrait".}

## Default seq implementation used by Nim's core.
type
  NimSeqPayload[T] = object
    cap: int
    allocator: Allocator
    data: UncheckedArray[T]

  NimSeqV2*[T] = object
    len: int
    p: ptr NimSeqPayload[T]

const nimSeqVersion {.core.} = 2

template payloadSize(cap): int = cap * sizeof(T) + sizeof(int) + sizeof(Allocator)

# XXX make code memory safe for overflows in '*'

when false:
  # this is currently not part of Nim's type bound operators and so it's
  # built into the tracing proc generation just like before.
  proc `=trace`[T](s: NimSeqV2[T]) =
    for i in 0 ..< s.len: `=trace`(s.data[i])

#[
Keep in mind that C optimizers are bad at detecting the connection
between ``s.p != nil`` and ``s.len != 0`` and that these are intermingled
with user-level code that accesses ``s.len`` only, never ``s.p`` directly.
This means the check for whether ``s.p`` needs to be freed should
be ``s.len == 0`` even though that feels slightly more awkward.
]#

when not defined(nimV2):
  proc `=destroy`[T](s: var seq[T]) =
    var x = cast[ptr NimSeqV2[T]](addr s)
    var p = x.p
    if p != nil:
      mixin `=destroy`
      when not supportsCopyMem(T):
        for i in 0..<x.len: `=destroy`(p.data[i])
      if p.allocator != nil:
        p.allocator.dealloc(p.allocator, p, payloadSize(p.cap))
      x.p = nil
      x.len = 0

  proc `=`[T](x: var seq[T]; y: seq[T]) =
    mixin `=destroy`
    var a = cast[ptr NimSeqV2[T]](addr x)
    var b = cast[ptr NimSeqV2[T]](unsafeAddr y)

    if a.p == b.p: return
    `=destroy`(x)
    a.len = b.len
    if b.p != nil:
      a.p = cast[type(a.p)](alloc(payloadSize(a.len)))
      when supportsCopyMem(T):
        if a.len > 0:
          copyMem(unsafeAddr a.p.data[0], unsafeAddr b.p.data[0], a.len * sizeof(T))
      else:
        for i in 0..<a.len:
          a.p.data[i] = b.p.data[i]

  proc `=sink`[T](x: var seq[T]; y: seq[T]) =
    mixin `=destroy`
    var a = cast[ptr NimSeqV2[T]](addr x)
    var b = cast[ptr NimSeqV2[T]](unsafeAddr y)
    if a.p != nil and a.p != b.p:
      `=destroy`(x)
    a.len = b.len
    a.p = b.p


type
  PayloadBase = object
    cap: int
    allocator: Allocator

proc newSeqPayload(cap, elemSize: int): pointer {.compilerRtl, raises: [].} =
  # we have to use type erasure here as Nim does not support generic
  # compilerProcs. Oh well, this will all be inlined anyway.
  if cap > 0:
    let allocator = getLocalAllocator()
    var p = cast[ptr PayloadBase](allocator.alloc(allocator, cap * elemSize + sizeof(int) + sizeof(Allocator)))
    p.allocator = allocator
    p.cap = cap
    result = p
  else:
    result = nil

proc prepareSeqAdd(len: int; p: pointer; addlen, elemSize: int): pointer {.
    compilerRtl, noSideEffect, raises: [].} =
  {.noSideEffect.}:
    if len+addlen <= len:
      result = p
    elif p == nil:
      result = newSeqPayload(len+addlen, elemSize)
    else:
      # Note: this means we cannot support things that have internal pointers as
      # they get reallocated here. This needs to be documented clearly.
      var p = cast[ptr PayloadBase](p)
      let allocator = if p.allocator == nil: getLocalAllocator() else: p.allocator
      let cap = max(resize(p.cap), len+addlen)
      var q = cast[ptr PayloadBase](allocator.realloc(allocator, p,
        sizeof(int) + sizeof(Allocator) + elemSize * p.cap,
        sizeof(int) + sizeof(Allocator) + elemSize * cap))
      q.allocator = allocator
      q.cap = cap
      result = q

proc shrink*[T](x: var seq[T]; newLen: Natural) =
  mixin `=destroy`
  sysAssert newLen <= x.len, "invalid newLen parameter for 'shrink'"
  when not supportsCopyMem(T):
    for i in countdown(x.len - 1, newLen - 1):
      `=destroy`(x[i])
  # XXX This is wrong for const seqs that were moved into 'x'!
  cast[ptr NimSeqV2[T]](addr x).len = newLen

proc grow*[T](x: var seq[T]; newLen: Natural; value: T) =
  let oldLen = x.len
  if newLen <= oldLen: return
  var xu = cast[ptr NimSeqV2[T]](addr x)
  if xu.p == nil or xu.p.cap < newLen:
    xu.p = cast[typeof(xu.p)](prepareSeqAdd(oldLen, xu.p, newLen - oldLen, sizeof(T)))
  xu.len = newLen
  for i in oldLen .. newLen-1:
    xu.p.data[i] = value

proc setLen[T](s: var seq[T], newlen: Natural) =
  {.noSideEffect.}:
    if newlen < s.len:
      shrink(s, newLen)
    else:
      var v: T # get the default value of 'v'
      grow(s, newLen, v)

when false:
  proc resize[T](s: var NimSeqV2[T]) =
    let old = s.cap
    if old == 0: s.cap = 8
    else: s.cap = (s.cap * 3) shr 1
    s.data = cast[type(s.data)](realloc(s.data, old * sizeof(T), s.cap * sizeof(T)))

  proc reserveSlot[T](x: var NimSeqV2[T]): ptr T =
    if x.len >= x.cap: resize(x)
    result = addr(x.data[x.len])
    inc x.len

  template add*[T](x: var NimSeqV2[T]; y: T) =
    reserveSlot(x)[] = y

  template `[]`*[T](x: NimSeqV2[T]; i: Natural): T =
    assert i < x.len
    x.data[i]

  template `[]=`*[T](x: NimSeqV2[T]; i: Natural; y: T) =
    assert i < x.len
    x.data[i] = y

  proc `@`*[T](elems: openArray[T]): NimSeqV2[T] =
    result.cap = elems.len
    result.len = elems.len
    result.data = cast[type(result.data)](alloc(result.cap * sizeof(T)))
    when supportsCopyMem(T):
      copyMem(result.data, unsafeAddr(elems[0]), result.cap * sizeof(T))
    else:
      for i in 0..<result.len:
        result.data[i] = elems[i]