Skip to content

Commit

Permalink
fix attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Oct 31, 2024
1 parent 788c65a commit 55bd35b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
11 changes: 6 additions & 5 deletions compiler/cbuilderdecls.nim
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ template addProcParams(builder: var Builder, params: out ProcParamBuilder, body:
body
finishProcParamBuilder(builder, params)

proc addProcHeader(builder: var Builder, m: BModule, prc: PSym, name: string, params, rettype: Snippet) =
proc addProcHeader(builder: var Builder, m: BModule, prc: PSym, name: string, params, rettype: Snippet, addAttributes: bool) =
# on nifc should build something like (proc name params type pragmas
# with no body given
let noreturn = isNoReturn(m, prc)
Expand All @@ -474,10 +474,11 @@ proc addProcHeader(builder: var Builder, m: BModule, prc: PSym, name: string, pa
builder.add(name)
builder.add(")")
builder.add(params)
if sfPure in prc.flags and hasAttribute in extccomp.CC[m.config.cCompiler].props:
builder.add(" __attribute__((naked))")
if noreturn and hasAttribute in extccomp.CC[m.config.cCompiler].props:
builder.add(" __attribute__((noreturn))")
if addAttributes:
if sfPure in prc.flags and hasAttribute in extccomp.CC[m.config.cCompiler].props:
builder.add(" __attribute__((naked))")
if noreturn and hasAttribute in extccomp.CC[m.config.cCompiler].props:
builder.add(" __attribute__((noreturn))")

proc finishProcHeaderAsProto(builder: var Builder) =
builder.add(";\n")
Expand Down
4 changes: 2 additions & 2 deletions compiler/ccgtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ proc genMemberProcHeader(m: BModule; prc: PSym; result: var Rope; asPtr: bool =
[rope(CallingConvToStr[prc.typ.callConv]), asPtrStr, rettype, name,
params, fnConst, override, superCall])

proc genProcHeader(m: BModule; prc: PSym; result: var Rope; visibility: var DeclVisibility, asPtr: bool = false) =
proc genProcHeader(m: BModule; prc: PSym; result: var Rope; visibility: var DeclVisibility, asPtr: bool, addAttributes: bool) =
# using static is needed for inline procs
var check = initIntSet()
fillBackendName(m, prc)
Expand Down Expand Up @@ -1242,7 +1242,7 @@ proc genProcHeader(m: BModule; prc: PSym; result: var Rope; visibility: var Decl
if asPtr:
result.addProcVar(m, prc, name, params, rettype, isStatic = isStaticVar)
else:
result.addProcHeader(m, prc, name, params, rettype)
result.addProcHeader(m, prc, name, params, rettype, addAttributes)
else:
let asPtrStr = if asPtr: (rope("(*") & name & ")") else: name
result.add runtimeFormat(prc.cgDeclFrmt, [rettype, asPtrStr, params])
Expand Down
4 changes: 2 additions & 2 deletions compiler/cgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,7 @@ proc genProcAux*(m: BModule, prc: PSym) =
if isCppMember:
genMemberProcHeader(m, prc, header)
else:
genProcHeader(m, prc, header, visibility)
genProcHeader(m, prc, header, visibility, asPtr = false, addAttributes = false)
var returnStmt: Rope = ""
assert(prc.ast != nil)

Expand Down Expand Up @@ -1357,7 +1357,7 @@ proc genProcPrototype(m: BModule, sym: PSym) =
let asPtr = isReloadable(m, sym)
var header = newRopeAppender()
var visibility: DeclVisibility = None
genProcHeader(m, sym, header, visibility, asPtr)
genProcHeader(m, sym, header, visibility, asPtr = asPtr, addAttributes = true)
if asPtr:
# genProcHeader would give variable declaration, add it directly
m.s[cfsProcHeaders].add(header)
Expand Down

0 comments on commit 55bd35b

Please sign in to comment.