Bug 23146 – bounds checking is still done in @system functions

Status
RESOLVED
Resolution
INVALID
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-05-29T04:23:51Z
Last change time
2022-05-29T04:26:04Z
Assigned to
No Owner
Creator
Walter Bright

Comments

Comment #0 by bugzilla — 2022-05-29T04:23:51Z
Given: @system int test(int[] a) { return a[3]; } and compiling it with -vasm: _D4testQfFAiZi: 0000: 55 push RBP 0001: 48 8B EC mov RBP,RSP 0004: 48 83 EC 20 sub RSP,020h 0008: 48 89 5D E8 mov -018h[RBP],RBX 000c: 48 89 7D F0 mov -010h[RBP],RDI 0010: 48 89 75 F8 mov -8[RBP],RSI 0014: B8 03 00 00 00 mov EAX,3 0019: 48 3B F8 cmp RDI,RAX 001c: 77 15 ja L33 001e: 48 89 F9 mov RCX,RDI 0021: 48 89 C2 mov RDX,RAX 0024: BE 07 00 00 00 mov ESI,7 0029: BF 00 00 00 00 mov EDI,0 002e: E8 00 00 00 00 call L0 0033: 48 8B 55 F8 mov RDX,-8[RBP] 0037: 48 8B 5D F0 mov RBX,-010h[RBP] 003b: 8B 42 0C mov EAX,0Ch[RDX] 003e: 48 8B 5D E8 mov RBX,-018h[RBP] 0042: C9 leave 0043: C3 ret as you can see, the bounds check is there. Now let's compile it with -boundscheck=off: 0000: 55 push RBP 0001: 48 8B EC mov RBP,RSP 0004: 48 83 EC 10 sub RSP,010h 0008: 48 89 7D F0 mov -010h[RBP],RDI 000c: 48 89 75 F8 mov -8[RBP],RSI 0010: 48 8B 55 F8 mov RDX,-8[RBP] 0014: 48 8B 45 F0 mov RAX,-010h[RBP] 0018: 8B 42 0C mov EAX,0Ch[RDX] 001b: C9 leave 001c: C3 ret and no bounds check. This bug was introduced by https://github.com/dlang/dmd/pull/14170