diff options
author | Joseph Myers <jsm28@cam.ac.uk> | 2001-11-18 03:30:57 +0000 |
---|---|---|
committer | Joseph Myers <jsm28@gcc.gnu.org> | 2001-11-18 03:30:57 +0000 |
commit | 7d14c755ce793f99c3e833e7115d954cfbed175c (patch) | |
tree | 3bf2e6da7732b3b856461efc1c4fffe0eba2760d | |
parent | 74a3070ffad610701440467a2bd0b6627a76e568 (diff) | |
download | gcc-7d14c755ce793f99c3e833e7115d954cfbed175c.zip gcc-7d14c755ce793f99c3e833e7115d954cfbed175c.tar.gz gcc-7d14c755ce793f99c3e833e7115d954cfbed175c.tar.bz2 |
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
-rw-r--r-- | gcc/ChangeLog | 10 | ||||
-rw-r--r-- | gcc/c-common.c | 50 | ||||
-rw-r--r-- | gcc/c-common.h | 2 | ||||
-rw-r--r-- | gcc/c-decl.c | 2 | ||||
-rw-r--r-- | gcc/doc/extend.texi | 4 | ||||
-rw-r--r-- | gcc/doc/invoke.texi | 17 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/no-builtin-1.c | 43 |
8 files changed, 129 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1d007a5..c27ba9d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -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 diff --git a/gcc/c-common.c b/gcc/c-common.c index 26a7f9e..6b6b36b 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -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) diff --git a/gcc/c-common.h b/gcc/c-common.h index 76c59aa..df6cd9d3 100644 --- a/gcc/c-common.h +++ b/gcc/c-common.h @@ -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 *)); diff --git a/gcc/c-decl.c b/gcc/c-decl.c index f240aac..5a34a2c 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -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")) diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 5461cae..d0fdae6 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -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}. diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index c8bfd474..83e5c97 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d79c9f6..154d9c5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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. diff --git a/gcc/testsuite/gcc.dg/no-builtin-1.c b/gcc/testsuite/gcc.dg/no-builtin-1.c new file mode 100644 index 0000000..4f392e8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/no-builtin-1.c @@ -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 (); +} |