From 716ff93161b4d4a02bd4a29860ddb9375e2fda5d Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Sat, 16 Mar 2024 13:23:15 +0800 Subject: [PATCH] fixes #23401; prevents nrvo for cdecl procs (#23409) fixes #23401 (cherry picked from commit f639cf063f66a160550bcf8955eb3446ca101cc2) --- compiler/ccgtypes.nim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 2613df14ad..3bc31e42e7 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -270,7 +270,10 @@ proc isInvalidReturnType(conf: ConfigRef; typ: PType, isProc = true): bool = {tyVar, tyLent, tyRef, tyPtr}) of ctStruct: let t = skipTypes(rettype, typedescInst) - if rettype.isImportedCppType or t.isImportedCppType: return false + if rettype.isImportedCppType or t.isImportedCppType or + (typ.callConv == ccCDecl and conf.selectedGC in {gcArc, gcAtomicArc, gcOrc}): + # prevents nrvo for cdecl procs; # bug #23401 + return false result = containsGarbageCollectedRef(t) or (t.kind == tyObject and not isObjLackingTypeField(t)) else: result = false