2017-03-14 Martin Sebor <msebor@redhat.com>
+ 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".
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. */
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)
+2017-03-14 Martin Sebor <msebor@redhat.com>
+
+ 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 <bschmidt@redhat.com>
PR rtl-optimization/79728
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" } */
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" } */
{
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" } */
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" } */
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));
{
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);
--- /dev/null
+/* 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" } } */