diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8affcaba43008db0b5edbeb74e647c874b954b7f..257cd21accbfad7661beace202c011d9ffa34523 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,41 @@ +2017-02-07 Richard Biener <rguenther@suse.de> + + PR tree-optimization/79256 + PR middle-end/79278 + * builtins.c (get_object_alignment_2): Use min_align_of_type + to extract alignment for MEM_REFs to honor BIGGEST_FIELD_ALIGNMENT + and ADJUST_FIELD_ALIGN. + + * doc/tm.texi.in (ADJUST_FIELD_ALIGN): Adjust to take additional + type parameter. + * doc/tm.texi: Regenerate. + * stor-layout.c (layout_decl): Adjust. + (update_alignment_for_field): Likewise. + (place_field): Likewise. + (min_align_of_type): Likewise. + * config/arc/arc.h (ADJUST_FIELD_ALIGN): Adjust. + * config/epiphany/epiphany.h (ADJUST_FIELD_ALIGN): Likewise. + * config/epiphany/epiphany.c (epiphany_adjust_field_align): Likewise. + * config/frv/frv.h (ADJUST_FIELD_ALIGN): Likewise. + * config/frv/frv.c (frv_adjust_field_align): Likewise. + * config/i386/i386.h (ADJUST_FIELD_ALIGN): Likewise. + * config/i386/i386.c (x86_field_alignment): Likewise. + * config/rs6000/aix.h (ADJUST_FIELD_ALIGN): Likewise. + * config/rs6000/darwin.h (ADJUST_FIELD_ALIGN): Likewise. + * config/rs6000/freebsd64.h (ADJUST_FIELD_ALIGN): Likewise. + * config/rs6000/linux64.h (ADJUST_FIELD_ALIGN): Likewise. + * config/rs6000/sysv4.h (ADJUST_FIELD_ALIGN): Likewise. + * config/rs6000/rs6000.c (rs6000_special_adjust_field_align_p): + Likewise. + + Revert + 2017-01-30 Richard Biener <rguenther@suse.de> + + PR tree-optimization/79256 + * targhooks.c (default_builtin_vector_alignment_reachable): Honor + BIGGEST_FIELD_ALIGNMENT and ADJUST_FIELD_ALIGN to fix up bogus + alignment on TYPE. + 2017-02-07 Toma Tabacu <toma.tabacu@imgtec.com> * config/mips/mips.c (mips_expand_builtin_insn): Convert the QImode diff --git a/gcc/builtins.c b/gcc/builtins.c index 0a0e8b9e2fa7bcfe2c4bc4e4d46c02228bf418d1..f3bee5bfc1afa653fd84983e15d6cc5daee09b98 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -334,9 +334,11 @@ get_object_alignment_2 (tree exp, unsigned int *alignp, Do so only if get_pointer_alignment_1 did not reveal absolute alignment knowledge and if using that alignment would improve the situation. */ + unsigned int talign; if (!addr_p && !known_alignment - && TYPE_ALIGN (TREE_TYPE (exp)) > align) - align = TYPE_ALIGN (TREE_TYPE (exp)); + && (talign = min_align_of_type (TREE_TYPE (exp)) * BITS_PER_UNIT) + && talign > align) + align = talign; else { /* Else adjust bitpos accordingly. */ diff --git a/gcc/config/arc/arc.h b/gcc/config/arc/arc.h index 9cf7668e985579267031355411caa951d4642613..b6464f18007f3166d2f3da6c82859dd5b9d57f3f 100644 --- a/gcc/config/arc/arc.h +++ b/gcc/config/arc/arc.h @@ -317,8 +317,8 @@ if (GET_MODE_CLASS (MODE) == MODE_INT \ construct. */ -#define ADJUST_FIELD_ALIGN(FIELD, COMPUTED) \ -(TYPE_MODE (strip_array_types (TREE_TYPE (FIELD))) == DFmode \ +#define ADJUST_FIELD_ALIGN(FIELD, TYPE, COMPUTED) \ +(TYPE_MODE (strip_array_types (TYPE)) == DFmode \ ? MIN ((COMPUTED), 32) : (COMPUTED)) diff --git a/gcc/config/epiphany/epiphany.c b/gcc/config/epiphany/epiphany.c index f8fa9bde7aa9b24e0edc160365937d62f60812ec..41864f2c502d51939b891c535121b3f5f85a4565 100644 --- a/gcc/config/epiphany/epiphany.c +++ b/gcc/config/epiphany/epiphany.c @@ -2855,12 +2855,12 @@ epiphany_special_round_type_align (tree type, unsigned computed, arrays-at-the-end-of-structs work, like for struct gcov_fn_info in libgcov.c . */ unsigned -epiphany_adjust_field_align (tree field, unsigned computed) +epiphany_adjust_field_align (tree type, unsigned computed) { if (computed == 32 - && TREE_CODE (TREE_TYPE (field)) == ARRAY_TYPE) + && TREE_CODE (type) == ARRAY_TYPE) { - tree elmsz = TYPE_SIZE (TREE_TYPE (TREE_TYPE (field))); + tree elmsz = TYPE_SIZE (TREE_TYPE (type)); if (!tree_fits_uhwi_p (elmsz) || tree_to_uhwi (elmsz) >= 32) return 64; diff --git a/gcc/config/epiphany/epiphany.h b/gcc/config/epiphany/epiphany.h index a9249a4469304e2e71a37b7027798254a31ba769..d20d400de7cb4534799f23f7a38ed7f01eb605d7 100644 --- a/gcc/config/epiphany/epiphany.h +++ b/gcc/config/epiphany/epiphany.h @@ -187,8 +187,8 @@ along with GCC; see the file COPYING3. If not see (SPECIFIED_ALIGN)) \ : MAX ((MANGLED_ALIGN), (SPECIFIED_ALIGN))) -#define ADJUST_FIELD_ALIGN(FIELD, COMPUTED) \ - epiphany_adjust_field_align((FIELD), (COMPUTED)) +#define ADJUST_FIELD_ALIGN(FIELD, TYPE, COMPUTED) \ + epiphany_adjust_field_align((TYPE), (COMPUTED)) /* Layout of source language data types. */ diff --git a/gcc/config/frv/frv.c b/gcc/config/frv/frv.c index a5c3313f6e8e8663a19640d83254b8fbd06626d3..0918b9835b94852408f873a9c14fffa4a120b026 100644 --- a/gcc/config/frv/frv.c +++ b/gcc/config/frv/frv.c @@ -6482,7 +6482,8 @@ int frv_adjust_field_align (tree field, int computed) { /* Make sure that the bitfield is not wider than the type. */ - if (DECL_BIT_FIELD (field) + if (field + && DECL_BIT_FIELD (field) && !DECL_ARTIFICIAL (field)) { tree parent = DECL_CONTEXT (field); diff --git a/gcc/config/frv/frv.h b/gcc/config/frv/frv.h index 8fcb17054dcdac0083982d5f5a800daf140d2fdf..4acaabb1a06948a0c1e606011dd119a8a1482a0f 100644 --- a/gcc/config/frv/frv.h +++ b/gcc/config/frv/frv.h @@ -331,7 +331,7 @@ alignment computed in the usual way is COMPUTED. GCC uses this value instead of the value in `BIGGEST_ALIGNMENT' or `BIGGEST_FIELD_ALIGNMENT', if defined, for structure fields only. */ -#define ADJUST_FIELD_ALIGN(FIELD, COMPUTED) \ +#define ADJUST_FIELD_ALIGN(FIELD, TYPE, COMPUTED) \ frv_adjust_field_align (FIELD, COMPUTED) #endif diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 3a659458ab0816730a740c6314ce92f087c3c45f..d7dce4be97c52e4ccd0c9dbe6cdbca26a79ed3b5 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -41691,10 +41691,9 @@ x86_file_start (void) } int -x86_field_alignment (tree field, int computed) +x86_field_alignment (tree type, int computed) { machine_mode mode; - tree type = TREE_TYPE (field); if (TARGET_64BIT || TARGET_ALIGN_DOUBLE) return computed; diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h index aeacf0f29dabb6bec715cad33ea8670b32cde990..f225b3eee9df90e27bf3775b53b33466f291c038 100644 --- a/gcc/config/i386/i386.h +++ b/gcc/config/i386/i386.h @@ -847,8 +847,8 @@ extern const char *host_detect_local_cpu (int argc, const char **argv); #define BIGGEST_FIELD_ALIGNMENT 32 #endif #else -#define ADJUST_FIELD_ALIGN(FIELD, COMPUTED) \ - x86_field_alignment ((FIELD), (COMPUTED)) +#define ADJUST_FIELD_ALIGN(FIELD, TYPE, COMPUTED) \ + x86_field_alignment ((TYPE), (COMPUTED)) #endif /* If defined, a C expression to compute the alignment given to a diff --git a/gcc/config/rs6000/aix.h b/gcc/config/rs6000/aix.h index 51801a2a3db426459a445c1ebf56a65cf0a88985..b90e2b065195a0ec0ade7c14ffae4709cec1e5bd 100644 --- a/gcc/config/rs6000/aix.h +++ b/gcc/config/rs6000/aix.h @@ -218,9 +218,9 @@ /* This now supports a natural alignment mode. */ /* AIX word-aligns FP doubles but doubleword-aligns 64-bit ints. */ -#define ADJUST_FIELD_ALIGN(FIELD, COMPUTED) \ +#define ADJUST_FIELD_ALIGN(FIELD, TYPE, COMPUTED) \ ((TARGET_ALIGN_NATURAL == 0 \ - && TYPE_MODE (strip_array_types (TREE_TYPE (FIELD))) == DFmode) \ + && TYPE_MODE (strip_array_types (TYPE)) == DFmode) \ ? MIN ((COMPUTED), 32) \ : (COMPUTED)) diff --git a/gcc/config/rs6000/darwin.h b/gcc/config/rs6000/darwin.h index 397ab1cc3cffdc05863e2940844bcb4acc1febe7..61e5e836de0044e3ac55d514ade59f681060f931 100644 --- a/gcc/config/rs6000/darwin.h +++ b/gcc/config/rs6000/darwin.h @@ -319,7 +319,7 @@ extern int darwin_emit_branch_islands; suppressed for vector and long double items (both 128 in size). There is a dummy use of the FIELD argument to avoid an unused variable warning (see PR59496). */ -#define ADJUST_FIELD_ALIGN(FIELD, COMPUTED) \ +#define ADJUST_FIELD_ALIGN(FIELD, TYPE, COMPUTED) \ ((void) (FIELD), \ (TARGET_ALIGN_NATURAL \ ? (COMPUTED) \ diff --git a/gcc/config/rs6000/freebsd64.h b/gcc/config/rs6000/freebsd64.h index 8f4bb615fed820a097b7218cad75afcd795f5d7b..d75ac2b9a5d65be751b19fbf069e33b8cd2c3ff3 100644 --- a/gcc/config/rs6000/freebsd64.h +++ b/gcc/config/rs6000/freebsd64.h @@ -365,12 +365,12 @@ extern int dot_symbols; /* PowerPC64 Linux word-aligns FP doubles when -malign-power is given. */ #undef ADJUST_FIELD_ALIGN -#define ADJUST_FIELD_ALIGN(FIELD, COMPUTED) \ - (rs6000_special_adjust_field_align_p ((FIELD), (COMPUTED)) \ +#define ADJUST_FIELD_ALIGN(FIELD, TYPE, COMPUTED) \ + (rs6000_special_adjust_field_align_p ((TYPE), (COMPUTED)) \ ? 128 \ : (TARGET_64BIT \ && TARGET_ALIGN_NATURAL == 0 \ - && TYPE_MODE (strip_array_types (TREE_TYPE (FIELD))) == DFmode) \ + && TYPE_MODE (strip_array_types (TYPE)) == DFmode) \ ? MIN ((COMPUTED), 32) \ : (COMPUTED)) diff --git a/gcc/config/rs6000/linux64.h b/gcc/config/rs6000/linux64.h index da0e5759826b42df0029db658ae79cc4c396bd94..71e35b709adf85456217229dc8d2d7433df9f038 100644 --- a/gcc/config/rs6000/linux64.h +++ b/gcc/config/rs6000/linux64.h @@ -292,12 +292,12 @@ extern int dot_symbols; /* PowerPC64 Linux word-aligns FP doubles when -malign-power is given. */ #undef ADJUST_FIELD_ALIGN -#define ADJUST_FIELD_ALIGN(FIELD, COMPUTED) \ - (rs6000_special_adjust_field_align_p ((FIELD), (COMPUTED)) \ +#define ADJUST_FIELD_ALIGN(FIELD, TYPE, COMPUTED) \ + (rs6000_special_adjust_field_align_p ((TYPE), (COMPUTED)) \ ? 128 \ : (TARGET_64BIT \ && TARGET_ALIGN_NATURAL == 0 \ - && TYPE_MODE (strip_array_types (TREE_TYPE (FIELD))) == DFmode) \ + && TYPE_MODE (strip_array_types (TYPE)) == DFmode) \ ? MIN ((COMPUTED), 32) \ : (COMPUTED)) diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c index 37e5458f30dd43f8da3dbeae6061e82bb5779ad1..f1dec8c3644a31a6b9434e209fe7c1681df5bdb8 100644 --- a/gcc/config/rs6000/rs6000.c +++ b/gcc/config/rs6000/rs6000.c @@ -7975,9 +7975,9 @@ rs6000_data_alignment (tree type, unsigned int align, enum data_align how) /* Previous GCC releases forced all vector types to have 16-byte alignment. */ bool -rs6000_special_adjust_field_align_p (tree field, unsigned int computed) +rs6000_special_adjust_field_align_p (tree type, unsigned int computed) { - if (TARGET_ALTIVEC && TREE_CODE (TREE_TYPE (field)) == VECTOR_TYPE) + if (TARGET_ALTIVEC && TREE_CODE (type) == VECTOR_TYPE) { if (computed != 128) { diff --git a/gcc/config/rs6000/sysv4.h b/gcc/config/rs6000/sysv4.h index a5abeee02e4474267a5638e155e79c67b9e1d026..de386291a5100d1803eb32364125c9ff9c3c1cac 100644 --- a/gcc/config/rs6000/sysv4.h +++ b/gcc/config/rs6000/sysv4.h @@ -298,8 +298,8 @@ do { \ /* An expression for the alignment of a structure field FIELD if the alignment computed in the usual way is COMPUTED. */ -#define ADJUST_FIELD_ALIGN(FIELD, COMPUTED) \ - (rs6000_special_adjust_field_align_p ((FIELD), (COMPUTED)) \ +#define ADJUST_FIELD_ALIGN(FIELD, TYPE, COMPUTED) \ + (rs6000_special_adjust_field_align_p ((TYPE), (COMPUTED)) \ ? 128 : COMPUTED) #undef BIGGEST_FIELD_ALIGNMENT diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index b34ee03278b62475bbbd74eab7606a7f0f89cba1..348fd6806bdacb7f9cb713b6907acb172214402c 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -1042,13 +1042,15 @@ structure and union fields only, unless the field alignment has been set by the @code{__attribute__ ((aligned (@var{n})))} construct. @end defmac -@defmac ADJUST_FIELD_ALIGN (@var{field}, @var{computed}) -An expression for the alignment of a structure field @var{field} if the -alignment computed in the usual way (including applying of -@code{BIGGEST_ALIGNMENT} and @code{BIGGEST_FIELD_ALIGNMENT} to the +@defmac ADJUST_FIELD_ALIGN (@var{field}, @var{type}, @var{computed}) +An expression for the alignment of a structure field @var{field} of +type @var{type} if the alignment computed in the usual way (including +applying of @code{BIGGEST_ALIGNMENT} and @code{BIGGEST_FIELD_ALIGNMENT} to the alignment) is @var{computed}. It overrides alignment only if the field alignment has not been set by the -@code{__attribute__ ((aligned (@var{n})))} construct. +@code{__attribute__ ((aligned (@var{n})))} construct. Note that @var{field} +may be @code{NULL_TREE} in case we just query for the minimum alignment +of a field of type @var{type} in structure context. @end defmac @defmac MAX_STACK_ALIGNMENT diff --git a/gcc/doc/tm.texi.in b/gcc/doc/tm.texi.in index 756c1182493eeea3a50e3b07fb1f413c0f3a0148..6cde83c7a21e3c1c250060797869a955024ab194 100644 --- a/gcc/doc/tm.texi.in +++ b/gcc/doc/tm.texi.in @@ -990,13 +990,15 @@ structure and union fields only, unless the field alignment has been set by the @code{__attribute__ ((aligned (@var{n})))} construct. @end defmac -@defmac ADJUST_FIELD_ALIGN (@var{field}, @var{computed}) -An expression for the alignment of a structure field @var{field} if the -alignment computed in the usual way (including applying of -@code{BIGGEST_ALIGNMENT} and @code{BIGGEST_FIELD_ALIGNMENT} to the +@defmac ADJUST_FIELD_ALIGN (@var{field}, @var{type}, @var{computed}) +An expression for the alignment of a structure field @var{field} of +type @var{type} if the alignment computed in the usual way (including +applying of @code{BIGGEST_ALIGNMENT} and @code{BIGGEST_FIELD_ALIGNMENT} to the alignment) is @var{computed}. It overrides alignment only if the field alignment has not been set by the -@code{__attribute__ ((aligned (@var{n})))} construct. +@code{__attribute__ ((aligned (@var{n})))} construct. Note that @var{field} +may be @code{NULL_TREE} in case we just query for the minimum alignment +of a field of type @var{type} in structure context. @end defmac @defmac MAX_STACK_ALIGNMENT diff --git a/gcc/go/ChangeLog b/gcc/go/ChangeLog index 8e37e8b3e015aed32104262b7633a798ef2d5e46..687c8d68992b966720e598d53176dd7c14d04282 100644 --- a/gcc/go/ChangeLog +++ b/gcc/go/ChangeLog @@ -1,3 +1,9 @@ +2017-02-07 Richard Biener <rguenther@suse.de> + + PR tree-optimization/79256 + PR middle-end/79278 + * go-backend.c (go_field_alignment): Adjust. + 2017-01-11 Than McIntosh <thanm@google.com> * go-gcc.cc (conditional_expression): Add Bfunction parameter. diff --git a/gcc/go/go-backend.c b/gcc/go/go-backend.c index 1705b849550f00383343bea799d5bc4118fbf00f..d60a79e296168a7133f19be607a089a84d239426 100644 --- a/gcc/go/go-backend.c +++ b/gcc/go/go-backend.c @@ -71,11 +71,7 @@ go_field_alignment (tree t) #endif #ifdef ADJUST_FIELD_ALIGN - { - tree field ATTRIBUTE_UNUSED; - field = build_decl (UNKNOWN_LOCATION, FIELD_DECL, NULL, t); - v = ADJUST_FIELD_ALIGN (field, v); - } + v = ADJUST_FIELD_ALIGN (NULL_TREE, t, v); #endif return v / BITS_PER_UNIT; diff --git a/gcc/stor-layout.c b/gcc/stor-layout.c index 7ad34f792df217b8cfc7ce4a3766c60f6ababafd..d0beebf06868545442f2b6431ae034a04252db8c 100644 --- a/gcc/stor-layout.c +++ b/gcc/stor-layout.c @@ -718,7 +718,8 @@ layout_decl (tree decl, unsigned int known_align) (unsigned) BIGGEST_FIELD_ALIGNMENT)); #endif #ifdef ADJUST_FIELD_ALIGN - SET_DECL_ALIGN (decl, ADJUST_FIELD_ALIGN (decl, DECL_ALIGN (decl))); + SET_DECL_ALIGN (decl, ADJUST_FIELD_ALIGN (decl, TREE_TYPE (decl), + DECL_ALIGN (decl))); #endif } @@ -1032,7 +1033,7 @@ update_alignment_for_field (record_layout_info rli, tree field, #ifdef ADJUST_FIELD_ALIGN if (! TYPE_USER_ALIGN (type)) - type_align = ADJUST_FIELD_ALIGN (field, type_align); + type_align = ADJUST_FIELD_ALIGN (field, type, type_align); #endif /* Targets might chose to handle unnamed and hence possibly @@ -1260,7 +1261,7 @@ place_field (record_layout_info rli, tree field) #ifdef ADJUST_FIELD_ALIGN if (! TYPE_USER_ALIGN (type)) - type_align = ADJUST_FIELD_ALIGN (field, type_align); + type_align = ADJUST_FIELD_ALIGN (field, type, type_align); #endif /* A bit field may not span more units of alignment of its type @@ -1303,7 +1304,7 @@ place_field (record_layout_info rli, tree field) #ifdef ADJUST_FIELD_ALIGN if (! TYPE_USER_ALIGN (type)) - type_align = ADJUST_FIELD_ALIGN (field, type_align); + type_align = ADJUST_FIELD_ALIGN (field, type, type_align); #endif if (maximum_field_alignment != 0) @@ -2411,9 +2412,7 @@ min_align_of_type (tree type) #endif unsigned int field_align = align; #ifdef ADJUST_FIELD_ALIGN - tree field = build_decl (UNKNOWN_LOCATION, FIELD_DECL, NULL_TREE, type); - field_align = ADJUST_FIELD_ALIGN (field, field_align); - ggc_free (field); + field_align = ADJUST_FIELD_ALIGN (NULL_TREE, type, field_align); #endif align = MIN (align, field_align); } diff --git a/gcc/targhooks.c b/gcc/targhooks.c index bf5d0d4efd0c0dc2b531a0a671b34df140e74416..1cdec068ed87456dc636e22ab0e187cd2bd55040 100644 --- a/gcc/targhooks.c +++ b/gcc/targhooks.c @@ -1130,14 +1130,9 @@ default_vector_alignment (const_tree type) /* By default assume vectors of element TYPE require a multiple of the natural alignment of TYPE. TYPE is naturally aligned if IS_PACKED is false. */ bool -default_builtin_vector_alignment_reachable (const_tree type, bool is_packed) +default_builtin_vector_alignment_reachable (const_tree /*type*/, bool is_packed) { - if (is_packed) - return false; - - /* If TYPE can be differently aligned in field context we have to punt - as TYPE may have wrong TYPE_ALIGN here (PR79278). */ - return min_align_of_type (CONST_CAST_TREE (type)) == TYPE_ALIGN_UNIT (type); + return ! is_packed; } /* By default, assume that a target supports any factor of misalignment diff --git a/libobjc/ChangeLog b/libobjc/ChangeLog index 55987a3ff3b8fb22cc5e44e92f3259f990ac0022..f73c54747a4ad3ee2dbfbad23d26c7c80d99a67a 100644 --- a/libobjc/ChangeLog +++ b/libobjc/ChangeLog @@ -1,3 +1,10 @@ +2017-02-07 Richard Biener <rguenther@suse.de> + + PR tree-optimization/79256 + PR middle-end/79278 + * encoding.c (objc_layout_structure_next_member): Adjust + ADJUST_FIELD_ALIGN usage. + 2017-01-18 Matthias Klose <doko@ubuntu.com> PR libobjc/78697 diff --git a/libobjc/encoding.c b/libobjc/encoding.c index 3850477fdb6723b9d69d3d45d0a46407b3111a47..6f18d604442663c25e66443ac29f900794c84801 100644 --- a/libobjc/encoding.c +++ b/libobjc/encoding.c @@ -1159,7 +1159,7 @@ objc_layout_structure_next_member (struct objc_struct_layout *layout) desired_align = MIN (desired_align, BIGGEST_FIELD_ALIGNMENT); #endif #ifdef ADJUST_FIELD_ALIGN - desired_align = ADJUST_FIELD_ALIGN (type, desired_align); + desired_align = ADJUST_FIELD_ALIGN (type, type, desired_align); #endif /* Record must have at least as much alignment as any field.