diff options
author | Martin Liska <mliska@suse.cz> | 2018-01-23 16:46:02 +0100 |
---|---|---|
committer | Martin Liska <marxin@gcc.gnu.org> | 2018-01-23 15:46:02 +0000 |
commit | cde9b2f815e3ce01bb84fef4b1c9a0cd45312eda (patch) | |
tree | 02ae09c4777c927755c987ca420a91e08314abea /gcc | |
parent | 813d6db9c42ae27854356c87f0fa16b0f9079118 (diff) | |
download | gcc-cde9b2f815e3ce01bb84fef4b1c9a0cd45312eda.zip gcc-cde9b2f815e3ce01bb84fef4b1c9a0cd45312eda.tar.gz gcc-cde9b2f815e3ce01bb84fef4b1c9a0cd45312eda.tar.bz2 |
Handle trailing arrays in ODR warning (PR lto/81440).
2018-01-23 Martin Liska <mliska@suse.cz>
PR lto/81440
* lto-symtab.c (lto_symtab_merge): Handle and do not warn about
trailing arrays at the end of a struct.
2018-01-23 Martin Liska <mliska@suse.cz>
PR lto/81440
* gcc.dg/lto/pr81440.h: New test.
* gcc.dg/lto/pr81440_0.c: New test.
* gcc.dg/lto/pr81440_1.c: New test.
From-SVN: r256989
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/lto/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/lto/lto-symtab.c | 25 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/lto/pr81440.h | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/lto/pr81440_0.c | 9 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/lto/pr81440_1.c | 6 |
6 files changed, 51 insertions, 6 deletions
diff --git a/gcc/lto/ChangeLog b/gcc/lto/ChangeLog index 9c5f292..67679bc 100644 --- a/gcc/lto/ChangeLog +++ b/gcc/lto/ChangeLog @@ -1,3 +1,9 @@ +2018-01-23 Martin Liska <mliska@suse.cz> + + PR lto/81440 + * lto-symtab.c (lto_symtab_merge): Handle and do not warn about + trailing arrays at the end of a struct. + 2018-01-03 Richard Sandiford <richard.sandiford@linaro.org> Alan Hayward <alan.hayward@arm.com> David Sherwood <david.sherwood@arm.com> diff --git a/gcc/lto/lto-symtab.c b/gcc/lto/lto-symtab.c index ee02a53..0f0b958 100644 --- a/gcc/lto/lto-symtab.c +++ b/gcc/lto/lto-symtab.c @@ -352,18 +352,31 @@ lto_symtab_merge (symtab_node *prevailing, symtab_node *entry) return false; if (DECL_SIZE (decl) && DECL_SIZE (prevailing_decl) - && !tree_int_cst_equal (DECL_SIZE (decl), DECL_SIZE (prevailing_decl)) + && !tree_int_cst_equal (DECL_SIZE (decl), DECL_SIZE (prevailing_decl))) + { + if (!DECL_COMMON (decl) && !DECL_EXTERNAL (decl)) + return false; + + tree type = TREE_TYPE (decl); + + /* For record type, check for array at the end of the structure. */ + if (TREE_CODE (type) == RECORD_TYPE) + { + tree field = TYPE_FIELDS (type); + while (DECL_CHAIN (field) != NULL_TREE) + field = DECL_CHAIN (field); + + return TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE; + } /* As a special case do not warn about merging int a[]; and int a[]={1,2,3}; here the first declaration is COMMON and sizeof(a) == sizeof (int). */ - && ((!DECL_COMMON (decl) && !DECL_EXTERNAL (decl)) - || TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE - || TYPE_SIZE (TREE_TYPE (decl)) - != TYPE_SIZE (TREE_TYPE (TREE_TYPE (decl))))) - return false; + else if (TREE_CODE (type) == ARRAY_TYPE) + return (TYPE_SIZE (decl) == TYPE_SIZE (TREE_TYPE (type))); + } return true; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 17399f9..b7211ce 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2018-01-23 Martin Liska <mliska@suse.cz> + + PR lto/81440 + * gcc.dg/lto/pr81440.h: New test. + * gcc.dg/lto/pr81440_0.c: New test. + * gcc.dg/lto/pr81440_1.c: New test. + 2018-01-23 Nathan Sidwell <nathan@acm.org> PR c++/83988 diff --git a/gcc/testsuite/gcc.dg/lto/pr81440.h b/gcc/testsuite/gcc.dg/lto/pr81440.h new file mode 100644 index 0000000..d9e6c3d --- /dev/null +++ b/gcc/testsuite/gcc.dg/lto/pr81440.h @@ -0,0 +1,4 @@ +typedef struct { + int i; + int ints[]; +} struct_t; diff --git a/gcc/testsuite/gcc.dg/lto/pr81440_0.c b/gcc/testsuite/gcc.dg/lto/pr81440_0.c new file mode 100644 index 0000000..07f2a87 --- /dev/null +++ b/gcc/testsuite/gcc.dg/lto/pr81440_0.c @@ -0,0 +1,9 @@ +/* { dg-lto-do link } */ + +#include "pr81440.h" + +extern struct_t my_struct; + +int main() { + return my_struct.ints[0]; +} diff --git a/gcc/testsuite/gcc.dg/lto/pr81440_1.c b/gcc/testsuite/gcc.dg/lto/pr81440_1.c new file mode 100644 index 0000000..d035330 --- /dev/null +++ b/gcc/testsuite/gcc.dg/lto/pr81440_1.c @@ -0,0 +1,6 @@ +#include "pr81440.h" + +struct_t my_struct = { + 20, + { 1, 2 } +}; |