Bug 17885 – Unable to remove a tuple from associative array.

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2017-10-08T12:46:05Z
Last change time
2019-07-05T09:30:11Z
Keywords
pull, wrong-code
Assigned to
No Owner
Creator
keepitsimplesirius

Comments

Comment #0 by keepitsimplesirius — 2017-10-08T12:46:05Z
Unable to remove a tuple from an associative array. Repro: unittest { import std.stdio; import std.typecons; auto set = (void[0][Tuple!(size_t, size_t)]).init; set[tuple!(size_t, size_t)(1, 2)] = (void[0]).init; set[tuple!(size_t, size_t)(10, 3)] = (void[0]).init; set[tuple!(size_t, size_t)(43, 3)] = (void[0]).init; writeln(set); set.remove(tuple!(size_t, size_t)(10, 3)); writeln(set); assert((tuple!(size_t, size_t)(10, 3) in set) is null); } int main() { return 0; } DMD64 D Compiler v2.076.0-dirty Copyright (c) 1999-2017 by Digital Mars written by Walter Bright
Comment #1 by ag0aep6g — 2017-10-08T21:02:26Z
I think this is a wrong-code bug in the compiler. For this D code: ---- struct T { ulong a, b; } T f() { return T(); } void main() { int[T] set; set.remove(f()); } ---- dmd generates this machine code for _Dmain (excerpt): ---- 0x00000000000300ba <+14>: call 0x30090 <_D4test1fFZSQk1T> 0x00000000000300bf <+19>: mov QWORD PTR [rbp-0x8],rax 0x00000000000300c3 <+23>: lea rdx,[rbp-0x8] 0x00000000000300c7 <+27>: lea rsi,[rip+0x238f42] # 0x269010 <_D17TypeInfo_S4test1T6__initZ> 0x00000000000300ce <+34>: mov rdi,QWORD PTR [rbp-0x10] 0x00000000000300d2 <+38>: call 0x303c0 <_aaDelX> ---- Note that after the `f` call, only rax gets copied to the stack. But the other half of the return value is in rdx which is not being copied. Changing component to dmd.
Comment #2 by dlang-bot — 2019-07-05T08:43:37Z
@FeepingCreature created dlang/dmd pull request #10140 "Fix issue 17885: use the correct expression's type when creating temporary for remove() call" fixing this issue: - Fix issue 17885: use the correct expression's type when creating temporary for remove() call https://github.com/dlang/dmd/pull/10140
Comment #3 by dlang-bot — 2019-07-05T09:30:11Z
dlang/dmd pull request #10140 "Fix issue 17885: use the correct expression's type when creating temporary for remove() call" was merged into stable: - 4b8438aeb1658c30f4b238c6c92925261ebb0531 by Mathis Beer: Fix issue 17885: use the correct expression's type when creating temporary for remove() call https://github.com/dlang/dmd/pull/10140