diff options
author | Eric Botcazou <ebotcazou@adacore.com> | 2016-10-10 08:47:52 +0000 |
---|---|---|
committer | Eric Botcazou <ebotcazou@gcc.gnu.org> | 2016-10-10 08:47:52 +0000 |
commit | 55cfd746c7d6e262d01a3cb8d5f32ebc8dceffbc (patch) | |
tree | cd931049bd8d161a77d9a6701765ae10189b47a7 /gcc | |
parent | f47ef399b62fdab4fdddc308885f3da986825c21 (diff) | |
download | gcc-55cfd746c7d6e262d01a3cb8d5f32ebc8dceffbc.zip gcc-55cfd746c7d6e262d01a3cb8d5f32ebc8dceffbc.tar.gz gcc-55cfd746c7d6e262d01a3cb8d5f32ebc8dceffbc.tar.bz2 |
utils.c (convert): For a biased input type, convert the bias itself to the base type before adding it.
* gcc-interface/utils.c (convert): For a biased input type, convert
the bias itself to the base type before adding it.
From-SVN: r240910
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ada/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/ada/gcc-interface/utils.c | 16 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gnat.dg/biased_subtype.adb | 20 |
4 files changed, 41 insertions, 4 deletions
diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index d1704f6..1e6f0a3 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,8 @@ +2016-10-10 Eric Botcazou <ebotcazou@adacore.com> + + * gcc-interface/utils.c (convert): For a biased input type, convert + the bias itself to the base type before adding it. + 2016-10-08 Eric Botcazou <ebotcazou@adacore.com> * gcc-interface/utils.c (convert) <VECTOR_CST>: Add missing break. diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c index d4cc941..8db92e5 100644 --- a/gcc/ada/gcc-interface/utils.c +++ b/gcc/ada/gcc-interface/utils.c @@ -4193,12 +4193,15 @@ convert (tree type, tree expr) return convert (type, unpadded); } - /* If the input is a biased type, adjust first. */ + /* If the input is a biased type, convert first to the base type and add + the bias. Note that the bias must go through a full conversion to the + base type, lest it is itself a biased value; this happens for subtypes + of biased types. */ if (ecode == INTEGER_TYPE && TYPE_BIASED_REPRESENTATION_P (etype)) return convert (type, fold_build2 (PLUS_EXPR, TREE_TYPE (etype), fold_convert (TREE_TYPE (etype), expr), - fold_convert (TREE_TYPE (etype), - TYPE_MIN_VALUE (etype)))); + convert (TREE_TYPE (etype), + TYPE_MIN_VALUE (etype)))); /* If the input is a justified modular type, we need to extract the actual object before converting it to any other type with the exceptions of an @@ -4502,7 +4505,12 @@ convert (tree type, tree expr) && (ecode == ARRAY_TYPE || ecode == UNCONSTRAINED_ARRAY_TYPE || (ecode == RECORD_TYPE && TYPE_CONTAINS_TEMPLATE_P (etype)))) return unchecked_convert (type, expr, false); - else if (TYPE_BIASED_REPRESENTATION_P (type)) + + /* If the output is a biased type, convert first to the base type and + subtract the bias. Note that the bias itself must go through a full + conversion to the base type, lest it is a biased value; this happens + for subtypes of biased types. */ + if (TYPE_BIASED_REPRESENTATION_P (type)) return fold_convert (type, fold_build2 (MINUS_EXPR, TREE_TYPE (type), convert (TREE_TYPE (type), expr), diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ec28259..1d07fcd 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2016-10-10 Eric Botcazou <ebotcazou@adacore.com> + + * gnat.dg/biased_subtype.adb: New test. + 2016-10-09 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/77901 diff --git a/gcc/testsuite/gnat.dg/biased_subtype.adb b/gcc/testsuite/gnat.dg/biased_subtype.adb new file mode 100644 index 0000000..3833022 --- /dev/null +++ b/gcc/testsuite/gnat.dg/biased_subtype.adb @@ -0,0 +1,20 @@ +-- { dg-do run } +-- { dg-options "-gnatws" } + +procedure Biased_Subtype is + + CIM_Max_AA : constant := 9_999_999; + CIM_Min_AA : constant := -999_999; + + type TIM_AA is range CIM_Min_AA..CIM_Max_AA + 1; + for TIM_AA'Size use 24; + + subtype STIM_AA is TIM_AA range TIM_AA(CIM_Min_AA)..TIM_AA(CIM_Max_AA); + + SAA : STIM_AA := 1; + +begin + if Integer(SAA) /= 1 then + raise Program_Error; + end if; +end; |