Mark RESULT_DECL as artificial

Richard Henderson rth@twiddle.net
Sun Jul 25 18:53:00 GMT 2004


A patch that I was working on managed to trigger an abort in dwarf2out,
when a decl duplicated from a RESULT_DECL (for inlining) couldn't find
it's origin die.

I believe that abort to be partially the fault of my patch, as dwarf2out
never saw the duplicated decl beforehand.  But it got me thinking that
marking these as artificial is Correct anyway.  We look at that flag in
the ssa optimizers when deciding which decls to fold away, so this could
result in slightly better resulting debug info.

Tested by itself on i686-linux.


r~


        * c-decl.c (start_function): Set DECL_ARTIFICIAL and DECL_IGNORED_P
        on the RESULT_DECL.
        * cgraphunit.c (cgraph_build_static_cdtor): Likewise.
        * integrate.c (copy_decl_for_inlining): Copy DECL_ARTIFICIAL and
        DECL_IGNORED_P to new decl.
ada/
        * utils.c (create_subprog_decl): Set DECL_ARTIFICIAL and
        DECL_IGNORED_P on RESULT_DECL.
cp/
        * decl.c (start_preparsed_function): Set DECL_ARTIFICIAL and
        DECL_IGNORED_P on RESULT_DECL.
        * semantics.c (finalize_nrv): Copy them too.
fortran/
        * trans-decl.c (gfc_build_function_decl): Set DECL_ARTIFICIAL
        and DECL_IGNORED_P on RESULT_DECL.
        (gfc_generate_constructors): Likewise.
java/
        * decl.c (build_result_decl): Set DECL_ARTIFICIAL and DECL_IGNORED_P.

