public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug modula2/114548] New: gm2 fails to identify variable in a const expression
@ 2024-04-01 16:27 gaius at gcc dot gnu.org
  2024-04-01 16:27 ` [Bug modula2/114548] " gaius at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: gaius at gcc dot gnu.org @ 2024-04-01 16:27 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114548
           Summary: gm2 fails to identify variable in a const expression
           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: ---

As reported on the gm2 mailing list.

gm2 fails to identify the specific variable within a const expression.  It
gives an error for the whole expression rather than the sub expression in
error.
For example:

$ cat testcmplx.mod
MODULE testcmplx ;

CONST
   foo = CMPLX (r, i) ;

VAR
   r, i: REAL ;
BEGIN

END testcmplx.

$ gm2 -fiso testcmplx.mod 
testcmplx.mod:4:8: error: In program module ‘testcmplx’: in assignment, cannot
assign a variable to a constant ‘foo’
    4 |    foo = CMPLX (r, i) ;
      |    ~~~~^~~~~~~~~~~~~
testcmplx.mod:4:4: error: designator ‘foo’ is declared as a CONST
    4 |    foo = CMPLX (r, i) ;
      |    ^~~

it could identify r and i as variables.

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

* [Bug modula2/114548] gm2 fails to identify variable in a const expression
  2024-04-01 16:27 [Bug modula2/114548] New: gm2 fails to identify variable in a const expression gaius at gcc dot gnu.org
@ 2024-04-01 16:27 ` gaius at gcc dot gnu.org
  2024-04-01 16:28 ` gaius at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: gaius at gcc dot gnu.org @ 2024-04-01 16:27 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2024-04-01

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

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

* [Bug modula2/114548] gm2 fails to identify variable in a const expression
  2024-04-01 16:27 [Bug modula2/114548] New: gm2 fails to identify variable in a const expression gaius at gcc dot gnu.org
  2024-04-01 16:27 ` [Bug modula2/114548] " gaius at gcc dot gnu.org
@ 2024-04-01 16:28 ` gaius at gcc dot gnu.org
  2024-04-01 16:44 ` gaius at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: gaius at gcc dot gnu.org @ 2024-04-01 16:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Gaius Mulley <gaius at gcc dot gnu.org> ---
This is true for many of the standard procedure functions.

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

* [Bug modula2/114548] gm2 fails to identify variable in a const expression
  2024-04-01 16:27 [Bug modula2/114548] New: gm2 fails to identify variable in a const expression gaius at gcc dot gnu.org
  2024-04-01 16:27 ` [Bug modula2/114548] " gaius at gcc dot gnu.org
  2024-04-01 16:28 ` gaius at gcc dot gnu.org
@ 2024-04-01 16:44 ` gaius at gcc dot gnu.org
  2024-04-01 18:20 ` cvs-commit at gcc dot gnu.org
  2024-04-01 18:20 ` gaius at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: gaius at gcc dot gnu.org @ 2024-04-01 16:44 UTC (permalink / raw)
  To: gcc-bugs

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

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

Here is a proposed patch (which fixes all the standard procedure function
const/var parameter checking):

$ gm2 -fiso testcmplx.mod 
testcmplx.mod:4:17: error: In program module ‘testcmplx’: the procedure
function ‘CMPLX’ is being called from within a constant expression and
therefore the parameter ‘r’ must be a constant, seen a variable
    4 |    foo = CMPLX (r, i) ;
      |                 ^
testcmplx.mod:4:20: error: the procedure function ‘CMPLX’ is being called from
within a constant expression and therefore the parameter ‘i’ must be a
constant, seen a variable
    4 |    foo = CMPLX (r, i) ;
      |                    ^
testcmplx.mod:4:8: error: in assignment, cannot assign a variable to a constant
‘foo’
    4 |    foo = CMPLX (r, i) ;
      |    ~~~~^~~~~~~~~~~~~
testcmplx.mod:4:4: error: designator ‘foo’ is declared as a CONST
    4 |    foo = CMPLX (r, i) ;
      |    ^~~

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

* [Bug modula2/114548] gm2 fails to identify variable in a const expression
  2024-04-01 16:27 [Bug modula2/114548] New: gm2 fails to identify variable in a const expression gaius at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2024-04-01 16:44 ` gaius at gcc dot gnu.org
@ 2024-04-01 18:20 ` cvs-commit at gcc dot gnu.org
  2024-04-01 18:20 ` gaius at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-04-01 18:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 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:4bd2f59af4a78cdc80039cffa51c1d9ad91081a3

