builtin-types.def (BT_FN_STRING_CONST_STRING): New builtin type.
* builtin-types.def (BT_FN_STRING_CONST_STRING): New builtin type. (BT_FN_PTR_SIZE_SIZE): Likewise. * builtins.def (BUILT_IN_MALLOC, BUILT_IN_CALLOC, BUILT_IN_STRDUP): New built-in functions for malloc, calloc and strdup respectively. * calls.c (special_function_p): No need to handle malloc-like functions any longer. ECF_MALLOC is set via built-in attributes. * c-decl.c (duplicate_decls): Preserve pure and malloc attributes. * cp/decl.c (duplicate_decls): Preserve pure and malloc attributes. * f/com.c (duplicate_decls): Preserve pure and malloc attributes. * doc/extend.texi: Document these new built-in functions. * gcc.dg/builtins-13.c: New test case. * gcc.dg/builtins-14.c: New test case. From-SVN: r65560
This commit is contained in:
parent
e235df1f71
commit
1331d16fd4
13 changed files with 148 additions and 22 deletions
|
@ -1,3 +1,16 @@
|
|||
2003-04-13 Roger Sayle <roger@eyesopen.com>
|
||||
|
||||
* builtin-types.def (BT_FN_STRING_CONST_STRING): New builtin type.
|
||||
(BT_FN_PTR_SIZE_SIZE): Likewise.
|
||||
* builtins.def (BUILT_IN_MALLOC, BUILT_IN_CALLOC, BUILT_IN_STRDUP):
|
||||
New built-in functions for malloc, calloc and strdup respectively.
|
||||
* calls.c (special_function_p): No need to handle malloc-like
|
||||
functions any longer. ECF_MALLOC is set via built-in attributes.
|
||||
|
||||
* c-decl.c (duplicate_decls): Preserve pure and malloc attributes.
|
||||
|
||||
* doc/extend.texi: Document these new built-in functions.
|
||||
|
||||
2003-04-13 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
|
||||
|
||||
* builtins.c (expand_builtin_memcpy): Add `endp' argument, use it.
|
||||
|
|
|
@ -124,6 +124,7 @@ DEF_FUNCTION_TYPE_1 (BT_FN_FLOAT_CONST_STRING, BT_FLOAT, BT_CONST_STRING)
|
|||
DEF_FUNCTION_TYPE_1 (BT_FN_DOUBLE_CONST_STRING, BT_DOUBLE, BT_CONST_STRING)
|
||||
DEF_FUNCTION_TYPE_1 (BT_FN_LONG_DOUBLE_CONST_STRING,
|
||||
BT_LONG_DOUBLE, BT_CONST_STRING)
|
||||
DEF_FUNCTION_TYPE_1 (BT_FN_STRING_CONST_STRING, BT_STRING, BT_CONST_STRING)
|
||||
|
||||
DEF_FUNCTION_TYPE_2 (BT_FN_VOID_PTR_INT, BT_VOID, BT_PTR, BT_INT)
|
||||
DEF_FUNCTION_TYPE_2 (BT_FN_STRING_STRING_CONST_STRING,
|
||||
|
@ -158,6 +159,8 @@ DEF_FUNCTION_TYPE_2 (BT_FN_LONG_DOUBLE_LONG_DOUBLE_LONG_DOUBLE,
|
|||
BT_LONG_DOUBLE, BT_LONG_DOUBLE, BT_LONG_DOUBLE)
|
||||
DEF_FUNCTION_TYPE_2 (BT_FN_INT_CONST_STRING_VALIST_ARG,
|
||||
BT_INT, BT_CONST_STRING, BT_VALIST_ARG)
|
||||
DEF_FUNCTION_TYPE_2 (BT_FN_PTR_SIZE_SIZE,
|
||||
BT_PTR, BT_SIZE, BT_SIZE)
|
||||
|
||||
DEF_FUNCTION_TYPE_3 (BT_FN_STRING_STRING_CONST_STRING_SIZE,
|
||||
BT_STRING, BT_STRING, BT_CONST_STRING, BT_SIZE)
|
||||
|
|
|
@ -936,3 +936,19 @@ DEF_C99_BUILTIN(BUILT_IN__EXIT2,
|
|||
BT_FN_VOID_INT,
|
||||
ATTR_NORETURN_NOTHROW_LIST)
|
||||
|
||||
/* Declare malloc, calloc and strdup. */
|
||||
DEF_LIB_BUILTIN(BUILT_IN_MALLOC,
|
||||
"__builtin_malloc",
|
||||
BT_FN_PTR_SIZE,
|
||||
ATTR_MALLOC_NOTHROW_LIST)
|
||||
|
||||
DEF_LIB_BUILTIN(BUILT_IN_CALLOC,
|
||||
"__builtin_calloc",
|
||||
BT_FN_PTR_SIZE_SIZE,
|
||||
ATTR_MALLOC_NOTHROW_LIST)
|
||||
|
||||
DEF_EXT_LIB_BUILTIN(BUILT_IN_STRDUP,
|
||||
"__builtin_strdup",
|
||||
BT_FN_STRING_CONST_STRING,
|
||||
ATTR_MALLOC_NOTHROW_LIST)
|
||||
|
||||
|
|
|
@ -1391,6 +1391,8 @@ duplicate_decls (newdecl, olddecl, different_binding_level)
|
|||
DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
|
||||
DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
|
||||
|= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
|
||||
DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
|
||||
DECL_IS_PURE (newdecl) |= DECL_IS_PURE (olddecl);
|
||||
}
|
||||
}
|
||||
/* If cannot merge, then use the new type and qualifiers,
|
||||
|
|
16
gcc/calls.c
16
gcc/calls.c
|
@ -665,9 +665,6 @@ emit_call_1 (funexp, fndecl, funtype, stack_size, rounded_stack_size,
|
|||
|
||||
Similarly set LONGJMP for if the function is in the longjmp family.
|
||||
|
||||
Set MALLOC for any of the standard memory allocation functions which
|
||||
allocate from the heap.
|
||||
|
||||
Set MAY_BE_ALLOCA for any memory allocation function that might allocate
|
||||
space from the stack such as alloca. */
|
||||
|
||||
|
@ -747,19 +744,6 @@ special_function_p (fndecl, flags)
|
|||
|| ((tname[5] == 'p' || tname[5] == 'e')
|
||||
&& tname[6] == '\0'))))
|
||||
flags |= ECF_FORK_OR_EXEC;
|
||||
|
||||
/* Do not add any more malloc-like functions to this list,
|
||||
instead mark them as malloc functions using the malloc attribute.
|
||||
Note, realloc is not suitable for attribute malloc since
|
||||
it may return the same address across multiple calls.
|
||||
C++ operator new is not suitable because it is not required
|
||||
to return a unique pointer; indeed, the standard placement new
|
||||
just returns its argument. */
|
||||
else if (TYPE_MODE (TREE_TYPE (TREE_TYPE (fndecl))) == Pmode
|
||||
&& (! strcmp (tname, "malloc")
|
||||
|| ! strcmp (tname, "calloc")
|
||||
|| ! strcmp (tname, "strdup")))
|
||||
flags |= ECF_MALLOC;
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
2003-04-13 Roger Sayle <roger@eyesopen.com>
|
||||
|
||||
* decl.c (duplicate_decls): Preserve pure and malloc attributes.
|
||||
|
||||
2003-04-12 Mark Mitchell <mark@codesourcery.com>
|
||||
|
||||
PR c++/10300
|
||||
|
|
|
@ -3359,8 +3359,9 @@ duplicate_decls (tree newdecl, tree olddecl)
|
|||
{
|
||||
DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (newdecl)
|
||||
|= DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (olddecl);
|
||||
DECL_NO_LIMIT_STACK (newdecl)
|
||||
|= DECL_NO_LIMIT_STACK (olddecl);
|
||||
DECL_NO_LIMIT_STACK (newdecl) |= DECL_NO_LIMIT_STACK (olddecl);
|
||||
DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
|
||||
DECL_IS_PURE (newdecl) |= DECL_IS_PURE (olddecl);
|
||||
/* Keep the old RTL. */
|
||||
COPY_DECL_RTL (olddecl, newdecl);
|
||||
}
|
||||
|
|
|
@ -4554,6 +4554,7 @@ v4si f (v4si a, v4si b, v4si c)
|
|||
@findex atan2l
|
||||
@findex bcmp
|
||||
@findex bzero
|
||||
@findex calloc
|
||||
@findex ceil
|
||||
@findex ceilf
|
||||
@findex ceill
|
||||
|
@ -4596,6 +4597,7 @@ v4si f (v4si a, v4si b, v4si c)
|
|||
@findex log
|
||||
@findex logf
|
||||
@findex logl
|
||||
@findex malloc
|
||||
@findex memcmp
|
||||
@findex memcpy
|
||||
@findex mempcpy
|
||||
|
@ -4630,6 +4632,7 @@ v4si f (v4si a, v4si b, v4si c)
|
|||
@findex strcmp
|
||||
@findex strcpy
|
||||
@findex strcspn
|
||||
@findex strdup
|
||||
@findex strlen
|
||||
@findex strncat
|
||||
@findex strncmp
|
||||
|
@ -4670,7 +4673,8 @@ Outside strict ISO C mode (@option{-ansi}, @option{-std=c89} or
|
|||
@option{-std=c99}), the functions @code{alloca}, @code{bcmp},
|
||||
@code{bzero}, @code{_exit}, @code{ffs}, @code{fprintf_unlocked},
|
||||
@code{fputs_unlocked}, @code{index}, @code{mempcpy}, @code{printf_unlocked},
|
||||
@code{rindex}, and @code{stpcpy} may be handled as built-in functions.
|
||||
@code{rindex}, @code{stpcpy} and @code{strdup}
|
||||
may be handled as built-in functions.
|
||||
All these functions have corresponding versions
|
||||
prefixed with @code{__builtin_}, which may be used even in strict C89
|
||||
mode.
|
||||
|
@ -4695,10 +4699,10 @@ that are recognized in any mode since ISO C90 reserves these names for
|
|||
the purpose to which ISO C99 puts them. All these functions have
|
||||
corresponding versions prefixed with @code{__builtin_}.
|
||||
|
||||
The ISO C90 functions @code{abort}, @code{abs}, @code{atan2}, @code{ceil},
|
||||
@code{cos}, @code{exit},
|
||||
The ISO C90 functions @code{abort}, @code{abs}, @code{atan2},
|
||||
@code{calloc}, @code{ceil}, @code{cos}, @code{exit},
|
||||
@code{exp}, @code{fabs}, @code{floor}, @code{fmod},
|
||||
@code{fprintf}, @code{fputs}, @code{labs}, @code{log},
|
||||
@code{fprintf}, @code{fputs}, @code{labs}, @code{log}, @code{malloc},
|
||||
@code{memcmp}, @code{memcpy}, @code{memset}, @code{pow}, @code{printf},
|
||||
@code{putchar}, @code{puts}, @code{scanf}, @code{sin}, @code{snprintf},
|
||||
@code{sprintf}, @code{sqrt}, @code{sscanf},
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
2003-04-13 Roger Sayle <roger@eyesopen.com>
|
||||
|
||||
* com.c (duplicate_decls): Preserve pure and malloc attributes.
|
||||
|
||||
2003-04-12 Zack Weinberg <zack@codesourcery.com>
|
||||
|
||||
* com.c (ffecom_build_complex_constant_, ffecom_expr_)
|
||||
|
|
|
@ -13335,6 +13335,8 @@ duplicate_decls (tree newdecl, tree olddecl)
|
|||
{
|
||||
DECL_STATIC_CONSTRUCTOR(newdecl) |= DECL_STATIC_CONSTRUCTOR(olddecl);
|
||||
DECL_STATIC_DESTRUCTOR (newdecl) |= DECL_STATIC_DESTRUCTOR (olddecl);
|
||||
DECL_IS_MALLOC (newdecl) |= DECL_IS_MALLOC (olddecl);
|
||||
DECL_IS_PURE (newdecl) |= DECL_IS_PURE (olddecl);
|
||||
}
|
||||
}
|
||||
/* If cannot merge, then use the new type and qualifiers,
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
2003-04-13 Roger Sayle <roger@eyesopen.com>
|
||||
|
||||
* gcc.dg/builtins-12.c: New test case.
|
||||
* gcc.dg/builtins-13.c: New test case.
|
||||
|
||||
2003-04-13 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
|
||||
|
||||
* gcc.c-torture/execute/string-opt-18.c: New test.
|
||||
|
|
27
gcc/testsuite/gcc.dg/builtins-12.c
Normal file
27
gcc/testsuite/gcc.dg/builtins-12.c
Normal file
|
@ -0,0 +1,27 @@
|
|||
/* Copyright (C) 2003 Free Software Foundation.
|
||||
|
||||
Verify that all the malloc-like __builtin_ allocation functions are
|
||||
recognized by the compiler.
|
||||
|
||||
Written by Roger Sayle, 12th April 2003. */
|
||||
|
||||
/* { dg-do compile } */
|
||||
/* { dg-final { scan-assembler-not "__builtin_" } } */
|
||||
|
||||
typedef __SIZE_TYPE__ size_t;
|
||||
|
||||
void *test1(size_t n)
|
||||
{
|
||||
return __builtin_malloc(n);
|
||||
}
|
||||
|
||||
void *test2(size_t n, size_t s)
|
||||
{
|
||||
return __builtin_calloc(n,s);
|
||||
}
|
||||
|
||||
char *test3(const char *ptr)
|
||||
{
|
||||
return __builtin_strdup(ptr);
|
||||
}
|
||||
|
61
gcc/testsuite/gcc.dg/builtins-13.c
Normal file
61
gcc/testsuite/gcc.dg/builtins-13.c
Normal file
|
@ -0,0 +1,61 @@
|
|||
/* Copyright (C) 2003 Free Software Foundation.
|
||||
|
||||
Verify that the malloc-like __builtin_ allocation functions are
|
||||
correctly aliased by the compiler.
|
||||
|
||||
Written by Roger Sayle, 12th April 2003. */
|
||||
|
||||
/* { dg-do link } */
|
||||
|
||||
typedef __SIZE_TYPE__ size_t;
|
||||
|
||||
extern void abort (void);
|
||||
extern void *malloc (size_t);
|
||||
extern void *calloc (size_t,size_t);
|
||||
|
||||
extern void link_error (void);
|
||||
|
||||
static int x;
|
||||
|
||||
void test1(void)
|
||||
{
|
||||
int *ptr1, *ptr2;
|
||||
|
||||
ptr1 = &x;
|
||||
ptr2 = (int*) malloc (sizeof (int));
|
||||
|
||||
*ptr1 = 12;
|
||||
*ptr2 = 8;
|
||||
|
||||
if (*ptr1 != 12)
|
||||
link_error();
|
||||
}
|
||||
|
||||
void test2(void)
|
||||
{
|
||||
int *ptr1, *ptr2;
|
||||
|
||||
ptr1 = &x;
|
||||
ptr2 = (int*) calloc (1, sizeof (int));
|
||||
|
||||
*ptr1 = 12;
|
||||
*ptr2 = 8;
|
||||
|
||||
if (*ptr1 != 12)
|
||||
link_error ();
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test1 ();
|
||||
test2 ();
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef __OPTIMIZE__
|
||||
void link_error (void)
|
||||
{
|
||||
abort ();
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Add table
Reference in a new issue