mirror of
https://github.com/cc65/cc65.git
synced 2024-12-27 00:29:31 +00:00
Fixed processing '\\' followed with a newline and line number output (-E) with it.
This commit is contained in:
parent
ad7c5a6617
commit
8fb2576626
@ -578,15 +578,16 @@ int NextLine (void)
|
||||
SB_Drop (Line, 1);
|
||||
}
|
||||
|
||||
/* If we don't have a line continuation character at the end,
|
||||
** we're done with this line. Otherwise replace the character
|
||||
** by a newline and continue reading.
|
||||
/* If we don't have a line continuation character at the end, we
|
||||
** are done with this line. Otherwise just skip the character and
|
||||
** continue reading.
|
||||
*/
|
||||
if (SB_LookAtLast (Line) == '\\') {
|
||||
Line->Buf[Line->Len-1] = '\n';
|
||||
} else {
|
||||
if (SB_LookAtLast (Line) != '\\') {
|
||||
Input->MissingNL = 0;
|
||||
break;
|
||||
} else {
|
||||
SB_Drop (Line, 1);
|
||||
ContinueLine ();
|
||||
}
|
||||
|
||||
} else if (C != '\0') { /* Ignore embedded NULs */
|
||||
|
@ -114,7 +114,8 @@ static StrBuf* MLine; /* Buffer for macro expansion in #pragma */
|
||||
static StrBuf* OLine; /* Buffer for #pragma output */
|
||||
|
||||
/* Newlines to be added to preprocessed text */
|
||||
static int PendingNewLines;
|
||||
static unsigned PendingNewLines;
|
||||
static unsigned ContinuedLines;
|
||||
static int FileChanged;
|
||||
|
||||
/* Structure used when expanding macros */
|
||||
@ -824,18 +825,24 @@ static void CheckForBadIdent (const char* Ident, int Std, const Macro* M)
|
||||
static void AddPreLine (StrBuf* Str)
|
||||
/* Add newlines to the string buffer */
|
||||
{
|
||||
/* No need to prettify the non-exist output */
|
||||
if (!PreprocessOnly) {
|
||||
PendingNewLines = 0;
|
||||
ContinuedLines = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
/* We'll adjust the line number later if necessary */
|
||||
PendingNewLines += ContinuedLines;
|
||||
|
||||
if (FileChanged || PendingNewLines > 6) {
|
||||
/* Output #line directives as source info */
|
||||
StrBuf Comment = AUTO_STRBUF_INITIALIZER;
|
||||
if (SB_NotEmpty (Str) && SB_LookAtLast (Str) != '\n') {
|
||||
SB_AppendChar (Str, '\n');
|
||||
}
|
||||
SB_Printf (&Comment, "#line %u \"%s\"\n", GetCurrentLine (), GetCurrentFile ());
|
||||
SB_Printf (&Comment, "#line %u \"%s\"\n",
|
||||
GetCurrentLine () - ContinuedLines, GetCurrentFile ());
|
||||
SB_Append (Str, &Comment);
|
||||
} else {
|
||||
/* Output new lines */
|
||||
@ -846,6 +853,7 @@ static void AddPreLine (StrBuf* Str)
|
||||
}
|
||||
FileChanged = 0;
|
||||
PendingNewLines = 0;
|
||||
ContinuedLines = 0;
|
||||
}
|
||||
|
||||
|
||||
@ -1528,14 +1536,14 @@ static unsigned ReadMacroArgs (unsigned NameIdx, MacroExp* E, const Macro* M, in
|
||||
/* Read the actual macro arguments */
|
||||
while (1) {
|
||||
/* Squeeze runs of blanks within an arg */
|
||||
int OldPendingNewLines = PendingNewLines;
|
||||
unsigned OldPendingNewLines = PendingNewLines;
|
||||
int Skipped = SkipWhitespace (MultiLine);
|
||||
|
||||
/* Directives can only be found in an argument list that spans
|
||||
** multiple lines.
|
||||
*/
|
||||
if (MultiLine && OldPendingNewLines < PendingNewLines && CurC == '#') {
|
||||
int Newlines = 0;
|
||||
unsigned Newlines = 0;
|
||||
|
||||
while (OldPendingNewLines < PendingNewLines && CurC == '#') {
|
||||
Newlines += PendingNewLines - OldPendingNewLines;
|
||||
@ -3362,6 +3370,14 @@ void SetPPIfStack (PPIfStack* Stack)
|
||||
|
||||
|
||||
|
||||
void ContinueLine (void)
|
||||
/* Continue the current line ended with a '\\' */
|
||||
{
|
||||
++ContinuedLines;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void PreprocessBegin (void)
|
||||
/* Initialize preprocessor with current file */
|
||||
{
|
||||
|
@ -68,6 +68,9 @@ void Preprocess (void);
|
||||
void SetPPIfStack (PPIfStack* Stack);
|
||||
/* Specify which PP #if stack to use */
|
||||
|
||||
void ContinueLine (void);
|
||||
/* Continue the current line ended with a '\\' */
|
||||
|
||||
void PreprocessBegin (void);
|
||||
/* Initialize preprocessor with current file */
|
||||
|
||||
|
19
test/val/bug1891.c
Normal file
19
test/val/bug1891.c
Normal file
@ -0,0 +1,19 @@
|
||||
/* bug #1891 - backslash/newline sequence in string constants is treated wrong */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
const char* a = "hello \
|
||||
world";
|
||||
const char* b = \
|
||||
"hello world";
|
||||
|
||||
int main(void)
|
||||
{
|
||||
if (strcmp(a, b) != 0) {
|
||||
printf("a:\n%s\n", a);
|
||||
printf("b:\n%s\n", b);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user