From: Nathan Sidwell Date: Tue, 17 Jul 2018 18:31:15 +0000 (+0000) Subject: macro.c (create_iso_definition): Create macro after saving parms. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=887cc5bad4aa397ccfc96a58a60e7fc106aa195c;p=thirdparty%2Fgcc.git macro.c (create_iso_definition): Create macro after saving parms. libcpp/ * macro.c (create_iso_definition): Create macro after saving parms. * traditional.c (_cpp_create_trad_definition): Likewise. From-SVN: r262834 --- diff --git a/ChangeLog.name-lookup b/ChangeLog.name-lookup index 3127271a3ec7..bb9b5a745cef 100644 --- a/ChangeLog.name-lookup +++ b/ChangeLog.name-lookup @@ -1,3 +1,10 @@ +2018-07-17 Nathan Sidwell + + libcpp/ + * macro.c (create_iso_definition): Create macro after saving + parms. + * traditional.c (_cpp_create_trad_definition): Likewise. + 2018-07-16 Nathan Sidwell libcpp/ diff --git a/libcpp/macro.c b/libcpp/macro.c index 52ae6ce5a9b9..23edff7695e0 100644 --- a/libcpp/macro.c +++ b/libcpp/macro.c @@ -3266,35 +3266,34 @@ lex_expansion_token (cpp_reader *pfile, cpp_macro *macro) static cpp_macro * create_iso_definition (cpp_reader *pfile) { - cpp_macro *macro = _cpp_new_macro (pfile, cmk_macro); bool following_paste_op = false; const char *paste_op_error_msg = N_("'##' cannot appear at either end of a macro expansion"); unsigned int num_extra_tokens = 0; unsigned nparms = 0; + cpp_hashnode **params = NULL; + bool varadic = false; bool ok = false; + cpp_macro *macro = NULL; /* Look at the first token, to see if this is a function-like macro. */ - cpp_token *token = lex_expansion_token (pfile, macro); + cpp_token first; + cpp_token *saved_cur_token = pfile->cur_token; + pfile->cur_token = &first; + cpp_token *token = _cpp_lex_direct (pfile); + pfile->cur_token = saved_cur_token; + if (token->flags & PREV_WHITE) /* Preceeded by space, must be part of expansion. */; else if (token->type == CPP_OPEN_PAREN) { /* An open-paren, get a parameter list. */ - bool varadic = false; - - /* Drop the '(' token. */ - macro->count = 0; if (!parse_params (pfile, &nparms, &varadic)) goto out; - macro->parm.params = (cpp_hashnode **)_cpp_commit_buff + params = (cpp_hashnode **)_cpp_commit_buff (pfile, sizeof (cpp_hashnode *) * nparms); - macro->variadic = varadic; - macro->paramc = nparms; - macro->fun_like = 1; - token = NULL; } else if (token->type != CPP_EOF @@ -3336,6 +3335,23 @@ create_iso_definition (cpp_reader *pfile) } } + macro = _cpp_new_macro (pfile, cmk_macro); + if (!token) + { + macro->variadic = varadic; + macro->paramc = nparms; + macro->parm.params = params; + macro->fun_like = true; + } + else + { + /* Preserve the token we peeked. */ + void *base = _cpp_reserve_room (pfile, 0, sizeof (cpp_token)); + *(cpp_token *)base = *token; + token = (cpp_token *)base; + macro->count = 1; + } + for (vaopt_state vaopt_tracker (pfile, macro->variadic, true);; token = NULL) { if (!token) diff --git a/libcpp/traditional.c b/libcpp/traditional.c index 17e4ef22dfac..7166f2544a14 100644 --- a/libcpp/traditional.c +++ b/libcpp/traditional.c @@ -1180,11 +1180,12 @@ save_replacement_text (cpp_reader *pfile, cpp_macro *macro, cpp_macro * _cpp_create_trad_definition (cpp_reader *pfile) { - cpp_macro *macro = _cpp_new_macro (pfile, cmk_traditional); const uchar *cur; uchar *limit; cpp_context *context = pfile->context; unsigned nparms = 0; + int fun_like = 0; + cpp_hashnode **params = NULL; /* The context has not been set up for command line defines, and CUR has not been updated for the macro name for in-file defines. */ @@ -1196,16 +1197,22 @@ _cpp_create_trad_definition (cpp_reader *pfile) /* Is this a function-like macro? */ if (* CUR (context) == '(') { + fun_like = +1; if (scan_parameters (pfile, &nparms)) - { - macro->paramc = nparms; - macro->parm.params = (cpp_hashnode **) BUFF_FRONT (pfile->a_buff); - BUFF_FRONT (pfile->a_buff) - = (uchar *) ¯o->parm.params[macro->paramc]; - macro->fun_like = 1; - } + params = (cpp_hashnode **)_cpp_commit_buff + (pfile, sizeof (cpp_hashnode *) * nparms); else - macro = NULL; + fun_like = -1; + } + + cpp_macro *macro = NULL; + + if (fun_like >= 0) + { + macro = _cpp_new_macro (pfile, cmk_traditional); + macro->parm.params = params; + macro->paramc = nparms; + macro->fun_like = fun_like != 0; } /* Skip leading whitespace in the replacement text. */