Hi. This is small series that fixes 2 Wodr warnings issue that we have in bugzilla. It should make in stable across targets, I've tested x86_64, ppc64le and aarch64.
Patch can bootstrap on x86_64-linux-gnu and ppc64le-linux-gnu. It's pre-approved by Honza who worked on that with me. I'm going to install it. Thanks, Martin
>From fee106e4bb7d25054ec153571734f36ca9f84609 Mon Sep 17 00:00:00 2001 From: marxin <mli...@suse.cz> Date: Wed, 18 Apr 2018 14:32:38 +0200 Subject: [PATCH 4/4] Fix coding style and typos. gcc/ChangeLog: 2018-04-18 Martin Liska <mli...@suse.cz> * ipa-devirt.c (odr_subtypes_equivalent_p): Fix GNU coding style. gcc/lto/ChangeLog: 2018-04-18 Martin Liska <mli...@suse.cz> * lto.c (lto_read_decls): Fix GNU coding style and typos. --- gcc/ipa-devirt.c | 2 +- gcc/lto/lto.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gcc/ipa-devirt.c b/gcc/ipa-devirt.c index a0c095e1d5d..308b6e6cdd5 100644 --- a/gcc/ipa-devirt.c +++ b/gcc/ipa-devirt.c @@ -685,7 +685,7 @@ odr_subtypes_equivalent_p (tree t1, tree t2, if (!types_same_for_odr (t1, t2, true)) return false; /* Limit recursion: If subtypes are ODR types and we know - that they are same, be happy. */ + that they are same, be happy. */ if (!odr_type_p (t1) || !get_odr_type (t1, true)->odr_violated) return true; } diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c index 1a6b18d3e34..1c55f3f691a 100644 --- a/gcc/lto/lto.c +++ b/gcc/lto/lto.c @@ -1808,9 +1808,9 @@ lto_read_decls (struct lto_file_decl_data *decl_data, const void *data, num_prevailing_types++; lto_fixup_prevailing_type (t); - /* Compute the canonical type of all types. - Because SCC components ar estreame in random (hash) order - we may have enountered the type before while registering + /* Compute the canonical type of all types. + Because SCC components are streamed in random (hash) order + we may have encountered the type before while registering type canonical of a derived type in the same SCC. */ if (!TYPE_CANONICAL (t)) gimple_register_canonical_type (t); -- 2.16.3
>From 78fa22944e8021a4cbb40b3b1b52ecd42672299b Mon Sep 17 00:00:00 2001 From: marxin <mli...@suse.cz> Date: Mon, 16 Apr 2018 14:54:02 +0200 Subject: [PATCH 3/4] Make Wodr warnings stable. gcc/lto/ChangeLog: 2018-04-18 Martin Liska <mli...@suse.cz> PR ipa/83983 PR ipa/85391 * lto.c (cmp_type_location): New function. (lto_read_decls): First collect all types, then sort them according by location before register_odr_type is called. gcc/testsuite/ChangeLog: 2018-04-18 Martin Liska <mli...@suse.cz> PR ipa/83983 PR ipa/85391 * g++.dg/lto/pr83121_1.C (struct Environment): Adjust expected output. --- gcc/lto/lto.c | 46 +++++++++++++++++++++++++++++++++++- gcc/testsuite/g++.dg/lto/pr83121_1.C | 2 +- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/gcc/lto/lto.c b/gcc/lto/lto.c index 0099398ece9..1a6b18d3e34 100644 --- a/gcc/lto/lto.c +++ b/gcc/lto/lto.c @@ -1695,6 +1695,40 @@ unify_scc (struct data_in *data_in, unsigned from, } +/* Compare types based on source file location. */ + +static int +cmp_type_location (const void *p1_, const void *p2_) +{ + tree *p1 = (tree*)(const_cast<void *>(p1_)); + tree *p2 = (tree*)(const_cast<void *>(p2_)); + if (*p1 == *p2) + return 0; + + tree tname1 = TYPE_NAME (*p1); + tree tname2 = TYPE_NAME (*p2); + + const char *f1 = DECL_SOURCE_FILE (tname1); + const char *f2 = DECL_SOURCE_FILE (tname2); + + int r = strcmp (f1, f2); + if (r == 0) + { + int l1 = DECL_SOURCE_LINE (tname1); + int l2 = DECL_SOURCE_LINE (tname2); + if (l1 == l2) + { + int l1 = DECL_SOURCE_COLUMN (tname1); + int l2 = DECL_SOURCE_COLUMN (tname2); + return l1 - l2; + } + else + return l1 - l2; + } + else + return r; +} + /* Read all the symbols from buffer DATA, using descriptors in DECL_DATA. RESOLUTIONS is the set of symbols picked by the linker (read from the resolution file when the linker plugin is being used). */ @@ -1711,6 +1745,7 @@ lto_read_decls (struct lto_file_decl_data *decl_data, const void *data, unsigned int i; const uint32_t *data_ptr, *data_end; uint32_t num_decl_states; + auto_vec<tree> odr_types; lto_input_block ib_main ((const char *) data + main_offset, header->main_size, decl_data->mode_table); @@ -1780,7 +1815,7 @@ lto_read_decls (struct lto_file_decl_data *decl_data, const void *data, if (!TYPE_CANONICAL (t)) gimple_register_canonical_type (t); if (odr_type_p (t)) - register_odr_type (t); + odr_types.safe_push (t); } /* Link shared INTEGER_CSTs into TYPE_CACHED_VALUEs of its type which is also member of this SCC. */ @@ -1842,6 +1877,15 @@ lto_read_decls (struct lto_file_decl_data *decl_data, const void *data, *slot = state; } + /* Sort types for the file before registering in ODR machinery. */ + if (lto_location_cache::current_cache) + lto_location_cache::current_cache->apply_location_cache (); + odr_types.qsort (cmp_type_location); + + /* Register ODR types. */ + for (unsigned i = 0; i < odr_types.length (); i++) + register_odr_type (odr_types[i]); + if (data_ptr != data_end) internal_error ("bytecode stream: garbage at the end of symbols section"); diff --git a/gcc/testsuite/g++.dg/lto/pr83121_1.C b/gcc/testsuite/g++.dg/lto/pr83121_1.C index 01b05f4e762..01d134e1da5 100644 --- a/gcc/testsuite/g++.dg/lto/pr83121_1.C +++ b/gcc/testsuite/g++.dg/lto/pr83121_1.C @@ -2,7 +2,7 @@ struct Environment { struct AsyncHooks { int providers_[1]; }; - AsyncHooks async_hooks_; // { dg-lto-message "a field of same name but different type is defined in another translation unit" } + AsyncHooks async_hooks_; }; void fn1() { Environment a; } int main () -- 2.16.3
>From 9991bac04878cc73f4bbcf4ada0d32dcda793bc7 Mon Sep 17 00:00:00 2001 From: marxin <mli...@suse.cz> Date: Mon, 16 Apr 2018 13:35:35 +0200 Subject: [PATCH 2/4] Revert r258133. gcc/ChangeLog: 2018-04-16 Martin Liska <mli...@suse.cz> Revert 2018-03-02 Eric Botcazou <ebotca...@adacore.com> PR ipa/83983 * ipa-devirt.c (odr_subtypes_equivalent_p): Get the ODR type of both arguments if they are comparable. --- gcc/ipa-devirt.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/gcc/ipa-devirt.c b/gcc/ipa-devirt.c index bec0c01ea09..a0c095e1d5d 100644 --- a/gcc/ipa-devirt.c +++ b/gcc/ipa-devirt.c @@ -684,14 +684,9 @@ odr_subtypes_equivalent_p (tree t1, tree t2, { if (!types_same_for_odr (t1, t2, true)) return false; - /* Limit recursion: if subtypes are ODR types and we know that they are - same, be happy. We need to call get_odr_type on both subtypes since - we don't know which among t1 and t2 defines the common ODR type and - therefore which call will report the ODR violation, if any. */ - if (!odr_type_p (t1) - || !odr_type_p (t2) - || (!get_odr_type (t1, true)->odr_violated - && !get_odr_type (t2, true)->odr_violated)) + /* Limit recursion: If subtypes are ODR types and we know + that they are same, be happy. */ + if (!odr_type_p (t1) || !get_odr_type (t1, true)->odr_violated) return true; } -- 2.16.3
>From da91962666663c7b0a22acd0ad0b5848323d306a Mon Sep 17 00:00:00 2001 From: marxin <mli...@suse.cz> Date: Mon, 16 Apr 2018 13:33:29 +0200 Subject: [PATCH 1/4] Revert r25841. gcc/ChangeLog: 2018-04-16 Martin Liska <mli...@suse.cz> Revert 2018-03-13 Eric Botcazou <ebotca...@adacore.com> PR lto/84805 * ipa-devirt.c (odr_subtypes_equivalent_p): Do not get the ODR type of incomplete types. --- gcc/ipa-devirt.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/gcc/ipa-devirt.c b/gcc/ipa-devirt.c index bdda7d6b4a9..bec0c01ea09 100644 --- a/gcc/ipa-devirt.c +++ b/gcc/ipa-devirt.c @@ -690,8 +690,6 @@ odr_subtypes_equivalent_p (tree t1, tree t2, therefore which call will report the ODR violation, if any. */ if (!odr_type_p (t1) || !odr_type_p (t2) - || !COMPLETE_TYPE_P (t1) - || !COMPLETE_TYPE_P (t2) || (!get_odr_type (t1, true)->odr_violated && !get_odr_type (t2, true)->odr_violated)) return true; -- 2.16.3