public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug modula2/113730] New: Unexpected handling of mixed-precision integer arithmetic
@ 2024-02-02 22:05 gaius at gcc dot gnu.org
  2024-02-02 22:05 ` [Bug modula2/113730] " 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-02 22:05 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113730
           Summary: Unexpected handling of mixed-precision integer
                    arithmetic
           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 the compiler incorrectly compiles mixed
precision arithmetic when an expression uses a ZType constant.   It would
appear that the expression is widened to a ZType which is then compatible with
another fixed sized type.

For example:

VAR
   c32: CARDINAL32 ;
   c64: CARDINAL64 ;
BEGIN
   c32 := 1 ;
   c64 := 2 ;
   c64 := c64 + c32 ;   (* Correctly: fails with incompatible expression.  *)
   c64 := c64 * 2 + c32 ;  (* Incorrectly passes!  *)

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

* [Bug modula2/113730] Unexpected handling of mixed-precision integer arithmetic
  2024-02-02 22:05 [Bug modula2/113730] New: Unexpected handling of mixed-precision integer arithmetic gaius at gcc dot gnu.org
@ 2024-02-02 22:05 ` gaius at gcc dot gnu.org
  2024-02-02 22:09 ` 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-02 22:05 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

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

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

* [Bug modula2/113730] Unexpected handling of mixed-precision integer arithmetic
  2024-02-02 22:05 [Bug modula2/113730] New: Unexpected handling of mixed-precision integer arithmetic gaius at gcc dot gnu.org
  2024-02-02 22:05 ` [Bug modula2/113730] " gaius at gcc dot gnu.org
@ 2024-02-02 22:09 ` gaius at gcc dot gnu.org
  2024-02-03  0:04 ` cvs-commit at gcc dot gnu.org
  2024-02-03  0:15 ` gaius at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: gaius at gcc dot gnu.org @ 2024-02-02 22:09 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |gaius at gcc dot gnu.org

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

Here is the proposed patch.

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

* [Bug modula2/113730] Unexpected handling of mixed-precision integer arithmetic
  2024-02-02 22:05 [Bug modula2/113730] New: Unexpected handling of mixed-precision integer arithmetic gaius at gcc dot gnu.org
  2024-02-02 22:05 ` [Bug modula2/113730] " gaius at gcc dot gnu.org
  2024-02-02 22:09 ` gaius at gcc dot gnu.org
@ 2024-02-03  0:04 ` cvs-commit at gcc dot gnu.org
  2024-02-03  0:15 ` gaius at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-02-03  0:04 UTC (permalink / raw)
  To: gcc-bugs

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

--- 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:64b0130bb6702c67a13caefaae9facef23d6ac60

commit r14-8769-g64b0130bb6702c67a13caefaae9facef23d6ac60
Author: Gaius Mulley <gaiusmod2@gmail.com>
Date:   Sat Feb 3 00:03:39 2024 +0000

    PR modula2/113730 Unexpected handling of mixed-precision integer arithmetic

    This patch fixes a bug which occurs when an expression is created with
    a ZType and an integer or cardinal.  The resulting subexpression is
    incorrecly given a ZType which allows compatibility with another
    integer/cardinal type.  The solution was to fix the subexpression
    type.  In turn this required a minor change to SArgs.mod.

    gcc/m2/ChangeLog:

            PR modula2/113730
            * gm2-compiler/M2Base.mod (IsUserType): New procedure function.
            (MixTypes): Use IsUserType instead of IsType before calling
MixTypes.
            * gm2-compiler/M2GenGCC.mod (GetTypeMode): Remove and import from
            SymbolTable.
            (CodeBinaryCheck): Replace call to MixTypes with MixTypesBinary.
            (CodeBinary): Replace call to MixTypes with MixTypesBinary.
            (CodeIfLess): Replace MixTypes with ComparisonMixTypes.
            (CodeIfGre): Replace MixTypes with ComparisonMixTypes.
            (CodeIfLessEqu): Replace MixTypes with ComparisonMixTypes.
            (CodeIfGreEqu): Replace MixTypes with ComparisonMixTypes.
            (CodeIfEqu): Replace MixTypes with ComparisonMixTypes.
            (CodeIfNotEqu): Replace MixTypes with ComparisonMixTypes.
            (ComparisonMixTypes): New procedure function.
            * gm2-compiler/M2Quads.mod (BuildEndFor): Replace GenQuadO
            with GenQuadOtok and pass tokenpos for the operands to the AddOp
            and XIndrOp.
            (CheckRangeIncDec): Check etype against NulSym and dtype for a
            pointer and set etype to Address.
            (BuildAddAdrFunction): New variable opa.  Convert operand to an
            address and save result in opa.  Replace GenQuad with GenQuadOtok.
            (BuildSubAdrFunction): New variable opa.  Convert operand to an
            address and save result in opa.  Replace GenQuad with GenQuadOtok.
            (BuildDiffAdrFunction): New variable opa.  Convert operand to an
            address and save result in opa.  Replace GenQuad with GenQuadOtok.
            (calculateMultipicand): Replace GenQuadO with GenQuadOtok.
            (ConvertToAddress): New procedure function.
            (BuildDynamicArray): Convert index to address before adding to
            the base.
            * gm2-compiler/SymbolTable.def (GetTypeMode): New procedure
function.
            * gm2-compiler/SymbolTable.mod (GetTypeMode): New procedure
            function implemented (moved from M2GenGCC.mod).
            * gm2-libs/SArgs.mod (GetArg): Replace cast to PtrToChar with
ADDRESS.

    gcc/testsuite/ChangeLog:

            PR modula2/113730
            * gm2/extensions/fail/arith1.mod: New test.
            * gm2/extensions/fail/arith2.mod: New test.
            * gm2/extensions/fail/arith3.mod: New test.
            * gm2/extensions/fail/arith4.mod: New test.
            * gm2/extensions/fail/arithpromote.mod: New test.
            * gm2/extensions/fail/extensions-fail.exp: New test.
            * gm2/linking/fail/badimp.def: New test.
            * gm2/linking/fail/badimp.mod: New test.
            * gm2/linking/fail/linking-fail.exp: New test.
            * gm2/linking/fail/testbadimp.mod: New test.

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

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

* [Bug modula2/113730] Unexpected handling of mixed-precision integer arithmetic
  2024-02-02 22:05 [Bug modula2/113730] New: Unexpected handling of mixed-precision integer arithmetic gaius at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2024-02-03  0:04 ` cvs-commit at gcc dot gnu.org
@ 2024-02-03  0:15 ` gaius at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: gaius at gcc dot gnu.org @ 2024-02-03  0:15 UTC (permalink / raw)
  To: gcc-bugs

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

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 that the patch has been applied.

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

end of thread, other threads:[~2024-02-03  0:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-02 22:05 [Bug modula2/113730] New: Unexpected handling of mixed-precision integer arithmetic gaius at gcc dot gnu.org
2024-02-02 22:05 ` [Bug modula2/113730] " gaius at gcc dot gnu.org
2024-02-02 22:09 ` gaius at gcc dot gnu.org
2024-02-03  0:04 ` cvs-commit at gcc dot gnu.org
2024-02-03  0:15 ` 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).