From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2126) id 20133385841F; Mon, 12 Sep 2022 20:26:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 20133385841F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1663014382; bh=PmFau2Xa/N2LCQQBLVI3Jo0enz0pn+DRyZDpqq9cF5I=; h=From:To:Subject:Date:From; b=nfyN9Y6xJ3Jss0lb2tD3U3loSr+N0wsUKGSxbnfzlXN38+owIi54p9E+fNby7d/Mu voZfYXqURI1BJVsaQ7PDP/RzrXh4m9FQyD6C61/jzFOjiqgmy9FsQyb7H+1PCBCxkh 402I6VVarcVun/pOUaAKjWl+ZkCPELfDkJX3fzj0= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tom Tromey To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Use checked_static_cast in more places X-Act-Checkin: binutils-gdb X-Git-Author: Tom Tromey X-Git-Refname: refs/heads/master X-Git-Oldrev: 29a6701e530a4119d3c0d261da2b7b24034c9233 X-Git-Newrev: 5f48d886a9ce0b7d109a26c860adf66330ca65cf Message-Id: <20220912202622.20133385841F@sourceware.org> Date: Mon, 12 Sep 2022 20:26:22 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D5f48d886a9ce= 0b7d109a26c860adf66330ca65cf commit 5f48d886a9ce0b7d109a26c860adf66330ca65cf Author: Tom Tromey Date: Wed Aug 17 11:47:17 2022 -0600 Use checked_static_cast in more places =20 I went through all the uses of dynamic_cast<> in gdb, looking for ones that could be replaced with checked_static_cast. This patch is the result. Regression tested on x86-64 Fedora 34. Diff: --- gdb/ada-exp.y | 4 +--- gdb/ax-gdb.c | 6 ++---- gdb/disasm.c | 3 +-- gdb/location.c | 4 ++-- gdb/mi/mi-out.c | 7 ++----- gdb/tracepoint.c | 8 ++++---- gdb/tui/tui-io.c | 4 ++-- 7 files changed, 14 insertions(+), 22 deletions(-) diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y index 8660205809a..78aec4e920b 100644 --- a/gdb/ada-exp.y +++ b/gdb/ada-exp.y @@ -342,9 +342,7 @@ static ada_choices_component * choice_component () { ada_component *last =3D components.back ().get (); - ada_choices_component *result =3D dynamic_cast = (last); - gdb_assert (result !=3D nullptr); - return result; + return gdb::checked_static_cast (last); } =20 /* Pop the most recent component from the global stack, and return diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c index 1fccfde559e..0d2566f1518 100644 --- a/gdb/ax-gdb.c +++ b/gdb/ax-gdb.c @@ -1920,8 +1920,7 @@ assign_operation::do_generate_ax (struct expression *= exp, error (_("May only assign to trace state variables")); =20 internalvar_operation *ivarop - =3D dynamic_cast (subop); - gdb_assert (ivarop !=3D nullptr); + =3D gdb::checked_static_cast (subop); =20 const char *name =3D internalvar_name (ivarop->get_internalvar ()); struct trace_state_variable *tsv; @@ -1950,8 +1949,7 @@ assign_modify_operation::do_generate_ax (struct expre= ssion *exp, error (_("May only assign to trace state variables")); =20 internalvar_operation *ivarop - =3D dynamic_cast (subop); - gdb_assert (ivarop !=3D nullptr); + =3D gdb::checked_static_cast (subop); =20 const char *name =3D internalvar_name (ivarop->get_internalvar ()); struct trace_state_variable *tsv; diff --git a/gdb/disasm.c b/gdb/disasm.c index fe4eed2d524..989120e05b1 100644 --- a/gdb/disasm.c +++ b/gdb/disasm.c @@ -246,8 +246,7 @@ gdb_printing_disassembler::stream_from_gdb_disassemble_= info (void *dis_info) { gdb_disassemble_info *di =3D (gdb_disassemble_info *) dis_info; gdb_printing_disassembler *dis - =3D dynamic_cast (di); - gdb_assert (dis !=3D nullptr); + =3D gdb::checked_static_cast (di); ui_file *stream =3D dis->stream (); gdb_assert (stream !=3D nullptr); return stream; diff --git a/gdb/location.c b/gdb/location.c index 2b31baa4c85..e4863fdefce 100644 --- a/gdb/location.c +++ b/gdb/location.c @@ -18,6 +18,7 @@ =20 #include "defs.h" #include "gdbsupport/gdb_assert.h" +#include "gdbsupport/gdb-checked-static-cast.h" #include "location.h" #include "symtab.h" #include "language.h" @@ -848,8 +849,7 @@ string_to_location_spec (const char **stringp, linespec parsing below and discard the explicit location spec. */ explicit_location_spec *xloc - =3D dynamic_cast (locspec.get ()); - gdb_assert (xloc !=3D nullptr); + =3D gdb::checked_static_cast (locspec.get ()); match_type =3D xloc->func_name_match_type; } =20 diff --git a/gdb/mi/mi-out.c b/gdb/mi/mi-out.c index eedc5f70549..96a847eb6b6 100644 --- a/gdb/mi/mi-out.c +++ b/gdb/mi/mi-out.c @@ -27,6 +27,7 @@ #include "interps.h" #include "ui-out.h" #include "utils.h" +#include "gdbsupport/gdb-checked-static-cast.h" =20 /* Mark beginning of a table. */ =20 @@ -327,11 +328,7 @@ mi_out_new (const char *mi_version) static mi_ui_out * as_mi_ui_out (ui_out *uiout) { - mi_ui_out *mi_uiout =3D dynamic_cast (uiout); - - gdb_assert (mi_uiout !=3D NULL); - - return mi_uiout; + return gdb::checked_static_cast (uiout); } =20 int diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c index 75ac0cef3b0..dfb62dcf62c 100644 --- a/gdb/tracepoint.c +++ b/gdb/tracepoint.c @@ -687,7 +687,7 @@ validate_actionline (const char *line, struct breakpoin= t *b) { symbol *sym; expr::var_value_operation *vvop - =3D (dynamic_cast + =3D (gdb::checked_static_cast (exp->op.get ())); sym =3D vvop->get_symbol (); =20 @@ -1357,7 +1357,7 @@ encode_actions_1 (struct command_line *action, case OP_REGISTER: { expr::register_operation *regop - =3D (dynamic_cast + =3D (gdb::checked_static_cast (exp->op.get ())); const char *name =3D regop->get_name (); =20 @@ -1380,7 +1380,7 @@ encode_actions_1 (struct command_line *action, tempval =3D evaluate_expression (exp.get ()); addr =3D value_address (tempval); expr::unop_memval_operation *memop - =3D (dynamic_cast + =3D (gdb::checked_static_cast (exp->op.get ())); struct type *type =3D memop->get_type (); /* Initialize the TYPE_LENGTH if it is a typedef. */ @@ -1397,7 +1397,7 @@ encode_actions_1 (struct command_line *action, case OP_VAR_VALUE: { expr::var_value_operation *vvo - =3D (dynamic_cast + =3D (gdb::checked_static_cast (exp->op.get ())); struct symbol *sym =3D vvo->get_symbol (); const char *name =3D sym->natural_name (); diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c index 0efaf69335c..a30000ef626 100644 --- a/gdb/tui/tui-io.c +++ b/gdb/tui/tui-io.c @@ -45,6 +45,7 @@ #include "gdb_curses.h" #include #include "pager.h" +#include "gdbsupport/gdb-checked-static-cast.h" =20 /* This redefines CTRL if it is not already defined, so it must come after terminal state releated include files like and @@ -832,8 +833,7 @@ tui_setup_io (int mode) tui_old_stdout =3D gdb_stdout; tui_old_stderr =3D gdb_stderr; tui_old_stdlog =3D gdb_stdlog; - tui_old_uiout =3D dynamic_cast (current_uiout); - gdb_assert (tui_old_uiout !=3D nullptr); + tui_old_uiout =3D gdb::checked_static_cast (current_ui= out); =20 /* Reconfigure gdb output. */ gdb_stdout =3D tui_stdout;