aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2007-11-01 23:50:32 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2007-11-01 23:50:32 +0100
commit3a44f39543e5c76226975a7897e3e8669b934327 (patch)
tree7d1eb8d75da2fff336b190393af33c47c0b7dfbe /gcc
parent945bfaca2e8a22850091765d667dc24e356ba420 (diff)
downloadgcc-3a44f39543e5c76226975a7897e3e8669b934327.zip
gcc-3a44f39543e5c76226975a7897e3e8669b934327.tar.gz
gcc-3a44f39543e5c76226975a7897e3e8669b934327.tar.bz2
re PR c++/32260 (too many warning: dereferencing type-punned pointer will break strict-aliasing rules)
PR c++/32260 * rtti.c (enum_tinfo_kind): Fix TK_TYPE_INFO_TYPE comment. (typeid_ok_p): Use the same alias set for abi::__type_info_pseudo as for std::type_info. * g++.dg/rtti/typeid7.C: New test. From-SVN: r129835
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog7
-rw-r--r--gcc/cp/rtti.c16
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/rtti/typeid7.C61
4 files changed, 88 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 6ea272f..c7946ac 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,10 @@
+2007-11-01 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/32260
+ * rtti.c (enum_tinfo_kind): Fix TK_TYPE_INFO_TYPE comment.
+ (typeid_ok_p): Use the same alias set for abi::__type_info_pseudo
+ as for std::type_info.
+
2007-10-31 Paolo Carlini <pcarlini@suse.de>
PR c++/33494
diff --git a/gcc/cp/rtti.c b/gcc/cp/rtti.c
index 9d2ffdf..92cddbf 100644
--- a/gcc/cp/rtti.c
+++ b/gcc/cp/rtti.c
@@ -79,7 +79,7 @@ DEF_VEC_ALLOC_O(tinfo_s,gc);
typedef enum tinfo_kind
{
- TK_TYPE_INFO_TYPE, /* std::type_info */
+ TK_TYPE_INFO_TYPE, /* abi::__type_info_pseudo */
TK_BASE_TYPE, /* abi::__base_class_type_info */
TK_BUILTIN_TYPE, /* abi::__fundamental_type_info */
TK_ARRAY_TYPE, /* abi::__array_type_info */
@@ -264,6 +264,8 @@ get_tinfo_decl_dynamic (tree exp)
static bool
typeid_ok_p (void)
{
+ tree pseudo_type_info, type_info_type;
+
if (! flag_rtti)
{
error ("cannot use typeid with -fno-rtti");
@@ -276,6 +278,18 @@ typeid_ok_p (void)
return false;
}
+ pseudo_type_info
+ = VEC_index (tinfo_s, tinfo_descs, TK_TYPE_INFO_TYPE)->type;
+ type_info_type = TYPE_MAIN_VARIANT (const_type_info_type_node);
+
+ /* Make sure abi::__type_info_pseudo has the same alias set
+ as std::type_info. */
+ if (! TYPE_ALIAS_SET_KNOWN_P (pseudo_type_info))
+ TYPE_ALIAS_SET (pseudo_type_info) = get_alias_set (type_info_type);
+ else
+ gcc_assert (TYPE_ALIAS_SET (pseudo_type_info)
+ == get_alias_set (type_info_type));
+
return true;
}
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 3d35ba0..74c7230 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2007-11-01 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/32260
+ * g++.dg/rtti/typeid7.C: New test.
+
2007-11-01 Tom Tromey <tromey@redhat.com>
PR preprocessor/30805:
diff --git a/gcc/testsuite/g++.dg/rtti/typeid7.C b/gcc/testsuite/g++.dg/rtti/typeid7.C
new file mode 100644
index 0000000..7391405
--- /dev/null
+++ b/gcc/testsuite/g++.dg/rtti/typeid7.C
@@ -0,0 +1,61 @@
+// PR c++/32260
+// { dg-do compile }
+// { dg-options "-O2 -W -Wall" }
+
+#include <typeinfo>
+
+const std::type_info &
+f1 (int i)
+{
+ return typeid (i + 1);
+}
+
+const std::type_info &
+f2 ()
+{
+ return typeid (int);
+}
+
+struct A
+{
+ A ();
+ virtual ~A ();
+ void foo ();
+};
+
+const std::type_info &
+f3 ()
+{
+ return typeid (A);
+}
+
+const std::type_info &
+f4 (A *p)
+{
+ return typeid (*p);
+}
+
+const std::type_info &
+f5 ()
+{
+ return typeid (int *);
+}
+
+const std::type_info &
+f6 ()
+{
+ return typeid (int [26][12]);
+}
+
+const std::type_info &
+f7 ()
+{
+ return typeid (int [26][12]);
+}
+
+void (A::*pmr) ();
+const std::type_info &
+f8 ()
+{
+ return typeid (pmr);
+}