https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117371
Bug ID: 117371
Summary: [14.2 Regression] type incompatibility between
‘INTEGER’ and ‘CARDINAL’
Product: gcc
Version: 14.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: modula2
Assignee: gaius at gcc dot gnu.org
Reporter: [email protected]
Target Milestone: ---
The following compiles and runs fine with gm2 13.0:
(* -*- mode: Modula-2; compile-command: "gm2 -fiso -g -O2 -o primes primes.mod"
-*- *)
MODULE primes;
FROM STextIO IMPORT WriteString, WriteLn, ReadChar;
FROM SWholeIO IMPORT WriteCard;
IMPORT RealMath;
PROCEDURE Compute_Primes (is_prime : ARRAY OF BOOLEAN);
VAR
k, m : CARDINAL; (* line 10 *)
BEGIN
FOR k := 1 TO HIGH (is_prime) DO is_prime[k] := TRUE; END;
WriteCard (1, 1);
WriteString (" ");
FOR k := 2 TO HIGH (is_prime) DO
IF is_prime[k] THEN
WriteCard (k, 1);
WriteString (" ");
END;
FOR m := k * k TO HIGH (is_prime) BY k DO (* line 20 *)
is_prime[m] := FALSE;
END;
END;
WriteLn;
END Compute_Primes;
VAR
is_prime : ARRAY [1 .. 16 * 1024] OF BOOLEAN;
BEGIN
Compute_Primes (is_prime);
END primes.
When recompiling the same with gm2 14.0, I get:
gm2 -fiso -g -O2 -o primes primes.mod
cc1gm2: error: In procedure ‘Compute_Primes’: type incompatibility between
‘INTEGER’ and ‘CARDINAL’
There is no indication on the location of the error.
If, at line 10, I change CARDINAL to INTEGER I get:
gm2 -fiso -g -O2 -o primes primes.mod
primes.mod:20:35: error: In procedure ‘Compute_Primes’: type incompatibility
between ‘INTEGER’ and ‘CARDINAL’
20 | FOR m := k * k TO HIGH (is_prime) BY k DO
| ~~~~~~^~~~~~~~
Now there is a location for the error but I think the error is legit as
m, k, k*k, are INTEGER whereas HIGH returns a CARDINAL. So I think the
bug is triggered by the original code where m and k are CARDINALs.
By the way:
gm2 --version -fiso -g -O2 -o primes primes.mod
gm2 (Debian 14.2.0-3) 14.2.0
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.