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]
Other format: [Raw text]

[C++ PATCH] Fix constexpr tree sharing problem (PR c++/46526)


Hi!

As mentioned in the PR, this testcase is miscompiled because of a tree
sharing problem.  cxx_eval_call_expression always returns the same result
(CONSTRUCTOR in this case) and cxx_eval_bare_aggregate modifies it in place,
which means on this testcase that Base's CONSTRUCTOR is first changed
to have _ZTV1A + 16 value in the first element and then to _ZTV1B + 16,
so a (with A type) ends up _ZTV1B + 16 instead of _ZTV1A + 16 pointer.

It seems that cxx_eval_constant_expression and its helpers mostly have
unsharing semantics (usually they build new trees from the old ones), so
unsharing in cxx_eval_call_expression looks best to me.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2010-11-19  Jakub Jelinek  <jakub@redhat.com>

	PR c++/46526
	* semantics.c (cxx_eval_call_expression): Unshare the result.

	* g++.dg/cpp0x/constexpr-base3.C: New test.

--- gcc/cp/semantics.c.jj	2010-11-11 09:04:25.000000000 +0100
+++ gcc/cp/semantics.c	2010-11-19 10:29:03.018372763 +0100
@@ -6042,7 +6042,7 @@ cxx_eval_call_expression (const constexp
     }
 
   pop_cx_call_context ();
-  return result;
+  return unshare_expr (result);
 }
 
 /* FIXME speed this up, it's taking 16% of compile time on sieve testcase.  */
--- gcc/testsuite/g++.dg/cpp0x/constexpr-base3.C.jj	2010-11-19 10:34:23.231529194 +0100
+++ gcc/testsuite/g++.dg/cpp0x/constexpr-base3.C	2010-11-19 10:32:22.000000000 +0100
@@ -0,0 +1,27 @@
+// PR c++/46526
+// { dg-do run }
+// { dg-options "-std=c++0x" }
+
+struct Base
+{
+  virtual int getid () = 0;
+};
+
+struct A : public Base
+{
+  virtual int getid () { return 1; }
+};
+
+struct B : public Base
+{
+  virtual int getid () { throw "here"; }
+};
+
+int
+main ()
+{
+  A a;
+  B b;
+  Base& ar = a;
+  ar.getid ();
+}

	Jakub


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