From 34d7c2b8ed5a4aaf9121e7ce6cb61f73c3ef27d2 Mon Sep 17 00:00:00 2001 From: Sree Kotay Date: Tue, 11 Aug 2026 01:08:50 -0400 Subject: [PATCH] pp_line: do not swallow #line with negative deltas The short-newline path used `d < 8`, which also matches negative deltas. The inner `while (d > 0)` is then a no-op, so a user #line that resumes an earlier line after a large injection is dropped and diagnostics drift. Restrict the swallow to `d >= 0 && d < 8`. --- tccpp.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tccpp.c b/tccpp.c index 214e9cd4a6..7e1ad87e16 100644 --- a/tccpp.c +++ b/tccpp.c @@ -3802,7 +3802,11 @@ static void pp_line(TCCState *s1, BufferedFile *f, int level) if (s1->Pflag == LINE_MACRO_OUTPUT_FORMAT_NONE) { ; - } else if (level == 0 && f->line_ref && d < 8) { + } else if (level == 0 && f->line_ref && d >= 0 && d < 8) { + /* Negative d (e.g. #line resume after a large synthetic injection) + * must not take the short-newline swallow path: while (d > 0) is a + * no-op then, so the directive was silently dropped and line + * tracking drifted. Restrict the swallow to non-negative deltas. */ while (d > 0) fputs("\n", s1->ppfp), --d; } else if (s1->Pflag == LINE_MACRO_OUTPUT_FORMAT_STD) {