diff options
author | ringabout <43030857+ringabout@users.noreply.github.com> | 2023-04-12 16:45:45 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-12 10:45:45 +0200 |
commit | 1ed54b7718eb373d1314269578ef4c9386aec96e (patch) | |
tree | 0f533707e9665084e97d76e20842d5e4e885e61a | |
parent | f05387045df55bf7123ee68002238e943716815e (diff) | |
download | Nim-1ed54b7718eb373d1314269578ef4c9386aec96e.tar.gz |
fixes #21632; enforce deref for `wasMoved` in ORC (#21647)
fixes #21632; enforce deref for `wasMoved`
-rw-r--r-- | compiler/ccgexprs.nim | 2 | ||||
-rw-r--r-- | compiler/cgen.nim | 8 | ||||
-rw-r--r-- | tests/stdlib/tpegs.nim | 11 |
3 files changed, 15 insertions, 6 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 80f9fb563..44466fb57 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -2339,7 +2339,7 @@ proc genWasMoved(p: BProc; n: PNode) = if p.withinBlockLeaveActions > 0 and notYetAlive(n1): discard else: - initLocExpr(p, n1, a) + initLocExpr(p, n1, a, {lfEnforceDeref}) resetLoc(p, a) #linefmt(p, cpsStmts, "#nimZeroMem((void*)$1, sizeof($2));$n", # [addrLoc(p.config, a), getTypeDesc(p.module, a.t)]) diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 64c48cf07..960805e8d 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -61,12 +61,12 @@ proc findPendingModule(m: BModule, s: PSym): BModule = var ms = getModule(s) result = m.g.modules[ms.position] -proc initLoc(result: var TLoc, k: TLocKind, lode: PNode, s: TStorageLoc) = +proc initLoc(result: var TLoc, k: TLocKind, lode: PNode, s: TStorageLoc, flags: TLocFlags = {}) = result.k = k result.storage = s result.lode = lode result.r = "" - result.flags = {} + result.flags = flags proc fillLoc(a: var TLoc, k: TLocKind, lode: PNode, r: Rope, s: TStorageLoc) {.inline.} = # fills the loc if it is not already initialized @@ -698,8 +698,8 @@ proc genLiteral(p: BProc, n: PNode; result: var Rope) proc genOtherArg(p: BProc; ri: PNode; i: int; typ: PType; result: var Rope; argsCounter: var int) proc raiseExit(p: BProc) -proc initLocExpr(p: BProc, e: PNode, result: var TLoc) = - initLoc(result, locNone, e, OnUnknown) +proc initLocExpr(p: BProc, e: PNode, result: var TLoc, flags: TLocFlags = {}) = + initLoc(result, locNone, e, OnUnknown, flags) expr(p, e, result) proc initLocExprSingleUse(p: BProc, e: PNode, result: var TLoc) = diff --git a/tests/stdlib/tpegs.nim b/tests/stdlib/tpegs.nim index ab2a6d395..a6079d47c 100644 --- a/tests/stdlib/tpegs.nim +++ b/tests/stdlib/tpegs.nim @@ -328,7 +328,16 @@ call() doAssert program.len == program.rawMatch(grammar, 0, c) doAssert c.ml == 1 + block: + # bug #21632 + + let p = peg""" + atext <- \w / \d + """ + + doAssert "a".match(p) + doAssert "1".match(p) + pegsTest() static: pegsTest() - |