]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - gcc/dumpfile.c
c++: Handle multiple aggregate overloads [PR95319].
[thirdparty/gcc.git] / gcc / dumpfile.c
index 14b6dfea75e46116b1d9d77aa32e8def608a5371..5d61946fc49a902cde3aff9ad035f99849ed96c7 100644 (file)
@@ -1,5 +1,5 @@
 /* Dump infrastructure for optimizations and intermediate representation.
-   Copyright (C) 2012-2019 Free Software Foundation, Inc.
+   Copyright (C) 2012-2020 Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -39,6 +39,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-pass.h" /* for "current_pass".  */
 #include "optinfo-emit-json.h"
 #include "stringpool.h" /* for get_identifier.  */
+#include "spellcheck.h"
 
 /* If non-NULL, return one past-the-end of the matching SUBPART of
    the WHOLE string.  */
@@ -115,6 +116,7 @@ static struct dump_file_info dump_files[TDI_end] =
    in dumpfile.h and opt_info_options below. */
 static const kv_pair<dump_flags_t> dump_options[] =
 {
+  {"none", TDF_NONE},
   {"address", TDF_ADDRESS},
   {"asmname", TDF_ASMNAME},
   {"slim", TDF_SLIM},
@@ -1531,21 +1533,17 @@ FILE *
 gcc::dump_manager::
 dump_begin (int phase, dump_flags_t *flag_ptr, int part)
 {
-  char *name;
-  struct dump_file_info *dfi;
-  FILE *stream;
-
   if (phase == TDI_none || !dump_phase_enabled_p (phase))
     return NULL;
 
-  name = get_dump_file_name (phase, part);
+  char *name = get_dump_file_name (phase, part);
   if (!name)
     return NULL;
-  dfi = get_dump_file_info (phase);
+  struct dump_file_info *dfi = get_dump_file_info (phase);
 
   /* We do not support re-opening of dump files with parts.  This would require
      tracking pstate per part of the dump file.  */
-  stream = dump_open (name, part != -1 || dfi->pstate < 0);
+  FILE *stream = dump_open (name, part != -1 || dfi->pstate < 0);
   if (stream)
     dfi->pstate = 1;
   free (name);
@@ -1770,28 +1768,19 @@ gcc::dump_manager::update_dfi_for_opt_info (dump_file_info *dfi) const
   return true;
 }
 
-/* Parse ARG as a dump switch. Return nonzero if it is, and store the
-   relevant details in the dump_files array.  */
+/* Helper routine to parse -<dump format>[=filename]
+   and return the corresponding dump flag.  If POS_P is non-NULL,
+   assign start of filename into *POS_P.  */
 
-int
-gcc::dump_manager::
-dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob)
+dump_flags_t
+parse_dump_option (const char *option_value, const char **pos_p)
 {
-  const char *option_value;
   const char *ptr;
   dump_flags_t flags;
 
-  if (doglob && !dfi->glob)
-    return 0;
-
-  option_value = skip_leading_substring (arg, doglob ? dfi->glob : dfi->swtch);
-  if (!option_value)
-    return 0;
-
-  if (*option_value && *option_value != '-' && *option_value != '=')
-    return 0;
-
   ptr = option_value;
+  if (pos_p)
+    *pos_p = NULL;
 
   /* Retain "user-facing" and "internals" messages, but filter out
      those from an opt_problem being re-emitted at the top level
@@ -1805,14 +1794,13 @@ dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob)
       const char *end_ptr;
       const char *eq_ptr;
       unsigned length;
-
       while (*ptr == '-')
        ptr++;
       end_ptr = strchr (ptr, '-');
       eq_ptr = strchr (ptr, '=');
 
       if (eq_ptr && !end_ptr)
-        end_ptr = eq_ptr;
+       end_ptr = eq_ptr;
 
       if (!end_ptr)
        end_ptr = ptr + strlen (ptr);
@@ -1821,25 +1809,59 @@ dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob)
       for (option_ptr = dump_options; option_ptr->name; option_ptr++)
        if (strlen (option_ptr->name) == length
            && !memcmp (option_ptr->name, ptr, length))
-          {
-            flags |= option_ptr->value;
+         {
+           flags |= option_ptr->value;
            goto found;
-          }
+         }
 
       if (*ptr == '=')
-        {
+       {
           /* Interpret rest of the argument as a dump filename.  This
              filename overrides other command line filenames.  */
-          if (dfi->pfilename)
-            free (CONST_CAST (char *, dfi->pfilename));
-          dfi->pfilename = xstrdup (ptr + 1);
-          break;
-        }
+         if (pos_p)
+           *pos_p = ptr + 1;
+         break;
+       }
       else
