[fpc-devel] Dangerous optimization in CASE..OF

Martok listbox at martoks-place.de
Sun Jul 16 21:31:03 CEST 2017


You (Florian) do realize that it's almost impossible to write a C++ program that
is not technically undefined? Their 'standards' are worse than our
'implementation-defined'.

FWIW, GCC agrees with Low-Level Enums, and given that clang regularly catches
hate when their 'optimizations' break stuff like the Linux kernel again...

g++:
  40058b:       8b 45 fc                mov    -0x4(%rbp),%eax
  40058e:       83 f8 07                cmp    $0x7,%eax
  400591:       77 76                   ja     400609 <_Z1f5tenum+0x89>
  400593:       89 c0                   mov    %eax,%eax
  400595:       48 8b 04 c5 d8 06 40    mov    0x4006d8(,%rax,8),%rax
  40059c:       00
  40059d:       ff e0                   jmpq   *%rax

g++ -O3:
  4005a4:       83 ff 07                cmp    $0x7,%edi
  4005a7:       77 14                   ja     4005bd <_Z1f5tenum+0x1d>
  4005a9:       89 ff                   mov    %edi,%edi
  4005ab:       ff 24 fd 18 07 40 00    jmpq   *0x400718(,%rdi,8)

Proving my point that we should aim to be better and safer than C, not worse.



More information about the fpc-devel mailing list