public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Fix for PR c++/59031
@ 2013-11-07 19:35 Easwaran Raman
  2013-11-11 18:32 ` Easwaran Raman
  2013-11-24  2:55 ` Jason Merrill
  0 siblings, 2 replies; 4+ messages in thread
From: Easwaran Raman @ 2013-11-07 19:35 UTC (permalink / raw)
  To: GCC Patches; +Cc: Jason Merrill, Paolo Carlini

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

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.

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

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)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Fix for PR c++/59031
  2013-11-07 19:35 Fix for PR c++/59031 Easwaran Raman
@ 2013-11-11 18:32 ` Easwaran Raman
  2013-11-15 18:44   ` Easwaran Raman
  2013-11-24  2:55 ` Jason Merrill
  1 sibling, 1 reply; 4+ messages in thread
From: Easwaran Raman @ 2013-11-11 18:32 UTC (permalink / raw)
  To: GCC Patches; +Cc: Jason Merrill, Paolo Carlini

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Fix for PR c++/59031
  2013-11-11 18:32 ` Easwaran Raman
@ 2013-11-15 18:44   ` Easwaran Raman
  0 siblings, 0 replies; 4+ messages in thread
From: Easwaran Raman @ 2013-11-15 18:44 UTC (permalink / raw)
  To: GCC Patches; +Cc: Jason Merrill, Paolo Carlini

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Fix for PR c++/59031
  2013-11-07 19:35 Fix for PR c++/59031 Easwaran Raman
  2013-11-11 18:32 ` Easwaran Raman
@ 2013-11-24  2:55 ` Jason Merrill
  1 sibling, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2013-11-24  2:55 UTC (permalink / raw)
  To: Easwaran Raman, GCC Patches; +Cc: Paolo Carlini

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

On 11/07/2013 02:14 PM, Easwaran Raman 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; I adjusted a couple of comments to be clearer, and changed 
TREE_TYPE to BINFO_TYPE.  Here's what I've checked in:


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

commit 6e2a16c94d25ad3489e21c0bb1ea238a3a27c9f7
Author: Easwaran Raman <eraman@google.com>
Date:   Thu Nov 7 11:14:52 2013 -0800

    	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.

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 6a4386e..4107afa 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -7514,7 +7514,7 @@ build_new_method_call_1 (tree instance, tree fns, vec<tree, va_gc> **args,
   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;
@@ -7553,6 +7553,7 @@ build_new_method_call_1 (tree instance, tree fns, vec<tree, va_gc> **args,
   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)
@@ -7799,13 +7800,13 @@ build_new_method_call_1 (tree instance, tree fns, vec<tree, va_gc> **args,
 	    {
 	      /* Optimize away vtable lookup if we know that this
 		 function can't be overridden.  We need to check if
-		 the context and the instance type are the same,
+		 the context and the type where we found fn are the same,
 		 actually FN might be defined in a different class
 		 type because of a using-declaration. In this case, we
 		 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), BINFO_TYPE (binfo))
 		  && resolves_to_fixed_type_p (instance, 0))
 		flags |= LOOKUP_NONVIRTUAL;
               if (explicit_targs)
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 4e26bd5..1fc4b59 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -359,7 +359,8 @@ struct GTY(()) tree_overload {
 /* Returns true iff NODE is a BASELINK.  */
 #define BASELINK_P(NODE) \
   (TREE_CODE (NODE) == BASELINK)
-/* The BINFO indicating the base from which the BASELINK_FUNCTIONS came.  */
+/* The BINFO indicating the base in which lookup found the
+   BASELINK_FUNCTIONS.  */
 #define BASELINK_BINFO(NODE) \
   (((struct tree_baselink*) BASELINK_CHECK (NODE))->binfo)
 /* The functions referred to by the BASELINK; either a FUNCTION_DECL,
diff --git a/gcc/testsuite/g++.dg/inherit/virtual11.C b/gcc/testsuite/g++.dg/inherit/virtual11.C
new file mode 100644
index 0000000..04c2412
--- /dev/null
+++ b/gcc/testsuite/g++.dg/inherit/virtual11.C
@@ -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" } }

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-11-23 21:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-07 19:35 Fix for PR c++/59031 Easwaran Raman
2013-11-11 18:32 ` Easwaran Raman
2013-11-15 18:44   ` Easwaran Raman
2013-11-24  2:55 ` 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).