public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug modula2/112893] New: gm2 fails to detect procedure address actual parameter is incompatible with cardinal formal parameter
@ 2023-12-07  2:23 gaius at gcc dot gnu.org
  2023-12-07  2:24 ` [Bug modula2/112893] " gaius at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: gaius at gcc dot gnu.org @ 2023-12-07  2:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112893

            Bug ID: 112893
           Summary: gm2 fails to detect procedure address actual parameter
                    is incompatible with cardinal formal parameter
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: modula2
          Assignee: gaius at gcc dot gnu.org
          Reporter: gaius at gcc dot gnu.org
  Target Milestone: ---

gm2 silently compiles the following code:

MODULE proccard ;

FROM NumberIO IMPORT WriteCard ;
FROM StrIO IMPORT WriteString, WriteLn ;

PROCEDURE func () : CARDINAL ;
BEGIN
   RETURN 42
END func ;


BEGIN
   WriteString ('the value is: ') ; WriteCard (func, 5) ; WriteLn
END proccard.

whereas it should detect that func is the address of a procedure and this is
incompatible with the cardinal 1st parameter of WriteCard.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug modula2/112893] gm2 fails to detect procedure address actual parameter is incompatible with cardinal formal parameter
  2023-12-07  2:23 [Bug modula2/112893] New: gm2 fails to detect procedure address actual parameter is incompatible with cardinal formal parameter gaius at gcc dot gnu.org
@ 2023-12-07  2:24 ` gaius at gcc dot gnu.org
  2023-12-07  2:26 ` gaius at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: gaius at gcc dot gnu.org @ 2023-12-07  2:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112893

Gaius Mulley <gaius at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2023-12-07
             Status|UNCONFIRMED                 |ASSIGNED

--- Comment #1 from Gaius Mulley <gaius at gcc dot gnu.org> ---
Confirmed.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug modula2/112893] gm2 fails to detect procedure address actual parameter is incompatible with cardinal formal parameter
  2023-12-07  2:23 [Bug modula2/112893] New: gm2 fails to detect procedure address actual parameter is incompatible with cardinal formal parameter gaius at gcc dot gnu.org
  2023-12-07  2:24 ` [Bug modula2/112893] " gaius at gcc dot gnu.org
@ 2023-12-07  2:26 ` gaius at gcc dot gnu.org
  2023-12-07  2:44 ` gaius at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: gaius at gcc dot gnu.org @ 2023-12-07  2:26 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112893

--- Comment #2 from Gaius Mulley <gaius at gcc dot gnu.org> ---
This bug has been forwarded from the gm2 mailing list.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug modula2/112893] gm2 fails to detect procedure address actual parameter is incompatible with cardinal formal parameter
  2023-12-07  2:23 [Bug modula2/112893] New: gm2 fails to detect procedure address actual parameter is incompatible with cardinal formal parameter gaius at gcc dot gnu.org
  2023-12-07  2:24 ` [Bug modula2/112893] " gaius at gcc dot gnu.org
  2023-12-07  2:26 ` gaius at gcc dot gnu.org
@ 2023-12-07  2:44 ` gaius at gcc dot gnu.org
  2023-12-07 12:58 ` gaius at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: gaius at gcc dot gnu.org @ 2023-12-07  2:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112893

--- Comment #3 from Gaius Mulley <gaius at gcc dot gnu.org> ---
Created attachment 56822
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56822&action=edit
Proposed fix v1

Here is version 1 of a bugfix which catches an actual parameter of type address
as a mismatch with a formal parameter of type cardinal.  It treats all
procedures without () as an address.  This satisfies ISO modula-2 but not the
PIM variants.

Version 2 should improve the type checker (M2Check) module by changing the
assumption that a procedure without () is an address to a pointer of a fully
formed proc type.  In turn SymbolTable.GetType should be changed to return the
pointer to proc type.  Every call to SymbolTable.GetType would need to be
eyeball checked and maybe replaced by GetReturnType if necessary.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug modula2/112893] gm2 fails to detect procedure address actual parameter is incompatible with cardinal formal parameter
  2023-12-07  2:23 [Bug modula2/112893] New: gm2 fails to detect procedure address actual parameter is incompatible with cardinal formal parameter gaius at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-12-07  2:44 ` gaius at gcc dot gnu.org
@ 2023-12-07 12:58 ` gaius at gcc dot gnu.org
  2023-12-07 13:11 ` cvs-commit at gcc dot gnu.org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: gaius at gcc dot gnu.org @ 2023-12-07 12:58 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112893

Gaius Mulley <gaius at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #56822|0                           |1
        is obsolete|                            |

--- Comment #4 from Gaius Mulley <gaius at gcc dot gnu.org> ---
Created attachment 56826
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56826&action=edit
Proposed fix v2

This version of the patch includes changes to the base type compatibility
assignment array to allow PIM dialect to assign cardinal to address.  This
patch does not implement the full idea mentioned in the previous comment
however it does fix this PR and provides ISO and PIM with different assignment
rules (for address and cardinal).

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug modula2/112893] gm2 fails to detect procedure address actual parameter is incompatible with cardinal formal parameter
  2023-12-07  2:23 [Bug modula2/112893] New: gm2 fails to detect procedure address actual parameter is incompatible with cardinal formal parameter gaius at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-12-07 12:58 ` gaius at gcc dot gnu.org
