From f37cfdf83742536a81a1878a94126827aeaddf7e Mon Sep 17 00:00:00 2001 From: Dennis Date: Wed, 12 Feb 2025 13:44:16 +0100 Subject: [PATCH] Fix #20831 - Mangle conflict after ImportC statement expression gets expanded from macro (#20854) --- compiler/src/dmd/identifier.d | 7 ++++--- compiler/test/runnable/test20831.c | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 compiler/test/runnable/test20831.c diff --git a/compiler/src/dmd/identifier.d b/compiler/src/dmd/identifier.d index 231aa5832f..9ef8285f8e 100644 --- a/compiler/src/dmd/identifier.d +++ b/compiler/src/dmd/identifier.d @@ -248,13 +248,14 @@ nothrow: * directly, but that would unnecessary lengthen symbols names. See issue: * https://issues.dlang.org/show_bug.cgi?id=23722 */ - static struct Key { uint fileOffset; string prefix; string parent; } + static struct Key { string locKey; string prefix; string parent; } __gshared uint[Key] counters; + string locKey = cast(string) (sl.filename ~ idBuf[]); static if (__traits(compiles, counters.update(Key.init, () => 0u, (ref uint a) => 0u))) { // 2.082+ - counters.update(Key(loc.fileOffset, prefix, parent), + counters.update(Key(locKey, prefix, parent), () => 1u, // insertion (ref uint counter) // update { @@ -266,7 +267,7 @@ nothrow: } else { - const key = Key(loc.fileOffset, prefix, parent); + const key = Key(locKey, prefix, parent); if (auto pCounter = key in counters) { idBuf.writestring("_"); diff --git a/compiler/test/runnable/test20831.c b/compiler/test/runnable/test20831.c new file mode 100644 index 0000000000..29a91a9f87 --- /dev/null +++ b/compiler/test/runnable/test20831.c @@ -0,0 +1,15 @@ +// https://github.com/dlang/dmd/issues/20831 +#include "assert.h" + +int* p; + +#define IMPL() \ +f()\ +{\ + assert(p);\ + assert(0);\ +} + +void IMPL() + +void main(void) {}