This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

PATCH: C++ vs. builtins (1 of 3)



This is the first patch to resolve the C++ issues with builtins
discussed yesterday.

This patch is for the C++ regression testsuite.  It uses `std::foo'
instead of `foo' for various names that should not be in the global
namespace, but accidentally were.  It also eliminates tests that
assume that `std::foo' will be a magic builtin; we now rely on the
library to call `__builtin_foo'.

Tested on i686-pc-linux-gnu, installed on the mainline and on the
branch.

--
Mark Mitchell                   mark@codesourcery.com
CodeSourcery, LLC               http://www.codesourcery.com

2001-05-24  Mark Mitchell  <mark@codesourcery.com>

	G++ no longer defines builtins that do not begin with __builtin.
	* g++.old-deja/g++.abi/bitfields.C: Update accordingly.
	* g++.old-deja/g++.brendand/misc13.C: Likewise.
	* g++.old-deja/g++.law/builtin1.C: Likewise.
	* g++.old-deja/g++.law/cvt2.C: Likewise.
	* g++.old-deja/g++.mike/net5.C: Likewise.
	* g++.old-deja/g++.other/builtins1.C: Likewise.
	* g++.old-deja/g++.other/builtins2.C: Likewise.
	* g++.old-deja/g++.other/builtins3.C: Likewise.
	* g++.old-deja/g++.other/builtins4.C: Likewise.
	* g++.old-deja/g++.other/inline8.C: Likewise.
	* g++.old-deja/g++.robertl/eb39.C: Likewise.

