This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: enable-build-with-cxx bootstrap compare broken by r149964
- From: Jason Merrill <jason at redhat dot com>
- To: Jerry Quinn <jlquinn at optonline dot net>
- Cc: Jakub Jelinek <jakub at redhat dot com>, GCC <gcc at gcc dot gnu dot org>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Sun, 01 Nov 2009 01:02:17 -0400
- Subject: Re: enable-build-with-cxx bootstrap compare broken by r149964
- References: <1250345548.19163.155.camel@cerberus.qb5.org> <4A960A78.8040704@redhat.com> <1251694626.7629.2.camel@cerberus.qb5.org> <4AAE6745.3070706@redhat.com> <4AB7B28E.7030501@redhat.com> <1253617474.4274.2795.camel@cerberus.qb5.org> <4AB8D3D1.8010704@redhat.com> <1253712164.4274.2800.camel@cerberus.qb5.org> <4ABA391C.2050903@redhat.com> <1256357452.31533.131.camel@cerberus.qb5.org> <20091026111448.GZ14664@tyan-ft48-01.lab.bos.redhat.com> <4AE5A9F4.30703@redhat.com> <1256729385.31256.445.camel@cerberus.qb5.org> <4AE864AD.30400@redhat.com> <1256792815.31256.1472.camel@cerberus.qb5.org> <4AE92982.4080308@redhat.com>
Here's the fix I'm checking in for the * path.
Jason
commit 16463ef55164d4668d6f1eeb150974452e1dbe58
Author: Jason Merrill <jason@redhat.com>
Date: Sat Oct 31 18:10:17 2009 -0400
* rtti.c (tinfo_name): Fix lengths for private case.
diff --git a/gcc/cp/rtti.c b/gcc/cp/rtti.c
index 2926f97..c7af74a 100644
--- a/gcc/cp/rtti.c
+++ b/gcc/cp/rtti.c
@@ -364,10 +364,10 @@ tinfo_name (tree type, bool mark_private)
if (mark_private)
{
/* Inject '*' at beginning of name to force pointer comparison. */
- char* buf = (char*) XALLOCAVEC (char, length + 1);
+ char* buf = (char*) XALLOCAVEC (char, length + 2);
buf[0] = '*';
- memcpy (buf + 1, name, length);
- name_string = build_string (length + 1, buf);
+ memcpy (buf + 1, name, length + 1);
+ name_string = build_string (length + 2, buf);
}
else
name_string = build_string (length + 1, name);
diff --git a/gcc/testsuite/g++.dg/rtti/typeid9.C b/gcc/testsuite/g++.dg/rtti/typeid9.C
new file mode 100644
index 0000000..381252d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/rtti/typeid9.C
@@ -0,0 +1,21 @@
+// Test that the typeid name for a local class is properly null-terminated.
+// { dg-do run }
+
+#include <string.h>
+#include <typeinfo>
+#include <stdio.h>
+
+int f()
+{
+ struct A {}; struct B {};
+ const std::type_info &ti = typeid(A);
+ const std::type_info &ti2 = typeid(B);
+ puts (ti.name());
+ puts (ti2.name());
+ return strcmp (ti.name(), "Z1fvE1A") || strcmp (ti2.name(), "Z1fvE1B");
+}
+
+int main()
+{
+ return f();
+}