From: Richard Biener Date: Wed, 18 Mar 2020 12:11:30 +0000 (+0100) Subject: middle-end/94206 fix memset folding to avoid types with padding X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=1ba9acb11e3589b96ed945ed2a3af6acd6377018;p=gcc.git middle-end/94206 fix memset folding to avoid types with padding This makes sure that the store a memset is folded to uses a type covering all bits. 2020-03-18 Richard Biener PR middle-end/94206 * gimple-fold.c (gimple_fold_builtin_memset): Avoid using partial int modes or not mode-precision integer types for the store. * gcc.dg/torture/pr94206.c: New testcase. --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 283ad1dde85..114d2992bcd 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2020-03-18 Richard Biener + + PR middle-end/94206 + * gimple-fold.c (gimple_fold_builtin_memset): Avoid using + partial int modes or not mode-precision integer types for + the store. + 2020-03-18 Jakub Jelinek * asan.c (get_mem_refs_of_builtin_call): Fix up duplicated word issue diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c index 3f17de974ed..c5939f19f59 100644 --- a/gcc/gimple-fold.c +++ b/gcc/gimple-fold.c @@ -1235,12 +1235,18 @@ gimple_fold_builtin_memset (gimple_stmt_iterator *gsi, tree c, tree len) length = tree_to_uhwi (len); if (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (etype)) != length + || (GET_MODE_PRECISION (SCALAR_INT_TYPE_MODE (etype)) + != GET_MODE_BITSIZE (SCALAR_INT_TYPE_MODE (etype))) || get_pointer_alignment (dest) / BITS_PER_UNIT < length) return NULL_TREE; if (length > HOST_BITS_PER_WIDE_INT / BITS_PER_UNIT) return NULL_TREE; + if (!type_has_mode_precision_p (etype)) + etype = lang_hooks.types.type_for_mode (SCALAR_INT_TYPE_MODE (etype), + TYPE_UNSIGNED (etype)); + if (integer_zerop (c)) cval = 0; else diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e8b78df02de..4aa798f8a48 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-03-18 Richard Biener + + PR middle-end/94206 + * gcc.dg/torture/pr94206.c: New testcase. + 2020-03-18 Duan bo PR target/94201 diff --git a/gcc/testsuite/gcc.dg/torture/pr94206.c b/gcc/testsuite/gcc.dg/torture/pr94206.c new file mode 100644 index 00000000000..9e54bba4ed4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr94206.c @@ -0,0 +1,17 @@ +/* { dg-do run { target lp64 } } */ + +struct { + unsigned long x:33; +} s; +typedef __typeof__(s.x + 0) uint33; + +int main() +{ + uint33 x; + __builtin_memset(&x, -1, sizeof x); + unsigned long u; + __builtin_memcpy(&u, &x, sizeof u); + if (u != -1ul) + __builtin_abort (); + return 0; +}