public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-5345] [Ada] Crash on right shift operator for signed integers
@ 2020-11-25 13:28 Pierre-Marie de Rodat
0 siblings, 0 replies; only message in thread
From: Pierre-Marie de Rodat @ 2020-11-25 13:28 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:e480bca2400d891bbde62e68d6a8f573848c22c6
commit r11-5345-ge480bca2400d891bbde62e68d6a8f573848c22c6
Author: Justin Squirek <squirek@adacore.com>
Date: Mon Oct 12 12:06:08 2020 -0400
[Ada] Crash on right shift operator for signed integers
gcc/ada/
* doc/gnat_rm/intrinsic_subprograms.rst (Shifts and Rotates):
Document behavior on negative numbers
* gnat_rm.texi: Regenerate.
* sem_eval.adb (Fold_Shift): Set modulus to be based on the RM
size for non-modular integer types.
Diff:
---
gcc/ada/doc/gnat_rm/intrinsic_subprograms.rst | 4 +++-
gcc/ada/gnat_rm.texi | 4 +++-
gcc/ada/sem_eval.adb | 22 ++++++++++++++++------
3 files changed, 22 insertions(+), 8 deletions(-)
diff --git a/gcc/ada/doc/gnat_rm/intrinsic_subprograms.rst b/gcc/ada/doc/gnat_rm/intrinsic_subprograms.rst
index bf9f0b9e6d9..e448816572f 100644
--- a/gcc/ada/doc/gnat_rm/intrinsic_subprograms.rst
+++ b/gcc/ada/doc/gnat_rm/intrinsic_subprograms.rst
@@ -217,7 +217,9 @@ The formal parameter names can be anything.
A more convenient way of providing these shift operators is to use
the Provide_Shift_Operators pragma, which provides the function declarations
-and corresponding pragma Import's for all five shift functions.
+and corresponding pragma Import's for all five shift functions. Note that in
+using these provided shift operations, shifts performed on negative numbers
+will result in modification of the sign bit.
.. _Source_Location:
diff --git a/gcc/ada/gnat_rm.texi b/gcc/ada/gnat_rm.texi
index 24afe79993d..decca9ef63f 100644
--- a/gcc/ada/gnat_rm.texi
+++ b/gcc/ada/gnat_rm.texi
@@ -17862,7 +17862,9 @@ The formal parameter names can be anything.
A more convenient way of providing these shift operators is to use
the Provide_Shift_Operators pragma, which provides the function declarations
-and corresponding pragma Import's for all five shift functions.
+and corresponding pragma Import's for all five shift functions. Note that in
+using these provided shift operations, shifts performed on negative numbers
+will result in modification of the sign bit.
@node Source_Location,,Shifts and Rotates,Intrinsic Subprograms
@anchor{gnat_rm/intrinsic_subprograms source-location}@anchor{271}@anchor{gnat_rm/intrinsic_subprograms id13}@anchor{272}
diff --git a/gcc/ada/sem_eval.adb b/gcc/ada/sem_eval.adb
index a04c5fa513c..52aa8c111da 100644
--- a/gcc/ada/sem_eval.adb
+++ b/gcc/ada/sem_eval.adb
@@ -4815,13 +4815,23 @@ package body Sem_Eval is
if Op = N_Op_Shift_Left then
Check_Elab_Call;
- -- Fold Shift_Left (X, Y) by computing (X * 2**Y) rem modulus
+ declare
+ Modulus : Uint;
+ begin
+ if Is_Modular_Integer_Type (Typ) then
+ Modulus := Einfo.Modulus (Typ);
+ else
+ Modulus := Uint_2 ** RM_Size (Typ);
+ end if;
- Fold_Uint
- (N,
- (Expr_Value (Left) * (Uint_2 ** Expr_Value (Right)))
- rem Modulus (Typ),
- Static => Static);
+ -- Fold Shift_Left (X, Y) by computing (X * 2**Y) rem modulus
+
+ Fold_Uint
+ (N,
+ (Expr_Value (Left) * (Uint_2 ** Expr_Value (Right)))
+ rem Modulus,
+ Static => Static);
+ end;
elsif Op = N_Op_Shift_Right then
Check_Elab_Call;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-11-25 13:28 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-25 13:28 [gcc r11-5345] [Ada] Crash on right shift operator for signed integers Pierre-Marie de Rodat
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).