@ 2023-12-07 13:11 ` cvs-commit at gcc dot gnu.org
  2023-12-07 13:12 ` gaius at gcc dot gnu.org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-12-07 13:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112893

--- Comment #5 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:f8c8aebc597611b8d37edce165a891d00e23a9c1

commit r14-6271-gf8c8aebc597611b8d37edce165a891d00e23a9c1
Author: Gaius Mulley <gaiusmod2@gmail.com>
Date:   Thu Dec 7 13:10:49 2023 +0000

    PR modula2/112893 detect procedure address incompatible with cardinal in
iso

    In ISO m2 the type cardinal is assignment incompatible with address (but
    it is allowed in PIM).  The patch also extends the type checker to include
    procedures (which appear as having GetType () = address).  At some point
    this should be be improved to use a pointer to proc type.  Perhaps in
    the next stage1.
    For now this will catch procedures being passed as actual parameters into
    a formal cardinal parameter in ISO m2 (for example).

    gcc/m2/ChangeLog:

            PR modula2/112893
            * gm2-compiler/M2Base.mod (Ass): Extend array to include proc row
            and column.  Allow PIM to assign cardinal variables to address
            variables.
            (Expr): Ditto.
            (Comp): Ditto.
            * gm2-compiler/M2Check.mod (getSType): New procedure function.
            Replace all occurances of GetSType with getSType.
            * gm2-compiler/M2GenGCC.mod (CodeParam): Rewrite format specifier
            error message.
            * gm2-compiler/M2Quads.mod (CheckProcTypeAndProcedure): Add tokno
            parameter.
            * gm2-compiler/M2Range.def (InitTypesParameterCheck): Add tokno
            parameter.
            (InitParameterRangeCheck): Add tokno parameter.
            Remove EXPORT QUALIFIED list.
            (InitParameterRangeCheck): Add tokno parameter.
            * gm2-compiler/M2Range.mod (InitTypesParameterCheck): Add tokno
            parameter and pass tokno to PutRangeParam.
            (InitParameterRangeCheck): Add tokno parameter and pass tokno to
            PutRangeParam.
            (PutRangeParam): Add tokno parameter and assign to tokenNo.
            (FoldTypeParam): Rewrite format string.

    gcc/testsuite/ChangeLog:

            PR modula2/112893
            * gm2/iso/fail/proccard.mod: New test.
            * gm2/pim/pass/proccard.mod: New test.

    Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug modula2/112893] gm2 fails to detect procedure address actual parameter is incompatible with cardinal formal parameter
  2023-12-07  2:23 [Bug modula2/112893] New: gm2 fails to detect procedure address actual parameter is incompatible with cardinal formal parameter gaius at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2023-12-07 13:11 ` cvs-commit at gcc dot gnu.org
@ 2023-12-07 13:12 ` gaius at gcc dot gnu.org
  2023-12-08 14:39 ` gaius at gcc dot gnu.org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: gaius at gcc dot gnu.org @ 2023-12-07 13:12 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112893

Gaius Mulley <gaius at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #6 from Gaius Mulley <gaius at gcc dot gnu.org> ---
Closing now the patch has been applied.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug modula2/112893] gm2 fails to detect procedure address actual parameter is incompatible with cardinal formal parameter
  2023-12-07  2:23 [Bug modula2/112893] New: gm2 fails to detect procedure address actual parameter is incompatible with cardinal formal parameter gaius at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2023-12-07 13:12 ` gaius at gcc dot gnu.org
@ 2023-12-08 14:39 ` gaius at gcc dot gnu.org
  2024-04-19 22:39 ` gaius at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: gaius at gcc dot gnu.org @ 2023-12-08 14:39 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112893

Gaius Mulley <gaius at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|FIXED                       |---
             Status|RESOLVED                    |REOPENED

--- Comment #7 from Gaius Mulley <gaius at gcc dot gnu.org> ---
Re-opening as this should issue an error for the PIM dialects.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug modula2/112893] gm2 fails to detect procedure address actual parameter is incompatible with cardinal formal parameter
  2023-12-07  2:23 [Bug modula2/112893] New: gm2 fails to detect procedure address actual parameter is incompatible with cardinal formal parameter gaius at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2023-12-08 14:39 ` gaius at gcc dot gnu.org
@ 2024-04-19 22:39 ` gaius at gcc dot gnu.org
  2024-04-20 13:36 ` cvs-commit at gcc dot gnu.org
  2024-04-20 13:40 ` gaius at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: gaius at gcc dot gnu.org @ 2024-04-19 22:39 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112893

