public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug modula2/114617] New: gm2 is unable to resolve const expression using relative operators ICE
@ 2024-04-06  2:53 gaius at gcc dot gnu.org
  2024-04-06  2:54 ` [Bug modula2/114617] " 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-06  2:53 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114617
           Summary: gm2 is unable to resolve const expression using
                    relative operators ICE
           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: ---

For example, it appears to occur if a constant expression has a relop.  The
result of the relop is stored in a variable and is not resolved at compile
time.


$ gm2 -g -c BasicFileSys.mod
-I../../../../Sandpit/gm2-outside-tree-tests/build/source/m2pp/src/ 
terminate called after throwing an instance of 'unsigned int'
cc1gm2: internal compiler error: Aborted
0x178a0e3 crash_signal
        ../../gcc/toplev.cc:319
0xffff8f590990 __pthread_kill_implementation
        ./nptl/pthread_kill.c:44
0xffff8f54a76b __GI_raise
        ../sysdeps/posix/raise.c:26
0xffff8f5374bb __GI_abort
        ./stdlib/abort.c:79
0xf1a64f InvokeHandler
        m2/gm2-libs-boot/RTExceptions.c:484
0xf1b1ff RTExceptions_Raise
        m2/gm2-libs-boot/RTExceptions.c:946
0xf1ac33 invalidloc
        m2/gm2-libs-boot/RTExceptions.c:755
0xf211a3 sigbusDespatcher
        ../../gcc/m2/gm2-libs-ch/SysExceptions.c:125
0x11fce74 fold(tree_node*)
        ../../gcc/fold-const.cc:13798
0xde8bd7 m2convert_BuildConvert
        ../../gcc/m2/gm2-gcc/m2convert.cc:439
0xdf1f33 m2expr_BuildIndirect
        ../../gcc/m2/gm2-gcc/m2expr.cc:3520
0xe5802b CodeXIndr
        m2/gm2-compiler-boot/M2GenGCC.c:9350
0xe47cd3 CodeStatement
        m2/gm2-compiler-boot/M2GenGCC.c:2062
0xe58177 M2GenGCC_ConvertQuadsToTree
        m2/gm2-compiler-boot/M2GenGCC.c:9380
0xe939af M2Scope_ForeachScopeBlockDo2
        m2/gm2-compiler-boot/M2Scope.c:675
0xe33783 M2Code_CodeBlock
        m2/gm2-compiler-boot/M2Code.c:529
0xe33027 DoCodeBlock
        m2/gm2-compiler-boot/M2Code.c:292
0xe336b3 M2Code_Code
        m2/gm2-compiler-boot/M2Code.c:467
0xe33c53 Compile
        m2/gm2-compiler-boot/M2Comp.c:469
0xe359a3 M2Comp_compile
        m2/gm2-compiler-boot/M2Comp.c:1592


The variable used to contain the result of the relop constant expression can be
seen in:

MODULE constbool3 ;


CONST
   AddressableBits = 32 ;
   MaxBits         = 16 ;

   BitsInUse = ORD(AddressableBits > MaxBits) * MaxBits + ORD(AddressableBits
<= MaxBits) * AddressableBits;

BEGIN

END constbool3.

$ gm2 -fiso constbool3.mod 
constbool3.mod:8:36: error: In program module 'constbool3': the procedure
function 'ORD' is being called from within a constant expression and therefore
the parameter must be a constant, seen a expression
    8 |    BitsInUse = ORD(AddressableBits > MaxBits) * MaxBits +
ORD(AddressableBits <= MaxBits) * AddressableBits;
      |                    ~~~~~~~~~~~~~~~~^~~~~~~~~
constbool3.mod:8:79: error: the procedure function 'ORD' is being called from
within a constant expression and therefore the parameter must be a constant,
seen a expression
    8 |    BitsInUse = ORD(AddressableBits > MaxBits) * MaxBits +
ORD(AddressableBits <= MaxBits) * AddressableBits;
      |                                                              
~~~~~~~~~~~~~~~~^~~~~~~~~~
constbool3.mod:8:14: error: in assignment, cannot assign a variable to a
constant 'BitsInUse'
    8 |    BitsInUse = ORD(AddressableBits > MaxBits) * MaxBits +
ORD(AddressableBits <= MaxBits) * AddressableBits;
      |   
~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
constbool3.mod:8:4: error: designator 'BitsInUse' is declared as a CONST
    8 |    BitsInUse = ORD(AddressableBits > MaxBits) * MaxBits +
ORD(AddressableBits <= MaxBits) * AddressableBits;
      |    ^~~~~~~~~

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

* [Bug modula2/114617] gm2 is unable to resolve const expression using relative operators ICE
  2024-04-06  2:53 [Bug modula2/114617] New: gm2 is unable to resolve const expression using relative operators ICE gaius at gcc dot gnu.org
@ 2024-04-06  2:54 ` gaius at gcc dot gnu.org
  2024-04-06  3:02 ` 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-06  2:54 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

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

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

* [Bug modula2/114617] gm2 is unable to resolve const expression using relative operators ICE
  2024-04-06  2:53 [Bug modula2/114617] New: gm2 is unable to resolve const expression using relative operators ICE gaius at gcc dot gnu.org
  2024-04-06  2:54 ` [Bug modula2/114617] " gaius at gcc dot gnu.org
