From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1851) id 5199F3858010; Thu, 3 Mar 2022 12:24:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5199F3858010 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Martin Liska To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/marxin/heads/PR104381-fix-fvar-tracking-auto)] opts: fix -gtoggle + optimize attribute X-Act-Checkin: gcc X-Git-Author: Martin Liska X-Git-Refname: refs/users/marxin/heads/PR104381-fix-fvar-tracking-auto X-Git-Oldrev: 5b5e456f0187406e17444b6e40d974f94524f2a2 X-Git-Newrev: 1d9f77f00f208cca4142abc9c56995b865291229 Message-Id: <20220303122402.5199F3858010@sourceware.org> Date: Thu, 3 Mar 2022 12:24:02 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Mar 2022 12:24:02 -0000 https://gcc.gnu.org/g:1d9f77f00f208cca4142abc9c56995b865291229 commit 1d9f77f00f208cca4142abc9c56995b865291229 Author: Martin Liska Date: Fri Feb 4 15:50:17 2022 +0100 opts: fix -gtoggle + optimize attribute Note -fvar-tracking is enabled automatically with OPT_LEVELS_1_PLUS and so we need to drop it if we are called from optimize attribute and the option is unset. PR middle-end/104381 gcc/ChangeLog: * opts.cc (finish_options): If debug info is disabled (debug_info_level) and -fvar-tracking is unset, disable it. gcc/testsuite/ChangeLog: * gcc.dg/pr104381.c: New test. Diff: --- gcc/opts.cc | 49 +++++++++++++++++++++++------------------ gcc/testsuite/gcc.dg/pr104381.c | 20 +++++++++++++++++ 2 files changed, 48 insertions(+), 21 deletions(-) diff --git a/gcc/opts.cc b/gcc/opts.cc index 19c68aed065..ef5fe9b11ca 100644 --- a/gcc/opts.cc +++ b/gcc/opts.cc @@ -1302,6 +1302,34 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set, SET_OPTION_IF_UNSET (opts, opts_set, flag_vect_cost_model, VECT_COST_MODEL_CHEAP); + if (flag_gtoggle) + { + /* Make sure to process -gtoggle only once. */ + flag_gtoggle = false; + if (debug_info_level == DINFO_LEVEL_NONE) + { + debug_info_level = DINFO_LEVEL_NORMAL; + + if (write_symbols == NO_DEBUG) + write_symbols = PREFERRED_DEBUGGING_TYPE; + } + else + debug_info_level = DINFO_LEVEL_NONE; + } + + if (!OPTION_SET_P (debug_nonbind_markers_p)) + debug_nonbind_markers_p + = (optimize + && debug_info_level >= DINFO_LEVEL_NORMAL + && dwarf_debuginfo_p () + && !(flag_selective_scheduling || flag_selective_scheduling2)); + + /* Note -fvar-tracking is enabled automatically with OPT_LEVELS_1_PLUS and + so we need to drop it if we are called from optimize attribute. */ + if (debug_info_level == DINFO_LEVEL_NONE + && !OPTION_SET_P (flag_var_tracking)) + flag_var_tracking = false; + /* One could use EnabledBy, but it would lead to a circular dependency. */ if (!OPTION_SET_P (flag_var_tracking_uninit)) flag_var_tracking_uninit = flag_var_tracking; @@ -1328,27 +1356,6 @@ finish_options (struct gcc_options *opts, struct gcc_options *opts_set, profile_flag = 0; } - if (flag_gtoggle) - { - /* Make sure to process -gtoggle only once. */ - flag_gtoggle = false; - if (debug_info_level == DINFO_LEVEL_NONE) - { - debug_info_level = DINFO_LEVEL_NORMAL; - - if (write_symbols == NO_DEBUG) - write_symbols = PREFERRED_DEBUGGING_TYPE; - } - else - debug_info_level = DINFO_LEVEL_NONE; - } - - if (!OPTION_SET_P (debug_nonbind_markers_p)) - debug_nonbind_markers_p - = (optimize - && debug_info_level >= DINFO_LEVEL_NORMAL - && dwarf_debuginfo_p () - && !(flag_selective_scheduling || flag_selective_scheduling2)); diagnose_options (opts, opts_set, loc); } diff --git a/gcc/testsuite/gcc.dg/pr104381.c b/gcc/testsuite/gcc.dg/pr104381.c new file mode 100644 index 00000000000..a3aec919bee --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr104381.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -g -gtoggle -fdump-tree-optimized" } */ + +int foo (int x) +{ + int tem = x + 1; + int tem2 = tem - 1; + return tem2; +} + +int +__attribute__((optimize("no-tree-pre"))) +bar (int x) +{ + int tem = x + 1; + int tem2 = tem - 1; + return tem2; +} + +// { dg-final { scan-tree-dump-not "DEBUG " "optimized" } }