Patchwork Fix for PR c++/59031

login
register
mail settings
Submitter Easwaran Raman
Date Nov. 7, 2013, 7:14 p.m.
Message ID <CAPK5YPatQxsM+awi=4YUdjgfQ0UmG+K4zNhxct=r2QZXF5BohA@mail.gmail.com>
Download mbox | patch
Permalink /patch/289465/
State New
Headers show

Comments

Easwaran Raman - Nov. 7, 2013, 7:14 p.m.
Before  r193504, if a method can not be overridden, LOOKUP_NONVIRTUAL
is set and the call is direct. The changes at r193504 (to fix PR
c++/11750) caused a regression to this behavior. This patch attempts
to fix that. Bootstraps and no test regressions on x86_64/linux. Is
this a correct fix and is this ok for trunk?

Thanks,
Easwaran

2013-11-07  Easwaran Raman  <eraman@google.com>

PR c++/59031
* call.c (build_new_method_call_1): Comnpare function context
with BASELINK_BINFO type rather than instance type before
marking the call with LOOKUP_NONVIRTUAL.

testsuite/ChangeLog:

2013-11-07  Easwaran Raman  <eraman@google.com>

PR c++/59031
* g++.dg/inherit/virtual11.C: New test.
Easwaran Raman - Nov. 11, 2013, 5:46 p.m.
Ping.

On Thu, Nov 7, 2013 at 11:14 AM, Easwaran Raman <eraman@google.com> wrote:
> Before  r193504, if a method can not be overridden, LOOKUP_NONVIRTUAL
> is set and the call is direct. The changes at r193504 (to fix PR
> c++/11750) caused a regression to this behavior. This patch attempts
> to fix that. Bootstraps and no test regressions on x86_64/linux. Is
> this a correct fix and is this ok for trunk?
>
> Thanks,
> Easwaran
>
> 2013-11-07  Easwaran Raman  <eraman@google.com>
>
> PR c++/59031
> * call.c (build_new_method_call_1): Comnpare function context
> with BASELINK_BINFO type rather than instance type before
> marking the call with LOOKUP_NONVIRTUAL.
>
> testsuite/ChangeLog:
>
> 2013-11-07  Easwaran Raman  <eraman@google.com>
>
> PR c++/59031
> * g++.dg/inherit/virtual11.C: New test.
Easwaran Raman - Nov. 15, 2013, 5:52 p.m.
Ping.


On Mon, Nov 11, 2013 at 9:46 AM, Easwaran Raman <eraman@google.com> wrote:
> Ping.
>
> On Thu, Nov 7, 2013 at 11:14 AM, Easwaran Raman <eraman@google.com> wrote:
>> Before  r193504, if a method can not be overridden, LOOKUP_NONVIRTUAL
>> is set and the call is direct. The changes at r193504 (to fix PR
>> c++/11750) caused a regression to this behavior. This patch attempts
>> to fix that. Bootstraps and no test regressions on x86_64/linux. Is
>> this a correct fix and is this ok for trunk?
>>
>> Thanks,
>> Easwaran
>>
>> 2013-11-07  Easwaran Raman  <eraman@google.com>
>>
>> PR c++/59031
>> * call.c (build_new_method_call_1): Comnpare function context
>> with BASELINK_BINFO type rather than instance type before
>> marking the call with LOOKUP_NONVIRTUAL.
>>
>> testsuite/ChangeLog:
>>
>> 2013-11-07  Easwaran Raman  <eraman@google.com>
>>
>> PR c++/59031
>> * g++.dg/inherit/virtual11.C: New test.

Patch

Index: testsuite/g++.dg/inherit/virtual11.C
===================================================================
--- testsuite/g++.dg/inherit/virtual11.C	(revision 0)
+++ testsuite/g++.dg/inherit/virtual11.C	(revision 0)
@@ -0,0 +1,17 @@ 
+// PR c++/59031 
+// { dg-do compile }
+// { dg-options "-fdump-tree-gimple " }
+class B {
+ public:
+  virtual int add (int a, int b) {return a+ b;}
+};
+
+class D : public B {
+};
+
+int foo (int a, int b) {
+  D d;
+  return d.add(a, b);
+}
+// { dg-final { scan-tree-dump-not "OBJ_TYPE_REF" "gimple" } }
+// { dg-final { cleanup-tree-dump "gimple" } }
Index: cp/call.c
===================================================================
--- cp/call.c	(revision 204466)
+++ cp/call.c	(working copy)
@@ -7511,7 +7511,7 @@  build_new_method_call_1 (tree instance, tree fns,
   struct z_candidate *candidates = 0, *cand;
   tree explicit_targs = NULL_TREE;
   tree basetype = NULL_TREE;
-  tree access_binfo;
+  tree access_binfo, binfo;
   tree optype;
   tree first_mem_arg = NULL_TREE;
   tree name;
@@ -7550,6 +7550,7 @@  build_new_method_call_1 (tree instance, tree fns,
   if (!conversion_path)
     conversion_path = BASELINK_BINFO (fns);
   access_binfo = BASELINK_ACCESS_BINFO (fns);
+  binfo = BASELINK_BINFO (fns);
   optype = BASELINK_OPTYPE (fns);
   fns = BASELINK_FUNCTIONS (fns);
   if (TREE_CODE (fns) == TEMPLATE_ID_EXPR)
@@ -7802,7 +7803,7 @@  build_new_method_call_1 (tree instance, tree fns,
 		 do not want to perform a non-virtual call.  */
 	      if (DECL_VINDEX (fn) && ! (flags & LOOKUP_NONVIRTUAL)
 		  && same_type_ignoring_top_level_qualifiers_p
-		  (DECL_CONTEXT (fn), TREE_TYPE (instance))
+		  (DECL_CONTEXT (fn), TREE_TYPE (binfo))
 		  && resolves_to_fixed_type_p (instance, 0))
 		flags |= LOOKUP_NONVIRTUAL;
               if (explicit_targs)