From af5975362b21c2a1268aac5b02545de482a2cc7c Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Wed, 18 Apr 2018 22:08:44 +0200 Subject: [PATCH] Make Wodr warnings stable. 2018-04-18 Martin Liska 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. 2018-04-18 Martin Liska PR ipa/83983 PR ipa/85391 * g++.dg/lto/pr83121_1.C (struct Environment): Adjust expected output. From-SVN: r259479 --- gcc/lto/ChangeLog | 9 ++++++ gcc/lto/lto.c | 46 +++++++++++++++++++++++++++- gcc/testsuite/ChangeLog | 7 +++++ gcc/testsuite/g++.dg/lto/pr83121_1.C | 2 +- 4 files changed, 62 insertions(+), 2 deletions(-) diff --git a/gcc/lto/ChangeLog b/gcc/lto/ChangeLog index fc0ecb79450..3df8fe8d775 100644 --- a/gcc/lto/ChangeLog +++ b/gcc/lto/ChangeLog @@ -1,3 +1,12 @@ +2018-04-18 Martin Liska + + 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. + 2018-04-18 Jan Hubicka Martin Liska 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(p1_)); + tree *p2 = (tree*)(const_cast(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 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/ChangeLog b/gcc/testsuite/ChangeLog index 9ac9731abb4..a5965b1123d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2018-04-18 Martin Liska + + PR ipa/83983 + PR ipa/85391 + * g++.dg/lto/pr83121_1.C (struct Environment): Adjust expected + output. + 2018-04-18 H.J. Lu PR target/85388 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.30.2