c-common.c (struct disabled_builtin, [...]): New.

* c-common.c (struct disabled_builtin, disabled_builtins,
	disable_builtin_function, builtin_function_disabled_p): New.
	(builtin_function_2): Check for disabled built-in functions.
	* c-common.h (disable_builtin_function): Declare.
	* c-decl.c (c_decode_option): Handle -fno-builtin-FUNCTION.
	* doc/invoke.texi: Document -fno-builtin-FUNCTION.
	* doc/extend.texi: Mention -fno-builtin-FUNCTION.

testsuite:
	* gcc.dg/no-builtin-1.c: New test.

From-SVN: r47133
This commit is contained in:
Joseph Myers 2001-11-18 03:30:57 +00:00 committed by Joseph Myers
parent 74a3070ffa
commit 7d14c755ce
8 changed files with 129 additions and 3 deletions

View File

@ -1,3 +1,13 @@
2001-11-18 Joseph S. Myers <jsm28@cam.ac.uk>
* c-common.c (struct disabled_builtin, disabled_builtins,
disable_builtin_function, builtin_function_disabled_p): New.
(builtin_function_2): Check for disabled built-in functions.
* c-common.h (disable_builtin_function): Declare.
* c-decl.c (c_decode_option): Handle -fno-builtin-FUNCTION.
* doc/invoke.texi: Document -fno-builtin-FUNCTION.
* doc/extend.texi: Mention -fno-builtin-FUNCTION.
2001-11-17 Craig Rodrigues <rodrigc@gcc.gnu.org>
PR target/4606

View File

@ -2703,6 +2703,53 @@ build_va_arg (expr, type)
}
/* Linked list of disabled built-in functions. */
typedef struct disabled_builtin
{
const char *name;
struct disabled_builtin *next;
} disabled_builtin;
static disabled_builtin *disabled_builtins = NULL;
static bool builtin_function_disabled_p PARAMS ((const char *));
/* Disable a built-in function specified by -fno-builtin-NAME. If NAME
begins with "__builtin_", give an error. */
void
disable_builtin_function (name)
const char *name;
{
if (strncmp (name, "__builtin_", strlen ("__builtin_")) == 0)
error ("cannot disable built-in function `%s'", name);
else
{
disabled_builtin *new = xmalloc (sizeof (disabled_builtin));
new->name = name;
new->next = disabled_builtins;
disabled_builtins = new;
}
}
/* Return true if the built-in function NAME has been disabled, false
otherwise. */
static bool
builtin_function_disabled_p (name)
const char *name;
{
disabled_builtin *p;
for (p = disabled_builtins; p != NULL; p = p->next)
{
if (strcmp (name, p->name) == 0)
return true;
}
return false;
}
/* Possibly define a builtin function with one or two names. BUILTIN_NAME
is an __builtin_-prefixed name; NAME is the ordinary name; one or both
of these may be NULL (though both being NULL is useless).
@ -2743,7 +2790,8 @@ builtin_function_2 (builtin_name, name, builtin_type, type, function_code,
TREE_SIDE_EFFECTS (bdecl) = 1;
}
}
if (name != 0 && !flag_no_builtin && !(nonansi_p && flag_no_nonansi_builtin))
if (name != 0 && !flag_no_builtin && !builtin_function_disabled_p (name)
&& !(nonansi_p && flag_no_nonansi_builtin))
{
decl = builtin_function (name, type, function_code, class, NULL);
if (nonansi_p)

View File

@ -538,6 +538,8 @@ extern tree c_build_qualified_type PARAMS ((tree, int));
frontends. */
extern void c_common_nodes_and_builtins PARAMS ((void));
extern void disable_builtin_function PARAMS ((const char *));
extern tree build_va_arg PARAMS ((tree, tree));
extern const char *c_common_lang_init PARAMS ((const char *));

View File

