From d0b60f1fe3f82facec7f99f39b8bf188be3661a0 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sun, 8 Jul 2018 22:07:45 +0200 Subject: [PATCH] Generate dynlib strings as a single rope (#8247) In order not to trip the optimization in genInfixCall we have to do so. The same trick is also used in setExternName. Fixes #8241 --- compiler/cgen.nim | 4 +++- tests/cpp/t8241.nim | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 tests/cpp/t8241.nim diff --git a/compiler/cgen.nim b/compiler/cgen.nim index a57192f9cd..32891c62ca 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -574,11 +574,13 @@ proc loadDynamicLib(m: BModule, lib: PLib) = if lib.name == nil: internalError(m.config, "loadDynamicLib") proc mangleDynLibProc(sym: PSym): Rope = + # we have to build this as a single rope in order not to trip the + # optimization in genInfixCall if sfCompilerProc in sym.flags: # NOTE: sym.loc.r is the external name! result = rope(sym.name.s) else: - result = "Dl_$1_" % [rope(sym.id)] + result = rope(strutils.`%`("Dl_$1_", $sym.id)) proc symInDynamicLib(m: BModule, sym: PSym) = var lib = sym.annex diff --git a/tests/cpp/t8241.nim b/tests/cpp/t8241.nim new file mode 100644 index 0000000000..8e98fda10a --- /dev/null +++ b/tests/cpp/t8241.nim @@ -0,0 +1,7 @@ +discard """ + targets: "cpp" + action: "compile" +""" + +proc foo(): cstring {.importcpp: "", dynlib: "".} +echo foo()