public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug modula2/114055] New: poor error message generated during when checking the BY constant expression type
@ 2024-02-22 11:25 gaius at gcc dot gnu.org
2024-02-22 11:25 ` [Bug modula2/114055] " gaius at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: gaius at gcc dot gnu.org @ 2024-02-22 11:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114055
Bug ID: 114055
Summary: poor error message generated during when checking the
BY constant expression type
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: modula2
Assignee: gaius at gcc dot gnu.org
Reporter: gaius at gcc dot gnu.org
Target Milestone: ---
This is a minor follow on bug to 114026.
$ cat forloopby.mod
MODULE forloopby ;
PROCEDURE init ;
CONST
increment = CARDINAL (1) ;
VAR
i: INTEGER ;
BEGIN
FOR i := 0 TO 10 BY increment DO
END
END init ;
BEGIN
init
END forloopby.
$ gm2 forloopby.mod
forloopby.mod: In function ‘init’:
forloopby.mod:10:8: error: In procedure ‘init’: type incompatibility between
‘INTEGER’ and ‘CARDINAL’
10 | FOR i := 0 TO 10 BY increment DO
| ^
which could be improved to mention the BY constant expression and designator
expression type fail.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug modula2/114055] poor error message generated during when checking the BY constant expression type
2024-02-22 11:25 [Bug modula2/114055] New: poor error message generated during when checking the BY constant expression type gaius at gcc dot gnu.org
@ 2024-02-22 11:25 ` gaius at gcc dot gnu.org
2024-02-22 13:44 ` gaius at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: gaius at gcc dot gnu.org @ 2024-02-22 11:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114055
Gaius Mulley <gaius at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |ASSIGNED
Last reconfirmed| |2024-02-22
Ever confirmed|0 |1
--- Comment #1 from Gaius Mulley <gaius at gcc dot gnu.org> ---
Confirmed.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug modula2/114055] poor error message generated during when checking the BY constant expression type
2024-02-22 11:25 [Bug modula2/114055] New: poor error message generated during when checking the BY constant expression type gaius at gcc dot gnu.org
2024-02-22 11:25 ` [Bug modula2/114055] " gaius at gcc dot gnu.org
@ 2024-02-22 13:44 ` gaius at gcc dot gnu.org
2024-02-22 15:06 ` cvs-commit at gcc dot gnu.org
2024-02-22 15:07 ` gaius at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: gaius at gcc dot gnu.org @ 2024-02-22 13:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114055
--- Comment #2 from Gaius Mulley <gaius at gcc dot gnu.org> ---
Created attachment 57497
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57497&action=edit
Proposed fix
The fix marks a constant created during the default BY clause of the FOR loop
as internal. The type checker will always return true if checking against an
internal const.
$ cat forloopby.mod
MODULE forloopby ;
PROCEDURE init ;
CONST
increment = CARDINAL (1) ;
VAR
i: INTEGER ;
BEGIN
FOR i := 0 TO 10 BY increment DO
END
END init ;
BEGIN
init
END forloopby.
gm2 forloopby.mod
forloopby.mod:10:8: error: In procedure ‘init’: type expression incompatibility
between ‘INTEGER’ and ‘CARDINAL’ detected between the designator ‘i’ and the BY
constant expression ‘increment’ in the FOR loop
10 | FOR i := 0 TO 10 BY increment DO
| ^~~~~~~~~~~~~~~~~~~~~~~~~
It also succeeds when compiling a for loop with a subrange which does not
include 1.
$ cat forloopby2.mod
MODULE forloopby2 ;
TYPE
negative = [-10..-1] ;
PROCEDURE init ;
VAR
i: negative ;
BEGIN
FOR i := MIN (negative) TO MAX (negative) DO
END
END init ;
BEGIN
init
END forloopby2.
$ gm2 forloopby2.mod
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug modula2/114055] poor error message generated during when checking the BY constant expression type
2024-02-22 11:25 [Bug modula2/114055] New: poor error message generated during when checking the BY constant expression type gaius at gcc dot gnu.org
2024-02-22 11:25 ` [Bug modula2/114055] " gaius at gcc dot gnu.org
2024-02-22 13:44 ` gaius at gcc dot gnu.org
@ 2024-02-22 15:06 ` cvs-commit at gcc dot gnu.org
2024-02-22 15:07 ` gaius at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-22 15:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114055
--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Gaius Mulley <gaius@gcc.gnu.org>:
https://gcc.gnu.org/g:c1667b1ef538e4da10cf83bdf1ae62d7bdd96128
commit r14-9136-gc1667b1ef538e4da10cf83bdf1ae62d7bdd96128
Author: Gaius Mulley <gaiusmod2@gmail.com>
Date: Thu Feb 22 15:02:19 2024 +0000
PR modula2/114055 improve error message when checking the BY constant
The fix marks a constant created during the default BY clause of the
FOR loop as internal. The type checker will always return true if
checking against an internal const.
gcc/m2/ChangeLog:
PR modula2/114055
* gm2-compiler/M2Check.mod (Import): IsConstLitInternal and
IsConstLit.
(isInternal): New procedure function.
(doCheck): Test for isInternal in either operand and early
return true.
* gm2-compiler/M2Quads.mod (PushOne): Rewrite with extra
parameter internal.
(BuildPseudoBy): Add TRUE parameter to PushOne call.
(BuildIncProcedure): Add FALSE parameter to PushOne call.
(BuildDecProcedure): Add FALSE parameter to PushOne call.
* gm2-compiler/M2Range.mod (ForLoopBeginTypeCompatible):
Uncomment code and tidy up error string.
* gm2-compiler/SymbolTable.def (PutConstLitInternal):
New procedure.
(IsConstLitInternal): New procedure function.
* gm2-compiler/SymbolTable.mod (PutConstLitInternal):
New procedure.
(IsConstLitInternal): New procedure function.
(SymConstLit): New field IsInternal.
(CreateConstLit): Initialize IsInternal to FALSE.
gcc/testsuite/ChangeLog:
PR modula2/114055
* gm2/pim/fail/forloopby.mod: New test.
* gm2/pim/pass/forloopby2.mod: New test.
Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug modula2/114055] poor error message generated during when checking the BY constant expression type
2024-02-22 11:25 [Bug modula2/114055] New: poor error message generated during when checking the BY constant expression type gaius at gcc dot gnu.org
` (2 preceding siblings ...)
2024-02-22 15:06 ` cvs-commit at gcc dot gnu.org
@ 2024-02-22 15:07 ` gaius at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: gaius at gcc dot gnu.org @ 2024-02-22 15:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114055
Gaius Mulley <gaius at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #4 from Gaius Mulley <gaius at gcc dot gnu.org> ---
Closing now the patch has been applied.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-02-22 15:07 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-22 11:25 [Bug modula2/114055] New: poor error message generated during when checking the BY constant expression type gaius at gcc dot gnu.org
2024-02-22 11:25 ` [Bug modula2/114055] " gaius at gcc dot gnu.org
2024-02-22 13:44 ` gaius at gcc dot gnu.org
2024-02-22 15:06 ` cvs-commit at gcc dot gnu.org
2024-02-22 15:07 ` gaius at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).