The passed.def & target-specific extra passes files are C++ source, #included into the compiler.

But, they're also processed by an AWK script. That script simply looks for 3 special macro names, regardless of context.

Thus to (temporarily) disable a pass, one must both
a) line-comment it out
b) change the macro name, (by inserting a space or similar)

This annoying.

I contemplated just changing AWK to only accept the names at the beginning of a line (with whitespace), but then considered just running the C preprocessor first -- that way one gets all the CPP behaviour and no surprises.

Here's a patch to do the latter. Because these are .def files you need to tell the preprocessor it's C (or maybe pipe into stdin?), and one also needs to strip the '# N FILE' line markers produced, to avoid later warnings about those being a GCC extension.

I'm guessing '-x c' is going to be accepted by other compilers, given both gcc and clang grok it. If one goes the stdin route, one doesn't need that.

nathan

--
Nathan Sidwell
From 9f590b31fd7472224c413a63f30a736b4dc4ebb4 Mon Sep 17 00:00:00 2001
From: Nathan Sidwell <[email protected]>
Date: Mon, 13 Jul 2026 09:21:45 -0400
Subject: [PATCH] Robustify awk pass generation

	gcc/
	* Makefile.in (pass-instances.def): Use preprocessor to strip comments.
---
 gcc/Makefile.in | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index fa46ada4980..c694774316e 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -2741,10 +2741,10 @@ CFLAGS-tree-diagnostic-client-data-hooks.o += -DTARGET_NAME=\"$(target_noncanoni
 CFLAGS-optinfo-emit-json.o += -DTARGET_NAME=\"$(target_noncanonical)\" $(ZLIBINC)
 CFLAGS-analyzer/engine.o += $(ZLIBINC)
 
-pass-instances.def: $(srcdir)/passes.def $(PASSES_EXTRA) \
-		    $(srcdir)/gen-pass-instances.awk
-	$(AWK) -f $(srcdir)/gen-pass-instances.awk \
-	  $(srcdir)/passes.def $(PASSES_EXTRA) > pass-instances.def
+pass-instances.def: $(srcdir)/gen-pass-instances.awk \
+		$(srcdir)/passes.def $(PASSES_EXTRA)
+	$(CC_FOR_BUILD) -E -x c $(wordlist 2,99,$^) | grep -v '^#' | \
+	$(AWK) -f $< >$@
 
 $(out_object_file): $(out_file)
 	$(COMPILE) $<
-- 
2.55.0

Reply via email to