From 23550159b5f18ef7a7e32ae184d59dd0bc5fd825 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Fri, 16 Dec 2022 21:05:44 +0800 Subject: [PATCH 1/4] fixes #21116; always mangles the param --- compiler/ccgtypes.nim | 4 ++-- tests/ccgbugs/t21116.nim | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 tests/ccgbugs/t21116.nim diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index d7b56de5bb866..2b3ab1ce770cb 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -69,8 +69,8 @@ proc fillParamName(m: BModule; s: PSym) = # and a function called in main or proxy uses `socket` as a parameter name. # That would lead to either needing to reload `proxy` or to overwrite the # executable file for the main module, which is running (or both!) -> error. - if m.hcrOn or isKeyword(s.name) or m.g.config.cppDefines.contains(res): - res.add "_0" + # always mangles the param; bug #21116 + res.add "_0" s.loc.r = res.rope writeMangledName(m.ndi, s, m.config) diff --git a/tests/ccgbugs/t21116.nim b/tests/ccgbugs/t21116.nim new file mode 100644 index 0000000000000..c4a583bdac42b --- /dev/null +++ b/tests/ccgbugs/t21116.nim @@ -0,0 +1,11 @@ +discard """ + target: "c cpp" + disabled: windows +""" +# bug #21116 +import posix + +proc p(glob: string) = + discard posix.glob(glob, 0, nil, nil) + +p "*" From ffbc693653685dccc601048175247ec6e44168de Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Fri, 16 Dec 2022 21:20:22 +0800 Subject: [PATCH 2/4] idOrSig --- compiler/ccgtypes.nim | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 2b3ab1ce770cb..3c9f9d923d5b6 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -48,11 +48,9 @@ proc fillBackendName(m: BModule; s: PSym) = writeMangledName(m.ndi, s, m.config) proc fillParamName(m: BModule; s: PSym) = - ## we cannot use 'sigConflicts' here since we have a BModule, not a BProc. - ## Fortunately C's scoping rules are sane enough so that that doesn't - ## cause any trouble. if s.loc.r == "": var res = s.name.s.mangle + res.add idOrSig(s, res, m.sigConflicts) # Take into account if HCR is on because of the following scenario: # if a module gets imported and it has some more importc symbols in it, # some param names might receive the "_0" suffix to distinguish from what @@ -69,8 +67,6 @@ proc fillParamName(m: BModule; s: PSym) = # and a function called in main or proxy uses `socket` as a parameter name. # That would lead to either needing to reload `proxy` or to overwrite the # executable file for the main module, which is running (or both!) -> error. - # always mangles the param; bug #21116 - res.add "_0" s.loc.r = res.rope writeMangledName(m.ndi, s, m.config) From 57ff5cd0fd71286a5e8dd4526ac94a377ccb2b33 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Fri, 16 Dec 2022 23:08:20 +0800 Subject: [PATCH 3/4] fixes tests --- tests/ccgbugs/tnoalias.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ccgbugs/tnoalias.nim b/tests/ccgbugs/tnoalias.nim index f200992d7522a..96c3d390b5376 100644 --- a/tests/ccgbugs/tnoalias.nim +++ b/tests/ccgbugs/tnoalias.nim @@ -1,5 +1,5 @@ discard """ - ccodecheck: "\\i@'NI* NIM_NOALIAS field;' @'NIM_CHAR* NIM_NOALIAS x,' @'void* NIM_NOALIAS q'" + ccodecheck: "\\i@'NI* NIM_NOALIAS field;' @'NIM_CHAR* NIM_NOALIAS x__0qEngDE9aYoYsF8tWnyPacw,' @'void* NIM_NOALIAS q'" """ type From 5c30bbf1c9ea1ce9015df7b528c10868c9756ed0 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Sat, 17 Dec 2022 01:38:31 +0800 Subject: [PATCH 4/4] Apply suggestions from code review --- tests/ccgbugs/t21116.nim | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/ccgbugs/t21116.nim b/tests/ccgbugs/t21116.nim index c4a583bdac42b..6418df5397e10 100644 --- a/tests/ccgbugs/t21116.nim +++ b/tests/ccgbugs/t21116.nim @@ -3,9 +3,8 @@ discard """ disabled: windows """ # bug #21116 -import posix +import std/os proc p(glob: string) = - discard posix.glob(glob, 0, nil, nil) - -p "*" + for _ in walkFiles(glob): discard +p("dir/*")