]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix some compile print errors.
authorKeith Seitz <keiths@redhat.com>
Mon, 9 Jan 2017 21:39:27 +0000 (13:39 -0800)
committerKeith Seitz <keiths@redhat.com>
Tue, 10 Jan 2017 19:39:59 +0000 (11:39 -0800)
Includes new code header, test corrections, using NULL for the name of anonymous
types, and some other little cleanups.

gdb/compile/compile-c-support.c
gdb/compile/compile-cplus-templates.c
gdb/compile/compile-cplus-types.c
gdb/testsuite/gdb.compile/cp-simple-anonymous.exp
gdb/testsuite/gdb.compile/cp-simple-member.exp

index 5c931bdc566b1f680c42adc1da5ebfedb4ec277d..1ee90ef0f53e9d05b623b6dcdc1763b4469db010 100644 (file)
@@ -451,6 +451,7 @@ struct cplus_add_code_header
     case COMPILE_I_PRINT_VALUE_SCOPE:
       fputs_unfiltered (
                        "#include <cstring>\n"
+                       "#include <bits/move.h>\n"
                        "void "
                        GCC_FE_WRAPPER_FUNCTION
                        " (struct "
@@ -486,15 +487,16 @@ struct cplus_add_input
       {
       case COMPILE_I_PRINT_ADDRESS_SCOPE:
       case COMPILE_I_PRINT_VALUE_SCOPE:
-       fprintf_unfiltered (buf,
-                           "auto " COMPILE_I_EXPR_VAL " = %s;\n"
-                           "decltype (%s) *" COMPILE_I_EXPR_PTR_TYPE ";\n"
-                           "std::memcpy (" COMPILE_I_PRINT_OUT_ARG ", %s"
-                           COMPILE_I_EXPR_VAL ",\n"
-                           "sizeof (*" COMPILE_I_EXPR_PTR_TYPE "));\n"
-                           ,input, input,
-                           (type == COMPILE_I_PRINT_ADDRESS_SCOPE
-                            ? "&" : ""));
+       fprintf_unfiltered
+         (buf,
+          "auto " COMPILE_I_EXPR_VAL " = %s;\n"
+          "decltype (" COMPILE_I_EXPR_VAL ") *" COMPILE_I_EXPR_PTR_TYPE ";\n"
+          "std::memcpy (" COMPILE_I_PRINT_OUT_ARG ", %s ("
+          COMPILE_I_EXPR_VAL "),\n"
+          "sizeof (" COMPILE_I_EXPR_VAL "));\n"
+          ,input,
+          (type == COMPILE_I_PRINT_ADDRESS_SCOPE
+           ? "std::__addressof" : ""));
        break;
 
       default:
index 0dd03c440f6fb8c498bb250ce3fd2d404dc1df57..f1922f932cfd883a99c5d5ee0cdcbb4efb870bf3 100644 (file)
@@ -635,7 +635,7 @@ void
 compile_cplus_instance::maybe_define_new_class_template
   (struct type *type, const char *decl_name)
 {
-  if (TYPE_N_TEMPLATE_ARGUMENTS (type) == 0)
+  if (TYPE_N_TEMPLATE_ARGUMENTS (type) == 0 || decl_name == NULL)
     return;
 
   std::string generic (compute_class_template_generic (decl_name, type));
index b313d5caf21b84d2e4e0e63ed24cffe197fa7498..973ea5a6ee30d0de2205fb1ddbcb7dd65a258362 100644 (file)
@@ -583,14 +583,11 @@ ccp_convert_typedef (compile_cplus_instance *instance,
   if (scope.nested_type () != GCC_TYPE_NONE)
     return scope.nested_type ();
 
-  struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);
   char *name = NULL;
+  struct cleanup *cleanups = make_cleanup (free_current_contents, &name);
 
   if (TYPE_NAME (type) != NULL)
-    {
-      name = cp_func_name (TYPE_NAME (type));
-      make_cleanup (xfree, name);
-    }
+    name = cp_func_name (TYPE_NAME (type));
 
   /* Make sure the scope for this type has been pushed.  */
   instance->enter_scope (scope);
@@ -1300,26 +1297,12 @@ ccp_convert_struct_or_union (compile_cplus_instance *instance,
 {
   const char *filename = NULL;  /* !!keiths: FIXME  */
   unsigned short line = 0;
+  char *name = NULL;
+  struct cleanup *back_to = make_cleanup (free_current_contents, &name);
 
   /* Get the decl name of this type.  */
-  std::string name;
   if (TYPE_NAME (type) != NULL)
-    {
-      char *str = decl_name (TYPE_NAME (type));
-
-      name = str;
-      xfree (str);
-    }
-  else
-    {
-      if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
-       {
-         name = (TYPE_DECLARED_CLASS (type) ? "anonymous class"
-                 : "anonymous struct");
-       }
-      else
-       name = "anonymous union";
-    }
+      name = decl_name (TYPE_NAME (type));
 
   /* First things first: If this type has any templates in it, make sure
      that we collect default arguments and get those types defined BEFORE
@@ -1328,7 +1311,7 @@ ccp_convert_struct_or_union (compile_cplus_instance *instance,
 
   /* If this is a new template class, make sure the generic has been seen
      and defined.  */
-  instance->maybe_define_new_class_template (type, name.c_str ());
+  instance->maybe_define_new_class_template (type, name);
   instance->emit_class_template_decls ();
 
   /* Create a new scope for TYPE.  */
@@ -1356,7 +1339,7 @@ ccp_convert_struct_or_union (compile_cplus_instance *instance,
     {
       const char *what = TYPE_DECLARED_CLASS (type) ? "struct" : "class";
 
-      resuld = instance->new_decl (what, name.c_str (),
+      resuld = instance->new_decl (what, name,
                                   GCC_CP_SYMBOL_CLASS | nested_access
                                   | (TYPE_DECLARED_CLASS (type)
                                      ? GCC_CP_FLAG_CLASS_NOFLAG
@@ -1366,7 +1349,7 @@ ccp_convert_struct_or_union (compile_cplus_instance *instance,
   else
     {
       gdb_assert (TYPE_CODE (type) == TYPE_CODE_UNION);
-      resuld = instance->new_decl ("union", name.c_str (),
+      resuld = instance->new_decl ("union", name,
                                   GCC_CP_SYMBOL_UNION | nested_access,
                                   0, NULL, 0, filename, line);
     }
@@ -1403,7 +1386,7 @@ ccp_convert_struct_or_union (compile_cplus_instance *instance,
            }
        }
 
-      result = instance->start_class_definition (name.c_str (), resuld, &bases,
+      result = instance->start_class_definition (name, resuld, &bases,
                                                 filename, line);
       xfree (bases.flags);
       xfree (bases.elements);
@@ -1412,7 +1395,7 @@ ccp_convert_struct_or_union (compile_cplus_instance *instance,
     {
       gdb_assert (TYPE_CODE (type) == TYPE_CODE_UNION);
       result
-       = instance->start_class_definition (name.c_str (), resuld, NULL,
+       = instance->start_class_definition (name, resuld, NULL,
                                            filename, line);
     }
 
@@ -1428,10 +1411,11 @@ ccp_convert_struct_or_union (compile_cplus_instance *instance,
   ccp_convert_struct_or_union_members (instance, type, result);
 
   /* All finished.  */
-  instance->finish_record_or_union (name.c_str (), TYPE_LENGTH (type));
+  instance->finish_record_or_union (name, TYPE_LENGTH (type));
 
   /* Pop all scopes.  */
   instance->leave_scope ();
+  do_cleanups (back_to);
   return result;
 }
 
@@ -1445,10 +1429,8 @@ ccp_convert_enum (compile_cplus_instance *instance, struct type *type,
 {
   int i;
   gcc_type int_type;
-  char *name = NULL;
   const char *filename = NULL;
   unsigned short line = 0;
-  struct cleanup *cleanups;
   /* !!keiths: This does not appear to work. GCC complains about
      being unable to convert enum values from '(MyEnum)0' to 'int'.  */
   int scoped_enum_p = /*TYPE_DECLARED_CLASS (type) ? TRUE :*/ FALSE;
@@ -1463,16 +1445,11 @@ ccp_convert_enum (compile_cplus_instance *instance, struct type *type,
       return scope.nested_type ();
     }
 
-  /* Create an empty cleanup chain.  */
-  cleanups = make_cleanup (null_cleanup, NULL);
+  char *name = NULL;
+  struct cleanup *cleanups = make_cleanup (free_current_contents, &name);
 
   if (TYPE_NAME (type) != NULL)
-    {
-      name = cp_func_name (TYPE_NAME (type));
-      make_cleanup (xfree, name);
-    }
-  else
-    name = "anonymous enum";
+    name = cp_func_name (TYPE_NAME (type));
 
   /* Push all scopes.  */
   instance->enter_scope (scope);
index 46db50f1d93b0e13c43b800f971889ac46e16f72..6ee1fbad25a91fb6de182e25bd6a2e58fa1be8f6 100644 (file)
@@ -44,12 +44,12 @@ gdb_continue_to_breakpoint "testing location"
 
 # Reminder, "var" is an integer; all these types get converted to `int'.
 CompileExpression::new "var"
-CompileExpression::test "anon_e" 3
+CompileExpression::test "anon_e" {(3|GHI)}
 CompileExpression::test "anon_u.aa" {97( 'a')?}
 CompileExpression::test "anon_s.len" 11
 CompileExpression::test "a.u.b" 0
 CompileExpression::test "a.s.len" 5
-CompileExpression::test "a.e" 10
+CompileExpression::test "a.e" {(10|A::AA)}
 CompileExpression::test "(*anon_s.ptr == 'a')" (1|true)
 CompileExpression::test "(*a.s.ptr != 'h')" (0|false)
-CompileExpression::test "A::BB" 11
+CompileExpression::test "A::BB" {(11|A::BB)}
index 5d759bcf17fa66701725dca7b6cb364ce415dfec..7fd734d8d00fcfddd0ca6bef374dceccedbbf70c 100644 (file)
@@ -46,9 +46,9 @@ CompileExpression::new "var"
 CompileExpression::test "a.public_" 1
 CompileExpression::test "a.protected_" {(21|N::AB)}
 CompileExpression::test "a.private_" 3
-CompileExpression::test "A::s_public_" 10
+CompileExpression::test "A::s_public_" {(10|E_A)}
 CompileExpression::test "A::s_protected_" {(20|N::AA)}
-CompileExpression::test "A::s_private_" 12
+CompileExpression::test "A::s_private_" {(12|E_C)}
 CompileExpression::test "A::ATYPE i = 10; var = i;" 10 -explicit
 CompileExpression::test "get_values (a)" 85
 CompileExpression::test "myenum me = E_B; var = me;" 11 -explicit