This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: cpplib: patch: three long-standing bugs
- To: Zack Weinberg <zack at bitmover dot com>
- Subject: Re: cpplib: patch: three long-standing bugs
- From: Dave Brolley <brolley at cygnus dot com>
- Date: Fri, 10 Sep 1999 11:05:34 -0400
- CC: egcs-patches at egcs dot cygnus dot com
- Organization: Cygnus Solutions Canada Ltd
- References: <199909100545.WAA27726@zack.bitmover.com>
This patch is OK.
Dave
Zack Weinberg wrote:
> Dave Brolley wrote:
> > Other than the issue of what to do with NUL bytes in the source, I have only
> > one
> > question about this patch. Why not generate a message for each unterminated
> > conditional on the stack? This patch appears to generate a message for the
> > innermost one.
>
> Here is an updated patch which generates a message for each
> unterminated conditional. It also contains a fix for the -traditional
> string handling, but not the NUL changes.
>
> zw
>
> 1999-09-09 22:42 -0700 Zack Weinberg <zack@bitmover.com>
>
> * cppalloc.c (xstrdup): Use memcpy.
> * cpperror.c (cpp_print_containing_files): Don't use
> cpp_notice.
> * cpplib.c (conditional_skip): Set temp->lineno.
> (do_endif): Make error message less obscure.
> (if_directive_name): New function.
> (cpp_get_token [case EOF]): Unwind the if stack and generate
> error messages for each unterminated conditional in this file.
> (parse_string): Do not behave differently if -traditional.
>
> ===================================================================
> Index: cppalloc.c
> --- cppalloc.c 1999/09/07 05:47:40 1.16
> +++ cppalloc.c 1999/09/10 05:37:16
> @@ -74,8 +74,8 @@ char *
> xstrdup (input)
> const char *input;
> {
> - unsigned size = strlen (input);
> - char *output = xmalloc (size + 1);
> - strcpy (output, input);
> + size_t size = strlen (input) + 1;
> + char *output = xmalloc (size);
> + memcpy (output, input, size);
> return output;
> }
> ===================================================================
> Index: cpperror.c
> --- cpperror.c 1999/09/07 15:41:24 1.17
> +++ cpperror.c 1999/09/10 05:37:16
> @@ -63,8 +63,8 @@ cpp_print_containing_files (pfile)
> if (first)
> {
> first = 0;
> - cpp_notice ("In file included from %s:%ld",
> - ip->nominal_fname, line);
> + cpp_message (pfile, -1, "In file included from %s:%ld",
> + ip->nominal_fname, line);
> }
> else
> cpp_message (pfile, -1, ",\n from %s:%ld",
> ===================================================================
> Index: cpplib.c
> --- cpplib.c 1999/09/09 04:00:36 1.92
> +++ cpplib.c 1999/09/10 05:37:17
> @@ -1944,9 +1944,7 @@ conditional_skip (pfile, skip, type, con
>
> temp = (IF_STACK_FRAME *) xcalloc (1, sizeof (IF_STACK_FRAME));
> temp->fname = CPP_BUFFER (pfile)->nominal_fname;
> -#if 0
> temp->lineno = CPP_BUFFER (pfile)->lineno;
> -#endif
> temp->next = pfile->if_stack;
> temp->control_macro = control_macro;
> pfile->if_stack = temp;
> @@ -2177,7 +2175,7 @@ do_endif (pfile, keyword)
> skip_rest_of_line (pfile);
>
> if (pfile->if_stack == CPP_BUFFER (pfile)->if_stack)
> - cpp_error (pfile, "unbalanced `#endif'");
> + cpp_error (pfile, "`#endif' not within a conditional");
> else
> {
> IF_STACK_FRAME *temp = pfile->if_stack;
> @@ -2235,6 +2233,25 @@ validate_else (pfile, directive)
> "text following `%s' violates ANSI standard", directive);
> }
>
> +/* Convert T_IF, etc. to a string. Used in error messages. */
> +static const char *
> +if_directive_name (pfile, ifs)
> + cpp_reader *pfile;
> + struct if_stack *ifs;
> +{
> + switch (ifs->type)
> + {
> + case T_IF: return "#if";
> + case T_IFDEF: return "#ifdef";
> + case T_IFNDEF: return "#ifndef";
> + case T_ELIF: return "#elif";
> + case T_ELSE: return "#else";
> + default:
> + cpp_fatal (pfile, "impossible if_stack->type value %d", ifs->type);
> + return "unknown";
> + }
> +}
> +
> /* Get the next token, and add it to the text in pfile->token_buffer.
> Return the kind of token we got. */
>
> @@ -2265,9 +2282,23 @@ cpp_get_token (pfile)
> }
> else
> {
> - cpp_buffer *next_buf
> - = CPP_PREV_BUFFER (CPP_BUFFER (pfile));
> - CPP_BUFFER (pfile)->seen_eof = 1;
> + cpp_buffer *next_buf = CPP_PREV_BUFFER (CPP_BUFFER (pfile));
> + struct if_stack *ifs, *nifs;
> +
> + /* Unwind the conditional stack and generate error messages. */
> + for (ifs = pfile->if_stack;
> + ifs != CPP_BUFFER (pfile)->if_stack;
> + ifs = nifs)
> + {
> + cpp_error_with_line (pfile, ifs->lineno, -1,
> + "unterminated `%s' conditional",
> + if_directive_name (pfile, ifs));
> +
> + nifs = ifs->next;
> + free (ifs);
> + }
> + pfile->if_stack = ifs;
> +
> if (CPP_BUFFER (pfile)->nominal_fname
> && next_buf != CPP_NULL_BUFFER (pfile))
> {
> @@ -2280,6 +2311,8 @@ cpp_get_token (pfile)
> output_line_command (pfile, leave_file);
> CPP_BUFFER (pfile) = cur_buffer;
> }
> +
> + CPP_BUFFER (pfile)->seen_eof = 1;
> return CPP_POP;
> }
> }
> @@ -2823,18 +2856,16 @@ parse_string (pfile, c)
> quote. */
> cpp_pop_buffer (pfile);
> continue;
> - }
> - if (!CPP_TRADITIONAL (pfile))
> - {
> - cpp_error_with_line (pfile, start_line, start_column,
> - "unterminated string or character constant");
> - if (pfile->multiline_string_line != start_line
> - && pfile->multiline_string_line != 0)
> - cpp_error_with_line (pfile,
> - pfile->multiline_string_line, -1,
> - "possible real start of unterminated constant");
> - pfile->multiline_string_line = 0;
> }
> +
> + cpp_error_with_line (pfile, start_line, start_column,
> + "unterminated string or character constant");
> + if (pfile->multiline_string_line != start_line
> + && pfile->multiline_string_line != 0)
> + cpp_error_with_line (pfile,
> + pfile->multiline_string_line, -1,
> + "possible real start of unterminated constant");
> + pfile->multiline_string_line = 0;
> break;
> }
> CPP_PUTC (pfile, cc);
> @@ -2843,11 +2874,9 @@ parse_string (pfile, c)
> case '\n':
> CPP_BUMP_LINE (pfile);
> pfile->lineno++;
> - /* Traditionally, end of line ends a string constant with
> - no error. */
> - if (CPP_TRADITIONAL (pfile))
> - return;
> - /* Character constants may not extend over multiple lines. */
> + /* Character constants may not extend over multiple lines.
> + In ANSI, neither may strings. We accept multiline strings
> + as an extension. */
> if (c == '\'')
> {
> cpp_error_with_line (pfile, start_line, start_column,