View Issue Details

IDProjectCategoryView StatusLast Update
0035897FPCCompilerpublic2019-08-03 15:53
ReporterShreevatsa RAssigned ToJonas Maebe 
PrioritylowSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version3.0.4Product Buildx86_64 
Target VersionFixed in Version3.3.1 
Summary0035897: Spurious warnings about unreachable code with iso mode and mod operator
DescriptionThe following example is minimized from a larger example (trying to compile some old programs of Donald Knuth). I needed the "{$mode iso}" so that the type "integer" uses a 32-bit integer. With that, I get several incorrect warnings about unreachable code, wherever the code uses the "mod" operator.

Here is an example, say test.pas:

{$mode iso}
program GLUE(input, output);

procedure printint(n: integer);
begin
  repeat
    writeln(n mod 10);
    n := n div 10;
  until n = 0;
end;

begin
  printint(23);
  writeln();
end.



The result of running "fpc test.pas" is:

Free Pascal Compiler version 3.0.4 [2018/10/02] for x86_64
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: Darwin for x86_64
Compiling test.pas
test.pas(7,15) Warning: unreachable code
Assembling (pipe) test.s
Linking test
(etc.)

The binary works fine, it's just that there's an incorrect warning about code that is obviously reachable.
Steps To Reproduce1. Create a file test.pas with the above contents (or see attached).

2. Run "fpc test.pas"

3. Look for warnings.
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget-
Attached Files
  • test.pas (192 bytes)
    {$mode iso}
    program GLUE(input, output);
    
    procedure printint(n: integer);
    begin
      repeat
        writeln(n mod 10);
        n := n div 10;
      until n = 0;
    end;
    
    begin
      printint(23);
      writeln();
    end.
    
    test.pas (192 bytes)

Activities

Shreevatsa R

2019-07-27 21:51

reporter  

test.pas (192 bytes)
{$mode iso}
program GLUE(input, output);

procedure printint(n: integer);
begin
  repeat
    writeln(n mod 10);
    n := n div 10;
  until n = 0;
end;

begin
  printint(23);
  writeln();
end.
test.pas (192 bytes)

Shreevatsa R

2019-07-27 21:55

reporter   ~0117442

Sorry, the title should say "iso mode", not "is mode". Also, here's an even shorter example:

{$mode iso}
program test(input, output);

procedure doit(n : integer);
begin
  writeln(n mod 10);
end;

begin
   doit(23);
end.

J. Gareth Moreton

2019-07-27 23:50

developer   ~0117445

Fixed spelling mistake in title and estimated priority as "Low", since it's only a warning and doesn't appear to produce bad code.

Thaddy de Koning

2019-07-28 07:51

reporter   ~0117448

With trunk I can not reproduce this.
I used fpc -vwhnql -CX -XXs -O4 test.pas

No warnings or hints.
I also tested other optimization settings
I used a Raspbian armhf compiler r 42485

Jonas Maebe

2019-08-03 15:53

manager   ~0117557

It's indeed already fixed in trunk. I added a test so it won't break again undetected.

Issue History

Date Modified Username Field Change
2019-07-27 21:51 Shreevatsa R New Issue
2019-07-27 21:51 Shreevatsa R File Added: test.pas
2019-07-27 21:55 Shreevatsa R Note Added: 0117442
2019-07-27 23:50 J. Gareth Moreton Priority normal => low
2019-07-27 23:50 J. Gareth Moreton Summary Spurious warnings about unreachable code with is mode and mod operator => Spurious warnings about unreachable code with iso mode and mod operator
2019-07-27 23:50 J. Gareth Moreton Description Updated View Revisions
2019-07-27 23:50 J. Gareth Moreton Steps to Reproduce Updated View Revisions
2019-07-27 23:50 J. Gareth Moreton FPCTarget => -
2019-07-27 23:50 J. Gareth Moreton Note Added: 0117445
2019-07-28 07:51 Thaddy de Koning Note Added: 0117448
2019-08-03 15:53 Jonas Maebe Assigned To => Jonas Maebe
2019-08-03 15:53 Jonas Maebe Status new => resolved
2019-08-03 15:53 Jonas Maebe Resolution open => fixed
2019-08-03 15:53 Jonas Maebe Fixed in Version => 3.3.1
2019-08-03 15:53 Jonas Maebe Note Added: 0117557