diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc index 4252e627b0c..880eaff8d0b 100644 --- a/gcc/ada/gcc-interface/decl.cc +++ b/gcc/ada/gcc-interface/decl.cc @@ -1563,6 +1563,13 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) prepend_one_attribute_pragma (&attr_list, Linker_Section_Pragma (gnat_entity)); + /* Do not initialize Out parameters with -ftrivial-auto-var-init. */ + if (kind == E_Out_Parameter) + prepend_one_attribute + (&attr_list, ATTR_MACHINE_ATTRIBUTE, + get_identifier ("uninitialized"), NULL_TREE, + gnat_entity); + /* Now create the variable or the constant and set various flags. */ gnu_decl = create_var_decl (gnu_entity_name, gnu_ext_name, gnu_type, diff --git a/gcc/ada/gcc-interface/utils.cc b/gcc/ada/gcc-interface/utils.cc index 60f36b1e50d..a88a23860d3 100644 --- a/gcc/ada/gcc-interface/utils.cc +++ b/gcc/ada/gcc-interface/utils.cc @@ -107,6 +107,7 @@ static tree handle_malloc_attribute (tree *, tree, tree, int, bool *); static tree handle_type_generic_attribute (tree *, tree, tree, int, bool *); static tree handle_flatten_attribute (tree *, tree, tree, int, bool *); static tree handle_used_attribute (tree *, tree, tree, int, bool *); +static tree handle_uninitialized_attribute (tree *, tree, tree, int, bool *); static tree handle_cold_attribute (tree *, tree, tree, int, bool *); static tree handle_hot_attribute (tree *, tree, tree, int, bool *); static tree handle_simd_attribute (tree *, tree, tree, int, bool *); @@ -214,6 +215,8 @@ static const attribute_spec gnat_internal_attributes[] = handle_flatten_attribute, NULL }, { "used", 0, 0, true, false, false, false, handle_used_attribute, NULL }, + { "uninitialized",0, 0, true, false, false, false, + handle_uninitialized_attribute, NULL }, { "cold", 0, 0, true, false, false, false, handle_cold_attribute, attr_cold_hot_exclusions }, { "hot", 0, 0, true, false, false, false, @@ -7171,6 +7174,30 @@ handle_used_attribute (tree *pnode, tree name, tree ARG_UNUSED (args), return NULL_TREE; } +/* Handle an "uninitialized" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +handle_uninitialized_attribute (tree *node, tree name, tree ARG_UNUSED (args), + int ARG_UNUSED (flags), bool *no_add_attrs) +{ + tree decl = *node; + if (!VAR_P (decl)) + { + warning (OPT_Wattributes, "%qE attribute ignored because %qD " + "is not a variable", name, decl); + *no_add_attrs = true; + } + else if (TREE_STATIC (decl) || DECL_EXTERNAL (decl)) + { + warning (OPT_Wattributes, "%qE attribute ignored because %qD " + "is not a local variable", name, decl); + *no_add_attrs = true; + } + + return NULL_TREE; +} + /* Handle a "cold" and attribute; arguments as in struct attribute_spec.handler. */ diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index dd7efa71b74..6cdc70d2130 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -1993,17 +1993,14 @@ gimple_add_init_for_auto_var (tree decl, { gcc_assert (auto_var_p (decl)); gcc_assert (init_type > AUTO_INIT_UNINITIALIZED); - location_t loc = EXPR_LOCATION (decl); + + const location_t loc = DECL_SOURCE_LOCATION (decl); tree decl_size = TYPE_SIZE_UNIT (TREE_TYPE (decl)); + tree init_type_node = build_int_cst (integer_type_node, (int) init_type); + tree decl_name; - tree init_type_node - = build_int_cst (integer_type_node, (int) init_type); - - tree decl_name = NULL_TREE; if (DECL_NAME (decl)) - decl_name = build_string_literal (DECL_NAME (decl)); - else { char decl_name_anonymous[3 + (HOST_BITS_PER_INT + 2) / 3]; diff --git a/gcc/testsuite/gnat.dg/auto_var_init.adb b/gcc/testsuite/gnat.dg/auto_var_init.adb new file mode 100644 index 00000000000..9f0ec7a8159 --- /dev/null +++ b/gcc/testsuite/gnat.dg/auto_var_init.adb @@ -0,0 +1,9 @@ +-- { dg-do run } +-- { dg-options "-ftrivial-auto-var-init=zero" } + +with Ada.Text_IO; use Ada.Text_IO; + +procedure Auto_Var_Init is +begin + Put_Line ("Hello World!"); +end; diff --git a/gcc/tree.cc b/gcc/tree.cc index bc50afca9a3..095c02c5474 100644 --- a/gcc/tree.cc +++ b/gcc/tree.cc @@ -9848,7 +9848,6 @@ build_common_builtin_nodes (void) ftype = build_function_type_list (void_type_node, ptr_type_node, ptr_type_node, - integer_type_node, NULL_TREE); local_define_builtin ("__builtin_clear_padding", ftype, BUILT_IN_CLEAR_PADDING,