From d305ca88fc9b180a1790e02b144e921d17b393f0 Mon Sep 17 00:00:00 2001 From: Richard Sandiford Date: Wed, 30 Aug 2017 11:18:37 +0000 Subject: [59/77] Add a rtx_jump_table_data::get_data_mode helper This patch adds a helper function to get the mode of the addresses or offsets in a jump table. It also changes the final.c code to use rtx_jump_table_data over rtx or rtx_insn in cases where it needed to use the new helper. This in turn meant adding a safe_dyn_cast equivalent of safe_as_a, to cope with null NEXT_INSNs. 2017-08-30 Richard Sandiford Alan Hayward David Sherwood gcc/ * is-a.h (safe_dyn_cast): New function. * rtl.h (rtx_jump_table_data::get_data_mode): New function. (jump_table_for_label): Likewise. * final.c (final_addr_vec_align): Take an rtx_jump_table_data * instead of an rtx_insn *. (shorten_branches): Use dyn_cast instead of LABEL_P and JUMP_TABLE_DATA_P. Use jump_table_for_label and rtx_jump_table_data::get_data_mode. (final_scan_insn): Likewise. Co-Authored-By: Alan Hayward Co-Authored-By: David Sherwood From-SVN: r251511 --- gcc/is-a.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'gcc/is-a.h') diff --git a/gcc/is-a.h b/gcc/is-a.h index b4e5279..2adc740 100644 --- a/gcc/is-a.h +++ b/gcc/is-a.h @@ -103,6 +103,11 @@ TYPE dyn_cast (pointer) Note that we have converted two sets of assertions in the calls to varpool into safe and efficient use of a variable. +TYPE safe_dyn_cast (pointer) + + Like dyn_cast (pointer), except that it accepts null pointers + and returns null results for them. + If you use these functions and get a 'inline function not defined' or a 'missing symbol' error message for 'is_a_helper<....>::test', it means that @@ -222,4 +227,13 @@ dyn_cast (U *p) return static_cast (0); } +/* Similar to dyn_cast, except that the pointer may be null. */ + +template +inline T +safe_dyn_cast (U *p) +{ + return p ? dyn_cast (p) : 0; +} + #endif /* GCC_IS_A_H */ -- cgit v1.1