Patchwork Add CONSTRUCTOR_NO_CLEARING flag

login
register
mail settings
Submitter Eric Botcazou
Date Nov. 11, 2013, 10:55 a.m.
Message ID <1396974.au2QbtdziC@polaris>
Download mbox | patch
Permalink /patch/290241/
State New
Headers show

Comments

Eric Botcazou - Nov. 11, 2013, 10:55 a.m.
Hi,

in Ada 2012 it is allowed to omit components of aggregates (the equivalent of 
initializers/constructors); in this case, the contents of the corresponding 
fields in the record become undefined.  Now the gimplifier implements the C 
semantics of clearing the missing components, so this patch introduces a new 
flag on constructors to modify that.

Tested on x86_64-suse-linux, OK for the mainline?


2013-11-11  Tristan Gingold  <gingold@adacore.com>
            Eric Botcazou  <ebotcazou@adacore.com>

	* tree.h (CONSTRUCTOR_NO_CLEARING): Define.
	* tree-core.h (CONSTRUCTOR_NO_CLEARING): Document it.
	* tree.def (CONSTRUCTOR): Likewise.
	* gimplify.c (gimplify_init_constructor): Do not clear the object when
	the constructor is incomplete and CONSTRUCTOR_NO_CLEARING is set.
ada/
	* gcc-interface/utils2.c (gnat_build_constructor): Also set the flag
	CONSTRUCTOR_NO_CLEARING on the constructor.
Richard Guenther - Nov. 11, 2013, 1:11 p.m.
On Mon, Nov 11, 2013 at 11:55 AM, Eric Botcazou <ebotcazou@adacore.com> wrote:
> Hi,
>
> in Ada 2012 it is allowed to omit components of aggregates (the equivalent of
> initializers/constructors); in this case, the contents of the corresponding
> fields in the record become undefined.  Now the gimplifier implements the C
> semantics of clearing the missing components, so this patch introduces a new
> flag on constructors to modify that.
>
> Tested on x86_64-suse-linux, OK for the mainline?

Ok.  Can you update doc/generic.texi?

Thanks,
Richard.

>
> 2013-11-11  Tristan Gingold  <gingold@adacore.com>
>             Eric Botcazou  <ebotcazou@adacore.com>
>
>         * tree.h (CONSTRUCTOR_NO_CLEARING): Define.
>         * tree-core.h (CONSTRUCTOR_NO_CLEARING): Document it.
>         * tree.def (CONSTRUCTOR): Likewise.
>         * gimplify.c (gimplify_init_constructor): Do not clear the object when
>         the constructor is incomplete and CONSTRUCTOR_NO_CLEARING is set.
> ada/
>         * gcc-interface/utils2.c (gnat_build_constructor): Also set the flag
>         CONSTRUCTOR_NO_CLEARING on the constructor.
>
>
> --
> Eric Botcazou
Eric Botcazou - Nov. 11, 2013, 4:56 p.m.
> Ok.  Can you update doc/generic.texi?

Thanks, done (it was still talking about TREE_LIST).
Eric Botcazou - Nov. 12, 2013, 5:32 p.m.
> in Ada 2012 it is allowed to omit components of aggregates (the equivalent
> of initializers/constructors); in this case, the contents of the
> corresponding fields in the record become undefined.  Now the gimplifier
> implements the C semantics of clearing the missing components, so this
> patch introduces a new flag on constructors to modify that.

My bad, I forgot to install the testcase written by Tristan...

Tested on x86_64-suse-linux, installed on the mainline.


2013-11-12  Tristan Gingold  <gingold@adacore.com>

	* gnat.dg/aggr21.adb: New test.
	* gnat.dg/aggr21_pkg.ad[sb]: New helper.

Patch

Index: tree-core.h
===================================================================
--- tree-core.h	(revision 204444)
+++ tree-core.h	(working copy)
@@ -823,6 +823,9 @@  struct GTY(()) tree_base {
            VAR_DECL, FUNCTION_DECL
            IDENTIFIER_NODE
 
+       CONSTRUCTOR_NO_CLEARING in
+           CONSTRUCTOR
+
        ASM_VOLATILE_P in
            ASM_EXPR
 
Index: tree.h
===================================================================
--- tree.h	(revision 204444)
+++ tree.h	(working copy)
@@ -957,6 +957,8 @@  extern void omp_clause_range_check_faile
   (&(*CONSTRUCTOR_ELTS (NODE))[IDX])
 #define CONSTRUCTOR_NELTS(NODE) \
   (vec_safe_length (CONSTRUCTOR_ELTS (NODE)))
+#define CONSTRUCTOR_NO_CLEARING(NODE) \
+  (CONSTRUCTOR_CHECK (NODE)->base.public_flag)
 
 /* Iterate through the vector V of CONSTRUCTOR_ELT elements, yielding the
    value of each element (stored within VAL). IX must be a scratch variable
Index: tree.def
===================================================================
--- tree.def	(revision 204444)
+++ tree.def	(working copy)
@@ -458,7 +458,10 @@  DEFTREECODE (OBJ_TYPE_REF, "obj_type_ref
    value in a SAVE_EXPR if you want to evaluate side effects only once.)
 
    For RECORD_TYPE, UNION_TYPE, or QUAL_UNION_TYPE:
-   The field INDEX of each node is a FIELD_DECL.  */
+   The field INDEX of each node is a FIELD_DECL.
+   Components that aren't present are cleared as per the C semantics,
+   unless the CONSTRUCTOR_NO_CLEARING flag is set, in which case they
+   become undefined.  */
 DEFTREECODE (CONSTRUCTOR, "constructor", tcc_exceptional, 0)
 
 /* The expression types are mostly straightforward, with the fourth argument
Index: gimplify.c
===================================================================
--- gimplify.c	(revision 204444)
+++ gimplify.c	(working copy)
@@ -4052,7 +4052,7 @@  gimplify_init_constructor (tree *expr_p,
 	     objects.  Initializers for such objects must explicitly set
 	     every field that needs to be set.  */
 	  cleared = false;
-	else if (!complete_p)
+	else if (!complete_p && !CONSTRUCTOR_NO_CLEARING (ctor))
 	  /* If the constructor isn't complete, clear the whole object
 	     beforehand.
 
Index: ada/gcc-interface/utils2.c
===================================================================
--- ada/gcc-interface/utils2.c	(revision 204444)
+++ ada/gcc-interface/utils2.c	(working copy)
@@ -1874,6 +1874,7 @@  gnat_build_constructor (tree type, vec<c
     v->qsort (compare_elmt_bitpos);
 
   result = build_constructor (type, v);
+  CONSTRUCTOR_NO_CLEARING (result) = 1;
   TREE_CONSTANT (result) = TREE_STATIC (result) = allconstant;
   TREE_SIDE_EFFECTS (result) = side_effects;
   TREE_READONLY (result) = TYPE_READONLY (type) || allconstant;