1
0
mirror of https://github.com/cc65/cc65.git synced 2025-04-06 20:37:16 +00:00

Merge pull request #2496 from kugelfuhr/kugelfuhr/fix-2458

Fix macro preprocessing for #include
This commit is contained in:
Bob Andrews 2024-09-01 17:54:36 +02:00 committed by GitHub
commit 4b38974918
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 34 additions and 4 deletions

View File

@ -2812,11 +2812,30 @@ static void DoInclude (void)
InputType IT;
StrBuf Filename = AUTO_STRBUF_INITIALIZER;
/* Macro-replace a single line with special support for <filename> */
SB_Clear (MLine);
PreprocessDirective (Line, MLine, MSM_TOK_HEADER);
/* Skip whitespace so the input pointer points to the argument */
SkipWhitespace (0);
/* Read from the processed line */
/* We may have three forms of the #include directive:
**
** - # include "q-char-sequence" new-line
** - # include <h-char-sequence> new-line
** - # include pp-tokens new-line
**
** The former two are processed as is while the latter is preprocessed and
** must then resemble one of the first two forms.
*/
if (CurC == '"' || CurC == '<') {
/* Copy the argument part over to MLine */
unsigned Start = SB_GetIndex (Line);
unsigned Length = SB_GetLen (Line) - Start;
SB_Slice (MLine, Line, Start, Length);
} else {
/* Macro-replace a single line with special support for <filename> */
SB_Clear (MLine);
PreprocessDirective (Line, MLine, MSM_TOK_HEADER);
}
/* Read from the copied/preprocessed line */
SB_Reset (MLine);
MLine = InitLine (MLine);

10
test/val/bug2458.c Normal file
View File

@ -0,0 +1,10 @@
#define str(arg) #arg
#include str(bug2458.h) /* Ok, macro replacement */
#define string foo
#include <string.h> /* Ok, no macro replacement */
int main()
{
return 0;
}

1
test/val/bug2458.h Normal file
View File

@ -0,0 +1 @@