From e02820c9b18a867cf3f109bd62385d7450f70258 Mon Sep 17 00:00:00 2001 From: Scott Graham Date: Sun, 5 May 2024 19:13:39 -0700 Subject: [PATCH] Fix bug in reading #line filename inside #if block --- src/preprocess.c | 3 ++- test/line_directive_bug.c | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 test/line_directive_bug.c diff --git a/src/preprocess.c b/src/preprocess.c index df0c993..a71257d 100644 --- a/src/preprocess.c +++ b/src/preprocess.c @@ -844,7 +844,8 @@ static Token* include_file(Token* tok, char* path, Token* filename_tok) { // Read #line arguments static void read_line_marker(Token** rest, Token* tok) { Token* start = tok; - tok = preprocess(copy_line(rest, tok)); + tok = preprocess2(copy_line(rest, tok)); + convert_pp_tokens(tok); if (tok->kind != TK_NUM || tok->ty->kind != TY_INT) error_tok(tok, "invalid line marker"); diff --git a/test/line_directive_bug.c b/test/line_directive_bug.c new file mode 100644 index 0000000..ddca712 --- /dev/null +++ b/test/line_directive_bug.c @@ -0,0 +1,4 @@ +#if 1 +#line 1 "file" +#endif +int main() {}