Using: #define LINE1 10 #line LINE1 #define LINE2 20 #define FILE "file" #line LINE2 FILE Should now work. Add new testcase tests/pp/23.S
Unified · Split
| @@ -1929,31 +1929,34 @@ ST_FUNC void preprocess(int is_bof) · 1928 unmodified lines | |||
| 1929 | break; | 1929 | break; |
| 1930 | 1930 | ||
| 1931 | case TOK_LINE: | 1931 | case TOK_LINE: |
| 1932 | next_nomacro(); | 1932 | next(); |
| 1933 | if (tok != TOK_PPNUM) { | 1933 | if (tok != TOK_CINT) { |
| 1934 | _line_err: | 1934 | _line_err: |
| 1935 | tcc_error("wrong #line format"); | 1935 | tcc_error("wrong #line format"); |
| 1936 | } | 1936 | } |
| 1937 | n = tokc.i; | ||
| 1937 | goto _line_num; | 1938 | goto _line_num; |
| 1938 | case TOK_PPNUM: | 1939 | case TOK_PPNUM: |
| 1939 | if (parse_flags & PARSE_FLAG_ASM_FILE) | 1940 | if (parse_flags & PARSE_FLAG_ASM_FILE) |
| 1940 | goto ignore; | 1941 | goto ignore; |
| 1941 | _line_num: | ||
| 1942 | for (n = 0, q = tokc.str.data; *q; ++q) { | 1942 | for (n = 0, q = tokc.str.data; *q; ++q) { |
| 1943 | if (!isnum(*q)) | 1943 | if (!isnum(*q)) |
| 1944 | goto _line_err; | 1944 | goto _line_err; |
| 1945 | n = n * 10 + *q - '0'; | 1945 | n = n * 10 + *q - '0'; |
| 1946 | } | 1946 | } |
| 1947 | next_nomacro(); | 1947 | _line_num: |
| 1948 | if (tok != TOK_LINEFEED) { | 1948 | next(); |
| 1949 | if (tok == TOK_PPSTR && tokc.str.data[0] == '"') { | 1949 | if (tok == TOK_STR) { |
| 1950 | tokc.str.data[tokc.str.size - 2] = 0; | 1950 | tccpp_putfile(tokc.str.data); |
| 1951 | tccpp_putfile(tokc.str.data + 1); | 1951 | n--; |
| 1952 | } else | 1952 | } |
| 1953 | goto _line_err; | 1953 | else if (tok != TOK_LINEFEED) |
| 1954 | } | 1954 | goto _line_err; |
| 1955 | if (macro_ptr && *macro_ptr == 0) | ||
| 1956 | macro_stack->save_line_num = n; | ||
| 1955 | if (file->fd > 0) | 1957 | if (file->fd > 0) |
| 1956 | total_lines += file->line_num - n; | 1958 | total_lines += file->line_num - n; |
| 1959 | file->line_ref += file->line_num - n; | ||
| 1957 | file->line_num = n; | 1960 | file->line_num = n; |
| 1958 | goto ignore; /* skip optional level number */ | 1961 | goto ignore; /* skip optional level number */ |
| 1959 | 1962 | ||
| @@ -0,0 +1,19 @@ | |||
| 1 | __LINE__ | ||
| 2 | # 10 | ||
| 3 | __LINE__ | ||
| 4 | # line 20 | ||
| 5 | __LINE__ | ||
| 6 | # 64mb | ||
| 7 | __LINE__ | ||
| 8 | # line 30 | ||
| 9 | __LINE__ | ||
| 10 | #define LINE1 40 | ||
| 11 | # line LINE1 | ||
| 12 | __LINE__ __FILE__ | ||
| 13 | #define LINE2 50 | ||
| 14 | # line LINE2 "file1" | ||
| 15 | __LINE__ __FILE__ | ||
| 16 | #define LINE3 60 | ||
| 17 | #define FILE "file2" | ||
| 18 | # line LINE3 FILE | ||
| 19 | __LINE__ __FILE__ | ||
| @@ -0,0 +1,8 @@ | |||
| 1 | 1 | ||
| 2 | 3 | ||
| 3 | 20 | ||
| 4 | 22 | ||
| 5 | 30 | ||
| 6 | 40 "23.S" | ||
| 7 | 50 "file1" | ||
| 8 | 60 "file2" | ||