[PATCH] Builtins and C++ and such

Roger Sayle roger@eyesopen.com
Thu Mar 21 09:17:00 GMT 2002


Hi Mark,
> Well, OK.  I'm certainly happy not to have to write the code myself.
>
> The new builtin_function needs to say what all of its parameters are
> in its comments.  Roger, would you commit both patches, with that
> change, or -- if you do not have checkin privileges -- send me an
> email with the combined patch, including that change, and then I'll
> be happy to apply it for you?

My apologies.  Once again things are never as simple as they first
appear.  Although, yesterday's "re-enable std:: builtins", and
December's "builtins in std:: and ::" patches both bootstraped without
regressions independently (with builtins enabled), the two patches
applied together introduce 5 failures in the g++ testsuite.

The problem is resolution in ambiguous_decl where a single function
call can match a builtin in one namespace that's been prototyped or
by an anticipated builtin in the second namespace that hasn't.  I'm
working on the obvious patch, to always resolve to the prototyped
scope.

I thought I'd explain where things were rather than have people
waiting and wondering.

However, if safely enabling just the std:: builtins is seen as a
significant improvement, here's take 2 of yesterday's patch.  By
deleting the assignment to flag_no_builtins, we no longer override
the "-fno-builtin" command line option, which should provide a
workaround if anyone encounters problems.  I've also added a new
test case, that check's that we correctly issue the undeclared
warnings.  This fails on GCC 2.x, but was fixed by Mark Mitchell
for GCC 3.x by disabling builtins.  Adding this to the testsuite
ensures that we don't break things again in the future.

Checked by bootstrapping and "make -k check" on i686-pc-linux-gnu
without any new regressions.  If this is still suitable, I don't
have check-in priviledges.  Sorry for the delay, I'll have a follow
up patch in a day or two.



2002-03-21  Roger Sayle  <roger@eyesopen.com>
	* decl.c (cxx_init_decl_processing): Re-enable built-in functions
	in the g++ front-end.  (lookup_namespace_name): Fail to find an
	identifier in the specified namespace if its still anticipated.
	* 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.

2002-03-21  Roger Sayle  <roger@eyesopen.com>
	* g++.old-deja/g++.other/builtins5.C: New test.



diff -c3pr gcc/gcc/cp/decl.c patch+/gcc/cp/decl.c
*** gcc/gcc/cp/decl.c	Tue Mar 19 21:31:30 2002
--- patch+/gcc/cp/decl.c	Thu Mar 21 10:17:04 2002
*************** lookup_namespace_name (namespace, name)
*** 5507,5513 ****
        /* 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;
      }

    error ("`%D' undeclared in namespace `%D'", name, namespace);
--- 5507,5518 ----
        /* 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);
!
!       /* 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);
*************** cxx_init_decl_processing ()
*** 6435,6446 ****
        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;

--- 6440,6445 ----
diff -c3pr gcc/gcc/cp/decl2.c patch+/gcc/cp/decl2.c
*** gcc/gcc/cp/decl2.c	Wed Mar 20 21:08:25 2002
--- patch+/gcc/cp/decl2.c	Thu Mar 21 02:05:02 2002
*************** do_nonmember_using_decl (scope, name, ol
*** 4928,4933 ****
--- 4928,4942 ----
  	      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.  */
*** /dev/null	Thu Aug 30 14:30:55 2001
--- builtins5.C	Wed Mar 20 21:55:21 2002
***************
*** 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
+ }


Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833



More information about the Gcc-patches mailing list