From 4da9454f16a4f4a3d3a63490beaa911a5e1ba119 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Wed, 2 Aug 2023 15:24:16 +0800 Subject: [PATCH] fixes #22362; Compiler crashes with staticBoundsCheck on --- compiler/cgendata.nim | 2 ++ compiler/jsgen.nim | 4 ++++ tests/pragmas/tpush.nim | 13 +++++++++++++ 3 files changed, 19 insertions(+) diff --git a/compiler/cgendata.nim b/compiler/cgendata.nim index 4d15cf131b89..9cc146c4db5f 100644 --- a/compiler/cgendata.nim +++ b/compiler/cgendata.nim @@ -196,6 +196,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()], diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index 8be4d9d07569..a5f4d29b2775 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -50,6 +50,7 @@ type graph: ModuleGraph config: ConfigRef sigConflicts: CountTable[SigHash] + initProc: PProc BModule = ref TJSGen TJSTypeKind = enum # necessary JS "types" @@ -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, @@ -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) diff --git a/tests/pragmas/tpush.nim b/tests/pragmas/tpush.nim index f2779ea70fc7..6d7eade91fc4 100644 --- a/tests/pragmas/tpush.nim +++ b/tests/pragmas/tpush.nim @@ -1,3 +1,7 @@ +discard """ + targets: "c js" +""" + # test the new pragmas {.push warnings: off, hints: off.} @@ -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()