From 73af7c60a11d70ff0c992bc458d2c72d35b86dd4 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 13 Jun 2024 02:51:52 +0800 Subject: [PATCH] nrvo for embedded importc'ed types (#23708) (cherry picked from commit 0b5a938f571133f6e876938387e37199d4c2ec16) --- compiler/ccgtypes.nim | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 4dc0e3ab71..5c3fdfaf75 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -273,9 +273,12 @@ proc isInvalidReturnType(conf: ConfigRef; typ: PType, isProc = true): bool = 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)) + result = false + else: + result = containsGarbageCollectedRef(t) or + (t.kind == tyObject and not isObjLackingTypeField(t)) or + (getSize(conf, rettype) == szUnknownSize and (t.sym == nil or sfImportc notin t.sym.flags)) + else: result = false const