Skip to content
GitLab
  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
    • Switch to GitLab Next
  • Sign in / Register
  • FPC Source FPC Source
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 1,275
    • Issues 1,275
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 59
    • Merge requests 59
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • External wiki
    • External wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • FPC
  • FPC
  • FPC SourceFPC Source
  • Issues
  • #38129
Closed
Open
Created Nov 25, 2020 by FPC Admin account@fpc_adminOwner

Wrong code generated on x86-64

Original Reporter info from Mantis: runewalsh
  • Reporter name:

Description:

Code below should write "#######... 70%", but depending on compiler settings it writes garbage or even crashes.
I have this happening on x86-64-win64 with optimization levels greater than -O1.

Bug vanishes after replacing
pChar(result)[i] :=
with conventional
result[1 + i] :=

or after removing the second condition part, i. e.
(i = int32(divs) - 1) and (progress >= 1)

or after replacing any of 32-bit variables with 64-bit equivalent

so I can't even come close to guessing what's going on here.

Steps to reproduce:

function Bar(const progress: single; divs: uint32): string;
const
	BarSym: array[boolean] of char = ('.', '#');
var
	i: int32;
begin
	SetLength(result, divs);
	for i := 0 to int32(divs) - 1 do
		pChar(result)[i] := BarSym[(progress >= (0.75 + i) / divs) or (i = int32(divs) - 1) and (progress >= 1)];
end;

var
	s: string;

begin
	writeln(Bar(0.7, 10) + ' 70%');
end.

Mantis conversion info:

  • Mantis ID: 38129
  • Build: 63950
  • Platform: x86-64-win64
  • Fixed in version: 3.3.1
  • Fixed in revision: 49095 (#cc64d9eb)
  • Monitored by: » Vincent (Vincent Snijders), » @MageSlayer (Denis Golovan), » @CuriousKit (J. Gareth Moreton)
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking