From 8df20276c9e7f714aacfad7b20f9308233f6bfdd Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Mon, 22 Jun 2020 13:06:22 +0200 Subject: [PATCH] fixes #14458 [backport:1.2] (#14756) --- compiler/cgen.nim | 9 ++++++--- compiler/pragmas.nim | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 338b337f2a..417acf1786 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -975,6 +975,9 @@ proc genProcBody(p: BProc; procBody: PNode) = p.blocks[0].sections[cpsLocals].add(ropecg(p.module, "NIM_BOOL* nimErr_;$n", [])) p.blocks[0].sections[cpsInit].add(ropecg(p.module, "nimErr_ = #nimErrorFlag();$n", [])) +proc isNoReturn(m: BModule; s: PSym): bool {.inline.} = + sfNoReturn in s.flags and m.config.exc != excGoto + proc genProcAux(m: BModule, prc: PSym) = var p = newProc(prc, m) var header = genProcHeader(m, prc) @@ -1029,7 +1032,7 @@ proc genProcAux(m: BModule, prc: PSym) = var generatedProc: Rope generatedProc.genCLineDir prc.info, m.config - if sfNoReturn in prc.flags: + if isNoReturn(p.module, prc): if hasDeclspec in extccomp.CC[p.config.cCompiler].props: header = "__declspec(noreturn) " & header if sfPure in prc.flags: @@ -1092,13 +1095,13 @@ proc genProcPrototype(m: BModule, sym: PSym) = let asPtr = isReloadable(m, sym) var header = genProcHeader(m, sym, asPtr) if not asPtr: - if sfNoReturn in sym.flags and hasDeclspec in extccomp.CC[m.config.cCompiler].props: + if isNoReturn(m, sym) and hasDeclspec in extccomp.CC[m.config.cCompiler].props: header = "__declspec(noreturn) " & header if sym.typ.callConv != ccInline and requiresExternC(m, sym): header = "extern \"C\" " & header if sfPure in sym.flags and hasAttribute in CC[m.config.cCompiler].props: header.add(" __attribute__((naked))") - if sfNoReturn in sym.flags and hasAttribute in CC[m.config.cCompiler].props: + if isNoReturn(m, sym) and hasAttribute in CC[m.config.cCompiler].props: header.add(" __attribute__((noreturn))") m.s[cfsProcHeaders].add(ropecg(m, "$1;$N", [header])) diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index 021a8b3396..c9fe3a5e14 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -904,7 +904,7 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, of wNoreturn: noVal(c, it) # Disable the 'noreturn' annotation when in the "Quirky Exceptions" mode! - if c.config.exc notin {excQuirky, excGoto}: + if c.config.exc != excQuirky: incl(sym.flags, sfNoReturn) if sym.typ[0] != nil: localError(c.config, sym.ast[paramsPos][0].info,