fix #21251 Compiler SIGSEGV when using SharedTable (#21876)

fix #21251

(cherry picked from commit 76a98fee65)
This commit is contained in:
Bung
2023-05-23 15:39:44 +08:00
committed by narimiran
parent c4380107d6
commit 173a15b370
5 changed files with 15 additions and 8 deletions

View File

@@ -2930,6 +2930,8 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}, expectedType: PType
else:
{checkUndeclared, checkModule, checkAmbiguity, checkPureEnumFields}
s = qualifiedLookUp(c, n, checks)
if s == nil:
return
if c.matchedConcept == nil: semCaptureSym(s, c.p.owner)
case s.kind
of skProc, skFunc, skMethod, skConverter, skIterator:

View File

@@ -71,9 +71,8 @@ template initImpl(result: typed, initialSize: int) =
newSeq(result.data, correctSize)
template checkIfInitialized(deq: typed) =
when compiles(defaultInitialSize):
if deq.mask == 0:
initImpl(deq, defaultInitialSize)
if deq.mask == 0:
initImpl(deq, defaultInitialSize)
proc initDeque*[T](initialSize: int = defaultInitialSize): Deque[T] =
## Creates a new empty deque.

View File

@@ -11,6 +11,9 @@
include hashcommon
const
defaultInitialSize* = 32
template rawGetDeepImpl() {.dirty.} = # Search algo for unconditional add
genHashImpl(key, hc)
var h: Hash = hc and maxHash(t)
@@ -31,9 +34,8 @@ proc rawInsert[X, A, B](t: var X, data: var KeyValuePairSeq[A, B],
rawInsertImpl()
template checkIfInitialized() =
when compiles(defaultInitialSize):
if t.dataLen == 0:
initImpl(t, defaultInitialSize)
if t.dataLen == 0:
initImpl(t, defaultInitialSize)
template addImpl(enlarge) {.dirty.} =
checkIfInitialized()

View File

@@ -217,8 +217,6 @@ type
## For creating a new empty TableRef, use `newTable proc
## <#newTable>`_.
const
defaultInitialSize* = 32
# ------------------------------ helpers ---------------------------------

6
tests/stdlib/t21251.nim Normal file
View File

@@ -0,0 +1,6 @@
import std / [tables, sets, sharedtables]
var shared: SharedTable[int, int]
shared.init
shared[1] = 1