Repository navigation
Incorrect source position for macro argument following a macro parameter separated only by white space #613
gwllx
started this conversation in
Issue Triage - General
Replies: 1 comment
|
I have a potential fix and could open a PR once an issue is created: diff --git a/src/lexical.c b/src/lexical.c
index b8a43fb6f6..5712ae5db2 100644
--- a/src/lexical.c
+++ b/src/lexical.c
@@ -5098,6 +5098,11 @@ terminator has a zero sequence number.
} /* if */
} /* if */
} else if (entries[idx].start_of_region == offset) {
+ /* Skip empty entries that cover no offset. */
+ while ((size_t)idx + 2 < mtmp->num_entries &&
+ entries[idx + 1].start_of_region == offset) {
+ ++idx;
+ } /* while */
result = &entries[idx];
} else if (idx > 0) {
/* start[idx] is greater than offset, so the previous entry covers it. */ |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Issue Summary
With
FULLY_RESOLVED_MACRO_POSITIONS, a token from a macro argument should get its position in the macro invocation. That doesn't happen when the parameter directly follows another parameter in the replacement list with only white space between them. In that case the token gets a position from the macro definition instead.Observed Behavior
The following testcase produces an intentional error in order to show the problem with the macro argument position.
Output:
The error for
undeclared_1is reported on the#defineline, with the caret just past the end of the replacement list. The error forundeclared_2correctly points at the argument.Expected Behavior
The expected position for
undeclared_1is on the macro invocation line, likeundeclared_2:Additional Details
This appears to be a regression from f5f6e84 "Eliminate calls to qsort and bsearch [EDGcpfe/29012]" . That change replaced the
bsearchlookup of macro text map entries withfind_macro_text_map_entry_for_offset. Bothget_source_pos_from_macro_text_mapandclone_macro_text_map_entriesuse it.The old
bsearchcomparator,compare_macro_text_map_entry_with_offset, matched an entry only when the offset was in its range:start_of_region <= offset < next.start_of_region. An empty entry, whose start equals the next entry's start, therefore never matched.bsearchreturned the following entry, which covers the offset.The new function uses
low_boundand returns the first entry whosestart_of_regionis at or after the offset. If that start equals the offset, the function returns it without checking that the entry's range is non-empty.Note: Empty entries are produced when a text section of the replacement list is only white space between two parameters, as in
(x op y)in the example'sADJmacro.I acknowledge that:
All reactions