From 7f1387e0f270d42df03d33c41e4bdac8d1491cdb Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Tue, 19 Jun 2018 09:37:31 +0000 Subject: [PATCH] gimplify.c (gimplify_init_constructor): Really never clear for an incomplete constructor if CONSTRUCTOR_NO_CLEARING is set. * gimplify.c (gimplify_init_constructor): Really never clear for an incomplete constructor if CONSTRUCTOR_NO_CLEARING is set. From-SVN: r261735 --- gcc/ChangeLog | 5 +++++ gcc/gimplify.c | 4 ++-- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gnat.dg/aggr24.adb | 13 +++++++++++++ gcc/testsuite/gnat.dg/aggr24_pkg.adb | 15 +++++++++++++++ gcc/testsuite/gnat.dg/aggr24_pkg.ads | 16 ++++++++++++++++ 6 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gnat.dg/aggr24.adb create mode 100644 gcc/testsuite/gnat.dg/aggr24_pkg.adb create mode 100644 gcc/testsuite/gnat.dg/aggr24_pkg.ads diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e1b5d2a00b9..3d3707d44e8 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2018-06-19 Eric Botcazou + + * gimplify.c (gimplify_init_constructor): Really never clear for an + incomplete constructor if CONSTRUCTOR_NO_CLEARING is set. + 2018-06-19 Richard Biener PR tree-optimization/86179 diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 4bcdf440d76..1523a27e828 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -4795,7 +4795,7 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, objects. Initializers for such objects must explicitly set every field that needs to be set. */ cleared = false; - else if (!complete_p && !CONSTRUCTOR_NO_CLEARING (ctor)) + else if (!complete_p) /* If the constructor isn't complete, clear the whole object beforehand, unless CONSTRUCTOR_NO_CLEARING is set on it. @@ -4804,7 +4804,7 @@ gimplify_init_constructor (tree *expr_p, gimple_seq *pre_p, gimple_seq *post_p, we'd need to *find* the elements that are not present, and that requires trickery to avoid quadratic compile-time behavior in large cases or excessive memory use in small cases. */ - cleared = true; + cleared = !CONSTRUCTOR_NO_CLEARING (ctor); else if (num_ctor_elements - num_nonzero_elements > CLEAR_RATIO (optimize_function_for_speed_p (cfun)) && num_nonzero_elements < num_ctor_elements / 4) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 67835408169..ca846009c6f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-06-19 Eric Botcazou + + * gnat.dg/aggr24.adb: New test. + * gnat.dg/aggr24_pkg.ad[sb]: New helper. + 2018-06-19 Richard Biener PR tree-optimization/86179 diff --git a/gcc/testsuite/gnat.dg/aggr24.adb b/gcc/testsuite/gnat.dg/aggr24.adb new file mode 100644 index 00000000000..b739c54fdc4 --- /dev/null +++ b/gcc/testsuite/gnat.dg/aggr24.adb @@ -0,0 +1,13 @@ +-- { dg-do run } + +with Aggr24_Pkg; use Aggr24_Pkg; + +procedure Aggr24 is + V : Rec; +begin + V.S := "Hello"; + Init (V); + if V.S /= "Hello" then + raise Program_Error; + end if; +end; diff --git a/gcc/testsuite/gnat.dg/aggr24_pkg.adb b/gcc/testsuite/gnat.dg/aggr24_pkg.adb new file mode 100644 index 00000000000..2ae3e79e322 --- /dev/null +++ b/gcc/testsuite/gnat.dg/aggr24_pkg.adb @@ -0,0 +1,15 @@ +package body Aggr24_Pkg is + + procedure Init (R : out Rec) is + begin + R := (I1 => 0, + I2 => 0, + I3 => 0, + I4 => 0, + I5 => 0, + I6 => 0, + I7 => 0, + S => <>); + end; + +end Aggr24_Pkg; diff --git a/gcc/testsuite/gnat.dg/aggr24_pkg.ads b/gcc/testsuite/gnat.dg/aggr24_pkg.ads new file mode 100644 index 00000000000..5918f5e8bd4 --- /dev/null +++ b/gcc/testsuite/gnat.dg/aggr24_pkg.ads @@ -0,0 +1,16 @@ +package Aggr24_Pkg is + + type Rec is record + I1 : Integer; + I2 : Integer; + I3 : Integer; + I4 : Integer; + I5 : Integer; + I6 : Integer; + I7 : Integer; + S : String (1 .. 5); + end record; + + procedure Init (R : out Rec); + +end Aggr24_Pkg; -- 2.30.2