From: Eric Botcazou Date: Fri, 10 Nov 2017 08:24:40 +0000 (+0000) Subject: utils.c (convert): Add comment and do not fall through to the next case. X-Git-Tag: releases/gcc-6.5.0~689 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2da244eb81a9ec693788fa70831a8d59d7b48f61;p=thirdparty%2Fgcc.git utils.c (convert): Add comment and do not fall through to the next case. * gcc-interface/utils.c (convert) : Add comment and do not fall through to the next case. : Deal specially with a dereference from another array type with the same element type. From-SVN: r254620 --- diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index e41237114c12..17b72d620ea6 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,10 @@ +2017-11-10 Eric Botcazou + + * gcc-interface/utils.c (convert) : Add comment and do + not fall through to the next case. + : Deal specially with a dereference from another array + type with the same element type. + 2017-09-15 Martin Liska Backport from mainline diff --git a/gcc/ada/gcc-interface/utils.c b/gcc/ada/gcc-interface/utils.c index d1c6da4e30cd..3543567b3657 100644 --- a/gcc/ada/gcc-interface/utils.c +++ b/gcc/ada/gcc-interface/utils.c @@ -4642,6 +4642,7 @@ convert (tree type, tree expr) return fold (convert_to_real (type, expr)); case RECORD_TYPE: + /* Do a normal conversion between scalar and justified modular type. */ if (TYPE_JUSTIFIED_MODULAR_P (type) && !AGGREGATE_TYPE_P (etype)) { vec *v; @@ -4653,9 +4654,27 @@ convert (tree type, tree expr) return gnat_build_constructor (type, v); } - /* ... fall through ... */ + /* In these cases, assume the front-end has validated the conversion. + If the conversion is valid, it will be a bit-wise conversion, so + it can be viewed as an unchecked conversion. */ + return unchecked_convert (type, expr, false); case ARRAY_TYPE: + /* Do a normal conversion between unconstrained and constrained array + type, assuming the latter is a constrained version of the former. */ + if (TREE_CODE (expr) == INDIRECT_REF + && ecode == ARRAY_TYPE + && TREE_TYPE (etype) == TREE_TYPE (type)) + { + tree ptr_type = build_pointer_type (type); + tree t = build_unary_op (INDIRECT_REF, NULL_TREE, + fold_convert (ptr_type, + TREE_OPERAND (expr, 0))); + TREE_READONLY (t) = TREE_READONLY (expr); + TREE_THIS_NOTRAP (t) = TREE_THIS_NOTRAP (expr); + return t; + } + /* In these cases, assume the front-end has validated the conversion. If the conversion is valid, it will be a bit-wise conversion, so it can be viewed as an unchecked conversion. */ diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e41932554cda..4584af5a152c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2017-11-10 Eric Botcazou + + * gnat.dg/opt69.adb: New test. + 2017-11-06 Paul Thomas Backported from trunk diff --git a/gcc/testsuite/gnat.dg/opt69.adb b/gcc/testsuite/gnat.dg/opt69.adb new file mode 100644 index 000000000000..e8c94dae2dc8 --- /dev/null +++ b/gcc/testsuite/gnat.dg/opt69.adb @@ -0,0 +1,28 @@ +-- { dg-do compile } +-- { dg-options "-O" } + +with Ada.Text_IO; + +procedure Opt69 is + + procedure Inner + (A : String := (1 .. 15 => ASCII.NUL); + B : String := (1 .. 5 => ASCII.NUL); + C : String := (1 .. 5 => ASCII.NUL)) + is + Aa : String (1 .. 15); + Bb : String (1 .. 5); + Cc : String (1 .. 5); + begin + Aa := A; + Bb := B; + Cc := C; + + Ada.Text_IO.Put_Line (Aa); + Ada.Text_IO.Put_Line (Bb); + Ada.Text_IO.Put_Line (Cc); + end; + +begin + Inner; +end;