PR modula2/108121 Re-implement overflow detection for constant literals
commit68201409bc2867da45791331e385198826fa4576
authorGaius Mulley <gaiusmod2@gmail.com>
Wed, 26 Apr 2023 01:55:59 +0000 (26 02:55 +0100)
committerGaius Mulley <gaiusmod2@gmail.com>
Wed, 26 Apr 2023 01:55:59 +0000 (26 02:55 +0100)
treec1e92629cd0fe3c2a1797063632bf9985e6d7d3f
parent49cea02d8bdbde27d202cab887ff38ea341aa82a
PR modula2/108121 Re-implement overflow detection for constant literals

This patch fixes the overflow detection for constant literals.
The ZTYPE is changed to int128 (or int64) if int128 is unavailable and
constant literals are built from widest_int.  The widest_int is converted
into the tree type and checked for overflow.
m2expr_interpret_integer and append_m2_digit are removed.

gcc/m2/ChangeLog:

PR modula2/108121
* gm2-compiler/M2ALU.mod (Less): Reformatted.
* gm2-compiler/SymbolTable.mod (DetermineSizeOfConstant): Remove
from import.
(ConstantStringExceedsZType): Import.
(GetConstLitType): Re-implement using ConstantStringExceedsZType.
* gm2-gcc/m2decl.cc (m2decl_DetermineSizeOfConstant): Remove.
(m2decl_ConstantStringExceedsZType): New function.
(m2decl_BuildConstLiteralNumber): Re-implement.
* gm2-gcc/m2decl.def (DetermineSizeOfConstant): Remove.
(ConstantStringExceedsZType): New function.
* gm2-gcc/m2decl.h (m2decl_DetermineSizeOfConstant): Remove.
(m2decl_ConstantStringExceedsZType): New function.
* gm2-gcc/m2expr.cc (append_digit): Remove.
(m2expr_interpret_integer): Remove.
(append_m2_digit): Remove.
(m2expr_StrToWideInt): New function.
(m2expr_interpret_m2_integer): Remove.
* gm2-gcc/m2expr.def (CheckConstStrZtypeRange): New function.
* gm2-gcc/m2expr.h (m2expr_StrToWideInt): New function.
* gm2-gcc/m2type.cc (build_m2_word64_type_node): New function.
(build_m2_ztype_node): New function.
(m2type_InitBaseTypes): Call build_m2_ztype_node.
* gm2-lang.cc (gm2_type_for_size): Re-write using early returns.

gcc/testsuite/ChangeLog:

PR modula2/108121
* gm2/pim/fail/largeconst.mod: Increased constant value test
to fail now that cc1gm2 uses widest_int to represent a ZTYPE.
* gm2/pim/fail/largeconst2.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
12 files changed:
gcc/m2/gm2-compiler/M2ALU.mod
gcc/m2/gm2-compiler/SymbolTable.mod
gcc/m2/gm2-gcc/m2decl.cc
gcc/m2/gm2-gcc/m2decl.def
gcc/m2/gm2-gcc/m2decl.h
gcc/m2/gm2-gcc/m2expr.cc
gcc/m2/gm2-gcc/m2expr.def
gcc/m2/gm2-gcc/m2expr.h
gcc/m2/gm2-gcc/m2type.cc
gcc/m2/gm2-lang.cc
gcc/testsuite/gm2/pim/fail/largeconst.mod
gcc/testsuite/gm2/pim/fail/largeconst2.mod [new file with mode: 0644]