Skip to content

Commit

Permalink
makes asmnostackframe work with cpp member nim-lang#22411
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgomez committed Aug 9, 2023
1 parent 5ec81d0 commit 22a5248
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
7 changes: 4 additions & 3 deletions compiler/cgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,8 @@ proc isNoReturn(m: BModule; s: PSym): bool {.inline.} =
proc genProcAux*(m: BModule, prc: PSym) =
var p = newProc(prc, m)
var header = newRopeAppender()
if m.config.backend == backendCpp and sfCppMember * prc.flags != {}:
let isCppMember = m.config.backend == backendCpp and sfCppMember * prc.flags != {}
if isCppMember:
genMemberProcHeader(m, prc, header)
else:
genProcHeader(m, prc, header)
Expand Down Expand Up @@ -1205,10 +1206,10 @@ proc genProcAux*(m: BModule, prc: PSym) =
var generatedProc: Rope = ""
generatedProc.genCLineDir prc.info, m.config
if isNoReturn(p.module, prc):
if hasDeclspec in extccomp.CC[p.config.cCompiler].props:
if hasDeclspec in extccomp.CC[p.config.cCompiler].props and not isCppMember:
header = "__declspec(noreturn) " & header
if sfPure in prc.flags:
if hasDeclspec in extccomp.CC[p.config.cCompiler].props:
if hasDeclspec in extccomp.CC[p.config.cCompiler].props and not isCppMember:
header = "__declspec(naked) " & header
generatedProc.add ropecg(p.module, "$1 {$n$2$3$4}$N$N",
[header, p.s(cpsLocals), p.s(cpsInit), p.s(cpsStmts)])
Expand Down
37 changes: 37 additions & 0 deletions tests/cpp/tvirtual.nim
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,40 @@ type Doo = object
proc naiveMember(x: Doo): int {. virtual .} = 2
discard naiveMember(Doo())

#asmnostackframe works with virtual
{.emit:"""/*TYPESECTION*/
template<typename T>
struct Box {
T* first;
Box(int x){
first = new T(x);
};
};
struct Inner {
int val;
//Coo() = default;
Inner(int x){
val = x;
};
};
struct Base {
virtual Box<Inner> test() = 0;
};
""".}

type
Inner {.importcpp.} = object
Base {.importcpp, inheritable.} = object
Child = object of Base
Box[T] {.importcpp, inheritable.} = object
first: T

proc makeBox[T](x:int32): Box[T] {.importcpp:"Box<'0>(@)", constructor.}

proc test(self: Child): Box[Inner] {.virtual, asmnostackframe.} =
let res {.exportc.} = makeBox[Inner](100)
{.emit:"return res;".}


discard Child().test()

0 comments on commit 22a5248

Please sign in to comment.