* [PATCH RFA] driver: fix validate_switches logic
@ 2022-12-01 16:50 Jason Merrill
2022-12-02 6:36 ` Alexandre Oliva
0 siblings, 1 reply; 3+ messages in thread
From: Jason Merrill @ 2022-12-01 16:50 UTC (permalink / raw)
To: gcc-patches; +Cc: oliva
Tested x86_64-pc-linux-gnu, OK for trunk?
-- 8< --
Under the old logic for validate_switches, once suffix or starred got set,
they stayed set for all later switches found in the spec. So for e.g.
%{g*:%{%:debug-level-gt(0):
Once we see g*, starred is set. Then we see %:, and it sees that as a
zero-length switch, which because starred is still set, matches any and all
command-line options. So targets that use such a spec accept all options in
the driver, while ones that don't reject some, such as the recent
-nostdlib++.
This patch fixes the inconsistency, so all targets would complain about
-nostdlib++, and then sets SKIPOPT for it so they don't.
gcc/ChangeLog:
* gcc.cc (validate_switches): Reset suffix/starred on loop.
gcc/cp/ChangeLog:
* g++spec.cc (lang_specific_driver): Set SKIPOPT for nostdlib++.
---
gcc/cp/g++spec.cc | 4 +++-
gcc/gcc.cc | 7 +++++--
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/gcc/cp/g++spec.cc b/gcc/cp/g++spec.cc
index e599ac906f6..3d3b042dd56 100644
--- a/gcc/cp/g++spec.cc
+++ b/gcc/cp/g++spec.cc
@@ -167,8 +167,10 @@ lang_specific_driver (struct cl_decoded_option **in_decoded_options,
need_experimental = true;
break;
- case OPT_nostdlib:
case OPT_nostdlib__:
+ args[i] |= SKIPOPT;
+ /* FALLTHRU */
+ case OPT_nostdlib:
case OPT_nodefaultlibs:
library = -1;
break;
diff --git a/gcc/gcc.cc b/gcc/gcc.cc
index ca1c9e27a94..2278e2b6bb1 100644
--- a/gcc/gcc.cc
+++ b/gcc/gcc.cc
@@ -9299,12 +9299,15 @@ validate_switches (const char *start, bool user_spec, bool braced)
const char *atom;
size_t len;
int i;
- bool suffix = false;
- bool starred = false;
+ bool suffix;
+ bool starred;
#define SKIP_WHITE() do { while (*p == ' ' || *p == '\t') p++; } while (0)
next_member:
+ suffix = false;
+ starred = false;
+
SKIP_WHITE ();
if (*p == '!')
base-commit: 4304e09a1617bcf1c87f5bc96017ae5017379d75
--
2.31.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH RFA] driver: fix validate_switches logic
2022-12-01 16:50 [PATCH RFA] driver: fix validate_switches logic Jason Merrill
@ 2022-12-02 6:36 ` Alexandre Oliva
2022-12-02 7:50 ` Richard Biener
0 siblings, 1 reply; 3+ messages in thread
From: Alexandre Oliva @ 2022-12-02 6:36 UTC (permalink / raw)
To: Jason Merrill; +Cc: gcc-patches
On Dec 1, 2022, Jason Merrill <jason@redhat.com> wrote:
> Once we see g*, starred is set. Then we see %:, and it sees that as a
> zero-length switch, which because starred is still set, matches any and all
> command-line options. So targets that use such a spec accept all options in
> the driver, while ones that don't reject some, such as the recent
> -nostdlib++.
Woo, nice catch, thanks!
I don't have authority to approve the patch,
but it's ok as far as I'm concerned.
--
Alexandre Oliva, happy hacker https://FSFLA.org/blogs/lxo/
Free Software Activist GNU Toolchain Engineer
Disinformation flourishes because many people care deeply about injustice
but very few check the facts. Ask me about <https://stallmansupport.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH RFA] driver: fix validate_switches logic
2022-12-02 6:36 ` Alexandre Oliva
@ 2022-12-02 7:50 ` Richard Biener
0 siblings, 0 replies; 3+ messages in thread
From: Richard Biener @ 2022-12-02 7:50 UTC (permalink / raw)
To: Alexandre Oliva; +Cc: Jason Merrill, gcc-patches
On Fri, Dec 2, 2022 at 7:37 AM Alexandre Oliva via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> On Dec 1, 2022, Jason Merrill <jason@redhat.com> wrote:
>
> > Once we see g*, starred is set. Then we see %:, and it sees that as a
> > zero-length switch, which because starred is still set, matches any and all
> > command-line options. So targets that use such a spec accept all options in
> > the driver, while ones that don't reject some, such as the recent
> > -nostdlib++.
>
> Woo, nice catch, thanks!
>
> I don't have authority to approve the patch,
> but it's ok as far as I'm concerned.
OK.
> --
> Alexandre Oliva, happy hacker https://FSFLA.org/blogs/lxo/
> Free Software Activist GNU Toolchain Engineer
> Disinformation flourishes because many people care deeply about injustice
> but very few check the facts. Ask me about <https://stallmansupport.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-12-02 7:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-01 16:50 [PATCH RFA] driver: fix validate_switches logic Jason Merrill
2022-12-02 6:36 ` Alexandre Oliva
2022-12-02 7:50 ` Richard Biener
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).