From 3a44f39543e5c76226975a7897e3e8669b934327 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Thu, 1 Nov 2007 23:50:32 +0100 Subject: [PATCH] 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 --- gcc/cp/ChangeLog | 7 ++++ gcc/cp/rtti.c | 16 +++++++- gcc/testsuite/ChangeLog | 5 +++ gcc/testsuite/g++.dg/rtti/typeid7.C | 61 +++++++++++++++++++++++++++++ 4 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/rtti/typeid7.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 6ea272f33f7..c7946ac9469 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2007-11-01 Jakub Jelinek + + 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 PR c++/33494 diff --git a/gcc/cp/rtti.c b/gcc/cp/rtti.c index 9d2ffdf2823..92cddbfb37f 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 3d35ba060bd..74c72305fa3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2007-11-01 Jakub Jelinek + + PR c++/32260 + * g++.dg/rtti/typeid7.C: New test. + 2007-11-01 Tom Tromey 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 00000000000..7391405fcd9 --- /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 + +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); +} -- 2.30.2