Bug 10642 – Win64: wrong codegen comparing different sized integer arguments

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
All
Creation time
2013-07-14T09:55:00Z
Last change time
2015-06-09T05:11:59Z
Keywords
wrong-code
Assigned to
nobody
Creator
r.sagitario

Comments

Comment #0 by r.sagitario — 2013-07-14T09:55:38Z
Another faiing reduction from the phobos unittests: import std.stdio; void _assertEq (ubyte lhs, short rhs, string msg, string file, size_t line) { immutable result = lhs == rhs; if(!result) { string op = "=="; if(msg.length > 0) writefln(`_assertEq failed: [%s] is not [%s].`, lhs, rhs); else writefln(`_assertEq failed: [%s] is not [%s]: %s`, lhs, rhs, msg); } assert(result); } struct Date { short year; ubyte month; ubyte day; } struct MonthDay { ubyte month; short day; } unittest { static void test(Date date, int day, MonthDay expected, size_t line = __LINE__) { _assertEq(date.day, expected.day, "", __FILE__, line); } test(Date(1999, 1, 1), 1, MonthDay(1,1)); } void main() {} compile with "dmd -O -m64 test.d" produces _assertEq failed: [208] is not [1]: core.exception.AssertError@test(16): Assertion failure Checking the disassembly shows that DIL is read in _assertEq, but never initialized properly. I guess bh was meant instead: _D4test9_assertEqFhsAyaAyamZv: 0000000000000000: 55 push rbp 0000000000000001: 48 8B EC mov rbp,rsp 0000000000000004: 48 83 EC 48 sub rsp,48h 0000000000000008: 56 push rsi 0000000000000009: 57 push rdi 000000000000000A: 41 54 push r12 000000000000000C: 4C 89 45 20 mov qword ptr [rbp+20h],r8 0000000000000010: 4C 89 CE mov rsi,r9 0000000000000013: 8A 7D 30 mov bh,byte ptr [rbp+30h] 0000000000000016: 44 0F B6 D7 movzx r10d,dil 000000000000001A: 44 0F BF DE movsx r11d,si 000000000000001E: 45 3B D3 cmp r10d,r11d 0000000000000021: 41 0F 94 C4 sete r12b 0000000000000025: 45 0F B6 E4 movzx r12d,r12b 0000000000000029: 44 88 65 F0 mov byte ptr [rbp-10h],r12b
Comment #1 by r.sagitario — 2013-07-14T09:57:16Z
Forgot to add that this only happens with optimizations enabled.
Comment #2 by bugzilla — 2013-07-15T16:55:23Z
> compile with "dmd -O -m64 test.d" produces Need to add -unittest
Comment #3 by bugzilla — 2013-07-15T17:48:51Z
Comment #4 by bugzilla — 2013-07-16T11:14:50Z
Comment #5 by github-bugzilla — 2013-07-16T13:06:42Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/439e85a7ed96dc9eb03a36c967cf854b8e176cf3 fix Issue 10642 - Win64: wrong codegen comparing different sized integer arguments https://github.com/D-Programming-Language/dmd/commit/43d47a1dbc378bbeebf7299b2075717f3e6db399 Merge pull request #2352 from WalterBright/fix10642-2 fix Issue 10642 - Win64: wrong codegen comparing different sized integer...
Comment #6 by github-bugzilla — 2013-07-16T13:12:13Z
Commit pushed to dmd-1.x at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/eab5bf88f306068adff69acf50f7536555f42151 Merge pull request #2352 from WalterBright/fix10642-2 fix Issue 10642 - Win64: wrong codegen comparing different sized integer...