Skip to content
GitLab
    • Why GitLab
    • Pricing
    • Contact Sales
    • Explore
  • Why GitLab
  • Pricing
  • Contact Sales
  • Explore
  • Sign in
  • Get free trial
  • FPC
  • FPC FPC
  • FPC SourceFPC Source
  • Issues
  • #35651

invalid mov size when reading byte followed by and not

Original Reporter info from Mantis: BeniBela @benibela
  • Reporter name: Benito van der Zander

Description:

This creates a 32-bit mov when it should create a 8-bit mov, on amd64

function getChar(source: pchar): integer;
begin
000000000040114F 00 add %cl,0x7fe08307(%rbx)
result := (ord(source^) and not $80);
0000000000401150 8b07 mov (%rdi),%eax
0000000000401152 83e07f and $0x7f,%eax
end;
0000000000401155 c3 retq

Steps to reproduce:

program Project1;
{$mode objfpc}{$H+}

function getChar(source: pchar): integer;
begin
  result := (ord(source^) and not $80);
end;

var
  s: string;
begin
  setlength(s, 100); //create a large string on heap, so valgrind actually gives an error
  s[100] := 'a';
  writeln(getChar(pchar(s)+length(s) - 1));
end.

Mantis conversion info:

  • Mantis ID: 35651
  • OS: linux
  • OS Build: opensuse
  • Build: r40721
  • Platform: amd64
  • Version: 3.3.1
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking