A more correct fix. This one don't break old logic. But if include file is not found, we try to search again with the new compare rule. A description of the problem: http://permalink.gmane.org/gmane.comp.compilers.tinycc.devel/2769
Unified · Split
| @@ -1528,6 +1528,7 @@ ST_FUNC void preprocess(int is_bof) · 1527 unmodified lines | |||
| 1528 | int i, c, n, saved_parse_flags; | 1528 | int i, c, n, saved_parse_flags; |
| 1529 | char buf[1024], *q; | 1529 | char buf[1024], *q; |
| 1530 | Sym *s; | 1530 | Sym *s; |
| 1531 | int include_next_first_try = 1; | ||
| 1531 | 1532 | ||
| 1532 | saved_parse_flags = parse_flags; | 1533 | saved_parse_flags = parse_flags; |
| 1533 | parse_flags = PARSE_FLAG_PREPROCESS | 1534 | parse_flags = PARSE_FLAG_PREPROCESS |
| @@ -1617,6 +1618,7 @@ ST_FUNC void preprocess(int is_bof) · 83 unmodified lines | |||
| 1617 | /* store current file in stack, but increment stack later below */ | 1618 | /* store current file in stack, but increment stack later below */ |
| 1618 | *s1->include_stack_ptr = file; | 1619 | *s1->include_stack_ptr = file; |
| 1619 | 1620 | ||
| 1621 | search_again: | ||
| 1620 | n = s1->nb_include_paths + s1->nb_sysinclude_paths; | 1622 | n = s1->nb_include_paths + s1->nb_sysinclude_paths; |
| 1621 | for (i = -2; i < n; ++i) { | 1623 | for (i = -2; i < n; ++i) { |
| 1622 | char buf1[sizeof file->filename]; | 1624 | char buf1[sizeof file->filename]; |
| @@ -1650,14 +1652,22 @@ ST_FUNC void preprocess(int is_bof) · 27 unmodified lines | |||
| 1650 | 1652 | ||
| 1651 | pstrcat(buf1, sizeof(buf1), buf); | 1653 | pstrcat(buf1, sizeof(buf1), buf); |
| 1652 | 1654 | ||
| 1653 | if (tok == TOK_INCLUDE_NEXT) | 1655 | if (tok == TOK_INCLUDE_NEXT) { |
| 1654 | for (f = s1->include_stack_ptr; f >= s1->include_stack; --f) | 1656 | for (f = s1->include_stack_ptr; f >= s1->include_stack; --f) |
| 1657 | if (include_next_first_try) { | ||
| 1655 | if (0 == PATHCMP((*f)->filename, buf1)) { | 1658 | if (0 == PATHCMP((*f)->filename, buf1)) { |
| 1656 | #ifdef INC_DEBUG | 1659 | #ifdef INC_DEBUG |
| 1657 | printf("%s: #include_next skipping %s\n", file->filename, buf1); | 1660 | printf("%s: #include_next skipping %s\n", file->filename, buf1); |
| 1658 | #endif | 1661 | #endif |
| 1662 | include_next_first_try++; | ||
| 1659 | goto include_trynext; | 1663 | goto include_trynext; |
| 1660 | } | 1664 | } |
| 1665 | } else { | ||
| 1666 | if (0 == PATHCMP(file->filename, buf1)) { | ||
| 1667 | goto include_trynext; | ||
| 1668 | } | ||
| 1669 | } | ||
| 1670 | } | ||
| 1661 | 1671 | ||
| 1662 | e = search_cached_include(s1, buf1); | 1672 | e = search_cached_include(s1, buf1); |
| 1663 | if (e && (define_find(e->ifndef_macro) || e->ifndef_macro == TOK_once)) { | 1673 | if (e && (define_find(e->ifndef_macro) || e->ifndef_macro == TOK_once)) { |
| @@ -1688,6 +1698,10 @@ include_trynext: · 24 unmodified lines | |||
| 1688 | ch = file->buf_ptr[0]; | 1698 | ch = file->buf_ptr[0]; |
| 1689 | goto the_end; | 1699 | goto the_end; |
| 1690 | } | 1700 | } |
| 1701 | if (include_next_first_try > 1) { | ||
| 1702 | include_next_first_try = 0; | ||
| 1703 | goto search_again; | ||
| 1704 | } | ||
| 1691 | tcc_error("include file '%s' not found", buf); | 1705 | tcc_error("include file '%s' not found", buf); |
| 1692 | include_done: | 1706 | include_done: |
| 1693 | break; | 1707 | break; |