Skip to content

seg fault on floating point code #21142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
WalterBright opened this issue Apr 3, 2025 · 0 comments · May be fixed by #21148
Open

seg fault on floating point code #21142

WalterBright opened this issue Apr 3, 2025 · 0 comments · May be fixed by #21148
Labels
Arch:x86_64 Issues specific to x86_64 Compiler:Backend glue code, optimizer, code generation Severity:Crash built program crashes

Comments

@WalterBright
Copy link
Member

The code:

void main() {
       double a,b,c;
       double* pa,pb;

       a = 5;
       b = a++;
       assert(a == 6);
       pa = &a;
       pb = &b;
       *pb = (*pa)++;
}

The generated code:

_Dmain:
0000:   55                       push      RBP
0001:   48 8B EC                 mov       RBP,RSP
0004:   48 83 EC 10              sub       RSP,010h
0008:   F2 0F 10 05 FC FF FF FF  movsd     XMM0,[0FFFFFFFCh][RIP]
0010:   F2 48 0F 11 45 F0        movsd     -010h[RBP],XMM0
0016:   F2 48 0F 11 45 F8        movsd     -8[RBP],XMM0
001c:   31 C0                    xor       EAX,EAX
001e:   F2 0F 10 0D FC FF FF FF  movsd     XMM1,[0FFFFFFFCh][RIP]
0026:   F2 48 0F 11 4D F0        movsd     -010h[RBP],XMM1
002c:   F2 48 0F 10 55 F0        movsd     XMM2,-010h[RBP]
0032:   F2 0F 10 DA              movsd     XMM3,XMM2
0036:   48 B8 00 00 00 00 00 00 F0 3F  mov       RAX,03FF0000000000000h
0040:   66 48 0F 6E C0           movd      XMM0,RAX
0045:   F2 0F 58 D0              addsd     XMM2,XMM0
0049:   F2 48 0F 11 55 F0        movsd     -010h[RBP],XMM2
004f:   F2 48 0F 11 5D F8        movsd     -8[RBP],XMM3
0055:   F2 0F 10 4D F0           movsd     XMM1,-010h[RBP]
005a:   F2 0F 10 15 FC FF FF FF  movsd     XMM2,[0FFFFFFFCh][RIP]
0062:   66 0F 2E D1              ucomisd   XMM2,XMM1
0066:   7A 02                    jp        L6a
0068:   74 0F                    je        L79
006a:   BE 08 00 00 00           mov       ESI,8
006f:   BF 00 00 00 00           mov       EDI,0
0074:   E8 00 00 00 00           call      L0
0079:   48 8D 45 F0              lea       RAX,-010h[RBP]  <= pointer value put in RAX
007d:   48 8D 4D F8              lea       RCX,-8[RBP]
0081:   F2 48 0F 10 00           movsd     XMM0,[RAX]
0086:   F2 0F 10 C8              movsd     XMM1,XMM0
008a:   48 B8 00 00 00 00 00 00 F0 3F  mov       RAX,03FF0000000000000h  <= stepped on RAX pointer value
0094:   66 48 0F 6E D0           movd      XMM2,RAX
0099:   F2 0F 58 C2              addsd     XMM0,XMM2
009d:   F2 48 0F 11 00           movsd     [RAX],XMM0   <= seg fault here
00a2:   F2 48 0F 11 09           movsd     [RCX],XMM1
00a7:   C9                       leave
00a8:   C3                       ret
@WalterBright WalterBright added Arch:x86_64 Issues specific to x86_64 Compiler:Backend glue code, optimizer, code generation Severity:Crash built program crashes labels Apr 3, 2025
WalterBright added a commit to WalterBright/dmd that referenced this issue Apr 4, 2025
@WalterBright WalterBright linked a pull request Apr 4, 2025 that will close this issue
@dkorpel dkorpel linked a pull request Apr 4, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arch:x86_64 Issues specific to x86_64 Compiler:Backend glue code, optimizer, code generation Severity:Crash built program crashes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant