public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for c++/67576 (multiple evaluation of typeid operand)
@ 2015-12-17 16:46 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2015-12-17 16:46 UTC (permalink / raw)
  To: gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 236 bytes --]

When I changed build_typeid to take the address of a polymorphic operand 
rather than using the lvalue directly, I forgot the parallel change from 
stabilize_reference to save_expr.

Tested x86_64-pc-linux-gnu, applying to trunk and 5.

[-- Attachment #2: 67576.patch --]
[-- Type: text/x-patch, Size: 1257 bytes --]

commit 5361caf55040d2a15b5ebb5ff0fc1e3e605dba9c
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Dec 17 00:10:20 2015 -0500

    	PR c++/67576
    	PR c++/25466
    	* rtti.c (build_typeid): Use save_expr, not stabilize_reference.

diff --git a/gcc/cp/rtti.c b/gcc/cp/rtti.c
index b397b55..f42b1cb 100644
--- a/gcc/cp/rtti.c
+++ b/gcc/cp/rtti.c
@@ -332,7 +332,7 @@ build_typeid (tree exp, tsubst_flags_t complain)
       /* So we need to look into the vtable of the type of exp.
          Make sure it isn't a null lvalue.  */
       exp = cp_build_addr_expr (exp, complain);
-      exp = stabilize_reference (exp);
+      exp = save_expr (exp);
       cond = cp_convert (boolean_type_node, exp, complain);
       exp = cp_build_indirect_ref (exp, RO_NULL, complain);
     }
diff --git a/gcc/testsuite/g++.dg/rtti/typeid11.C b/gcc/testsuite/g++.dg/rtti/typeid11.C
new file mode 100644
index 0000000..384b0f4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/rtti/typeid11.C
@@ -0,0 +1,16 @@
+// { dg-do run }
+
+#include <typeinfo>
+
+struct Base { virtual void foo() {} }; // polymorphic
+
+int main()
+{
+  Base b;
+  Base *ary[] = { &b, &b, &b};
+
+  int iter = 0;
+  typeid(*ary[iter++]);
+  if (iter != 1)	// should be 1
+    __builtin_abort();	// but 2
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-12-17 16:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-12-17 16:46 C++ PATCH for c++/67576 (multiple evaluation of typeid operand) Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).