From: Eric Botcazou Date: Wed, 11 Nov 2020 12:53:01 +0000 (+0100) Subject: Fix internal error with Shift_Right operator on signed type X-Git-Tag: releases/gcc-10.3.0~660 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4cbbe6c067cf13d73728375d8eb28f77818c0e8e;p=thirdparty%2Fgcc.git Fix internal error with Shift_Right operator on signed type This is a regression present on the mainline and 10 branch in the form of an ICE with a shift operator applied to a variable of a signed type, and which is caused by a type mismatch. gcc/ada/ChangeLog: * gcc-interface/trans.c (gnat_to_gnu) : Also convert GNU_MAX_SHIFT if the type of the operation has been changed. * gcc-interface/utils.c (can_materialize_object_renaming_p): Add pair of missing parentheses. gcc/testsuite/ChangeLog: * gnat.dg/shift1.adb: New test. --- diff --git a/gcc/ada/gcc-interface/trans.c b/gcc/ada/gcc-interface/trans.c index bda2d956d661..b39b32e28d58 100644 --- a/gcc/ada/gcc-interface/trans.c +++ b/gcc/ada/gcc-interface/trans.c @@ -7662,6 +7662,8 @@ gnat_to_gnu (Node_Id gnat_node) if (TREE_CODE (gnu_lhs) == INTEGER_CST && ignore_lhs_overflow) TREE_OVERFLOW (gnu_lhs) = TREE_OVERFLOW (gnu_old_lhs); gnu_rhs = convert (gnu_type, gnu_rhs); + if (gnu_max_shift) + gnu_max_shift = convert (gnu_type, gnu_max_shift); } /* For signed integer addition, subtraction and multiplication, do an diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c index 010f82cfd4f9..4ec19c7f1917 100644 --- a/gcc/ada/gcc-interface/utils.c +++ b/gcc/ada/gcc-interface/utils.c @@ -5740,7 +5740,7 @@ can_materialize_object_renaming_p (Node_Id expr) { expr = Original_Node (expr); - switch Nkind (expr) + switch (Nkind (expr)) { case N_Identifier: case N_Expanded_Name: diff --git a/gcc/testsuite/gnat.dg/shift1.adb b/gcc/testsuite/gnat.dg/shift1.adb new file mode 100644 index 000000000000..85a0fecdae4c --- /dev/null +++ b/gcc/testsuite/gnat.dg/shift1.adb @@ -0,0 +1,15 @@ +-- { dg-do compile } +-- { dg-options "-gnatws" } + +procedure Shift1 is + + type T_Integer_8 is range -2 ** 7 .. 2 ** 7 - 1 + with Size => 8; + + pragma Provide_Shift_Operators (T_Integer_8); + + X : T_Integer_8; + +begin + X := Shift_Right (X, 1); +end;