From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by sourceware.org (Postfix) with ESMTPS id BD0873858C78 for ; Tue, 1 Mar 2022 08:48:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BD0873858C78 Received: by mail-ej1-x631.google.com with SMTP id a8so29986898ejc.8 for ; Tue, 01 Mar 2022 00:48:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=ONuCGLRojOpwnvfWPOrsmoDBd+AAFgX3Csi5LgeApvM=; b=0SNB9U7X8Q0eZiiOOhCnnYMtZ0XbZ8yu8vLo6q6P4DdvY3Vs02moXxL1wcWvmyqtk/ 2Hsap9Hyk4DuGGDIbvGFDOz6QwJ7lbnpXte4yoaOy7GmsY1sQpEJiRnpKNxACae6oQjh GrZnpfSPnfIpmhRDg2IAfdhGQoNbZ2jFcAkN2UzaEFtwyeIsl6GFfyIE8V57C6fE+snF qBZDEAkwBBdvKTQPyVJoNcA/7YEMwC3B0bwonkEo1ic5/psp+ZdQGQfgkjYfPcEn51zy vrIwMBEgVvslktcMJbzIlQYTKtZnk9F1oUWCywjxpPaviuoCJsPbOn5u7cZKYBWgUT+q yE6g== X-Gm-Message-State: AOAM531xyAQlJELv23wLGhML7Yglo/FUBrA11PT2UBNhveucjdDmIoP6 SgFzsGwfJ9CkUqp/9s2F7/+MNyG+59HPjRUHt80= X-Google-Smtp-Source: ABdhPJzknLVWGcevJ6P7OuHO7MrF9AxDICEVZ38v9D7+0j83jJhYVLogr8m6MRicDtETbh85u3G6uVm5FdP2XiCqnyg= X-Received: by 2002:a17:907:6006:b0:6cd:efc0:3d67 with SMTP id fs6-20020a170907600600b006cdefc03d67mr18354009ejc.32.1646124508687; Tue, 01 Mar 2022 00:48:28 -0800 (PST) MIME-Version: 1.0 References: <65d104c2-eef6-fa92-7e6d-a42387c7526a@suse.cz> In-Reply-To: <65d104c2-eef6-fa92-7e6d-a42387c7526a@suse.cz> From: Richard Biener Date: Tue, 1 Mar 2022 09:48:17 +0100 Message-ID: Subject: Re: [PATCH] opts: fix -gtoggle + optimize attribute To: =?UTF-8?Q?Martin_Li=C5=A1ka?= Cc: GCC Patches Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Mar 2022 08:48:34 -0000 On Mon, Feb 28, 2022 at 10:03 AM Martin Li=C5=A1ka wrote: > > 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. > > Patch can bootstrap on x86_64-linux-gnu and survives regression tests. > > Ready to be installed? > Thanks, > Martin > > 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. > --- > gcc/opts.cc | 49 +++++++++++++++++++-------------- > gcc/testsuite/gcc.dg/pr104381.c | 20 ++++++++++++++ > 2 files changed, 48 insertions(+), 21 deletions(-) > create mode 100644 gcc/testsuite/gcc.dg/pr104381.c > > diff --git a/gcc/opts.cc b/gcc/opts.cc > index 19c68aed065..2370bb0aafe 100644 > --- a/gcc/opts.cc > +++ b/gcc/opts.cc > @@ -1302,6 +1302,34 @@ finish_options (struct gcc_options *opts, struct g= cc_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 =3D false; > + if (debug_info_level =3D=3D DINFO_LEVEL_NONE) > + { > + debug_info_level =3D DINFO_LEVEL_NORMAL; > + > + if (write_symbols =3D=3D NO_DEBUG) > + write_symbols =3D PREFERRED_DEBUGGING_TYPE; > + } > + else > + debug_info_level =3D DINFO_LEVEL_NONE; > + } > + > + if (!OPTION_SET_P (debug_nonbind_markers_p)) > + debug_nonbind_markers_p > + =3D (optimize > + && debug_info_level >=3D 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_NORMAL > + && !OPTION_SET_P (flag_var_tracking)) > + flag_var_tracking =3D false; > + I think moving flag_gtoggle handling before the flag_syntax_only handling is a good thing. But I don't quite understand the flag_var_tracking disabl= ing or how it worked before. At least I think you want to check for debug_info_level =3D=3D NONE, no? Why should DINFO_LEVEL_TERSE be special? > /* One could use EnabledBy, but it would lead to a circular dependenc= y. */ > if (!OPTION_SET_P (flag_var_tracking_uninit)) > flag_var_tracking_uninit =3D flag_var_tracking; > @@ -1328,27 +1356,6 @@ finish_options (struct gcc_options *opts, struct g= cc_options *opts_set, > profile_flag =3D 0; > } > > - if (flag_gtoggle) > - { > - /* Make sure to process -gtoggle only once. */ > - flag_gtoggle =3D false; > - if (debug_info_level =3D=3D DINFO_LEVEL_NONE) > - { > - debug_info_level =3D DINFO_LEVEL_NORMAL; > - > - if (write_symbols =3D=3D NO_DEBUG) > - write_symbols =3D PREFERRED_DEBUGGING_TYPE; > - } > - else > - debug_info_level =3D DINFO_LEVEL_NONE; > - } > - > - if (!OPTION_SET_P (debug_nonbind_markers_p)) > - debug_nonbind_markers_p > - =3D (optimize > - && debug_info_level >=3D 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/pr104= 381.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 =3D x + 1; > + int tem2 =3D tem - 1; > + return tem2; > +} > + > +int > +__attribute__((optimize("no-tree-pre"))) > +bar (int x) > +{ > + int tem =3D x + 1; > + int tem2 =3D tem - 1; > + return tem2; > +} > + > +// { dg-final { scan-tree-dump-not "DEBUG " "optimized" } } > -- > 2.35.1 >