Index: gcc/testsuite/g++.old-deja/g++.abi/bitfields.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.old-deja/g++.abi/bitfields.C,v
retrieving revision 1.1
diff -c -p -r1.1 bitfields.C
*** bitfields.C	1999/12/03 16:45:53	1.1
--- bitfields.C	2001/05/25 00:56:07
*************** check_bits (char *buf,
*** 55,61 ****
  #define CHECK_FIELD(AGGREGATE, FIELD, START_BIT, NUM_BITS, RVAL)          \
    do {                                                                    \
      AGGREGATE a__;                                                        \
!     memset (& a__, 0, sizeof (a__));                                      \
      a__.FIELD = -1;                                                       \
      if (! check_bits ((char *) & a__, sizeof (a__), START_BIT, NUM_BITS)) \
        return RVAL;                                                        \
--- 55,61 ----
  #define CHECK_FIELD(AGGREGATE, FIELD, START_BIT, NUM_BITS, RVAL)          \
    do {                                                                    \
      AGGREGATE a__;                                                        \
!     std::memset (& a__, 0, sizeof (a__));                                 \
      a__.FIELD = -1;                                                       \
      if (! check_bits ((char *) & a__, sizeof (a__), START_BIT, NUM_BITS)) \
        return RVAL;                                                        \
Index: gcc/testsuite/g++.old-deja/g++.brendan/misc13.C
===================================================================
RCS file: misc13.C
diff -N misc13.C
*** /sourceware/cvs-tmp/cvssieF4n	Thu May 24 17:56:29 2001
--- /dev/null	Tue May  5 13:32:27 1998
***************
*** 1,11 ****
- // Build don't link: 
- // GROUPS passed miscellaneous-bugs
- // This should only give warnings from duplicate_decls; it should not get
- // errors from push_overloaded_decl as well.
- 
- namespace std {
- extern "C"
- {
-   long unsigned int strlen(char*);// ERROR -  warning// ERROR -  warning.*
- }
- }
--- 0 ----
Index: gcc/testsuite/g++.old-deja/g++.law/builtin1.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.old-deja/g++.law/builtin1.C,v
retrieving revision 1.3
diff -c -p -r1.3 builtin1.C
*** builtin1.C	2000/10/26 23:17:34	1.3
--- builtin1.C	2001/05/25 00:56:07
***************
*** 8,17 ****
  //  the use of __builtin_alloca, and thus ends up being unresolved.
  // Special g++ Options: 
  
- extern "C" void* alloca( __SIZE_TYPE__ );
  extern "C" int printf (const char *, ...);
  
  void* junk() {
!   return std::alloca(10);
  }
  main() { printf ("PASS\n");}
--- 8,16 ----
  //  the use of __builtin_alloca, and thus ends up being unresolved.
  // Special g++ Options: 
  
  extern "C" int printf (const char *, ...);
  
  void* junk() {
!   return __builtin_alloca(10);
  }
  main() { printf ("PASS\n");}
Index: gcc/testsuite/g++.old-deja/g++.law/cvt2.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.old-deja/g++.law/cvt2.C,v
retrieving revision 1.5.6.1
diff -c -p -r1.5.6.1 cvt2.C
*** cvt2.C	2001/05/14 19:38:09	1.5.6.1
--- cvt2.C	2001/05/25 00:56:07
***************
*** 8,15 ****
  class cvec {
  public:
          ~cvec(){ delete s; }
!         cvec(const char*x) { s = new char[strlen(x)+1]; strcpy(s, x); }
! 	cvec(const cvec& c) { s = new char[strlen(c.s)+1]; strcpy(s, c.s); }
          operator const char*() { return s; }
  private:
          char *s;
--- 8,15 ----
  class cvec {
  public:
          ~cvec(){ delete s; }
!         cvec(const char*x) { s = new char[std::strlen(x)+1]; std::strcpy(s, x); }
! 	cvec(const cvec& c) { s = new char[std::strlen(c.s)+1]; std::strcpy(s, c.s); }
          operator const char*() { return s; }
  private:
          char *s;
Index: gcc/testsuite/g++.old-deja/g++.mike/net5.C
===================================================================
RCS file: net5.C
diff -N net5.C
*** /sourceware/cvs-tmp/cvsfUSfRA	Thu May 24 17:56:32 2001
--- /dev/null	Tue May  5 13:32:27 1998
***************
*** 1,10 ****
- // Build don't link:
- // Special g++ Options:
- 
- namespace std {
- volatile void abort();		// WARNING - mismatch
- }
- 
- volatile void oink() {
-   std::abort() ;
- }				// gets bogus error - 
--- 0 ----
Index: gcc/testsuite/g++.old-deja/g++.other/builtins1.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.old-deja/g++.other/builtins1.C,v
retrieving revision 1.1
diff -c -p -r1.1 builtins1.C
*** builtins1.C	2001/01/17 19:09:35	1.1
--- builtins1.C	2001/05/25 00:56:07
***************
*** 7,33 ****
  namespace std 
  {
    extern "C" void abort (void);
-   extern "C" __SIZE_TYPE__ strlen (const char *);
  }
  
  int main ()
  {
    using namespace std;
    
-   if (strlen ("hello") != 5)
-     abort ();
-   if (std::strlen ("hello") != 5)
-     abort ();
    if (::__builtin_strlen ("hello") != 5)
      abort ();
    
    return 0;
- }
- 
- extern "C"
- {
-   static __SIZE_TYPE__ ::strlen (const char *)
-   {
-     std::abort ();
-   }
  }
--- 7,20 ----
Index: gcc/testsuite/g++.old-deja/g++.other/builtins2.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.old-deja/g++.other/builtins2.C,v
retrieving revision 1.1
diff -c -p -r1.1 builtins2.C
*** builtins2.C	2001/01/17 19:09:35	1.1
--- builtins2.C	2001/05/25 00:56:07
***************
*** 7,14 ****
  namespace std 
  {
    extern "C" void abort (void);
-   extern "C" char *strcpy (char *, const char *);
-   extern "C" int memcmp (const void *, const void *, __SIZE_TYPE__);
  }
  
  int main ()
--- 7,12 ----
*************** int main ()
*** 16,40 ****
    using namespace std;
    char f[16];
    
-   if (strcpy (f, "hello world") != f
-       || memcmp (f, "hello world", sizeof ("hello world")))
-     abort ();
- 
-   if (std::strcpy (f, "bye world") != f
-       || memcmp (f, "bye world", sizeof ("bye world")))
-     abort ();
- 
    if (::__builtin_strcpy (f, "hello world") != f
!       || memcmp (f, "hello world", sizeof ("hello world")))
      abort ();
    
    return 0;
- }
- 
- extern "C"
- {
-   static char * ::strcpy (char *, const char *)
-   {
-     std::abort ();
-   }
  }
--- 14,22 ----
    using namespace std;
    char f[16];
    
    if (::__builtin_strcpy (f, "hello world") != f
!       || __builtin_memcmp (f, "hello world", sizeof ("hello world")))
      abort ();
    
    return 0;
  }
Index: gcc/testsuite/g++.old-deja/g++.other/builtins3.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.old-deja/g++.other/builtins3.C,v
retrieving revision 1.1
diff -c -p -r1.1 builtins3.C
*** builtins3.C	2001/01/17 19:09:35	1.1
--- builtins3.C	2001/05/25 00:56:07
***************
*** 7,13 ****
  namespace std 
  {
    extern "C" void abort (void);
-   extern "C" void *alloca (__SIZE_TYPE__);
  }
  
  int main ()
--- 7,12 ----
*************** int main ()
*** 15,28 ****
    using namespace std;
    void *foo;
    
-   foo = alloca (32);
-   if (!foo)
-     abort ();
- 
-   foo = std::alloca (32);
-   if (!foo)
-     abort ();
- 
    foo = ::__builtin_alloca (32);
    if (!foo)
      abort ();
--- 14,19 ----
*************** int main ()
*** 30,39 ****
    return 0;
  }
  
- extern "C"
- {
-   static void * ::alloca (__SIZE_TYPE__)
-   {
-     std::abort ();
-   }
- }
--- 21,23 ----
Index: gcc/testsuite/g++.old-deja/g++.other/builtins4.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.old-deja/g++.other/builtins4.C,v
retrieving revision 1.1
diff -c -p -r1.1 builtins4.C
*** builtins4.C	2001/01/17 19:09:35	1.1
--- builtins4.C	2001/05/25 00:56:07
***************
*** 7,27 ****
  namespace std 
  {
    extern "C" void abort (void);
-   extern "C" int printf (const char *, ...);
  }
  
  int main ()
  {
    using namespace std;
    
-   printf ("hello world\n");
-   printf ("\n");
-   printf ("%s\n", "hello world");
-   printf ("%c", '\n');
-   std::printf ("hello world\n");
-   std::printf ("\n");
-   std::printf ("%s\n", "hello world");
-   std::printf ("%c", '\n');
    ::__builtin_printf ("hello world\n");
    ::__builtin_printf ("\n");
    ::__builtin_printf ("%s\n", "hello world");
--- 7,18 ----
*************** int main ()
*** 30,39 ****
    return 0;
  }
  
- extern "C"
- {
-   static int ::printf (const char *, ...)
-   {
-     std::abort ();
-   }
- }
--- 21,23 ----
Index: gcc/testsuite/g++.old-deja/g++.other/inline8.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.old-deja/g++.other/inline8.C,v
retrieving revision 1.2
diff -c -p -r1.2 inline8.C
*** inline8.C	2000/06/12 23:48:12	1.2
--- inline8.C	2001/05/25 00:56:07
*************** public:
*** 23,45 ****
  
  NAMES_ITEM::NAMES_ITEM (const NAMES_ITEM& item2)
          {
!         size_t length=strlen(item2.name);
  
          name=new char[length+1];
!         memcpy(name,item2.name,length+1);
          }
  
  NAMES_ITEM::NAMES_ITEM (const char* name2)      
          {
!         size_t length=strlen(name2);
  
          name=new char[length+1];
!         memcpy(name,name2,length+1);
          }
  
  NAMES_ITEM::~NAMES_ITEM ()
  {
!   if (strcmp (name, "one") != 0)
      abort ();
    
    name=0;
--- 23,45 ----
  
  NAMES_ITEM::NAMES_ITEM (const NAMES_ITEM& item2)
          {
!         size_t length=std::strlen(item2.name);
  
          name=new char[length+1];
!         std::memcpy(name,item2.name,length+1);
          }
  
  NAMES_ITEM::NAMES_ITEM (const char* name2)      
          {
!         size_t length=std::strlen(name2);
  
          name=new char[length+1];
!         std::memcpy(name,name2,length+1);
          }
  
  NAMES_ITEM::~NAMES_ITEM ()
  {
!   if (std::strcmp (name, "one") != 0)
      abort ();
    
    name=0;
*************** NAMES_ITEM::~NAMES_ITEM ()
*** 47,58 ****
  
  bool NAMES_ITEM::operator==(const NAMES_ITEM& n) const
  {
!   return (strcmp(name,n.name) == 0);
  }
  
  bool operator<(const NAMES_ITEM& n1, const NAMES_ITEM& n2)
      {
!     return (strcmp(n1.name,n2.name) < 0);
      }
  
      typedef map<NAMES_ITEM,size_t,less<NAMES_ITEM> > lookup_t;
--- 47,58 ----
  
  bool NAMES_ITEM::operator==(const NAMES_ITEM& n) const
  {
!   return (std::strcmp(name,n.name) == 0);
  }
  
  bool operator<(const NAMES_ITEM& n1, const NAMES_ITEM& n2)
      {
!     return (std::strcmp(n1.name,n2.name) < 0);
      }
  
      typedef map<NAMES_ITEM,size_t,less<NAMES_ITEM> > lookup_t;
Index: gcc/testsuite/g++.old-deja/g++.robertl/eb39.C
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/g++.old-deja/g++.robertl/eb39.C,v
retrieving revision 1.5.4.1
diff -c -p -r1.5.4.1 eb39.C
*** eb39.C	2001/05/14 19:38:10	1.5.4.1
--- eb39.C	2001/05/25 00:56:07
*************** extern bool foo2 (ostream &out, istream 
*** 11,17 ****
  bool
  foo1 (ostream &out, const char *in)
  {
!   string tmp(in, strlen(in));
    stringbuf sb (tmp);
    istream fmt (&sb);
    return foo2 (out, fmt);
--- 11,17 ----
  bool
  foo1 (ostream &out, const char *in)
  {
!   string tmp(in, std::strlen(in));
    stringbuf sb (tmp);
    istream fmt (&sb);
    return foo2 (out, fmt);


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]