aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEaswaran Raman <eraman@google.com>2013-11-23 21:01:46 +0000
committerJason Merrill <jason@gcc.gnu.org>2013-11-23 16:01:46 -0500
commitf8b0f44f2e5437e06e6def089f81d53a3ee2ce38 (patch)
tree971f6a535d597aa1a2375e50049f8a5f22a27d8d
parent18768faed3875e1d33b122fbf867788add95f056 (diff)
downloadgcc-f8b0f44f2e5437e06e6def089f81d53a3ee2ce38.zip
gcc-f8b0f44f2e5437e06e6def089f81d53a3ee2ce38.tar.gz
gcc-f8b0f44f2e5437e06e6def089f81d53a3ee2ce38.tar.bz2
re PR c++/59031 (vtable lookup not optimized away)
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. From-SVN: r205317
-rw-r--r--gcc/cp/ChangeLog7
-rw-r--r--gcc/cp/call.c7
-rw-r--r--gcc/cp/cp-tree.h3
-rw-r--r--gcc/testsuite/g++.dg/inherit/virtual11.C17
4 files changed, 30 insertions, 4 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 91e4132..aadecdd 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,10 @@
+2013-11-23 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.
+
2013-11-23 Jason Merrill <jason@redhat.com>
PR c++/58868
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" } }