2016-01-20 Christian Bruel <christian.bruel@st.com>
PR target/69245
* config/arm/arm-c.c (arm_pragma_target_parse): Add comments.
Move arm_reset_previous_fndecl and set_target_option_current_node in the conditional part.
* config/arm/arm.c (arm_set_current_function):
Refactor to better support #pragma target and attribute mix.
2016-01-20 Christian Bruel <christian.bruel@st.com>
PR target/69245
* gcc.target/arm/pr69245.c: New test.
===================================================================
@@ -221,9 +221,6 @@ arm_pragma_target_parse (tree args, tree pop_targe
}
}
- target_option_current_node = cur_tree;
- arm_reset_previous_fndecl ();
-
/* Figure out the previous mode. */
prev_opt = TREE_TARGET_OPTION (prev_tree);
cur_opt = TREE_TARGET_OPTION (cur_tree);
@@ -261,8 +255,13 @@ arm_pragma_target_parse (tree args, tree pop_targe
arm_cpu_builtins (parse_in);
cpp_opts->warn_unused_macros = saved_warn_unused_macros;
+
+ /* Make sure that target_reinit is called for next function, since
+ TREE_TARGET_OPTION might change with the #pragma even if there are
+ no target attribute attached to the function. */
+ target_option_current_node = cur_tree;
+ arm_reset_previous_fndecl ();
}
return true;
===================================================================
@@ -29768,35 +29768,28 @@ arm_set_current_function (tree fndecl)
tree new_tree = DECL_FUNCTION_SPECIFIC_TARGET (fndecl);
- arm_previous_fndecl = fndecl;
+ /* if no attribute, use the mode set by the current pragma target. */
+ if (! new_tree)
+ new_tree = target_option_current_node;
+
if (old_tree == new_tree)
return;
- if (new_tree && new_tree != target_option_default_node)
- {
- cl_target_option_restore (&global_options,
- TREE_TARGET_OPTION (new_tree));
+ arm_previous_fndecl = fndecl;
- if (TREE_TARGET_GLOBALS (new_tree))
- restore_target_globals (TREE_TARGET_GLOBALS (new_tree));
- else
- TREE_TARGET_GLOBALS (new_tree)
- = save_target_globals_default_opts ();
- }
+ /* First set the target options. */
+ cl_target_option_restore (&global_options, TREE_TARGET_OPTION (new_tree));
- else if (old_tree && old_tree != target_option_default_node)
+ /* If we have a previous state, use it. */
+ if (TREE_TARGET_GLOBALS (new_tree))
+ restore_target_globals (TREE_TARGET_GLOBALS (new_tree));
+ else if (new_tree == target_option_default_node)
+ restore_target_globals (&default_target_globals);
+ else
{
- new_tree = target_option_current_node;
-
- cl_target_option_restore (&global_options,
- TREE_TARGET_OPTION (new_tree));
- if (TREE_TARGET_GLOBALS (new_tree))
- restore_target_globals (TREE_TARGET_GLOBALS (new_tree));
- else if (new_tree == target_option_default_node)
- restore_target_globals (&default_target_globals);
- else
- TREE_TARGET_GLOBALS (new_tree)
- = save_target_globals_default_opts ();
+ /* now target_reinit can save the state for later. */
+ TREE_TARGET_GLOBALS (new_tree)
+ = save_target_globals_default_opts ();
}
arm_option_params_internal ();
===================================================================
@@ -0,0 +1,24 @@
+/* PR target/69245 */
+/* Test that pop_options restores the vfp fpu mode. */
+/* { dg-do compile } */
+/* { dg-require-effective-target arm_fp_ok } */
+/* { dg-add-options arm_fp } */
+
+#pragma GCC target "fpu=vfp"
+
+#pragma GCC push_options
+#pragma GCC target "fpu=neon"
+int a, c, d;
+float b;
+static int fn1 ()
+{
+ return 0;
+}
+#pragma GCC pop_options
+
+void fn2 ()
+{
+ d = b * c + a;
+}
+
+/* { dg-final { scan-assembler-times "\.fpu vfp" 1 } } */