From: Martin Liska Date: Tue, 1 Jun 2021 08:41:04 +0000 (+0200) Subject: Fix sanity checking of global_options. X-Git-Tag: basepoints/gcc-13~7171 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b195d84561a5c31108c7bbbd7c5b63fe3cebe35f;p=thirdparty%2Fgcc.git Fix sanity checking of global_options. gcc/c-family/ChangeLog: PR other/100759 * c-attribs.c (handle_optimize_attribute): Limit sanity check to a situation where we are not in processing of an optimize pragma. * c-pragma.c (handle_pragma_pop_options): Restore target options. --- diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c index 804374d5acc8..156f7b3e8e1b 100644 --- a/gcc/c-family/c-attribs.c +++ b/gcc/c-family/c-attribs.c @@ -5389,7 +5389,11 @@ handle_optimize_attribute (tree *node, tree name, tree args, /* If we previously had some optimization options, use them as the default. */ gcc_options *saved_global_options = NULL; - if (flag_checking) + + /* When #pragma GCC optimize pragma is used, it modifies global_options + without calling targetm.override_options_after_change. That can leave + target flags inconsistent for comparison. */ + if (flag_checking && optimization_current_node == optimization_default_node) { saved_global_options = XNEW (gcc_options); *saved_global_options = global_options; diff --git a/gcc/c-family/c-pragma.c b/gcc/c-family/c-pragma.c index 7f658ea56468..f46b5b93c29a 100644 --- a/gcc/c-family/c-pragma.c +++ b/gcc/c-family/c-pragma.c @@ -1088,6 +1088,8 @@ handle_pragma_pop_options (cpp_reader *ARG_UNUSED(dummy)) * overwritten by invoke_set_current_function_hook. */ cl_optimization_restore (&global_options, &global_options_set, TREE_OPTIMIZATION (p->optimize_binary)); + cl_target_option_restore (&global_options, &global_options_set, + TREE_TARGET_OPTION (p->target_binary)); if (p->optimize_binary != optimization_current_node) {