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]

Re: [C++ PATCH] Fix a builtin function problem


 > From: Kriang Lerdsuwanakij <lerdsuwa@users.sourceforge.net>
 > 
 > Hi
 > 
 > Certain builtin functions, especially strlen, were not 
 > properly expanded by the C++ frontend.  I found that
 > they are handled properly in build_over_call.  However,
 > its companion build_function_call_real lacks the call
 > to fold() to expand builtins.  The patch below fixes
 > this.
 > 
 > Tested on i586-pc-linux-gnu, OK to install?
 > 
 > --Kriang
 > 
 > 2001-01-15  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>
 > 
 > 	* typeck.c (build_function_call_real): Call fold on the CALL_EXPR.

Thanks for fixing this.

Jason, I'd like to install a few G++ builtins testcases to prevent
regressions in the future.  Do these look like they are correct WRT
namespace issues, etc and do they test the correct situation?

With Kriang's patch installed, they all pass.

		--Kaveh


2001-01-16  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* g++.old-deja/g++.other/builtins1.C: New test.
	* g++.old-deja/g++.other/builtins2.C: Likewise.
	* g++.old-deja/g++.other/builtins3.C: Likewise.
	* g++.old-deja/g++.other/builtins4.C: Likewise.

diff -rup orig/egcs-CVS20010115/gcc/testsuite/g++.old-deja/g++.other/builtins1.C egcs-CVS20010115/gcc/testsuite/g++.old-deja/g++.other/builtins1.C
--- orig/egcs-CVS20010115/gcc/testsuite/g++.old-deja/g++.other/builtins1.C	Tue Jan 16 08:15:54 2001
+++ egcs-CVS20010115/gcc/testsuite/g++.old-deja/g++.other/builtins1.C	Tue Jan 16 08:12:51 2001
@@ -0,0 +1,33 @@
+// Test whether this builtin minimally works in G++.
+// Origin: Kaveh Ghazi Jan 16, 2001
+// Copyright (C) 2001 Free Software Foundation.
+//
+// Special g++ Options: -O2
+
+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 ();
+  }
+}
diff -rup orig/egcs-CVS20010115/gcc/testsuite/g++.old-deja/g++.other/builtins2.C egcs-CVS20010115/gcc/testsuite/g++.old-deja/g++.other/builtins2.C
--- orig/egcs-CVS20010115/gcc/testsuite/g++.old-deja/g++.other/builtins2.C	Tue Jan 16 08:15:56 2001
+++ egcs-CVS20010115/gcc/testsuite/g++.old-deja/g++.other/builtins2.C	Tue Jan 16 08:12:51 2001
@@ -0,0 +1,40 @@
+// Test whether this builtin minimally works in G++.
+// Origin: Kaveh Ghazi Jan 16, 2001
+// Copyright (C) 2001 Free Software Foundation.
+//
+// Special g++ Options: -O2
+
+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 ()
+{
+  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 ();
+  }
+}
diff -rup orig/egcs-CVS20010115/gcc/testsuite/g++.old-deja/g++.other/builtins3.C egcs-CVS20010115/gcc/testsuite/g++.old-deja/g++.other/builtins3.C
--- orig/egcs-CVS20010115/gcc/testsuite/g++.old-deja/g++.other/builtins3.C	Tue Jan 16 08:15:58 2001
+++ egcs-CVS20010115/gcc/testsuite/g++.old-deja/g++.other/builtins3.C	Tue Jan 16 08:12:51 2001
@@ -0,0 +1,39 @@
+// Test whether this builtin minimally works in G++.
+// Origin: Kaveh Ghazi Jan 16, 2001
+// Copyright (C) 2001 Free Software Foundation.
+//
+// Special g++ Options: -O2
+
+namespace std 
+{
+  extern "C" void abort (void);
+  extern "C" void *alloca (__SIZE_TYPE__);
+}
+
+int main ()
+{
+  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 ();
+
+  return 0;
+}
+
+extern "C"
+{
+  static void *alloca (__SIZE_TYPE__)
+  {
+    std::abort ();
+  }
+}
diff -rup orig/egcs-CVS20010115/gcc/testsuite/g++.old-deja/g++.other/builtins4.C egcs-CVS20010115/gcc/testsuite/g++.old-deja/g++.other/builtins4.C
--- orig/egcs-CVS20010115/gcc/testsuite/g++.old-deja/g++.other/builtins4.C	Tue Jan 16 08:16:00 2001
+++ egcs-CVS20010115/gcc/testsuite/g++.old-deja/g++.other/builtins4.C	Tue Jan 16 08:12:51 2001
@@ -0,0 +1,39 @@
+// Test whether this builtin minimally works in G++.
+// Origin: Kaveh Ghazi Jan 16, 2001
+// Copyright (C) 2001 Free Software Foundation.
+//
+// Special g++ Options: -O2
+
+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");
+  ::__builtin_printf ("%c", '\n');
+  
+  return 0;
+}
+
+extern "C"
+{
+  static int printf (const char *, ...)
+  {
+    std::abort ();
+  }
+}

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