Index: gcc/cgraph.c
===================================================================
--- gcc/cgraph.c	(revision 215888)
+++ gcc/cgraph.c	(working copy)
@@ -2101,15 +2101,17 @@ cgraph_node::can_be_local_p (void)
 						NULL, true));
 }
 
-/* Call calback on cgraph_node, thunks and aliases associated to cgraph_node.
+/* Call callback on cgraph_node, thunks and aliases associated to cgraph_node.
    When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
-   skipped. */
+   skipped.  When EXCLUDE_VIRTUAL_THUNKS is true, virtual thunks are
+   skipped.  */
 
 bool
-cgraph_node::call_for_symbol_thunks_and_aliases (bool (*callback)
-						   (cgraph_node *, void *),
-						 void *data,
-						 bool include_overwritable)
+cgraph_node::call_for_symbol_thunks_and_aliases_1 (bool (*callback)
+						     (cgraph_node *, void *),
+						   void *data,
+						   bool include_overwritable,
+						   bool exclude_virtual_thunks)
 {
   cgraph_edge *e;
   ipa_ref *ref;
@@ -2119,9 +2121,12 @@ bool
   for (e = callers; e; e = e->next_caller)
     if (e->caller->thunk.thunk_p
 	&& (include_overwritable
-	    || e->caller->get_availability () > AVAIL_INTERPOSABLE))
-      if (e->caller->call_for_symbol_thunks_and_aliases (callback, data,
-						       include_overwritable))
+	    || e->caller->get_availability () > AVAIL_INTERPOSABLE)
+	&& !(exclude_virtual_thunks
+	     && e->caller->thunk.virtual_offset_p))
+      if (e->caller->call_for_symbol_thunks_and_aliases_1 (callback, data,
+						       include_overwritable,
+						       exclude_virtual_thunks))
 	return true;
 
   FOR_EACH_ALIAS (this, ref)
@@ -2129,16 +2134,17 @@ bool
       cgraph_node *alias = dyn_cast <cgraph_node *> (ref->referring);
       if (include_overwritable
 	  || alias->get_availability () > AVAIL_INTERPOSABLE)
-	if (alias->call_for_symbol_thunks_and_aliases (callback, data,
-						     include_overwritable))
+	if (alias->call_for_symbol_thunks_and_aliases_1 (callback, data,
+						     include_overwritable,
+						     exclude_virtual_thunks))
 	  return true;
     }
   return false;
 }
 
-/* Call calback on function and aliases associated to the function.
+/* Call callback on function and aliases associated to the function.
    When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
-   skipped. */
+   skipped.  */
 
 bool
 cgraph_node::call_for_symbol_and_aliases (bool (*callback) (cgraph_node *,
@@ -2244,9 +2250,9 @@ cgraph_set_const_flag_1 (cgraph_node *node, void *
 void
 cgraph_node::set_const_flag (bool readonly, bool looping)
 {
-  call_for_symbol_thunks_and_aliases (cgraph_set_const_flag_1,
+  call_for_symbol_thunks_and_aliases_1 (cgraph_set_const_flag_1,
 				    (void *)(size_t)(readonly + (int)looping * 2),
-				      false);
+				    false, true);
 }
 
 /* Worker to set pure flag.  */
@@ -2274,9 +2280,9 @@ cgraph_set_pure_flag_1 (cgraph_node *node, void *d
 void
 cgraph_node::set_pure_flag (bool pure, bool looping)
 {
-  call_for_symbol_thunks_and_aliases (cgraph_set_pure_flag_1,
+  call_for_symbol_thunks_and_aliases_1 (cgraph_set_pure_flag_1,
 				    (void *)(size_t)(pure + (int)looping * 2),
-				    false);
+				    false, true);
 }
 
 /* Return true when cgraph_node can not return or throw and thus
Index: gcc/cgraph.h
===================================================================
--- gcc/cgraph.h	(revision 215888)
+++ gcc/cgraph.h	(working copy)
@@ -248,9 +248,9 @@ class GTY((desc ("%h.type"), tag ("SYMTAB_SYMBOL")
      body aliases.  */
   void fixup_same_cpp_alias_visibility (symtab_node *target);
 
-  /* Call calback on symtab node and aliases associated to this node.
+  /* Call callback on symtab node and aliases associated to this node.
      When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
-     skipped. */
+     skipped.  */
   bool call_for_symbol_and_aliases (bool (*callback) (symtab_node *, void *),
 				  void *data,
 				  bool include_overwrite);
@@ -985,7 +985,7 @@ struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node
      if any to PURE.  */
   void set_pure_flag (bool pure, bool looping);
 
-  /* Call calback on function and aliases associated to the function.
+  /* Call callback on function and aliases associated to the function.
      When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
      skipped. */
 
@@ -993,13 +993,27 @@ struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node
 						      void *),
 				    void *data, bool include_overwritable);
 
-  /* Call calback on cgraph_node, thunks and aliases associated to NODE.
+  /* Call callback on cgraph_node, thunks and aliases associated to NODE.
      When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
+     skipped.  When EXCLUDE_VIRTUAL_THUNKS is true, virtual thunks are
      skipped.  */
+  bool call_for_symbol_thunks_and_aliases_1 (bool (*callback)
+					       (cgraph_node *, void *),
+					     void *data,
+					     bool include_overwritable,
+					     bool exclude_virtual_thunks);
+
+  /* Call callback on cgraph_node, thunks and aliases associated to NODE.
+     When INCLUDE_OVERWRITABLE is false, overwritable aliases and thunks are
+     skipped.  */
   bool call_for_symbol_thunks_and_aliases (bool (*callback) (cgraph_node *node,
-							   void *data),
-					 void *data,
-					 bool include_overwritable);
+							     void *data),
+					   void *data,
+					   bool include_overwritable)
+  {
+    return call_for_symbol_thunks_and_aliases_1 (callback, data,
+						 include_overwritable, false);
+  }
 
   /* Likewise indicate that a node is needed, i.e. reachable via some
      external means.  */
Index: gcc/ipa-pure-const.c
===================================================================
--- gcc/ipa-pure-const.c	(revision 215888)
+++ gcc/ipa-pure-const.c	(working copy)
@@ -744,6 +744,8 @@ analyze_function (struct cgraph_node *fn, bool ipa
     {
       /* Thunk gets propagated through, so nothing interesting happens.  */
       gcc_assert (ipa);
+      if (fn->thunk.virtual_offset_p)
+	l->pure_const_state = IPA_NEITHER;
       return l;
     }
 
Index: gcc/testsuite/g++.old-deja/g++.mike/p4736b.C
===================================================================
--- gcc/testsuite/g++.old-deja/g++.mike/p4736b.C	(revision 215888)
+++ gcc/testsuite/g++.old-deja/g++.mike/p4736b.C	(working copy)
@@ -1,4 +1,5 @@
 // { dg-do run  }
+// { dg-options "-O2" }
 // prms-id: 4736
 
 class Rep {
