From patchwork Thu Nov 11 10:35:47 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 70792 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 379F9B7126 for ; Thu, 11 Nov 2010 21:36:04 +1100 (EST) Received: (qmail 29781 invoked by alias); 11 Nov 2010 10:36:01 -0000 Received: (qmail 29349 invoked by uid 22791); 11 Nov 2010 10:35:57 -0000 X-SWARE-Spam-Status: No, hits=-3.7 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from cantor2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 11 Nov 2010 10:35:50 +0000 Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.221.2]) by mx2.suse.de (Postfix) with ESMTP id 3009886A2E for ; Thu, 11 Nov 2010 11:35:48 +0100 (CET) Date: Thu, 11 Nov 2010 11:35:47 +0100 From: Martin Jambor To: GCC Patches Cc: Richard Guenther Subject: [PATCH, PR 46383] Ignore IPA_JF_ANCESTOR jump functions with a negative offset Message-ID: <20101111103547.GB15816@virgil.arch.suse.de> Mail-Followup-To: GCC Patches , Richard Guenther MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hi, the assert I inserted to get_binfo_at_offset in tree.c is bogus. Negative offsets can be result of unsuccessful searches for BINFOs and, as in the case of PR 46383, can currently even be the offset stored in IPA_JF_ANCESTOR jump functions which are meant to describe up-casting when they actually describes some down-casting. In both cases, we should just stop trying if we see a negative offset because nothing useful can really come out of it and so that is exactly what the patch below does. Bootstrapped and tested on x86_64-linux. OK for trunk? Thanks, Martin 2010-11-10 Martin Jambor PR tree-optimization/46383 * ipa-prop.c (compute_complex_assign_jump_func): Ignore negative offsets. (compute_complex_ancestor_jump_func): Likewise. * tree.c (get_binfo_at_offset): Return NULL_TREE if offset is negative. * testsuite/g++.dg/torture/pr46383.C: New test. Index: icln/gcc/ipa-prop.c =================================================================== --- icln.orig/gcc/ipa-prop.c +++ icln/gcc/ipa-prop.c @@ -413,7 +413,8 @@ compute_complex_assign_jump_func (struct offset += mem_ref_offset (op1).low * BITS_PER_UNIT; op1 = TREE_OPERAND (op1, 0); if (TREE_CODE (op1) != SSA_NAME - || !SSA_NAME_IS_DEFAULT_DEF (op1)) + || !SSA_NAME_IS_DEFAULT_DEF (op1) + || offset < 0) return; index = ipa_get_param_decl_index (info, SSA_NAME_VAR (op1)); @@ -490,7 +491,8 @@ compute_complex_ancestor_jump_func (stru offset += mem_ref_offset (expr).low * BITS_PER_UNIT; parm = TREE_OPERAND (expr, 0); if (TREE_CODE (parm) != SSA_NAME - || !SSA_NAME_IS_DEFAULT_DEF (parm)) + || !SSA_NAME_IS_DEFAULT_DEF (parm) + || offset < 0) return; index = ipa_get_param_decl_index (info, SSA_NAME_VAR (parm)); Index: icln/gcc/testsuite/g++.dg/torture/pr46383.C =================================================================== --- /dev/null +++ icln/gcc/testsuite/g++.dg/torture/pr46383.C @@ -0,0 +1,252 @@ +// { dg-do compile } + +namespace std { +templatestruct pair{}; + template struct _Vector_base { + struct _Vector_impl + { + _Tp* _M_start; + _Tp* _M_finish; + _Tp* _M_end_of_storage; + }; + _Vector_impl _M_impl; + }; + template + struct vector : _Vector_base<_Tp> + { + vector(const vector& __x); + }; +} +namespace boost { +struct G{}; +template +struct modable2 +: G +{ }; +} +namespace CGAL { +struct Rep { }; +struct Handle +{ + Handle() ; + Handle(const Handle& x) ; + Rep* PTR; +}; +template class Lazy_exact_nt + : Handle + , boost::modable2< Lazy_exact_nt, int > + , boost::modable2< Lazy_exact_nt, double > +{ }; + struct CC_iterator { }; +struct Triangulation_data_structure_3 { + typedef CC_iterator Vertex_handle; + typedef CC_iterator Cell_handle; + typedef std::pair Facet; +}; +template < class GT, class Tds_ > struct Triangulation_3 { + typedef Tds_ Tds; + typedef typename GT::Point_3 Point; + typedef typename Tds::Facet Facet; + typedef typename Tds::Vertex_handle Vertex_handle; + enum Locate_type { VERTEX=0, EDGE, FACET, CELL, OUTSIDE_CONVEX_HULL, OUTSIDE_AFFINE_HULL }; + Tds _tds; + bool is_infinite(const Facet & f) const ; +}; +template < class Gt, class Tds_ > struct Delaunay_triangulation_3 : public Triangulation_3 { }; + namespace Surface_mesher { enum Verbose_flag { VERBOSE, NOT_VERBOSE }; } +enum Mesher_level_conflict_status { NO_CONFLICT = 0, CONFLICT_BUT_ELEMENT_CAN_BE_RECONSIDERED, CONFLICT_AND_ELEMENT_SHOULD_BE_DROPPED }; +struct Null_mesher_level { + template Mesher_level_conflict_status test_point_conflict_from_superior(P, Z) ; +}; +template < class Tr, class Derived, class Element, class Previous, class Triangulation_traits > struct Mesher_level { + typedef Tr Triangulation; + typedef typename Triangulation::Point Point; + typedef typename Triangulation::Vertex_handle Vertex_handle; + typedef typename Triangulation_traits::Zone Zone; + typedef Previous Previous_level; + Derived& derived() { return static_cast(*this); } + Previous& previous_level; + Mesher_level(Previous_level& previous) + : previous_level(previous) + { } + Vertex_handle insert(Point p, Zone& z) ; + Zone conflicts_zone(const Point& p, Element e) ; + Element get_next_element() ; + template void before_insertion(Element& e, const Point& p, Zone& zone, Mesh_visitor visitor) { + visitor.before_insertion(e, p, zone); + } + template void after_insertion(Vertex_handle vh, Mesh_visitor visitor) { + derived().after_insertion_impl(vh); + } + template void after_no_insertion(const Element& e, const Point& p, Zone& zone, Mesh_visitor visitor) { + visitor.after_no_insertion(e, p, zone); + } + template void refine(Mesh_visitor visitor) + { + Element e = get_next_element(); + const Mesher_level_conflict_status result = try_to_refine_element(e, visitor); + } + template Mesher_level_conflict_status try_to_refine_element(Element e, Mesh_visitor visitor) + { + Point p ; + Zone zone = conflicts_zone(p, e); + const Mesher_level_conflict_status result = test_point_conflict(p, zone); + before_insertion(e, p, zone, visitor); + Vertex_handle v = insert(p, zone); + after_insertion(v, visitor); + after_no_insertion(e, p, zone, visitor); + } + Mesher_level_conflict_status test_point_conflict(const Point& p, Zone& zone) + { + return previous_level.test_point_conflict_from_superior(p, zone); + } +}; +struct Null_mesh_visitor { + template void before_insertion(E, P, Z) const {} + template void after_no_insertion(E, P, Z) const {} +}; +template struct Triangulation_ref_impl { + Triangulation_ref_impl(Tr& t); +}; +template struct Triangulation_mesher_level_traits_3 +: public Triangulation_ref_impl +{ + typedef typename Tr::Facet Facet; + Triangulation_mesher_level_traits_3(Tr& t) + : Triangulation_ref_impl(t) + { } + struct Zone { + typedef std::vector Cells; + typedef std::vector Facets; + typedef typename Tr::Locate_type Locate_type; + Locate_type locate_type; + Cells cells; + Facets boundary_facets; + Facets internal_facets; + }; +}; + namespace Surface_mesher { + namespace details { + template struct Triangulation_generator { + typedef typename Base::Complex_2_in_triangulation_3 C2T3; + typedef typename C2T3::Triangulation Triangulation; + typedef Triangulation Type; + typedef Type type; + }; + template struct Facet_generator { + typedef typename Triangulation_generator::type Tr; + typedef typename Tr::Facet Type; + typedef Type type; + }; + template struct Mesher_level_generator { + typedef typename Base::Complex_2_in_triangulation_3 C2T3; + typedef typename C2T3::Triangulation Triangulation; + typedef Triangulation_mesher_level_traits_3 Tr_m_l_traits_3; + typedef Mesher_level Type; + }; + } + template < class C2T3, class Surface_, class SurfaceMeshTraits, class Criteria_ > struct Surface_mesher_base + : public Triangulation_mesher_level_traits_3 + { + typedef C2T3 Complex_2_in_triangulation_3; + typedef Surface_ Surface; + typedef SurfaceMeshTraits Surface_mesh_traits; + typedef Criteria_ Criteria; + typedef typename C2T3::Triangulation Tr; + typedef typename Tr::Vertex_handle Vertex_handle; + typedef typename Tr::Facet Facet; + Surface_mesher_base (C2T3& co, const Surface& s, const Surface_mesh_traits& mesh_traits, const Criteria& c) +: Triangulation_mesher_level_traits_3(co.triangulation()), c2t3(co), tr(co.triangulation()), surf(s), meshtraits(mesh_traits), criteria(c) + { } + C2T3& c2t3; + Tr& tr; + const Surface& surf; + const Surface_mesh_traits& meshtraits; + const Criteria& criteria; + void after_insertion_impl(const Vertex_handle& v) { + after_insertion_handle_opposite_facet (Facet ()); + after_insertion_handle_incident_facet (Facet ()); + } + void after_insertion_handle_incident_facet (const Facet& f) { + tr.is_infinite(f) ; + new_facet(f); + } + template void new_facet (const Facet& f) ; + void after_insertion_handle_opposite_facet (const Facet& f) { + after_insertion_handle_incident_facet (f); + } + }; + template < typename Base, typename Element = typename details::Facet_generator::type, typename PreviousLevel = Null_mesher_level, Verbose_flag verbose = NOT_VERBOSE > struct Surface_mesher + : public Base , public details::Mesher_level_generator< Base, Surface_mesher, Element, PreviousLevel >::Type + { + typedef typename Base::Complex_2_in_triangulation_3 C2T3; + typedef typename Base::Surface Surface; + typedef typename Base::Criteria Criteria; + typedef typename Base::Surface_mesh_traits Surface_mesh_traits; + typedef typename details::Mesher_level_generator< Base, Surface_mesher, Element, PreviousLevel >::Type Mesher_lvl; + using Mesher_lvl::refine; + Null_mesher_level null_mesher_level; + Null_mesh_visitor null_visitor; + bool initialized; + Surface_mesher(C2T3& c2t3, const Surface& surface, const Surface_mesh_traits& mesh_traits, const Criteria& criteria) + : Base(c2t3, surface, mesh_traits, criteria), Mesher_lvl(null_mesher_level), initialized(false) + { } + void refine_mesh () { + refine(null_visitor); + } + }; + } +template struct Surface_mesh_traits_generator_3 { + typedef typename Surface::Surface_mesher_traits_3 Type; + typedef Type type; +}; +template < class Tr, typename Edge_info_ = void > struct Complex_2_in_triangulation_3 { + typedef Tr Triangulation; + Triangulation& triangulation(); +}; +template struct Surface_mesh_complex_2_in_triangulation_3 +: public Complex_2_in_triangulation_3 +{ }; + struct Non_manifold_tag {}; + template < typename C2T3, typename SurfaceMeshTraits_3, typename Criteria, typename Tag > struct Make_surface_mesh_helper { + typedef Surface_mesher::Surface_mesher_base< C2T3, typename SurfaceMeshTraits_3::Surface_3, SurfaceMeshTraits_3, Criteria> Mesher_base; + }; + template struct Surface_mesher_generator { + typedef typename Make_surface_mesh_helper< C2T3, SurfaceMeshTraits_3, Criteria, Tag>::Mesher_base Mesher_base; + typedef Surface_mesher::Surface_mesher< Mesher_base, typename Surface_mesher::details::Facet_generator::type, Null_mesher_level, verbosity> Mesher; + typedef Mesher type; + }; +template void make_surface_mesh(C2T3& c2t3, const typename SurfaceMeshTraits_3::Surface_3& surface, const SurfaceMeshTraits_3& surface_mesh_traits, const Criteria& criteria) { + typedef typename Surface_mesher_generator< C2T3, SurfaceMeshTraits_3, Criteria, Non_manifold_tag, Surface_mesher::NOT_VERBOSE >::type Mesher; + Mesher mesher(c2t3, surface, surface_mesh_traits, criteria); + mesher.refine_mesh(); +} +template struct Surface_mesh_triangulation_generator_3 { + typedef CGAL::Triangulation_data_structure_3 Tds; + typedef CGAL::Delaunay_triangulation_3 Type; +}; + namespace Surface_mesher { + namespace { struct Return_min { }; } + template < class GT, class Surface, class Unused = Return_min > struct Implicit_surface_oracle_3 { + typedef Surface Surface_3; + }; + } + template< typename GT> struct Implicit_surface_3 { + typedef GT Geom_traits; + typedef Implicit_surface_3 Self; + typedef Surface_mesher::Implicit_surface_oracle_3< Geom_traits, Self> Surface_mesher_traits_3; + }; +} +struct K { +struct Point_3 { +CGAL::Lazy_exact_nt a[3]; +}; +}; +typedef CGAL::Surface_mesh_triangulation_generator_3::Type Tr; +typedef CGAL::Surface_mesh_complex_2_in_triangulation_3 C2T3; +typedef CGAL::Implicit_surface_3 Surface; +typedef CGAL::Surface_mesh_traits_generator_3::type Traits; +void f() { + C2T3 c2t3 ; + CGAL::make_surface_mesh(c2t3, Surface(), Traits(), 3); +} Index: icln/gcc/tree.c =================================================================== --- icln.orig/gcc/tree.c +++ icln/gcc/tree.c @@ -10944,10 +10944,10 @@ get_binfo_at_offset (tree binfo, HOST_WI tree fld; int i; - gcc_checking_assert (offset >= 0); if (type == expected_type) return binfo; - if (TREE_CODE (type) != RECORD_TYPE) + if (TREE_CODE (type) != RECORD_TYPE + || offset < 0) return NULL_TREE; for (fld = TYPE_FIELDS (type); fld; fld = DECL_CHAIN (fld))