From 23d9b93401349fca03efaef0fef0960933f4c316 Mon Sep 17 00:00:00 2001 From: Thomas Schwinge Date: Tue, 31 Aug 2021 22:01:23 +0200 Subject: [PATCH 2/3] Clarify 'key_type_t' to 'location_t' as used for 'gcc/diagnostic-spec.h:nowarn_map' To make it obvious what exactly the key type is. No change in behavior. gcc/ * diagnostic-spec.h (typedef xint_hash_t): Use 'location_t' instead of... (typedef key_type_t): ... this. Remove. (nowarn_map): Document. * diagnostic-spec.c (nowarn_map): Likewise. * warning-control.cc (convert_to_key): Evolve functions into... (get_location): ... these. Adjust all users. --- gcc/diagnostic-spec.c | 2 +- gcc/diagnostic-spec.h | 6 ++---- gcc/warning-control.cc | 41 ++++++++++++++++++++++------------------- 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/gcc/diagnostic-spec.c b/gcc/diagnostic-spec.c index 5e961e1b9f9..eac5a3317c8 100644 --- a/gcc/diagnostic-spec.c +++ b/gcc/diagnostic-spec.c @@ -105,7 +105,7 @@ nowarn_spec_t::nowarn_spec_t (opt_code opt) } } -/* Map from location to its no-warning disposition. */ +/* A mapping from a 'location_t' to the warning spec set for it. */ GTY(()) xint_hash_map_t *nowarn_map; diff --git a/gcc/diagnostic-spec.h b/gcc/diagnostic-spec.h index 4e4d260f74a..9b3aaaa3ce6 100644 --- a/gcc/diagnostic-spec.h +++ b/gcc/diagnostic-spec.h @@ -130,12 +130,10 @@ operator!= (const nowarn_spec_t &lhs, const nowarn_spec_t &rhs) return !(lhs == rhs); } -typedef location_t key_type_t; -typedef int_hash xint_hash_t; +typedef int_hash xint_hash_t; typedef hash_map xint_hash_map_t; -/* A mapping from the location of an expression to the warning spec - set for it. */ +/* A mapping from a 'location_t' to the warning spec set for it. */ extern GTY(()) xint_hash_map_t *nowarn_map; #endif // DIAGNOSTIC_SPEC_H_INCLUDED diff --git a/gcc/warning-control.cc b/gcc/warning-control.cc index 9c506e163d6..8d6c0828445 100644 --- a/gcc/warning-control.cc +++ b/gcc/warning-control.cc @@ -62,22 +62,22 @@ set_no_warning_bit (gimple *stmt, bool value) stmt->no_warning = value; } -/* Return EXPR location or zero. */ +/* Return EXPR location or 'UNKNOWN_LOCATION'. */ -static inline key_type_t -convert_to_key (const_tree expr) +static inline location_t +get_location (const_tree expr) { if (DECL_P (expr)) return DECL_SOURCE_LOCATION (expr); if (EXPR_P (expr)) return EXPR_LOCATION (expr); - return 0; + return UNKNOWN_LOCATION; } -/* Return STMT location (may be zero). */ +/* Return STMT location (may be 'UNKNOWN_LOCATION'). */ -static inline key_type_t -convert_to_key (const gimple *stmt) +static inline location_t +get_location (const gimple *stmt) { return gimple_location (stmt); } @@ -87,12 +87,15 @@ convert_to_key (const gimple *stmt) static nowarn_spec_t * get_nowarn_spec (const_tree expr) { - const key_type_t key = convert_to_key (expr); + const location_t loc = get_location (expr); - if (!get_no_warning_bit (expr) || !key) + if (loc == UNKNOWN_LOCATION) return NULL; - return nowarn_map ? nowarn_map->get (key) : NULL; + if (!get_no_warning_bit (expr)) + return NULL; + + return nowarn_map ? nowarn_map->get (loc) : NULL; } /* Return the no-warning bitmap for stateemt STMT. */ @@ -100,12 +103,12 @@ get_nowarn_spec (const_tree expr) static nowarn_spec_t * get_nowarn_spec (const gimple *stmt) { - const key_type_t key = convert_to_key (stmt); + const location_t loc = get_location (stmt); if (!get_no_warning_bit (stmt)) return NULL; - return nowarn_map ? nowarn_map->get (key) : NULL; + return nowarn_map ? nowarn_map->get (loc) : NULL; } /* Return true if warning OPT is suppressed for decl/expression EXPR. @@ -153,9 +156,9 @@ suppress_warning (tree expr, opt_code opt /* = all_warnings */, if (opt == no_warning) return; - const key_type_t key = convert_to_key (expr); + const location_t loc = get_location (expr); - supp = suppress_warning_at (key, opt, supp) || supp; + supp = suppress_warning_at (loc, opt, supp) || supp; set_no_warning_bit (expr, supp); } @@ -169,9 +172,9 @@ suppress_warning (gimple *stmt, opt_code opt /* = all_warnings */, if (opt == no_warning) return; - const key_type_t key = convert_to_key (stmt); + const location_t loc = get_location (stmt); - supp = suppress_warning_at (key, opt, supp) || supp; + supp = suppress_warning_at (loc, opt, supp) || supp; set_no_warning_bit (stmt, supp); } @@ -181,7 +184,7 @@ suppress_warning (gimple *stmt, opt_code opt /* = all_warnings */, template void copy_warning (ToType to, FromType from) { - const key_type_t to_key = convert_to_key (to); + const location_t to_loc = get_location (to); if (nowarn_spec_t *from_map = get_nowarn_spec (from)) { @@ -189,13 +192,13 @@ void copy_warning (ToType to, FromType from) gcc_assert (get_no_warning_bit (from)); gcc_checking_assert (nowarn_map); - nowarn_map->put (to_key, *from_map); + nowarn_map->put (to_loc, *from_map); set_no_warning_bit (to, true); } else { if (nowarn_map) - nowarn_map->remove (to_key); + nowarn_map->remove (to_loc); /* The no-warning bit might be set even if there's no entry in the map. */ -- 2.30.2