Index: gcc/c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.538
diff -u -p -u -r1.538 c-decl.c
--- gcc/c-decl.c	25 Jul 2004 03:58:46 -0000	1.538
+++ gcc/c-decl.c	25 Jul 2004 08:01:57 -0000
@@ -5661,7 +5661,7 @@ int
 start_function (tree declspecs, tree declarator, tree attributes)
 {
   tree decl1, old_decl;
-  tree restype;
+  tree restype, resdecl;
 
   current_function_returns_value = 0;  /* Assume, until we see it does.  */
   current_function_returns_null = 0;
@@ -5857,8 +5857,11 @@ start_function (tree declspecs, tree dec
       else
 	restype = integer_type_node;
     }
-  DECL_RESULT (current_function_decl)
-    = build_decl (RESULT_DECL, NULL_TREE, restype);
+
+  resdecl = build_decl (RESULT_DECL, NULL_TREE, restype);
+  DECL_ARTIFICIAL (resdecl) = 1;
+  DECL_IGNORED_P (resdecl) = 1;
+  DECL_RESULT (current_function_decl) = resdecl;
 
   start_fname_decls ();
 
Index: gcc/cgraphunit.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cgraphunit.c,v
retrieving revision 1.69
diff -u -p -u -r1.69 cgraphunit.c
--- gcc/cgraphunit.c	15 Jul 2004 17:32:58 -0000	1.69
+++ gcc/cgraphunit.c	25 Jul 2004 08:01:58 -0000
@@ -1796,7 +1796,7 @@ cgraph_build_static_cdtor (char which, t
 {
   static int counter = 0;
   char which_buf[16];
-  tree decl, name;
+  tree decl, name, resdecl;
 
   sprintf (which_buf, "%c_%d", which, counter++);
   name = get_file_function_name_long (which_buf);
@@ -1805,7 +1805,11 @@ cgraph_build_static_cdtor (char which, t
 		     build_function_type (void_type_node, void_list_node));
   current_function_decl = decl;
 
-  DECL_RESULT (decl) = build_decl (RESULT_DECL, NULL_TREE, void_type_node);
+  resdecl = build_decl (RESULT_DECL, NULL_TREE, void_type_node);
+  DECL_ARTIFICIAL (resdecl) = 1;
+  DECL_IGNORED_P (resdecl) = 1;
+  DECL_RESULT (decl) = resdecl;
+
   allocate_struct_function (decl);
 
   TREE_STATIC (decl) = 1;
Index: gcc/integrate.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/integrate.c,v
retrieving revision 1.267
diff -u -p -u -r1.267 integrate.c
--- gcc/integrate.c	22 Jul 2004 19:01:02 -0000	1.267
+++ gcc/integrate.c	25 Jul 2004 08:01:58 -0000
@@ -141,6 +141,11 @@ copy_decl_for_inlining (tree decl, tree 
 	}
     }
 
+  /* Don't generate debug information for the copy if we wouldn't have
+     generated it for the copy either.  */
+  DECL_ARTIFICIAL (copy) = DECL_ARTIFICIAL (decl);
+  DECL_IGNORED_P (copy) = DECL_IGNORED_P (decl);
+
   /* Set the DECL_ABSTRACT_ORIGIN so the debugging routines know what
      declaration inspired this copy.  */
   DECL_ABSTRACT_ORIGIN (copy) = DECL_ORIGIN (decl);
Index: gcc/ada/utils.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/ada/utils.c,v
retrieving revision 1.69
diff -u -p -u -r1.69 utils.c
--- gcc/ada/utils.c	15 Jul 2004 03:17:42 -0000	1.69
+++ gcc/ada/utils.c	25 Jul 2004 08:02:00 -0000
@@ -1687,6 +1687,8 @@ create_subprog_decl (tree subprog_name, 
   TREE_SIDE_EFFECTS (subprog_decl) = TYPE_VOLATILE (subprog_type);
   DECL_ARGUMENTS (subprog_decl) = param_decl_list;
   DECL_RESULT (subprog_decl)    = build_decl (RESULT_DECL, 0, return_type);
+  DECL_ARTIFICIAL (DECL_RESULT (subprog_decl)) = 1;
+  DECL_IGNORED_P (DECL_RESULT (subprog_decl)) = 1;
 
   if (inline_flag)
     DECL_DECLARED_INLINE_P (subprog_decl) = 1;
Index: gcc/cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1259
diff -u -p -u -r1.1259 decl.c
--- gcc/cp/decl.c	21 Jul 2004 19:23:03 -0000	1.1259
+++ gcc/cp/decl.c	25 Jul 2004 08:02:04 -0000
@@ -9689,10 +9689,14 @@ start_preparsed_function (tree decl1, tr
     restype = type_promotes_to (restype);
   if (DECL_RESULT (decl1) == NULL_TREE)
     {
-      DECL_RESULT (decl1)
-	= build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (restype));
-      c_apply_type_quals_to_decl (cp_type_quals (restype),
-				  DECL_RESULT (decl1));
+      tree resdecl;
+
+      resdecl = build_decl (RESULT_DECL, 0, TYPE_MAIN_VARIANT (restype));
+      DECL_ARTIFICIAL (resdecl) = 1;
+      DECL_IGNORED_P (resdecl) = 1;
+      DECL_RESULT (decl1) = resdecl;
+
+      c_apply_type_quals_to_decl (cp_type_quals (restype), resdecl);
     }
 
   /* Initialize RTL machinery.  We cannot do this until
Index: gcc/cp/semantics.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/semantics.c,v
retrieving revision 1.418
diff -u -p -u -r1.418 semantics.c
--- gcc/cp/semantics.c	18 Jul 2004 23:57:31 -0000	1.418
+++ gcc/cp/semantics.c	25 Jul 2004 08:02:05 -0000
@@ -3050,6 +3050,8 @@ finalize_nrv (tree *tp, tree var, tree r
 
   /* Copy debugging information from VAR to RESULT.  */
   DECL_NAME (result) = DECL_NAME (var);
+  DECL_ARTIFICIAL (result) = DECL_ARTIFICIAL (var);
+  DECL_IGNORED_P (result) = DECL_IGNORED_P (var);
   DECL_SOURCE_LOCATION (result) = DECL_SOURCE_LOCATION (var);
   DECL_ABSTRACT_ORIGIN (result) = DECL_ABSTRACT_ORIGIN (var);
   /* Don't forget that we take its address.  */
Index: gcc/fortran/trans-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/trans-decl.c,v
retrieving revision 1.24
diff -u -p -u -r1.24 trans-decl.c
--- gcc/fortran/trans-decl.c	15 Jul 2004 18:50:13 -0000	1.24
+++ gcc/fortran/trans-decl.c	25 Jul 2004 08:02:06 -0000
@@ -1030,6 +1030,8 @@ gfc_build_function_decl (gfc_symbol * sy
     }
 
   result_decl = build_decl (RESULT_DECL, result_decl, type);
+  DECL_ARTIFICIAL (result_decl) = 1;
+  DECL_IGNORED_P (result_decl) = 1;
   DECL_CONTEXT (result_decl) = fndecl;
   DECL_RESULT (fndecl) = result_decl;
 
@@ -2124,6 +2126,8 @@ gfc_generate_constructors (void)
   TREE_PUBLIC (fndecl) = 1;
 
   decl = build_decl (RESULT_DECL, NULL_TREE, void_type_node);
+  DECL_ARTIFICIAL (decl) = 1;
+  DECL_IGNORED_P (decl) = 1;
   DECL_CONTEXT (decl) = fndecl;
   DECL_RESULT (fndecl) = decl;
 
Index: gcc/java/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/decl.c,v
retrieving revision 1.190
diff -u -p -u -r1.190 decl.c
--- gcc/java/decl.c	25 Jul 2004 00:13:01 -0000	1.190
+++ gcc/java/decl.c	25 Jul 2004 08:02:06 -0000
@@ -1804,6 +1804,8 @@ build_result_decl (tree fndecl)
 	  && TYPE_PRECISION (restype) < TYPE_PRECISION (integer_type_node))
 	restype = integer_type_node;
       result = build_decl (RESULT_DECL, NULL_TREE, restype);
+      DECL_ARTIFICIAL (result) = 1;
+      DECL_IGNORED_P (result) = 1;
       DECL_CONTEXT (result) = fndecl;
       DECL_RESULT (fndecl) = result;
     }



More information about the Gcc-patches mailing list