-        warning (0, "ignoring unknown option %q.*s in %<-fdump-%s%>",
-                 length, ptr, dfi->swtch);
-    found:;
+      {
+       warning (0, "ignoring unknown option %q.*s",
+                length, ptr);
+       flags = TDF_ERROR;
+      }
+    found:
       ptr = end_ptr;
+  }
+
+  return flags;
+}
+
+/* Parse ARG as a dump switch.  Return nonzero if it is, and store the
+   relevant details in the dump_files array.  */
+
+int
+gcc::dump_manager::
+dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob)
+{
+  const char *option_value;
+  dump_flags_t flags = TDF_NONE;
+
+  if (doglob && !dfi->glob)
+    return 0;
+
+  option_value = skip_leading_substring (arg, doglob ? dfi->glob : dfi->swtch);
+  if (!option_value)
+    return 0;
+
+  if (*option_value && *option_value != '-' && *option_value != '=')
+    return 0;
+
+  const char *filename;
+  flags = parse_dump_option (option_value, &filename);
+  if (filename)
+    {
+      if (dfi->pfilename)
+  free (CONST_CAST (char *, dfi->pfilename));
+      dfi->pfilename = xstrdup (filename);
     }
 
   dfi->pstate = -1;
@@ -1853,7 +1875,7 @@ dump_switch_p_1 (const char *arg, struct dump_file_info *dfi, bool doglob)
   return 1;
 }
 
-int
+void
 gcc::dump_manager::
 dump_switch_p (const char *arg)
 {
@@ -1875,8 +1897,20 @@ dump_switch_p (const char *arg)
     for (i = 0; i < m_extra_dump_files_in_use; i++)
       any |= dump_switch_p_1 (arg, &m_extra_dump_files[i], true);
 
-
-  return any;
+  if (!any)
+    {
+      auto_vec<const char *> candidates;
+      for (size_t i = TDI_none + 1; i != TDI_end; i++)
+       candidates.safe_push (dump_files[i].swtch);
+      for (size_t i = 0; i < m_extra_dump_files_in_use; i++)
+       candidates.safe_push (m_extra_dump_files[i].swtch);
+      const char *hint = find_closest_string (arg, &candidates);
+      if (hint)
+       error ("unrecognized command-line option %<-fdump-%s%>; "
+              "did you mean %<-fdump-%s%>?", arg, hint);
+      else
+       error ("unrecognized command-line option %<-fdump-%s%>", arg);
+    }
 }
 
 /* Parse ARG as a -fopt-info switch and store flags, optgroup_flags
@@ -2044,6 +2078,34 @@ enable_rtl_dump_file (void)
   return num_enabled > 0;
 }
 
+/* debug_dump_context's ctor.  Temporarily override the dump_context
+   (to forcibly enable output to stderr).  */
+
+debug_dump_context::debug_dump_context ()
+: m_context (),
+  m_saved (&dump_context::get ()),
+  m_saved_flags (dump_flags),
+  m_saved_pflags (pflags),
+  m_saved_file (dump_file)
+{
+  set_dump_file (stderr);
+  dump_context::s_current = &m_context;
+  pflags = dump_flags = MSG_ALL_KINDS | MSG_ALL_PRIORITIES;
+  dump_context::get ().refresh_dumps_are_enabled ();
+}
+
+/* debug_dump_context's dtor.  Restore the saved dump_context.  */
+
+debug_dump_context::~debug_dump_context ()
+{
+  set_dump_file (m_saved_file);
+  dump_context::s_current = m_saved;
+  dump_flags = m_saved_flags;
+  pflags = m_saved_pflags;
+  dump_context::get ().refresh_dumps_are_enabled ();
+}
+
+
 #if CHECKING_P
 
 namespace selftest {
@@ -2055,7 +2117,7 @@ temp_dump_context::temp_dump_context (bool forcibly_enable_optinfo,
                                      bool forcibly_enable_dumping,
                                      dump_flags_t test_pp_flags)
 : m_context (),
-  m_saved (&dump_context ().get ())
+  m_saved (&dump_context::get ())
 {
   dump_context::s_current = &m_context;
   if (forcibly_enable_optinfo)