@ 2024-04-06  3:02 ` gaius at gcc dot gnu.org
  2024-04-06  8:46 ` 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-06  3:02 UTC (permalink / raw)
  To: gcc-bugs

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

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

Here is a proposed fix which stores the result of the relop as a constant.
The fix requires M2Quads to mark a const expression relop and M2GenGCC to
evaluate the relop and then to remove the redundant quadruples.

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

* [Bug modula2/114617] gm2 is unable to resolve const expression using relative operators ICE
  2024-04-06  2:53 [Bug modula2/114617] New: gm2 is unable to resolve const expression using relative operators ICE gaius at gcc dot gnu.org
  2024-04-06  2:54 ` [Bug modula2/114617] " gaius at gcc dot gnu.org
  2024-04-06  3:02 ` gaius at gcc dot gnu.org
@ 2024-04-06  8:46 ` gaius at gcc dot gnu.org
  2024-04-06 22:46 ` cvs-commit at gcc dot gnu.org
  2024-04-06 22:52 ` gaius at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: gaius at gcc dot gnu.org @ 2024-04-06  8:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Gaius Mulley <gaius at gcc dot gnu.org> ---
With the patch the reported failure examples above pass:

$ gm2 -g -c BasicFileSys.mod
-I../../../../Sandpit/gm2-outside-tree-tests/build/source/m2pp/src/ -fsources
Compiling: BasicFileSys.mod
Pass 0: lexical analysis, parsing, modules and associated filenames
   Module SYSTEM               :
/home/gaius/opt/lib/gcc/x86_64-pc-linux-gnu/14.0.1/m2/m2cor/SYSTEM.def [m2cor]
   Module M2RTS                :
/home/gaius/opt/lib/gcc/x86_64-pc-linux-gnu/14.0.1/m2/m2pim/M2RTS.def [m2pim]
   Module RTExceptions         :
/home/gaius/opt/lib/gcc/x86_64-pc-linux-gnu/14.0.1/m2/m2pim/RTExceptions.def
[m2pim]
   Module BasicFileSys         :
../../../../Sandpit/gm2-outside-tree-tests/build/source/m2pp/src/BasicFileSys.def
   Module BasicFileSys         : BasicFileSys.mod
   Module COROUTINES           :
/home/gaius/opt/lib/gcc/x86_64-pc-linux-gnu/14.0.1/m2/m2pim/COROUTINES.def
[m2pim] (for C)
   Module Size                 : ./Size.def
   Module stat                 : ./stat.def
   Module stdio                : ./stdio.def (for C)
   Module unistd               : ./unistd.def (for C)
   Module fcntl                : ./fcntl.def (for C)
   Module stat0                : ./stat0.def (for C)
   Module SysTypes             : ./SysTypes.def
Pass 1: scopes, enumerated types, imports and exports
Pass 2: constants and types
Pass C: aggregate constants
Pass 3: quadruple generation
Pass 4: gcc tree generation
        symbols to gcc trees
        statements to gcc trees
        gcc trees given to the gcc backend

and

$ gm2 -c -fiso constbool3.mod

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

* [Bug modula2/114617] gm2 is unable to resolve const expression using relative operators ICE
  2024-04-06  2:53 [Bug modula2/114617] New: gm2 is unable to resolve const expression using relative operators ICE gaius at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2024-04-06  8:46 ` gaius at gcc dot gnu.org