commit r14-9739-g4bd2f59af4a78cdc80039cffa51c1d9ad91081a3
Author: Gaius Mulley <gaiusmod2@gmail.com>
Date:   Mon Apr 1 19:18:36 2024 +0100

    PR modula2/114548 gm2 fails to identify variable in a const expression

    This patch introduces stricter checking within standard procedure
    functions which detect whether paramaters are variable when used
    in a const expression.

    gcc/m2/ChangeLog:

            PR modula2/114548
            * gm2-compiler/M2Quads.mod (ConvertToAddress): Pass
            procedure, false parameters to BuildConvertFunction.
            (PushOne): Pass procedure, true parameters to
            BuildConvertFunction.
            Remove usused parameter internal.
            (BuildPseudoBy): Remove parameter to PushOne.
            (BuildIncProcedure): Ditto.
            (BuildDecProcedure): Ditto.
            (BuildFunctionCall): Add ConstExpr parameter to
            BuildPseudoFunctionCall.
            (BuildConstFunctionCall): Add procedure and true to
            BuildConvertFunction.
            (BuildPseudoFunctionCall): Add ConstExpr parameter.
            Pass ProcSym and ConstExpr to BuildLengthFunction,
            BuildConvertFunction, BuildOddFunction, BuildAbsFunction,
            BuildCapFunction, BuildValFunction, BuildChrFunction,
            BuildOrdFunction, BuildIntFunction, BuildTruncFunction,
            BuildFloatFunction, BuildAddAdrFunction, BuildSubAdrFunction,
            BuildDifAdrFunction, BuildCastFunction, BuildReFunction,
            BuildImFunction and BuildCmplxFunction.
            (BuildAddAdrFunction): Add ProcSym, ConstExpr parameters and
            check for constant parameters.
            (BuildSubAdrFunction): Ditto.
            (BuildDifAdrFunction): Ditto.
            (ConstExprError): Ditto.
            (BuildLengthFunction): Ditto.
            (BuildOddFunction): Ditto.
            (BuildAbsFunction): Ditto.
            (BuildCapFunction): Ditto.
            (BuildChrFunction): Ditto.
            (BuildOrdFunction): Ditto.
            (BuildIntFunction): Ditto.
            (BuildValFunction): Ditto.
            (BuildCastFunction): Ditto.
            (BuildConvertFunction): Ditto.
            (BuildTruncFunction): Ditto.
            (BuildFloatFunction): Ditto.
            (BuildReFunction): Ditto.
            (BuildImFunction): Ditto.
            (BuildCmplxFunction): Ditto.

    gcc/testsuite/ChangeLog:

            PR modula2/114548
            * gm2/iso/const/fail/expression.mod: New test.
            * gm2/iso/const/fail/iso-const-fail.exp: New test.
            * gm2/iso/const/fail/testabs.mod: New test.
            * gm2/iso/const/fail/testaddadr.mod: New test.
            * gm2/iso/const/fail/testcap.mod: New test.
            * gm2/iso/const/fail/testcap2.mod: New test.
            * gm2/iso/const/fail/testchr.mod: New test.
            * gm2/iso/const/fail/testchr2.mod: New test.
            * gm2/iso/const/fail/testcmplx.mod: New test.
            * gm2/iso/const/fail/testfloat.mod: New test.
            * gm2/iso/const/fail/testim.mod: New test.
            * gm2/iso/const/fail/testint.mod: New test.
            * gm2/iso/const/fail/testlength.mod: New test.
            * gm2/iso/const/fail/testodd.mod: New test.
            * gm2/iso/const/fail/testord.mod: New test.
            * gm2/iso/const/fail/testre.mod: New test.
            * gm2/iso/const/fail/testtrunc.mod: New test.
            * gm2/iso/const/fail/testval.mod: New test.
            * gm2/iso/const/pass/constbool.mod: New test.
            * gm2/iso/const/pass/constbool2.mod: New test.
            * gm2/iso/const/pass/constbool3.mod: New test.

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

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

* [Bug modula2/114548] gm2 fails to identify variable in a const expression
  2024-04-01 16:27 [Bug modula2/114548] New: gm2 fails to identify variable in a const expression gaius at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2024-04-01 18:20 ` cvs-commit at gcc dot gnu.org
@ 2024-04-01 18:20 ` gaius at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: gaius at gcc dot gnu.org @ 2024-04-01 18:20 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

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

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

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

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-01 16:27 [Bug modula2/114548] New: gm2 fails to identify variable in a const expression gaius at gcc dot gnu.org
2024-04-01 16:27 ` [Bug modula2/114548] " gaius at gcc dot gnu.org
2024-04-01 16:28 ` gaius at gcc dot gnu.org
2024-04-01 16:44 ` gaius at gcc dot gnu.org
2024-04-01 18:20 ` cvs-commit at gcc dot gnu.org
2024-04-01 18:20 ` 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).