Commit c7b6c6cd by Kaveh R. Ghazi Committed by Kaveh Ghazi

builtins.c (expand_builtin): Handle BUILT_IN_INDEX and BUILT_IN_RINDEX.

	* builtins.c (expand_builtin): Handle BUILT_IN_INDEX and
	BUILT_IN_RINDEX.  Add missing checks for BUILT_IN_STRCHR and
	BUILT_IN_STRRCHR.

	* builtins.def (BUILT_IN_INDEX, BUILT_IN_RINDEX): New entries.

	* c-common.c (c_common_nodes_and_builtins): Declare index and
	rindex when nonansi builtins are allowed.

	* extend.texi (index, rindex): Document new builtins.

testsuite:
	* gcc.c-torture/execute/string-opt-3.c: Also test builtin rindex.
	* gcc.c-torture/execute/string-opt-4.c: Also test builtin index.

From-SVN: r37416
parent 34f6fbdb
2000-11-12 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* builtins.c (expand_builtin): Handle BUILT_IN_INDEX and
BUILT_IN_RINDEX. Add missing checks for BUILT_IN_STRCHR and
BUILT_IN_STRRCHR.
* builtins.def (BUILT_IN_INDEX, BUILT_IN_RINDEX): New entries.
* c-common.c (c_common_nodes_and_builtins): Declare index and
rindex when nonansi builtins are allowed.
* extend.texi (index, rindex): Document new builtins.
2000-11-12 Mark Mitchell <mark@codesourcery.com> 2000-11-12 Mark Mitchell <mark@codesourcery.com>
* configure.in: Turn on libstdc++ V3 by default. * configure.in: Turn on libstdc++ V3 by default.
......
...@@ -2746,6 +2746,8 @@ expand_builtin (exp, target, subtarget, mode, ignore) ...@@ -2746,6 +2746,8 @@ expand_builtin (exp, target, subtarget, mode, ignore)
|| fcode == BUILT_IN_FSQRT || fcode == BUILT_IN_MEMSET || fcode == BUILT_IN_FSQRT || fcode == BUILT_IN_MEMSET
|| fcode == BUILT_IN_MEMCPY || fcode == BUILT_IN_MEMCMP || fcode == BUILT_IN_MEMCPY || fcode == BUILT_IN_MEMCMP
|| fcode == BUILT_IN_BCMP || fcode == BUILT_IN_BZERO || fcode == BUILT_IN_BCMP || fcode == BUILT_IN_BZERO
|| fcode == BUILT_IN_INDEX || fcode == BUILT_IN_RINDEX
|| fcode == BUILT_IN_STRCHR || fcode == BUILT_IN_STRRCHR
|| fcode == BUILT_IN_STRLEN || fcode == BUILT_IN_STRCPY || fcode == BUILT_IN_STRLEN || fcode == BUILT_IN_STRCPY
|| fcode == BUILT_IN_STRSTR || fcode == BUILT_IN_STRPBRK || fcode == BUILT_IN_STRSTR || fcode == BUILT_IN_STRPBRK
|| fcode == BUILT_IN_STRCMP || fcode == BUILT_IN_FFS || fcode == BUILT_IN_STRCMP || fcode == BUILT_IN_FFS
...@@ -2888,12 +2890,14 @@ expand_builtin (exp, target, subtarget, mode, ignore) ...@@ -2888,12 +2890,14 @@ expand_builtin (exp, target, subtarget, mode, ignore)
return target; return target;
break; break;
case BUILT_IN_INDEX:
case BUILT_IN_STRCHR: case BUILT_IN_STRCHR:
target = expand_builtin_strchr (arglist, target, mode); target = expand_builtin_strchr (arglist, target, mode);
if (target) if (target)
return target; return target;
break; break;
case BUILT_IN_RINDEX:
case BUILT_IN_STRRCHR: case BUILT_IN_STRRCHR:
target = expand_builtin_strrchr (arglist, target, mode); target = expand_builtin_strrchr (arglist, target, mode);
if (target) if (target)
......
...@@ -36,6 +36,8 @@ DEF_BUILTIN(BUILT_IN_MEMCMP) ...@@ -36,6 +36,8 @@ DEF_BUILTIN(BUILT_IN_MEMCMP)
DEF_BUILTIN(BUILT_IN_MEMSET) DEF_BUILTIN(BUILT_IN_MEMSET)
DEF_BUILTIN(BUILT_IN_BZERO) DEF_BUILTIN(BUILT_IN_BZERO)
DEF_BUILTIN(BUILT_IN_BCMP) DEF_BUILTIN(BUILT_IN_BCMP)
DEF_BUILTIN(BUILT_IN_INDEX)
DEF_BUILTIN(BUILT_IN_RINDEX)
DEF_BUILTIN(BUILT_IN_STRCPY) DEF_BUILTIN(BUILT_IN_STRCPY)
DEF_BUILTIN(BUILT_IN_STRCMP) DEF_BUILTIN(BUILT_IN_STRCMP)
DEF_BUILTIN(BUILT_IN_STRLEN) DEF_BUILTIN(BUILT_IN_STRLEN)
......
...@@ -5045,6 +5045,12 @@ c_common_nodes_and_builtins () ...@@ -5045,6 +5045,12 @@ c_common_nodes_and_builtins ()
/* Suppress error if redefined as a non-function. */ /* Suppress error if redefined as a non-function. */
DECL_BUILT_IN_NONANSI (temp) = 1; DECL_BUILT_IN_NONANSI (temp) = 1;
temp = builtin_function ("index", string_ftype_string_int,
BUILT_IN_INDEX, BUILT_IN_NORMAL, NULL_PTR);
DECL_BUILT_IN_NONANSI (temp) = 1;
temp = builtin_function ("rindex", string_ftype_string_int,
BUILT_IN_RINDEX, BUILT_IN_NORMAL, NULL_PTR);
DECL_BUILT_IN_NONANSI (temp) = 1;
/* The system prototypes for these functions have many /* The system prototypes for these functions have many
variations, so don't specify parameters to avoid conflicts. variations, so don't specify parameters to avoid conflicts.
The expand_* functions check the argument types anyway. */ The expand_* functions check the argument types anyway. */
...@@ -5175,6 +5181,10 @@ c_common_nodes_and_builtins () ...@@ -5175,6 +5181,10 @@ c_common_nodes_and_builtins ()
BUILT_IN_BZERO, BUILT_IN_NORMAL, "bzero"); BUILT_IN_BZERO, BUILT_IN_NORMAL, "bzero");
builtin_function ("__builtin_bcmp", bcmp_ftype, builtin_function ("__builtin_bcmp", bcmp_ftype,
BUILT_IN_BCMP, BUILT_IN_NORMAL, "bcmp"); BUILT_IN_BCMP, BUILT_IN_NORMAL, "bcmp");
builtin_function ("__builtin_index", string_ftype_string_int,
BUILT_IN_INDEX, BUILT_IN_NORMAL, "index");
builtin_function ("__builtin_rindex", string_ftype_string_int,
BUILT_IN_RINDEX, BUILT_IN_NORMAL, "rindex");
builtin_function ("__builtin_strcmp", int_ftype_string_string, builtin_function ("__builtin_strcmp", int_ftype_string_string,
BUILT_IN_STRCMP, BUILT_IN_NORMAL, "strcmp"); BUILT_IN_STRCMP, BUILT_IN_NORMAL, "strcmp");
builtin_function ("__builtin_strstr", string_ftype_string_string, builtin_function ("__builtin_strstr", string_ftype_string_string,
......
...@@ -3247,12 +3247,14 @@ function as well. ...@@ -3247,12 +3247,14 @@ function as well.
@findex fabsl @findex fabsl
@findex ffs @findex ffs
@findex fputs @findex fputs
@findex index
@findex labs @findex labs
@findex llabs @findex llabs
@findex memcmp @findex memcmp
@findex memcpy @findex memcpy
@findex memset @findex memset
@findex printf @findex printf
@findex rindex
@findex sin @findex sin
@findex sinf @findex sinf
@findex sinl @findex sinl
...@@ -3289,9 +3291,10 @@ and presumed not to return, but otherwise are not built in. ...@@ -3289,9 +3291,10 @@ and presumed not to return, but otherwise are not built in.
@samp{-std=c89} or @samp{-std=c99}). @samp{-std=c89} or @samp{-std=c99}).
Outside strict ISO C mode, the functions @code{alloca}, @code{bcmp}, Outside strict ISO C mode, the functions @code{alloca}, @code{bcmp},
@code{bzero}, and @code{ffs} may be handled as builtins. Corresponding @code{bzero}, @code{index}, @code{rindex} and @code{ffs} may be handled
versions @code{__builtin_alloca}, @code{__builtin_bcmp}, as builtins. Corresponding versions @code{__builtin_alloca},
@code{__builtin_bzero}, and @code{__builtin_ffs} are also recognized in @code{__builtin_bcmp}, @code{__builtin_bzero}, @code{__builtin_index},
@code{__builtin_rindex} and @code{__builtin_ffs} are also recognized in
strict ISO C mode. strict ISO C mode.
The ISO C99 function @code{llabs} is handled as a builtin except in The ISO C99 function @code{llabs} is handled as a builtin except in
......
2000-11-12 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* gcc.c-torture/execute/string-opt-3.c: Also test builtin rindex.
* gcc.c-torture/execute/string-opt-4.c: Also test builtin index.
2000-11-11 Mark Mitchell <mark@codesourcery.com> 2000-11-11 Mark Mitchell <mark@codesourcery.com>
* g++.brendan/err-msg8.C: Avoid capricious line-number issues with * g++.brendan/err-msg8.C: Avoid capricious line-number issues with
......
/* Copyright (C) 2000 Free Software Foundation. /* Copyright (C) 2000 Free Software Foundation.
Ensure all expected transformations of builtin strlen, strcmp and strrchr Ensure all expected transformations of builtin strlen, strcmp,
occur and perform correctly. strrchr and rindex occur and perform correctly.
Written by Jakub Jelinek, 11/7/2000. */ Written by Jakub Jelinek, 11/7/2000. */
...@@ -55,10 +55,22 @@ int main() ...@@ -55,10 +55,22 @@ int main()
abort (); abort ();
if (x != 8) if (x != 8)
abort (); abort ();
/* For systems which don't have rindex, we test the __builtin_
version to avoid spurious link failures at -O0. We only need to
test one case since everything is handled in the same code path
as builtin strrchr. */
if (__builtin_rindex ("hello", 'z') != 0)
abort ();
return 0; return 0;
} }
static char *
rindex (const char *s, int c)
{
abort ();
}
#ifdef __OPTIMIZE__ #ifdef __OPTIMIZE__
/* When optimizing, all the above cases should be transformed into /* When optimizing, all the above cases should be transformed into
something else. So any remaining calls to the original function something else. So any remaining calls to the original function
......
/* Copyright (C) 2000 Free Software Foundation. /* Copyright (C) 2000 Free Software Foundation.
Ensure all expected transformations of builtin strchr occur and Ensure all expected transformations of builtin strchr and index
perform correctly. occur and perform correctly.
Written by Jakub Jelinek, 11/7/2000. */ Written by Jakub Jelinek, 11/7/2000. */
...@@ -20,10 +20,22 @@ int main() ...@@ -20,10 +20,22 @@ int main()
abort (); abort ();
if (strchr (foo, '\0') != foo + 11) if (strchr (foo, '\0') != foo + 11)
abort (); abort ();
/* For systems which don't have index, we test the __builtin_
version to avoid spurious link failures at -O0. We only need to
test one case since everything is handled in the same code path
as builtin strchr. */
if (__builtin_index ("hello", 'z') != 0)
abort ();
return 0; return 0;
} }
static char *
index (const char *s, int c)
{
abort ();
}
#ifdef __OPTIMIZE__ #ifdef __OPTIMIZE__
/* When optimizing, all the above cases should be transformed into /* When optimizing, all the above cases should be transformed into
something else. So any remaining calls to the original function something else. So any remaining calls to the original function
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment