From: Eric Botcazou <ebotcazou@adacore.com>
To: gcc-patches@gcc.gnu.org
Subject: [Ada] Fix ICE on type witn zero precision
Date: Tue, 05 Sep 2017 09:17:00 -0000 [thread overview]
Message-ID: <2161599.Jq0VYmRpBJ@polaris> (raw)
[-- Attachment #1: Type: text/plain, Size: 525 bytes --]
This is a regression present on the mainline, 7 and 6 branches, in the form of
an ICE during tree-ccp, which is confused by a type witn zero precision.
Tested on x86_64-suse-linux, applied on mainline, 7 and 6 branches.
2017-09-05 Eric Botcazou <ebotcazou@adacore.com>
* gcc-interface/utils.c (unchecked_convert): When the result type is a
non-biased integral type with size 0, set the result to 0 directly.
2017-09-05 Eric Botcazou <ebotcazou@adacore.com>
* gnat.dg/specs/uc2.ads: New test.
--
Eric Botcazou
[-- Attachment #2: p.diff --]
[-- Type: text/x-patch, Size: 1458 bytes --]
Index: gcc-interface/utils.c
===================================================================
--- gcc-interface/utils.c (revision 251700)
+++ gcc-interface/utils.c (working copy)
@@ -5257,20 +5257,26 @@ unchecked_convert (tree type, tree expr,
? TYPE_RM_SIZE (etype)
: TYPE_SIZE (etype)) == 0)))
{
- tree base_type
- = gnat_type_for_size (TREE_INT_CST_LOW (TYPE_SIZE (type)),
- type_unsigned_for_rm (type));
- tree shift_expr
- = convert (base_type,
- size_binop (MINUS_EXPR,
- TYPE_SIZE (type), TYPE_RM_SIZE (type)));
- expr
- = convert (type,
- build_binary_op (RSHIFT_EXPR, base_type,
- build_binary_op (LSHIFT_EXPR, base_type,
- convert (base_type, expr),
- shift_expr),
- shift_expr));
+ if (integer_zerop (TYPE_RM_SIZE (type)))
+ expr = build_int_cst (type, 0);
+ else
+ {
+ tree base_type
+ = gnat_type_for_size (TREE_INT_CST_LOW (TYPE_SIZE (type)),
+ type_unsigned_for_rm (type));
+ tree shift_expr
+ = convert (base_type,
+ size_binop (MINUS_EXPR,
+ TYPE_SIZE (type), TYPE_RM_SIZE (type)));
+ expr
+ = convert (type,
+ build_binary_op (RSHIFT_EXPR, base_type,
+ build_binary_op (LSHIFT_EXPR, base_type,
+ convert (base_type,
+ expr),
+ shift_expr),
+ shift_expr));
+ }
}
/* An unchecked conversion should never raise Constraint_Error. The code
[-- Attachment #3: uc2.ads --]
[-- Type: text/x-adasrc, Size: 354 bytes --]
-- { dg-do compile }
-- { dg-options "-O" }
with Ada.Unchecked_Conversion;
package UC2 is
subtype Word_Type is Integer range 0 .. 0;
type Arr is array (1 .. Word_Type'Size) of Boolean;
pragma Pack(Arr);
function Conv is
new Ada.Unchecked_Conversion (Source => Arr, Target => Word_Type);
A : Arr;
W : Word_Type := Conv(A);
end UC2;
reply other threads:[~2017-09-05 9:17 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2161599.Jq0VYmRpBJ@polaris \
--to=ebotcazou@adacore.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).