Single array assignments get mixed up with -O2
Original Reporter info from Mantis: Michalis @michaliskambi
-
Reporter name: Michalis Kamburelis
Original Reporter info from Mantis: Michalis @michaliskambi
- Reporter name: Michalis Kamburelis
Description:
See the attached source code. It passes around values of the TVector3Single type (array [0..2] of Single). Somehow, the value of the Normal is incorrect inside the 1st DoTexCoordVertex call. Looks like the value of the Normal variable is replaced by the current value of the Vertex variable.
Happens only when compiled with -O2. With -O1 or none, everything works correctly.
$ fpc single_array_mixup.pas
$ ./single_array_mixup
Normal: 123.0 456.0 789.0
Normal: 987.0 654.0 321.0
$ fpc -O2 single_array_mixup.pas
$ ./single_array_mixup
Normal: 111.0 222.0 333.0 # <--- this is wrong
Normal: 987.0 654.0 321.0
Tested and confirmed with both FPC 2.4.0 and recent trunk (revision 15976), both on Linux i386.
Various code changes make the bug disappear:
- if I move procedure RenderFromViewEverything implementation into the main program (begin end.), the bug disappears.
- if I remove the second assignment of the Normal variable, the bug disappears.
Mantis conversion info:
- Mantis ID: 17413
- OS: Debian GNU/Linux
- OS Build: (testing)
- Platform: i386
- Version: 2.5.1
- Fixed in version: 2.6.0
- Fixed in revision: 15990 (#ac8add7c)
- Monitored by: » crossbuilder (Burkhard Carstens), » luizamerico (Luiz Americo)