From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 121337 invoked by alias); 8 Oct 2016 15:45:01 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 121306 invoked by uid 89); 8 Oct 2016 15:44:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.5 required=5.0 tests=AWL,BAYES_00,KAM_ASCII_DIVIDERS,RCVD_IN_DNSWL_LOW,RP_MATCHES_RCVD,SPF_PASS,UNPARSEABLE_RELAY autolearn=ham version=3.3.2 spammy=cxx_dialect, Leave, null_rtx, NULL_RTX X-HELO: mtlfep01.bell.net Received: from belmont79srvr.owm.bell.net (HELO mtlfep01.bell.net) (184.150.200.79) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 08 Oct 2016 15:44:49 +0000 Received: from bell.net mtlfep01 184.150.200.30 by mtlfep01.bell.net with ESMTP id <20161008154447.QLJJ31835.mtlfep01.bell.net@mtlspm02.bell.net> for ; Sat, 8 Oct 2016 11:44:47 -0400 Received: from [192.168.2.10] (really [70.54.56.11]) by mtlspm02.bell.net with ESMTP id <20161008154446.CDGV29689.mtlspm02.bell.net@[192.168.2.10]>; Sat, 8 Oct 2016 11:44:46 -0400 From: John David Anglin Mime-Version: 1.0 (Apple Message framework v1085) Content-Type: multipart/mixed; boundary=Apple-Mail-51--581919684 Date: Sat, 08 Oct 2016 15:45:00 -0000 Subject: [PATCH] Implement new hook for max_align_t_align Cc: Jeff Law , jason@redhat.com To: GCC Patches Message-Id: X-Opwv-CommTouchExtSvcRefID: str=0001.0A020205.57F9146F.0004,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0 X-SW-Source: 2016-10/txt/msg00528.txt.bz2 --Apple-Mail-51--581919684 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Content-length: 986 Various pthread types on hppa-linux require an alignment of 16 bytes for AB= I reasons. This is larger than the current implementations of max_align_t and max_align_t_align. As = a result, the patch to implement C++17 over-aligned new causes warnings on hppa. The thread here= discusses the problem: https://gcc.gnu.org/ml/gcc-patches/2016-09/msg01593.html The attached patch implements a new hook to allow overriding the default im= plementation of max_align_t_align in the PA backend. It changes the max_align_t alignment to 16 bytes on 32-= bit hppa-linux. I added an additional comment to BIGGEST_ALIGNMENT in pa.h to document the alignment choices for = long double on hpux. I also defined MALLOC_ABI_ALIGNMENT so that it reflects the behaviour of the glibc= and hpux malloc implementations. Tested on hppa2.0w-hp-hpux11.11, hppa64-hp-hpux11.11 and hppa-unknown-linux= -gnu with no observed regressions. Okay for trunk? Dave -- John David Anglin dave.anglin@bell.net --Apple-Mail-51--581919684 Content-Disposition: attachment; filename=ldcw-align.d.txt Content-Type: text/plain; name="ldcw-align.d.txt" Content-Transfer-Encoding: quoted-printable Content-length: 11835 2016-10-08 John David Anglin gcc/c-family/ * c-common.c (max_align_t_align): Move to targhooks.c. * c-common.h (max_align_t_align): Delete. gcc/ * target.def (max_align_t_align): New target hook. * targhooks.c (default_max_align_t_align): New. * targhooks.h (default_max_align_t_align): Declare. * config/pa/pa.h (BIGGEST_ALIGNMENT): Adjust comment. (MALLOC_ABI_ALIGNMENT): Define. * config/pa/pa.c (pa_max_align_t_align): New. (TARGET_MAX_ALIGN_T_ALIGN): Define. * doc/tm.texi.in (TARGET_MAX_ALIGN_T_ALIGN): Add documentation hook. * doc/tm.texi: Update. gcc/cp/ * decl.c (cxx_init_decl_processing): Use max_align_t_align target hook. * init.c (build_new_1): Likewise. Index: c-family/c-common.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- c-family/c-common.c (revision 240688) +++ c-family/c-common.c (working copy) @@ -12899,22 +12899,6 @@ return stv_nothing; } =20 -/* Return the alignment of std::max_align_t. - - [support.types.layout] The type max_align_t is a POD type whose alignme= nt - requirement is at least as great as that of every scalar type, and whose - alignment requirement is supported in every context. */ - -unsigned -max_align_t_align () -{ - unsigned int max_align =3D MAX (TYPE_ALIGN (long_long_integer_type_node), - TYPE_ALIGN (long_double_type_node)); - if (float128_type_node !=3D NULL_TREE) - max_align =3D MAX (max_align, TYPE_ALIGN (float128_type_node)); - return max_align; -} - /* Return true iff ALIGN is an integral constant that is a fundamental alignment, as defined by [basic.align] in the c++-11 specifications. @@ -12928,7 +12912,7 @@ bool cxx_fundamental_alignment_p (unsigned align) { - return (align <=3D max_align_t_align ()); + return (align <=3D targetm.max_align_t_align ()); } =20 /* Return true if T is a pointer to a zero-sized aggregate. */ Index: c-family/c-common.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- c-family/c-common.h (revision 240688) +++ c-family/c-common.h (working copy) @@ -864,7 +864,6 @@ extern bool keyword_is_storage_class_specifier (enum rid); extern bool keyword_is_type_qualifier (enum rid); extern bool keyword_is_decl_specifier (enum rid); -extern unsigned max_align_t_align (void); extern bool cxx_fundamental_alignment_p (unsigned); extern bool pointer_to_zero_sized_aggr_p (tree); extern bool diagnose_mismatched_attributes (tree, tree); Index: config/pa/pa.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- config/pa/pa.c (revision 240688) +++ config/pa/pa.c (working copy) @@ -194,6 +194,7 @@ static bool pa_legitimate_constant_p (machine_mode, rtx); static unsigned int pa_section_type_flags (tree, const char *, int); static bool pa_legitimate_address_p (machine_mode, rtx, bool); +static unsigned int pa_max_align_t_align (void); =20 /* The following extra sections are only used for SOM. */ static GTY(()) section *som_readonly_data_section; @@ -400,6 +401,9 @@ #undef TARGET_LRA_P #define TARGET_LRA_P hook_bool_void_false =20 +#undef TARGET_MAX_ALIGN_T_ALIGN +#define TARGET_MAX_ALIGN_T_ALIGN pa_max_align_t_align + struct gcc_target targetm =3D TARGET_INITIALIZER; =0C /* Parse the -mfixed-range=3D option string. */ @@ -10719,4 +10723,16 @@ return NULL_RTX; } =20 +/* The maximimum alignment in bits for the POD type std:max_align_t. + This is set to 128 on 32-bit non HP-UX systems to suppress warnings + about new with extended alignment. This arises because various POSIX + types such as pthread_mutex_t have for historical reasons 128-bit + alignment but the default alignment of std:max_align_t is 64 bits. */ + +static unsigned int +pa_max_align_t_align (void) +{ + return TARGET_HPUX && !TARGET_64BIT ? 64 : 128; +} + #include "gt-pa.h" Index: config/pa/pa.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- config/pa/pa.h (revision 240688) +++ config/pa/pa.h (working copy) @@ -292,9 +292,21 @@ /* A bit-field declared as `int' forces `int' alignment for the struct. */ #define PCC_BITFIELD_TYPE_MATTERS 1 =20 -/* No data type wants to be aligned rounder than this. */ +/* No data type wants to be aligned rounder than this. The long double + type has 16-byte alignment on the 64-bit target even though it was never + implemented in hardware. The software implementation only needs 8-byte + alignment. This is to match the HP compilers. */ #define BIGGEST_ALIGNMENT (2 * BITS_PER_WORD) =20 +/* Alignment, in bits, a C conformant malloc implementation has to provide. + The HP-UX malloc implementation provides a default alignment of 8 bytes. + This can be increased with mallopt. The glibc implementation also prov= ides + 8-byte alignment. Note that this isn't enough for various POSIX types = such + as pthread_mutex_t. However, since we no longer need the 16-byte align= ment + for atomic operations, we ignore the nominal alignment specified for th= ese + types. The same is true for long double on 64-bit HP-UX. */ +#define MALLOC_ABI_ALIGNMENT (64) + /* Get around hp-ux assembler bug, and make strcpy of constants fast. */ #define CONSTANT_ALIGNMENT(EXP, ALIGN) \ (TREE_CODE (EXP) =3D=3D STRING_CST \ Index: cp/decl.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- cp/decl.c (revision 240688) +++ cp/decl.c (working copy) @@ -4141,7 +4141,7 @@ if (aligned_new_threshold =3D=3D -1) aligned_new_threshold =3D (cxx_dialect >=3D cxx1z) ? 1 : 0; if (aligned_new_threshold =3D=3D 1) - aligned_new_threshold =3D max_align_t_align () / BITS_PER_UNIT; + aligned_new_threshold =3D targetm.max_align_t_align () / BITS_PER_UNIT; =20 { tree newattrs, extvisattr; Index: cp/init.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- cp/init.c (revision 240688) +++ cp/init.c (working copy) @@ -3017,7 +3017,7 @@ gcc_assert (alloc_fn !=3D NULL_TREE); =20 if (warn_aligned_new - && TYPE_ALIGN (elt_type) > max_align_t_align () + && TYPE_ALIGN (elt_type) > targetm.max_align_t_align () && (warn_aligned_new > 1 || CP_DECL_CONTEXT (alloc_fn) =3D=3D global_namespace) && !aligned_allocation_fn_p (alloc_fn)) Index: doc/tm.texi =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- doc/tm.texi (revision 240688) +++ doc/tm.texi (working copy) @@ -11686,6 +11686,10 @@ ISO C11 requires atomic compound assignments that may raise floating-point= exceptions to raise exceptions corresponding to the arithmetic operation w= hose result was successfully stored in a compare-and-exchange sequence. Th= is requires code equivalent to calls to @code{feholdexcept}, @code{fecleare= xcept} and @code{feupdateenv} to be generated at appropriate points in the = compare-and-exchange sequence. This hook should set @code{*@var{hold}} to = an expression equivalent to the call to @code{feholdexcept}, @code{*@var{cl= ear}} to an expression equivalent to the call to @code{feclearexcept} and @= code{*@var{update}} to an expression equivalent to the call to @code{feupda= teenv}. The three expressions are @code{NULL_TREE} on entry to the hook an= d may be left as @code{NULL_TREE} if no code is required in a particular pl= ace. The default implementation leaves all three expressions as @code{NULL= _TREE}. The @code{__atomic_feraiseexcept} function from @code{libatomic} m= ay be of use as part of the code generated in @code{*@var{update}}. @end deftypefn =20 +@deftypefn {Target Hook} {unsigned int} TARGET_MAX_ALIGN_T_ALIGN (void) +If defined, this function returns the alignment in bits for std:max_align_= t. The default is suitable for most targets.=20=20 +@end deftypefn + @deftypefn {Target Hook} void TARGET_RECORD_OFFLOAD_SYMBOL (tree) Used when offloaded functions are seen in the compilation unit and no named sections are available. It is called once for each symbol that must be Index: doc/tm.texi.in =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- doc/tm.texi.in (revision 240688) +++ doc/tm.texi.in (working copy) @@ -8224,6 +8224,8 @@ =20 @hook TARGET_ATOMIC_ASSIGN_EXPAND_FENV =20 +@hook TARGET_MAX_ALIGN_T_ALIGN + @hook TARGET_RECORD_OFFLOAD_SYMBOL =20 @hook TARGET_OFFLOAD_OPTIONS Index: target.def =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- target.def (revision 240688) +++ target.def (working copy) @@ -5894,6 +5894,15 @@ void, (tree *hold, tree *clear, tree *update), default_atomic_assign_expand_fenv) =20 +/* Return an unsigned int representing the alignment (in bits) of + std:max_align_t. This allows the default alignment to be overridden. = */ +DEFHOOK +(max_align_t_align, +"If defined, this function returns the alignment in bits for std:max_align= _t.\ + The default is suitable for most targets. ", + unsigned int, (void), + default_max_align_t_align) + /* Leave the boolean fields at the end. */ =20 /* True if we can create zeroed data by switching to a BSS section Index: targhooks.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- targhooks.c (revision 240688) +++ targhooks.c (working copy) @@ -1907,6 +1907,23 @@ { } =20 +/* Default implementation of TARGET_MAX_ALIGN_T_ALIGN to return alignment + in bits of std::max_align_t. + + [support.types.layout] The type max_align_t is a POD type whose alignme= nt + requirement is at least as great as that of every scalar type, and whose + alignment requirement is supported in every context. */ + +unsigned int +default_max_align_t_align (void) +{ + unsigned int max_align =3D MAX (TYPE_ALIGN (long_long_integer_type_node), + TYPE_ALIGN (long_double_type_node)); + if (float128_type_node !=3D NULL_TREE) + max_align =3D MAX (max_align, TYPE_ALIGN (float128_type_node)); + return max_align; +} + #ifndef PAD_VARARGS_DOWN #define PAD_VARARGS_DOWN BYTES_BIG_ENDIAN #endif Index: targhooks.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- targhooks.h (revision 240688) +++ targhooks.h (working copy) @@ -262,5 +262,6 @@ optimization_type); =20 extern unsigned int default_max_noce_ifcvt_seq_cost (edge); +extern unsigned int default_max_align_t_align (void); =20 #endif /* GCC_TARGHOOKS_H */ --Apple-Mail-51--581919684--