Skip to content

Commit

Permalink
fixes #22362; Compiler crashes with staticBoundsCheck on (#22363)
Browse files Browse the repository at this point in the history
(cherry picked from commit 825a0e7)
  • Loading branch information
ringabout authored and narimiran committed Apr 17, 2024
1 parent 4133958 commit 1c19d5c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions compiler/cgendata.nim
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ proc newProc*(prc: PSym, module: BModule): BProc =
result = BProc(
prc: prc,
module: module,
optionsStack: if module.initProc != nil: module.initProc.optionsStack
else: @[],
options: if prc != nil: prc.options
else: module.config.options,
blocks: @[initBlock()],
Expand Down
4 changes: 4 additions & 0 deletions compiler/jsgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type
graph: ModuleGraph
config: ConfigRef
sigConflicts: CountTable[SigHash]
initProc: PProc

BModule = ref TJSGen
TJSTypeKind = enum # necessary JS "types"
Expand Down Expand Up @@ -158,6 +159,8 @@ proc newProc(globals: PGlobals, module: BModule, procDef: PNode,
options: TOptions): PProc =
result = PProc(
blocks: @[],
optionsStack: if module.initProc != nil: module.initProc.optionsStack
else: @[],
options: options,
module: module,
procDef: procDef,
Expand Down Expand Up @@ -3036,6 +3039,7 @@ proc processJSCodeGen*(b: PPassContext, n: PNode): PNode =
if m.module == nil: internalError(m.config, n.info, "myProcess")
let globals = PGlobals(m.graph.backend)
var p = newInitProc(globals, m)
m.initProc = p
p.unique = globals.unique
genModule(p, n)
p.g.code.add(p.locals)
Expand Down
13 changes: 13 additions & 0 deletions tests/pragmas/tpush.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
discard """
targets: "c js"
"""

# test the new pragmas

{.push warnings: off, hints: off.}
Expand Down Expand Up @@ -25,3 +29,12 @@ proc foo(x: string, y: int, res: int) =

foo("", 0, 48)
foo("abc", 40, 51)

# bug #22362
{.push staticBoundChecks: on.}
proc main(): void =
{.pop.}
discard
{.push staticBoundChecks: on.}

main()

0 comments on commit 1c19d5c

Please sign in to comment.