@ 2024-04-06 22:46 ` cvs-commit at gcc dot gnu.org
  2024-04-06 22:52 ` gaius at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-04-06 22:46 UTC (permalink / raw)
  To: gcc-bugs

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

--- 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:4e3c8257304c55f2ebfb24bd6de3236bda0f054e

commit r14-9823-g4e3c8257304c55f2ebfb24bd6de3236bda0f054e
Author: Gaius Mulley <gaiusmod2@gmail.com>
Date:   Sat Apr 6 23:45:35 2024 +0100

    PR modula2/114617 gm2 unable to resolve const expressions using relop ICE

    This patch allows cc1gm2 to resolve constant expressions which use
    relative operators.  Previous to the patch the result of a relop
    was stored in a temporary variable set by an if then else quadruple
    sequence.  This patch marks a const expression in the quadruples
    and then reduces this sequence of quadruples into a single
    assignment to an internal constant.

    gcc/m2/ChangeLog:

            PR modula2/114617
            * gm2-compiler/M2GenGCC.mod (CodeStatememt): Add quad trace.
            (ResolveConstantExpressions): Add parameter p to FoldIfLess,
            FoldIfGre, FoldIfLessEqu, FoldIfGreEqu, FoldIfEqu, FoldIfNotEqu,
            FoldIfIn and FoldIfNotIn.
            (CodeInline): Add constExpr variable and pass it to GetQuadOtok.
            (CodeReturnValue): Ditto.
            (CodeParam): Ditto.
            (FoldStringLength): Ditto.
            (FoldStringConvertM2nul): Ditto.
            (FoldStringConvertCnul): Ditto.
            (DeclaredOperandsBecomes): Ditto.
            (TypeCheckBecomes): Ditto.
            (PerformFoldBecomes): Ditto.
            (CodeBecomes): Ditto.
            (CheckElementSetTypes): Ditto.
            (CodeBinarySet): Ditto.
            (PerformCodeIfLess): Ditto.
            (PerformCodeIfGre): Ditto.
            (PerformCodeIfLessEqu): Ditto.
            (PerformCodeIfGreEqu): Ditto.
            (PerformCodeIfEqu): Ditto.
            (PerformCodeIfNotEqu): Ditto.
            (IsValidExpressionRelOp): Ditto.
            (PerformCodeIfIn): Ditto.
            (PerformCodeIfNotIn): Ditto.
            (CodeXIndr): Ditto.
            (QuadCondition): New procedure function.
            (IsBooleanRelOpPattern): Ditto.
            (FoldBooleanRelopPattern): Ditto.
            (FoldIfGre): Check for boolean relop constant expression and
            add parameter p.
            (FoldIfLessEqu): Ditto.
            (FoldIfIn): Ditto.
            (FoldIfEqu): Ditto.
            (FoldIfNotIn): Ditto.
            (FoldIfGreEqu): New procedure.
            (FoldIfNotEqu): Ditto.
            * gm2-compiler/M2Optimize.mod (ReduceBranch): Add constExpr
            variable and pass it to GetQuadOtok.
            * gm2-compiler/M2Quads.def (IsBecomes): New procedure function.
            (IsDummy): Ditto.
            (IsQuadConstExpr): Ditto.
            (SetQuadConstExpr): Ditto.
            (GetQuadDest): New procedure.
            (GetQuadOp1): New procedure.
            (GetQuadOp2): New procedure.
            (GetQuadOp3): New procedure.
            (GetQuadOtok): New procedure.
            (GetQuadOTypetok): New procedure.
            (PutQuadOtok): New procedure.
            (IsInConstParameters): New procedure function.
            * gm2-compiler/M2Quads.mod (IsBecomes): New procedure function.
            (IsDummy): Ditto.
            (IsQuadConstExpr): Ditto.
            (SetQuadConstExpr): Ditto.
            (GetQuadDest): New procedure.
            (GetQuadOp1): New procedure.
            (GetQuadOp2): New procedure.
            (GetQuadOp3): New procedure.
            (GetQuadOtok): New procedure.
            (GetQuadOTypetok): New procedure.
            (PutQuadOtok): New procedure.
            (IsInConstParameters): New procedure function.
            (ConstStack): Remove to ...
            (ConstExprStack): ... this.
            (ConstParamStack): New variable and initialize.
            (QuadFrame): New field ConstExpr.
            (GetQuadOtok): Add parameter constExpr and assign.
            (PutQuadOtok): Add constExpr parameter and assign.
            (PutQuadOType): Ditto.
            (GetQuadOTypetok): Ditto.
            (EraseQuad): Assign ConstExpr to FALSE.
            (FoldSubrange): Set ConstExpr to FALSE in BecomesOp.
            (PushInConstParameters): New procedure.
            (PopInConstParameters): New procedure.
            (IsInConstParameters): New procedure function.
            * gm2-compiler/M2SymInit.mod (IssueConditional): Add
            constExpr boolean variable.
            (CheckReadBeforeInitQuad): Ditto.
            (trashParam): Ditto.
            * gm2-compiler/P3Build.bnf (ConstExpression): Call
            PushInConstExpression and PopInConstExpression.
            (ConstSetOrQualidentOrFunction): Call
            PushInConstParameters and PopInConstParameters.
            * gm2-compiler/PCBuild.bnf (ConstExpression): Call
            PushInConstExpression and PopInConstExpression.
            * gm2-compiler/PHBuild.bnf: Ditto
            * gm2-gcc/m2expr.cc (m2expr_BuildCondIfExpression): New
            function.
            * gm2-gcc/m2expr.def (BuildCondIfExpression): New prototype.
            * gm2-gcc/m2expr.h (m2expr_BuildCondIfExpression): New function.

    gcc/testsuite/ChangeLog:

            PR modula2/114617
            * gm2/iso/const/pass/iso-const-pass.exp: New test.

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

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

* [Bug modula2/114617] gm2 is unable to resolve const expression using relative operators ICE
  2024-04-06  2:53 [Bug modula2/114617] New: gm2 is unable to resolve const expression using relative operators ICE gaius at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2024-04-06 22:46 ` cvs-commit at gcc dot gnu.org
@ 2024-04-06 22:52 ` gaius at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: gaius at gcc dot gnu.org @ 2024-04-06 22:52 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

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

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

end of thread, other threads:[~2024-04-06 22:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-06  2:53 [Bug modula2/114617] New: gm2 is unable to resolve const expression using relative operators ICE gaius at gcc dot gnu.org
2024-04-06  2:54 ` [Bug modula2/114617] " gaius at gcc dot gnu.org
2024-04-06  3:02 ` gaius at gcc dot gnu.org
2024-04-06  8:46 ` gaius at gcc dot gnu.org
2024-04-06 22:46 ` cvs-commit at gcc dot gnu.org
2024-04-06 22:52 ` 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).