]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libcpp/directives.cc
updat_bb_profile_for_threading TLC
[thirdparty/gcc.git] / libcpp / directives.cc
index 918752f6b1f0f51a24df6ed246d01f90c6187880..ee5419d1f40965aecf7ce641148ef9a4c700b817 100644 (file)
@@ -1,5 +1,5 @@
 /* CPP Library. (Directive handling.)
-   Copyright (C) 1986-2022 Free Software Foundation, Inc.
+   Copyright (C) 1986-2023 Free Software Foundation, Inc.
    Contributed by Per Bothner, 1994-95.
    Based on CCCP program by Paul Rubin, June 1986
    Adapted to ANSI C, Richard Stallman, Jan 1987
@@ -655,6 +655,10 @@ do_define (cpp_reader *pfile)
 
   if (node)
     {
+      /* This is a better location than pfile->directive_line to store
+        as the macro location.  */
+      const location_t name_loc = cpp_diagnostic_get_current_location (pfile);
+
       /* If we have been requested to expand comments into macros,
         then re-enable saving of comments.  */
       pfile->state.save_comments =
@@ -663,7 +667,7 @@ do_define (cpp_reader *pfile)
       if (pfile->cb.before_define)
        pfile->cb.before_define (pfile);
 
-      if (_cpp_create_definition (pfile, node))
+      if (_cpp_create_definition (pfile, node, name_loc))
        if (pfile->cb.define)
          pfile->cb.define (pfile, pfile->directive_line, node);
 
@@ -694,9 +698,8 @@ do_undef (cpp_reader *pfile)
                       "undefining \"%s\"", NODE_NAME (node));
          else if (cpp_builtin_macro_p (node)
                   && CPP_OPTION (pfile, warn_builtin_macro_redefined))
-           cpp_warning_with_line (pfile, CPP_W_BUILTIN_MACRO_REDEFINED,
-                                  pfile->directive_line, 0,
-                                  "undefining \"%s\"", NODE_NAME (node));
+           cpp_warning (pfile, CPP_W_BUILTIN_MACRO_REDEFINED,
+                        "undefining \"%s\"", NODE_NAME (node));
 
          if (node->value.macro
              && CPP_OPTION (pfile, warn_unused_macros))
@@ -1565,15 +1568,15 @@ do_pragma (cpp_reader *pfile)
        {
          /* Invalid name comes from macro expansion, _cpp_backup_tokens
             won't allow backing 2 tokens.  */
-         /* ??? The token buffer is leaked.  Perhaps if def_pragma hook
-            reads both tokens, we could perhaps free it, but if it doesn't,
-            we don't know the exact lifespan.  */
-         cpp_token *toks = XNEWVEC (cpp_token, 2);
+         const auto tok_buff = _cpp_get_buff (pfile, 2 * sizeof (cpp_token));
+         const auto toks = (cpp_token *)tok_buff->base;
          toks[0] = ns_token;
          toks[0].flags |= NO_EXPAND;
          toks[1] = *token;
-         toks[1].flags |= NO_EXPAND;
+         toks[1].flags |= NO_EXPAND | PREV_WHITE;
          _cpp_push_token_context (pfile, NULL, toks, 2);
+         /* Arrange to free this buffer when no longer needed.  */
+         pfile->context->buff = tok_buff;
        }
       pfile->cb.def_pragma (pfile, pfile->directive_line);
     }
@@ -1996,7 +1999,12 @@ destringize_and_run (cpp_reader *pfile, const cpp_string *in,
 int
 _cpp_do__Pragma (cpp_reader *pfile, location_t expansion_loc)
 {
+  /* Make sure we don't invalidate the string token, if the closing parenthesis
+   ended up on a different line.  */
+  ++pfile->keep_tokens;
   const cpp_token *string = get__Pragma_string (pfile);
+  --pfile->keep_tokens;
+
   pfile->directive_result.type = CPP_PADDING;
 
   if (string)
@@ -2637,7 +2645,7 @@ cpp_pop_definition (cpp_reader *pfile, struct def_pragma_macro *c)
       {
        _cpp_clean_line (pfile);
        nbuf->sysp = 1;
-       if (!_cpp_create_definition (pfile, h))
+       if (!_cpp_create_definition (pfile, h, 0))
          abort ();
        _cpp_pop_buffer (pfile);
       }