fixes #19603; some pragmas were really only supported as top level statements. Now this is enforced properly. (#19646)

This commit is contained in:
Andreas Rumpf 2022-03-26 06:47:04 +01:00 • committed by GitHub
commit 51df9ff1c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 7 deletions

View file

@ -47,18 +47,21 @@ const
wDiscardable, wGensym, wInject, wRaises, wEffectsOf, wDiscardable, wGensym, wInject, wRaises, wEffectsOf,
wTags, wLocks, wGcSafe, wRequires, wEnsures} wTags, wLocks, wGcSafe, wRequires, wEnsures}
exprPragmas* = {wLine, wLocks, wNoRewrite, wGcSafe, wNoSideEffect} exprPragmas* = {wLine, wLocks, wNoRewrite, wGcSafe, wNoSideEffect}
stmtPragmas* = {wChecks, wObjChecks, wFieldChecks, wRangeChecks, stmtPragmas* = {
wBoundChecks, wOverflowChecks, wNilChecks, wStaticBoundchecks, wHint, wWarning, wError,
wStyleChecks, wAssertions,
wWarnings, wHints,
wLineDir, wStackTrace, wLineTrace, wOptimization, wHint, wWarning, wError,
wFatal, wDefine, wUndef, wCompile, wLink, wLinksys, wPure, wPush, wPop, wFatal, wDefine, wUndef, wCompile, wLink, wLinksys, wPure, wPush, wPop,
wPassl, wPassc, wLocalPassc, wPassl, wPassc, wLocalPassc,
wDeadCodeElimUnused, # deprecated, always on wDeadCodeElimUnused, # deprecated, always on
wDeprecated, wDeprecated,
wFloatChecks, wInfChecks, wNanChecks, wPragma, wEmit, wUnroll, wPragma, wEmit, wUnroll,
wLinearScanEnd, wPatterns, wTrMacros, wEffects, wNoForward, wReorder, wComputedGoto, wLinearScanEnd, wPatterns, wTrMacros, wEffects, wNoForward, wReorder, wComputedGoto,
wExperimental, wThis, wUsed, wInvariant, wAssume, wAssert} wExperimental, wThis, wUsed, wInvariant, wAssume, wAssert}
stmtPragmasTopLevel* = {wChecks, wObjChecks, wFieldChecks, wRangeChecks,
wBoundChecks, wOverflowChecks, wNilChecks, wStaticBoundchecks,
wStyleChecks, wAssertions,
wWarnings, wHints,
wLineDir, wStackTrace, wLineTrace, wOptimization,
wFloatChecks, wInfChecks, wNanChecks}
lambdaPragmas* = {FirstCallConv..LastCallConv, lambdaPragmas* = {FirstCallConv..LastCallConv,
wNoSideEffect, wSideEffect, wNoreturn, wNosinks, wDynlib, wHeader, wNoSideEffect, wSideEffect, wNoreturn, wNosinks, wDynlib, wHeader,
wThread, wAsmNoStackFrame, wThread, wAsmNoStackFrame,

View file

@ -2769,6 +2769,12 @@ proc enumFieldSymChoice(c: PContext, n: PNode, s: PSym): PNode =
onUse(info, a) onUse(info, a)
a = nextOverloadIter(o, c, n) a = nextOverloadIter(o, c, n)
proc semPragmaStmt(c: PContext; n: PNode) =
if c.p.owner.kind == skModule:
pragma(c, c.p.owner, n, stmtPragmas+stmtPragmasTopLevel, true)
else:
pragma(c, c.p.owner, n, stmtPragmas, true)
proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode = proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
when defined(nimCompilerStacktraceHints): when defined(nimCompilerStacktraceHints):
setFrameMsg c.config$n.info & " " & $n.kind setFrameMsg c.config$n.info & " " & $n.kind
@ -3017,7 +3023,7 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
of nkUsingStmt: result = semUsing(c, n) of nkUsingStmt: result = semUsing(c, n)
of nkAsmStmt: result = semAsm(c, n) of nkAsmStmt: result = semAsm(c, n)
of nkYieldStmt: result = semYield(c, n) of nkYieldStmt: result = semYield(c, n)
of nkPragma: pragma(c, c.p.owner, n, stmtPragmas, true) of nkPragma: semPragmaStmt(c, n)
of nkIteratorDef: result = semIterator(c, n) of nkIteratorDef: result = semIterator(c, n)
of nkProcDef: result = semProc(c, n) of nkProcDef: result = semProc(c, n)
of nkFuncDef: result = semFunc(c, n) of nkFuncDef: result = semFunc(c, n)