--- Comment #8 from Gaius Mulley <gaius at gcc dot gnu.org> ---
Created attachment 57992
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57992&action=edit
Proposed fix v3

This patch creates a proctype for every procedure and then uses this associated
proctype during type checking.  M2Check.mod calls upon GetProcedureProcType
rather than assume a procedure is an ADDRESS type.  The patch also
changes/fixes some test code which assumed procedure/address types were the
same.

All regressions pass on x86_64 (non bootstrap, once full bootstrap completes
and passes the patch will be applied and the pr closed).

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug modula2/112893] gm2 fails to detect procedure address actual parameter is incompatible with cardinal formal parameter
  2023-12-07  2:23 [Bug modula2/112893] New: gm2 fails to detect procedure address actual parameter is incompatible with cardinal formal parameter gaius at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2024-04-19 22:39 ` gaius at gcc dot gnu.org
@ 2024-04-20 13:36 ` cvs-commit at gcc dot gnu.org
  2024-04-20 13:40 ` gaius at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-04-20 13:36 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112893

--- Comment #9 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:f9a48fe7032d9894e88d0d121ba6f75b08ea5dcb

commit r14-10053-gf9a48fe7032d9894e88d0d121ba6f75b08ea5dcb
Author: Gaius Mulley <gaiusmod2@gmail.com>
Date:   Sat Apr 20 14:35:18 2024 +0100

    PR modula2/112893 full type checking between proctype and procedure not
implemented

    This patch implements full type checking between proctype and procedures.
    The change implements an associated proc type built for each
    procedure.  M2Check.mod will request GetProcedureProcType if it encounters
    a procedure.  Before this patch a procedure was associated with the type
    ADDRESS in the type checking module M2Check.  The
    gm2/pim/pass/proccard.mod have been corrected now this assumption has
    been removed.

    gcc/m2/ChangeLog:

            PR modula2/112893
            * gm2-compiler/M2Check.mod (GetProcedureProcType): Import.
            (getType): Return value using GetProcedureProcType if sym is a
            procedure.
            * gm2-compiler/M2Range.mod (FoldTypeExpr): Remove quad if
            expression is type compatible.
            * gm2-compiler/SymbolTable.def (GetProcedureProcType): New
            procedure function.
            * gm2-compiler/SymbolTable.mod (Procedure): Add ProcedureType.
            (MakeProcedure): Initialize ProcedureType.
            (PutParam): Call AddProcedureProcTypeParam.
            (PutVarParam): Call AddProcedureProcTypeParam.
            (AddProcedureProcTypeParam): New procedure.
            (GetProcedureProcType): New procedure function.

    gcc/testsuite/ChangeLog:

            PR modula2/112893
            * gm2/pim/pass/another.mod: Correct bug exposed by type checker.
            Swap ProcA and ProcB assignments.
            * gm2/pim/pass/proccard.mod: Use VAL to convert procedure into a
            cardinal.
            * gm2/iso/const/fail/castproctype.mod: New test.
            * gm2/pim/fail/badproctype.mod: New test.

    Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [Bug modula2/112893] gm2 fails to detect procedure address actual parameter is incompatible with cardinal formal parameter
  2023-12-07  2:23 [Bug modula2/112893] New: gm2 fails to detect procedure address actual parameter is incompatible with cardinal formal parameter gaius at gcc dot gnu.org
                   ` (8 preceding siblings ...)
  2024-04-20 13:36 ` cvs-commit at gcc dot gnu.org
@ 2024-04-20 13:40 ` gaius at gcc dot gnu.org
  9 siblings, 0 replies; 11+ messages in thread
From: gaius at gcc dot gnu.org @ 2024-04-20 13:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112893

Gaius Mulley <gaius at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|REOPENED                    |RESOLVED

--- Comment #10 from Gaius Mulley <gaius at gcc dot gnu.org> ---
Closing now the patch has been applied.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-04-20 13:40 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-07  2:23 [Bug modula2/112893] New: gm2 fails to detect procedure address actual parameter is incompatible with cardinal formal parameter gaius at gcc dot gnu.org
2023-12-07  2:24 ` [Bug modula2/112893] " gaius at gcc dot gnu.org
2023-12-07  2:26 ` gaius at gcc dot gnu.org
2023-12-07  2:44 ` gaius at gcc dot gnu.org
2023-12-07 12:58 ` gaius at gcc dot gnu.org
2023-12-07 13:11 ` cvs-commit at gcc dot gnu.org
2023-12-07 13:12 ` gaius at gcc dot gnu.org
2023-12-08 14:39 ` gaius at gcc dot gnu.org
2024-04-19 22:39 ` gaius at gcc dot gnu.org
2024-04-20 13:36 ` cvs-commit at gcc dot gnu.org
2024-04-20 13:40 ` 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).