aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRoger Sayle <roger@eyesopen.com>2002-03-29 20:41:53 +0000
committerMark Mitchell <mmitchel@gcc.gnu.org>2002-03-29 20:41:53 +0000
commitd52e4867caba3a5833cc2c90ac8df8fe7ccd7b76 (patch)
tree187fa816b67c22e5eb8cf4e72e061f67f62adfcc /gcc
parent5843e8704e27a84b1b2b4536bed073eee6361800 (diff)
downloadgcc-d52e4867caba3a5833cc2c90ac8df8fe7ccd7b76.zip
gcc-d52e4867caba3a5833cc2c90ac8df8fe7ccd7b76.tar.gz
gcc-d52e4867caba3a5833cc2c90ac8df8fe7ccd7b76.tar.bz2
re PR c++/5998 (regression, all builtins disabled)
* include/c_std/std_cmath.h: To prevent problems overloading g++ builtins, use the double variants from the global namespace before defining float and long double variants in std::. PR c++/5998: * decl.c (cxx_init_decl_processing): Re-enable built-in functions in the g++ front-end. (duplicate_decl): Allow redefinition of anticipated built-ins. Fix inlining problem by over-writing the old DECL_RTL. (lookup_namespace_name): Fail to find an identifier in the specified namespace if its still anticipated. (builtin_function_1): New function split out from builtin_function to create a builtin in the current namespace with given context. (builtin_function): Call builtin_function_1 to define the appropriate builtins in both the std and global namespaces. (select_decl): Don't test for anticipated decls here. (unqualified_namespace_lookup): Instead ignore them whilst searching through scopes and namespaces. * decl2.c (do_nonmember_using_decl): If a using declaration specifies an anticipated built-in function, mark it as no longer anticipated in that scope. (ambiguous_decl): Avoid resolving to an anticipated decl. * lex.c (do_scoped_id): Fail to find an identifier in the global namespace if its still anticipated. * g++.old-deja/g++.other/builtins5.C: New test. * g++.old-deja/g++.other/builtins6.C: New test. * g++.old-deja/g++.other/builtins7.C: New test. * g++.old-deja/g++.other/builtins8.C: New test. * g++.old-deja/g++.other/builtins9.C: New test. From-SVN: r51568
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog23
-rw-r--r--gcc/cp/decl.c108
-rw-r--r--gcc/cp/decl2.c14
-rw-r--r--gcc/cp/lex.c3
-rw-r--r--gcc/testsuite/ChangeLog8
-rw-r--r--gcc/testsuite/g++.old-deja/g++.other/builtins5.C16
-rw-r--r--gcc/testsuite/g++.old-deja/g++.other/builtins6.C18
-rw-r--r--gcc/testsuite/g++.old-deja/g++.other/builtins7.C20
-rw-r--r--gcc/testsuite/g++.old-deja/g++.other/builtins8.C24
-rw-r--r--gcc/testsuite/g++.old-deja/g++.other/builtins9.C13
10 files changed, 210 insertions, 37 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 6a69a7a..b7f8cb2 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,26 @@
+2002-03-28 Roger Sayle <roger@eyesopen.com>
+
+ PR c++/5998:
+ * decl.c (cxx_init_decl_processing): Re-enable built-in functions
+ in the g++ front-end.
+ (duplicate_decl): Allow redefinition of anticipated built-ins.
+ Fix inlining problem by over-writing the old DECL_RTL.
+ (lookup_namespace_name): Fail to find an identifier in the
+ specified namespace if its still anticipated.
+ (builtin_function_1): New function split out from builtin_function
+ to create a builtin in the current namespace with given context.
+ (builtin_function): Call builtin_function_1 to define the
+ appropriate builtins in both the std and global namespaces.
+ (select_decl): Don't test for anticipated decls here.
+ (unqualified_namespace_lookup): Instead ignore them whilst
+ searching through scopes and namespaces.
+ * decl2.c (do_nonmember_using_decl): If a using declaration
+ specifies an anticipated built-in function, mark it as no longer
+ anticipated in that scope.
+ (ambiguous_decl): Avoid resolving to an anticipated decl.
+ * lex.c (do_scoped_id): Fail to find an identifier in the global
+ namespace if its still anticipated.
+
2002-03-29 Neil Booth <neil@daikokuya.demon.co.uk>
* cp-lang.c (LANG_HOOKS_MAKE_TYPE): Redefine.
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 7dbb55b..1739771 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -87,6 +87,8 @@ static tree lookup_tag PARAMS ((enum tree_code, tree,
static void set_identifier_type_value_with_scope
PARAMS ((tree, tree, struct binding_level *));
static void record_unknown_type PARAMS ((tree, const char *));
+static tree builtin_function_1 PARAMS ((const char *, tree, tree, int,
+ enum built_in_class, const char *));
static tree build_library_fn_1 PARAMS ((tree, enum tree_code, tree));
static int member_function_or_else PARAMS ((tree, tree, enum overload_flags));
static void bad_specifiers PARAMS ((tree, const char *, int, int, int, int,
@@ -3145,6 +3147,10 @@ duplicate_decls (newdecl, olddecl)
{
if (TREE_CODE (newdecl) != FUNCTION_DECL)
{
+ /* Avoid warnings redeclaring anticipated built-ins. */
+ if (DECL_ANTICIPATED (olddecl))
+ return 0;
+
/* If you declare a built-in or predefined function name as static,
the old definition is overridden, but optionally warn this was a
bad choice of name. */
@@ -3172,7 +3178,10 @@ duplicate_decls (newdecl, olddecl)
}
else if (!types_match)
{
- if ((DECL_EXTERN_C_P (newdecl)
+ /* Avoid warnings redeclaring anticipated built-ins. */
+ if (DECL_ANTICIPATED (olddecl))
+ ; /* Do nothing yet. */
+ else if ((DECL_EXTERN_C_P (newdecl)
&& DECL_EXTERN_C_P (olddecl))
|| compparms (TYPE_ARG_TYPES (TREE_TYPE (newdecl)),
TYPE_ARG_TYPES (TREE_TYPE (olddecl))))
@@ -3614,6 +3623,7 @@ duplicate_decls (newdecl, olddecl)
TREE_READONLY (olddecl) = TREE_READONLY (newdecl);
TREE_THIS_VOLATILE (olddecl) = TREE_THIS_VOLATILE (newdecl);
TREE_SIDE_EFFECTS (olddecl) = TREE_SIDE_EFFECTS (newdecl);
+ COPY_DECL_RTL (newdecl, olddecl);
}
/* Merge the storage class information. */
@@ -5507,7 +5517,12 @@ lookup_namespace_name (namespace, name)
/* If we have a single function from a using decl, pull it out. */
if (TREE_CODE (val) == OVERLOAD && ! really_overloaded_fn (val))
val = OVL_FUNCTION (val);
- return val;
+
+ /* Ignore built-in functions that haven't been prototyped yet. */
+ if (!val || !DECL_P(val)
+ || !DECL_LANG_SPECIFIC(val)
+ || !DECL_ANTICIPATED (val))
+ return val;
}
error ("`%D' undeclared in namespace `%D'", name, namespace);
@@ -5786,14 +5801,6 @@ select_decl (binding, flags)
tree val;
val = BINDING_VALUE (binding);
- /* When we implicitly declare some builtin entity, we mark it
- DECL_ANTICIPATED, so that we know to ignore it until it is
- really declared. */
- if (val && DECL_P (val)
- && DECL_LANG_SPECIFIC (val)
- && DECL_ANTICIPATED (val))
- return NULL_TREE;
-
if (LOOKUP_NAMESPACES_ONLY (flags))
{
/* We are not interested in types. */
@@ -5843,9 +5850,21 @@ unqualified_namespace_lookup (name, flags, spacesp)
*spacesp = tree_cons (scope, NULL_TREE, *spacesp);
val = binding_for_name (name, scope);
- /* Initialize binding for this context. */
- BINDING_VALUE (b) = BINDING_VALUE (val);
- BINDING_TYPE (b) = BINDING_TYPE (val);
+ /* Ignore anticipated built-in functions. */
+ if (val && BINDING_VALUE (val)
+ && DECL_P (BINDING_VALUE (val))
+ && DECL_LANG_SPECIFIC (BINDING_VALUE (val))
+ && DECL_ANTICIPATED (BINDING_VALUE (val)))
+ {
+ BINDING_VALUE (b) = NULL_TREE;
+ BINDING_TYPE (b) = NULL_TREE;
+ }
+ else
+ {
+ /* Initialize binding for this context. */
+ BINDING_VALUE (b) = BINDING_VALUE (val);
+ BINDING_TYPE (b) = BINDING_TYPE (val);
+ }
/* Add all _DECLs seen through local using-directives. */
for (level = current_binding_level;
@@ -6435,12 +6454,6 @@ cxx_init_decl_processing ()
flag_inline_functions = 0;
}
- /* In C++, we never create builtin functions whose name does not
- begin with `__'. Users should be using headers to get prototypes
- in C++. It would be nice if we could warn when `-fbuiltin' is
- used explicitly, but we do not have that information. */
- flag_no_builtin = 1;
-
/* Initially, C. */
current_lang_name = lang_name_c;
@@ -6704,10 +6717,9 @@ cp_make_fname_decl (id, type_dep)
return decl;
}
-/* Entry point for the benefit of c_common_nodes_and_builtins.
-
- Make a definition for a builtin function named NAME and whose data type
- is TYPE. TYPE should be a function type with argument types.
+/* Make a definition for a builtin function named NAME in the current
+ namespace, whose data type is TYPE and whose context is CONTEXT.
+ TYPE should be a function type with argument types.
CLASS and CODE tell later passes how to compile calls to this function.
See tree.h for possible values.
@@ -6715,10 +6727,11 @@ cp_make_fname_decl (id, type_dep)
If LIBNAME is nonzero, use that for DECL_ASSEMBLER_NAME,
the name to be called if we can't opencode the function. */
-tree
-builtin_function (name, type, code, class, libname)
+static tree
+builtin_function_1 (name, type, context, code, class, libname)
const char *name;
tree type;
+ tree context;
int code;
enum built_in_class class;
const char *libname;
@@ -6726,23 +6739,13 @@ builtin_function (name, type, code, class, libname)
tree decl = build_library_fn_1 (get_identifier (name), ERROR_MARK, type);
DECL_BUILT_IN_CLASS (decl) = class;
DECL_FUNCTION_CODE (decl) = code;
+ DECL_CONTEXT (decl) = context;
/* The return builtins leave the current function. */
if (code == BUILT_IN_RETURN || code == BUILT_IN_EH_RETURN)
TREE_THIS_VOLATILE (decl) = 1;
- my_friendly_assert (DECL_CONTEXT (decl) == NULL_TREE, 392);
-
- /* All builtins that don't begin with an `_' should go in the `std'
- namespace. */
- if (name[0] != '_')
- {
- push_namespace (std_identifier);
- DECL_CONTEXT (decl) = std_node;
- }
pushdecl (decl);
- if (name[0] != '_')
- pop_namespace ();
/* Since `pushdecl' relies on DECL_ASSEMBLER_NAME instead of DECL_NAME,
we cannot change DECL_ASSEMBLER_NAME until we have installed this
@@ -6762,6 +6765,39 @@ builtin_function (name, type, code, class, libname)
return decl;
}
+/* Entry point for the benefit of c_common_nodes_and_builtins.
+
+ Make a defintion for a builtin function named NAME and whose data type
+ is TYPE. TYPE should be a function type with argument types. This
+ function places the anticipated declaration in the global namespace
+ and additionally in the std namespace if appropriate.
+
+ CLASS and CODE tell later passes how to compile calls to this function.
+ See tree.h for possible values.
+
+ If LIBNAME is nonzero, use that for DECL_ASSEMBLER_NAME,
+ the name to be called if we can't opencode the function. */
+
+tree
+builtin_function (name, type, code, class, libname)
+ const char *name;
+ tree type;
+ int code;
+ enum built_in_class class;
+ const char *libname;
+{
+ /* All builtins that don't begin with an '_' should additionally
+ go in the 'std' namespace. */
+ if (name[0] != '_')
+ {
+ push_namespace (std_identifier);
+ builtin_function_1 (name, type, std_node, code, class, libname);
+ pop_namespace ();
+ }
+
+ return builtin_function_1 (name, type, NULL_TREE, code, class, libname);
+}
+
/* Generate a FUNCTION_DECL with the typical flags for a runtime library
function. Not called directly. */
diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index 6763b45..95dc8e0 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -4178,6 +4178,11 @@ ambiguous_decl (name, old, new, flags)
if (LOOKUP_TYPES_ONLY (flags))
val = NULL_TREE;
break;
+ case FUNCTION_DECL:
+ /* Ignore built-in functions that are still anticipated. */
+ if (LOOKUP_QUALIFIERS_ONLY (flags) || DECL_ANTICIPATED (val))
+ val = NULL_TREE;
+ break;
default:
if (LOOKUP_QUALIFIERS_ONLY (flags))
val = NULL_TREE;
@@ -4930,6 +4935,15 @@ do_nonmember_using_decl (scope, name, oldval, oldtype, newval, newtype)
else if (compparms (TYPE_ARG_TYPES (TREE_TYPE (new_fn)),
TYPE_ARG_TYPES (TREE_TYPE (old_fn))))
{
+ /* If this using declaration introduces a function
+ recognized as a built-in, no longer mark it as
+ anticipated in this scope. */
+ if (DECL_ANTICIPATED (old_fn))
+ {
+ DECL_ANTICIPATED (old_fn) = 0;
+ break;
+ }
+
/* There was already a non-using declaration in
this scope with the same parameter types. If both
are the same extern "C" functions, that's ok. */
diff --git a/gcc/cp/lex.c b/gcc/cp/lex.c
index 8ab072e..e9e660d 100644
--- a/gcc/cp/lex.c
+++ b/gcc/cp/lex.c
@@ -1326,7 +1326,8 @@ do_scoped_id (token, parsing)
id = IDENTIFIER_GLOBAL_VALUE (token);
if (parsing && yychar == YYEMPTY)
yychar = yylex ();
- if (! id)
+ if (!id || (TREE_CODE (id) == FUNCTION_DECL
+ && DECL_ANTICIPATED (id)))
{
if (processing_template_decl)
{
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index fec72b8..606df33 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2002-03-28 Roger Sayle <roger@eyesopen.com>
+
+ * g++.old-deja/g++.other/builtins5.C: New test.
+ * g++.old-deja/g++.other/builtins6.C: New test.
+ * g++.old-deja/g++.other/builtins7.C: New test.
+ * g++.old-deja/g++.other/builtins8.C: New test.
+ * g++.old-deja/g++.other/builtins9.C: New test.
+
2002-03-29 Jakub Jelinek <jakub@redhat.com>
* g++.dg/opt/static1.C: New test.
diff --git a/gcc/testsuite/g++.old-deja/g++.other/builtins5.C b/gcc/testsuite/g++.old-deja/g++.other/builtins5.C
new file mode 100644
index 0000000..9a2cdaf
--- /dev/null
+++ b/gcc/testsuite/g++.old-deja/g++.other/builtins5.C
@@ -0,0 +1,16 @@
+// Build don't link:
+// Test that built-in functions aren't recognized without a prototype.
+// Origin: Roger Sayle Mar 20, 2002
+// Copyright (C) 2002 Free Software Foundation.
+
+int
+foo ()
+{
+ return (int) ::strlen ("foo"); // ERROR - undeclared
+}
+
+int
+bar ()
+{
+ return (int) std::strlen ("bar"); // ERROR - undeclared
+}
diff --git a/gcc/testsuite/g++.old-deja/g++.other/builtins6.C b/gcc/testsuite/g++.old-deja/g++.other/builtins6.C
new file mode 100644
index 0000000..347f4ad
--- /dev/null
+++ b/gcc/testsuite/g++.old-deja/g++.other/builtins6.C
@@ -0,0 +1,18 @@
+// Test that built-in functions are recognized with a prototype.
+// Origin: Roger Sayle Mar 20, 2002
+// Copyright (C) 2002 Free Software Foundation.
+//
+// Special g++ Options: -O2
+
+typedef __SIZE_TYPE__ size_t;
+extern "C" size_t strlen (const char*);
+extern "C" void link_error (void);
+
+int
+main ()
+{
+ if (strlen ("foo") != 3)
+ link_error ();
+ return 0;
+}
+
diff --git a/gcc/testsuite/g++.old-deja/g++.other/builtins7.C b/gcc/testsuite/g++.old-deja/g++.other/builtins7.C
new file mode 100644
index 0000000..9d4cb74
--- /dev/null
+++ b/gcc/testsuite/g++.old-deja/g++.other/builtins7.C
@@ -0,0 +1,20 @@
+// Test that built-in functions are recognized with a prototype.
+// Origin: Roger Sayle Mar 20, 2002
+// Copyright (C) 2002 Free Software Foundation.
+//
+// Special g++ Options: -O2
+
+extern "C" void link_error (void);
+
+namespace std {
+typedef __SIZE_TYPE__ size_t;
+extern "C" size_t strlen (const char*);
+}
+
+int
+main ()
+{
+ if (std::strlen ("foo") != 3)
+ link_error ();
+ return 0;
+}
diff --git a/gcc/testsuite/g++.old-deja/g++.other/builtins8.C b/gcc/testsuite/g++.old-deja/g++.other/builtins8.C
new file mode 100644
index 0000000..4eaa56e
--- /dev/null
+++ b/gcc/testsuite/g++.old-deja/g++.other/builtins8.C
@@ -0,0 +1,24 @@
+// Test that built-in functions are recognized with a prototype.
+// Origin: Roger Sayle Mar 20, 2002
+// Copyright (C) 2002 Free Software Foundation.
+//
+// Special g++ Options: -O2
+
+
+extern "C" void link_error (void);
+
+namespace std {
+typedef __SIZE_TYPE__ size_t;
+extern "C" size_t strlen (const char*);
+}
+
+using namespace std;
+
+int
+main ()
+{
+ if (strlen ("foo") != 3)
+ link_error ();
+ return 0;
+}
+
diff --git a/gcc/testsuite/g++.old-deja/g++.other/builtins9.C b/gcc/testsuite/g++.old-deja/g++.other/builtins9.C
new file mode 100644
index 0000000..8f32c9f
--- /dev/null
+++ b/gcc/testsuite/g++.old-deja/g++.other/builtins9.C
@@ -0,0 +1,13 @@
+// Test that inline redeclarations of builtins are emitted.
+// Origin: Roger Sayle Mar 28, 2002
+// Copyright (C) 2002 Free Software Foundation.
+
+namespace std {
+ inline int fabs (void) { return 0; }
+}
+
+
+int main ()
+{
+ return std::fabs ();
+}