@ -596,6 +596,8 @@ c_decode_option (argc, argv)
flag_no_builtin = 0;
else if (!strcmp (p, "-fno-builtin"))
flag_no_builtin = 1;
else if (!strncmp (p, "-fno-builtin-", strlen ("-fno-builtin-")))
disable_builtin_function (p + strlen ("-fno-builtin-"));
else if (p[0] == '-' && p[1] == 'f' && dump_switch_p (p + 2))
;
else if (!strcmp (p, "-ansi"))

View File

@ -4376,7 +4376,9 @@ The ISO C89 functions @code{abs}, @code{cos}, @code{fabs},
@code{strlen}, @code{strncat}, @code{strncmp}, @code{strncpy},
@code{strpbrk}, @code{strrchr}, @code{strspn}, and @code{strstr} are all
recognized as built-in functions unless @option{-fno-builtin} is
specified. All of these functions have corresponding versions prefixed
specified (or @option{-fno-builtin-@var{function}} is specified for an
individual function). All of these functions have
corresponding versions prefixed
with @code{__builtin_}, except that the version for @code{sqrt} is
called @code{__builtin_fsqrt}.

View File

@ -162,7 +162,7 @@ in the following sections.
@xref{C Dialect Options,,Options Controlling C Dialect}.
@gccoptlist{
-ansi -std=@var{standard} -aux-info @var{filename} @gol
-fno-asm -fno-builtin @gol
-fno-asm -fno-builtin -fno-builtin-@var{function} @gol
-fhosted -ffreestanding @gol
-trigraphs -traditional -traditional-cpp @gol
-fallow-single-precision -fcond-mismatch @gol
@ -1025,6 +1025,7 @@ switch only affects the @code{asm} and @code{typeof} keywords, since
@code{inline} is a standard keyword in ISO C99.
@item -fno-builtin
@itemx -fno-builtin-@var{function} @r{(C and Objective-C only)}
@opindex fno-builtin
@cindex built-in functions
Don't recognize built-in functions that do not begin with
@ -1049,6 +1050,20 @@ using the @samp{__builtin_} prefix. The GNU C++ Standard Library uses
built-in functions to implement many functions (like
@code{std::strchr}), so that you automatically get efficient code.
With the @option{-fno-builtin-@var{function}} option, not available
when compiling C++, only the built-in function @var{function} is
disabled. @var{function} must not begin with @samp{__builtin_}. If a
function is named this is not built-in in this version of GCC, this
option is ignored. There is no corresponding
@option{-fbuiltin-@var{function}} option; if you wish to enable
built-in functions selectively when using @option{-fno-builtin} or
@option{-ffreestanding}, you may define macros such as:
@smallexample
#define abs(n) __builtin_abs ((n))
#define strcpy(d, s) __builtin_strcpy ((d), (s))
@end smallexample
@item -fhosted
@opindex fhosted
@cindex hosted environment

View File

@ -1,3 +1,7 @@
2001-11-18 Joseph S. Myers <jsm28@cam.ac.uk>
* gcc.dg/no-builtin-1.c: New test.
2001-11-16 Jakub Jelinek <jakub@redhat.com>
* gcc.c-torture/execute/20011115-1.c: New test.

View File

@ -0,0 +1,43 @@
/* Test for -fno-builtin-FUNCTION. */
/* Origin: Joseph Myers <jsm28@cam.ac.uk>. */
/* { dg-do run } */
/* { dg-options "-fno-builtin-abs" } */
/* GCC normally handles abs and labs as built-in functions even without
optimization. So test that with -fno-builtin-abs, labs is so handled
but abs isn't. */
int abs_called = 0;
extern int abs (int);
extern long labs (long);
extern void abort (void);
extern void exit (int);
int
main (void)
{
if (labs (0) != 0)
abort ();
if (abs (0) != 0)
abort ();
if (!abs_called)
abort ();
exit (0);
}
/* The labs call above should have been optimized, but the abs call
shouldn't have been. */
static int
abs (int x)
{ /* { dg-warning "static" "static decl warning" } */
abs_called = 1;
return (x < 0 ? -1 : x);
}
static long
labs (long x)
{
abort ();
}