Skip to content

Commit

Permalink
adds ccMember CC fixes #23434 (#23457)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgomez committed Mar 29, 2024
1 parent 4b6a9e4 commit cf00b2f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 4 deletions.
1 change: 1 addition & 0 deletions compiler/ast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type
ccThisCall = "thiscall" # thiscall (parameters are pushed right-to-left)
ccClosure = "closure" # proc has a closure
ccNoConvention = "noconv" # needed for generating proper C procs sometimes
ccMember = "member" # proc is a (cpp) member

TNodeKinds* = set[TNodeKind]

Expand Down
4 changes: 3 additions & 1 deletion compiler/ccgtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,9 @@ const
"N_STDCALL", "N_CDECL", "N_SAFECALL",
"N_SYSCALL", # this is probably not correct for all platforms,
# but one can #define it to what one wants
"N_INLINE", "N_NOINLINE", "N_FASTCALL", "N_THISCALL", "N_CLOSURE", "N_NOCONV"]
"N_INLINE", "N_NOINLINE", "N_FASTCALL", "N_THISCALL", "N_CLOSURE", "N_NOCONV",
"N_NOCONV" #ccMember is N_NOCONV
]

proc cacheGetType(tab: TypeCache; sig: SigHash): Rope =
# returns nil if we need to declare this type
Expand Down
2 changes: 1 addition & 1 deletion compiler/nir/ast2ir.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2423,7 +2423,7 @@ proc addCallConv(c: var ProcCon; info: PackedLineInfo; callConv: TCallingConvent
of ccInline: ann InlineCall
of ccNoInline: ann NoinlineCall
of ccThisCall: ann ThisCall
of ccNoConvention: ann NoCall
of ccNoConvention, ccMember: ann NoCall

proc genProc(cOuter: var ProcCon; prc: PSym) =
if prc.magic notin generatedMagics: return
Expand Down
2 changes: 1 addition & 1 deletion compiler/nir/types2ir.nim
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ proc procToIr(c: var TypesCon; g: var TypeGraph; t: PType; addEnv = false): Type
of ccInline: g.addAnnotation "__inline"
of ccNoInline: g.addAnnotation "__noinline"
of ccThisCall: g.addAnnotation "__thiscall"
of ccNoConvention: g.addAnnotation ""
of ccNoConvention, ccMember: g.addAnnotation ""

for i in 0..<fieldTypes.len:
g.addType fieldTypes[i]
Expand Down
2 changes: 1 addition & 1 deletion compiler/pragmas.nim
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ proc processVirtual(c: PContext, n: PNode, s: PSym, flag: TSymFlag) =
s.constraint.strVal = s.constraint.strVal % s.name.s
s.flags.incl {flag, sfInfixCall, sfExportc, sfMangleCpp}

s.typ.callConv = ccNoConvention
s.typ.callConv = ccMember
incl c.config.globalOptions, optMixedMode

proc processCodegenDecl(c: PContext, n: PNode, sym: PSym) =
Expand Down
17 changes: 17 additions & 0 deletions tests/cpp/t23434.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
discard """
cmd:"nim cpp $file"
errormsg: "type mismatch: got <proc (self: SomeObject){.member, gcsafe.}>"
line: 17
"""
type SomeObject = object
value: int

proc printValue(self: SomeObject) {.virtual.} =
echo "The value is ", self.value

proc callAProc(p: proc(self: SomeObject){.noconv.}) =
let someObj = SomeObject(value: 4)
echo "calling param proc"
p(someObj)

callAProc(printValue)

0 comments on commit cf00b2f

Please sign in to comment.