From 5d9a283ac6aaa10d7f1052dba4cde7a8a63c88fc Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Tue, 14 Mar 2017 22:16:27 +0000 Subject: [PATCH] re PR middle-end/80020 (gcc confused about aligned_alloc argument order) PR middle-end/80020 * builtin-attrs.def (ATTR_ALLOC_SIZE_2_NOTHROW_LIST): New macro. * builtins.def (aligned_alloc): Use it. PR middle-end/80020 * gcc.dg/attr-alloc_size-6.c: Correct aligned_alloc argument order. * gcc.dg/attr-alloc_size-7.c: Same. * gcc.dg/attr-alloc_size-9.c: Same. * gcc.dg/builtin-alloc-size.c: Same. * gcc.dg/pr80020.c: New test. From-SVN: r246145 --- gcc/ChangeLog | 5 +++++ gcc/builtin-attrs.def | 5 ++++- gcc/builtins.def | 2 +- gcc/testsuite/ChangeLog | 9 ++++++++ gcc/testsuite/gcc.dg/attr-alloc_size-6.c | 8 +++---- gcc/testsuite/gcc.dg/attr-alloc_size-7.c | 8 +++---- gcc/testsuite/gcc.dg/attr-alloc_size-9.c | 2 +- gcc/testsuite/gcc.dg/builtin-alloc-size.c | 2 +- gcc/testsuite/gcc.dg/pr80020.c | 26 +++++++++++++++++++++++ 9 files changed, 55 insertions(+), 12 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr80020.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 61277c36287..63597cd4c6b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,10 @@ 2017-03-14 Martin Sebor + PR middle-end/80020 + * builtin-attrs.def (ATTR_ALLOC_SIZE_2_NOTHROW_LIST): New macro. + * builtins.def (aligned_alloc): Use it. + + PR c/79936 * Makefile.in (GTFILES): Add calls.c. * calls.c: Include "gt-calls.h". diff --git a/gcc/builtin-attrs.def b/gcc/builtin-attrs.def index 275328893f1..38fb1bb8810 100644 --- a/gcc/builtin-attrs.def +++ b/gcc/builtin-attrs.def @@ -156,9 +156,12 @@ DEF_ATTR_TREE_LIST (ATTR_COLD_CONST_NORETURN_NOTHROW_LEAF_LIST, ATTR_CONST,\ ATTR_NULL, ATTR_COLD_NORETURN_NOTHROW_LEAF_LIST) /* Allocation functions like malloc and realloc whose first argument - specifies the size of the allocated object. */ + with _SIZE_1, or second argument with _SIZE_2, specifies the size + of the allocated object. */ DEF_ATTR_TREE_LIST (ATTR_MALLOC_SIZE_1_NOTHROW_LIST, ATTR_ALLOC_SIZE, \ ATTR_LIST_1, ATTR_MALLOC_NOTHROW_LIST) +DEF_ATTR_TREE_LIST (ATTR_ALLOC_SIZE_2_NOTHROW_LIST, ATTR_ALLOC_SIZE, \ + ATTR_LIST_2, ATTR_MALLOC_NOTHROW_LIST) DEF_ATTR_TREE_LIST (ATTR_MALLOC_SIZE_1_NOTHROW_LEAF_LIST, ATTR_ALLOC_SIZE, \ ATTR_LIST_1, ATTR_MALLOC_NOTHROW_LEAF_LIST) /* Alloca is just like malloc except that it never returns null. */ diff --git a/gcc/builtins.def b/gcc/builtins.def index d7f80e66bd9..e383c80145f 100644 --- a/gcc/builtins.def +++ b/gcc/builtins.def @@ -297,7 +297,7 @@ DEF_C99_BUILTIN (BUILT_IN_ACOSH, "acosh", BT_FN_DOUBLE_DOUBLE, ATTR_MATHF DEF_C99_BUILTIN (BUILT_IN_ACOSHF, "acoshf", BT_FN_FLOAT_FLOAT, ATTR_MATHFN_FPROUNDING_ERRNO) DEF_C99_BUILTIN (BUILT_IN_ACOSHL, "acoshl", BT_FN_LONGDOUBLE_LONGDOUBLE, ATTR_MATHFN_FPROUNDING_ERRNO) DEF_C99_C90RES_BUILTIN (BUILT_IN_ACOSL, "acosl", BT_FN_LONGDOUBLE_LONGDOUBLE, ATTR_MATHFN_FPROUNDING_ERRNO) -DEF_C11_BUILTIN (BUILT_IN_ALIGNED_ALLOC, "aligned_alloc", BT_FN_PTR_SIZE_SIZE, ATTR_MALLOC_SIZE_1_NOTHROW_LIST) +DEF_C11_BUILTIN (BUILT_IN_ALIGNED_ALLOC, "aligned_alloc", BT_FN_PTR_SIZE_SIZE, ATTR_ALLOC_SIZE_2_NOTHROW_LIST) DEF_LIB_BUILTIN (BUILT_IN_ASIN, "asin", BT_FN_DOUBLE_DOUBLE, ATTR_MATHFN_FPROUNDING_ERRNO) DEF_C99_C90RES_BUILTIN (BUILT_IN_ASINF, "asinf", BT_FN_FLOAT_FLOAT, ATTR_MATHFN_FPROUNDING_ERRNO) DEF_C99_BUILTIN (BUILT_IN_ASINH, "asinh", BT_FN_DOUBLE_DOUBLE, ATTR_MATHFN_FPROUNDING) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8e7a1dda435..63daa280f66 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2017-03-14 Martin Sebor + + PR middle-end/80020 + * gcc.dg/attr-alloc_size-6.c: Correct aligned_alloc argument order. + * gcc.dg/attr-alloc_size-7.c: Same. + * gcc.dg/attr-alloc_size-9.c: Same. + * gcc.dg/builtin-alloc-size.c: Same. + * gcc.dg/pr80020.c: New test. + 2017-03-14 Bernd Schmidt PR rtl-optimization/79728 diff --git a/gcc/testsuite/gcc.dg/attr-alloc_size-6.c b/gcc/testsuite/gcc.dg/attr-alloc_size-6.c index 38890b69147..fc3e22c5c36 100644 --- a/gcc/testsuite/gcc.dg/attr-alloc_size-6.c +++ b/gcc/testsuite/gcc.dg/attr-alloc_size-6.c @@ -15,8 +15,8 @@ void sink (void*); void test_lit (char *p, char *q) { - sink (__builtin_aligned_alloc (MAXOBJSZ, 1)); - sink (__builtin_aligned_alloc (MAXOBJSZ + 1, 1)); /* { dg-warning "argument 1 value .12346\[lu\]*. exceeds maximum object size 12345" } */ + sink (__builtin_aligned_alloc (1, MAXOBJSZ)); + sink (__builtin_aligned_alloc (1, MAXOBJSZ + 1)); /* { dg-warning "argument 2 value .12346\[lu\]*. exceeds maximum object size 12345" } */ sink (__builtin_alloca (MAXOBJSZ)); sink (__builtin_alloca (MAXOBJSZ + 2)); /* { dg-warning "argument 1 value .12347\[lu\]*. exceeds maximum object size 12345" } */ @@ -46,8 +46,8 @@ enum { max = MAXOBJSZ }; void test_cst (char *p, char *q) { - sink (__builtin_aligned_alloc (max, 1)); - sink (__builtin_aligned_alloc (max + 1, 1)); /* { dg-warning "argument 1 value .12346\[lu\]*. exceeds maximum object size 12345" } */ + sink (__builtin_aligned_alloc (1, max)); + sink (__builtin_aligned_alloc (1, max + 1)); /* { dg-warning "argument 2 value .12346\[lu\]*. exceeds maximum object size 12345" } */ sink (__builtin_alloca (max)); sink (__builtin_alloca (max + 2)); /* { dg-warning "argument 1 value .12347\[lu\]*. exceeds maximum object size 12345" } */ diff --git a/gcc/testsuite/gcc.dg/attr-alloc_size-7.c b/gcc/testsuite/gcc.dg/attr-alloc_size-7.c index d6e618d2768..a3b2a6bbb4f 100644 --- a/gcc/testsuite/gcc.dg/attr-alloc_size-7.c +++ b/gcc/testsuite/gcc.dg/attr-alloc_size-7.c @@ -22,8 +22,8 @@ void test_var (void *p) { size_t max = maxobjsize (); - sink (__builtin_aligned_alloc (max, 1)); - sink (__builtin_aligned_alloc (max + 1, 1)); /* { dg-warning "argument 1 value .12346\[lu\]*. exceeds maximum object size 12345" } */ + sink (__builtin_aligned_alloc (1, max)); + sink (__builtin_aligned_alloc (1, max + 1)); /* { dg-warning "argument 2 value .12346\[lu\]*. exceeds maximum object size 12345" } */ sink (__builtin_alloca (max)); sink (__builtin_alloca (max + 2)); /* { dg-warning "argument 1 value .12347\[lu\]*. exceeds maximum object size 12345" } */ @@ -52,8 +52,8 @@ void test_range (void *p, size_t range) if (range < max || 2 * max <= range) range = maxobjsize (); - sink (__builtin_aligned_alloc (range, 1)); - sink (__builtin_aligned_alloc (range + 1, 1)); /* { dg-warning "argument 1 range \\\[12346\[lu\]*, \[0-9\]+\[lu\]*\\\] exceeds maximum object size 12345" } */ + sink (__builtin_aligned_alloc (1, range)); + sink (__builtin_aligned_alloc (1, range + 1)); /* { dg-warning "argument 2 range \\\[12346\[lu\]*, \[0-9\]+\[lu\]*\\\] exceeds maximum object size 12345" } */ sink (__builtin_alloca (range)); sink (__builtin_alloca (range + 2)); /* { dg-warning "argument 1 range \\\[12347\[lu\]*, \[0-9\]+\[lu\]*\\\] exceeds maximum object size 12345" } */ diff --git a/gcc/testsuite/gcc.dg/attr-alloc_size-9.c b/gcc/testsuite/gcc.dg/attr-alloc_size-9.c index 66765fd4836..0e75bb2b535 100644 --- a/gcc/testsuite/gcc.dg/attr-alloc_size-9.c +++ b/gcc/testsuite/gcc.dg/attr-alloc_size-9.c @@ -20,7 +20,7 @@ extern int x; void test (void *p, unsigned n) { - TEST (__builtin_aligned_alloc (n, 8)); + TEST (__builtin_aligned_alloc (8, n)); TEST (__builtin_alloca (n)); TEST (__builtin_calloc (4, n)); TEST (__builtin_malloc (n)); diff --git a/gcc/testsuite/gcc.dg/builtin-alloc-size.c b/gcc/testsuite/gcc.dg/builtin-alloc-size.c index 5a40862faf8..6929e884601 100644 --- a/gcc/testsuite/gcc.dg/builtin-alloc-size.c +++ b/gcc/testsuite/gcc.dg/builtin-alloc-size.c @@ -16,7 +16,7 @@ void test_aligned_alloc (unsigned a) { unsigned n = size (7); - void *p = __builtin_aligned_alloc (n, a); + void *p = __builtin_aligned_alloc (a, n); if (__builtin_object_size (p, 0) != n) __builtin_abort (); sink (p); diff --git a/gcc/testsuite/gcc.dg/pr80020.c b/gcc/testsuite/gcc.dg/pr80020.c new file mode 100644 index 00000000000..5e79c375dc3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr80020.c @@ -0,0 +1,26 @@ +/* PR middle-end/80020 - gcc confused about aligned_alloc argument order + { dg-compile } + { dg-options "-O2 -Wall -fdump-tree-optimized" } */ + +void sink (void*); + +void foo (void) +{ + enum { + Align = 32, + Size = 123 + }; + + void *p = __builtin_aligned_alloc (Align, Size); + unsigned n = __builtin_object_size (p, 0); + + if (n != Size) + __builtin_abort (); + + __builtin___memset_chk (p, 0, Size, n); + + sink (p); +} + +/* { dg-final { scan-tree-dump-not "abort" "optimized" } } + { dg-final { scan-tree-dump-not "memset_chk" "optimized" } } */ -- 2.30.2