diff --git a/tccpp.c b/tccpp.c index b2ae48af..077f7dfe 100644 --- a/tccpp.c +++ b/tccpp.c @@ -1929,31 +1929,34 @@ ST_FUNC void preprocess(int is_bof) break; case TOK_LINE: - next_nomacro(); - if (tok != TOK_PPNUM) { + next(); + if (tok != TOK_CINT) { _line_err: tcc_error("wrong #line format"); } + n = tokc.i; goto _line_num; case TOK_PPNUM: if (parse_flags & PARSE_FLAG_ASM_FILE) goto ignore; - _line_num: for (n = 0, q = tokc.str.data; *q; ++q) { if (!isnum(*q)) goto _line_err; n = n * 10 + *q - '0'; } - next_nomacro(); - if (tok != TOK_LINEFEED) { - if (tok == TOK_PPSTR && tokc.str.data[0] == '"') { - tokc.str.data[tokc.str.size - 2] = 0; - tccpp_putfile(tokc.str.data + 1); - } else - goto _line_err; + _line_num: + next(); + if (tok == TOK_STR) { + tccpp_putfile(tokc.str.data); + n--; } + else if (tok != TOK_LINEFEED) + goto _line_err; + if (macro_ptr && *macro_ptr == 0) + macro_stack->save_line_num = n; if (file->fd > 0) total_lines += file->line_num - n; + file->line_ref += file->line_num - n; file->line_num = n; goto ignore; /* skip optional level number */ diff --git a/tests/pp/23.S b/tests/pp/23.S new file mode 100644 index 00000000..bfacc935 --- /dev/null +++ b/tests/pp/23.S @@ -0,0 +1,19 @@ +__LINE__ +# 10 +__LINE__ +# line 20 +__LINE__ +# 64mb +__LINE__ +# line 30 +__LINE__ +#define LINE1 40 +# line LINE1 +__LINE__ __FILE__ +#define LINE2 50 +# line LINE2 "file1" +__LINE__ __FILE__ +#define LINE3 60 +#define FILE "file2" +# line LINE3 FILE +__LINE__ __FILE__ diff --git a/tests/pp/23.expect b/tests/pp/23.expect new file mode 100644 index 00000000..ac1f0c7a --- /dev/null +++ b/tests/pp/23.expect @@ -0,0 +1,8 @@ +1 +3 +20 +22 +30 +40 "23.S" +50 "file1" +60 "file2"