fix(format): keep a macro-named label line whole

A label whose name is a macro expands into whatever the body is, so the
line's statement structure exists only after expansion; splitting the
label off changed clean input into a different statement sequence.  The
formatter now records the names #define'd above each line and renders
such a label line unsplit, and the crashing input joins the corpus.

Assisted-by: GLM 5.3
This commit is contained in:
petrbalvin committed 2026-10-07 13:54:42 +02:00
1 parent 715298ed23
commit f452b8a995
3 files changed
+53 -4

No files matched your search

+20
View File
@@ -95,6 +95,26 @@ func TestFormatPreservesExpansionSemantics(t *testing.T) {
"\tM(1, R0)\n" +
"\tRET\n",
},
{
// A label whose name is a macro: the expansion decides what the
// line becomes (here an instruction with several operands), so
// the canonical form keeps the line whole instead of splitting
// the label off, which would change the statement structure.
name: "label named as a macro",
src: "#define M B0, C0\n" +
"TEXT ·f(SB), $0\n" +
"\tM: A00\n" +
"\tRET\n",
},
{
// A use before the define: the name is not a macro yet at that
// point of the file, so the label splits as any other does.
name: "label before the define of its name",
src: "TEXT ·f(SB), $0\n" +
"\tM: A00\n" +
"\tRET\n" +
"#define M B0, C0\n",
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {