GCC 4.4.7 and strict aliasing warnings

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

GCC 4.4.7 and strict aliasing warnings

Patrick J. LoPresti
(Using the develop branch)

This is with Red Hat Enterprise 6.5, although I suspect it will happen
with most RHEL 6 variants since they all use some variant of GCC
4.4.7. See the (short) program appended to this message.

Although I do not see how this even possible, since I do not see any
pointer or reference casts at all... GCC bug, maybe?

$ /usr/bin/g++ -I/path/to/modular-boost -O3 -Wall -S alias.cc
In file included from
/path/to/modular-boost/boost/geometry/index/detail/rtree/rstar/rstar.hpp:16,
                 from /path/to/modular-boost/boost/geometry/index/rtree.hpp:72,
                 from
/path/to/modular-boost/boost/geometry/algorithms/detail/closest_feature/range_to_range.hpp:23,
                 from
/path/to/modular-boost/boost/geometry/algorithms/detail/distance/range_to_geometry_rtree.hpp:26,
                 from
/path/to/modular-boost/boost/geometry/algorithms/detail/distance/multipoint_to_geometry.hpp:26,
                 from
/path/to/modular-boost/boost/geometry/algorithms/detail/distance/implementation.hpp:25,
                 from
/path/to/modular-boost/boost/geometry/algorithms/detail/comparable_distance/implementation.hpp:22,
                 from
/path/to/modular-boost/boost/geometry/algorithms/comparable_distance.hpp:23,
                 from
/path/to/modular-boost/boost/geometry/algorithms/detail/buffer/turn_in_piece_visitor.hpp:24,
                 from
/path/to/modular-boost/boost/geometry/algorithms/detail/buffer/buffered_piece_collection.hpp:32,
                 from
/path/to/modular-boost/boost/geometry/algorithms/detail/buffer/buffer_inserter.hpp:27,
                 from
/path/to/modular-boost/boost/geometry/algorithms/buffer.hpp:32,
                 from /path/to/modular-boost/boost/geometry/geometry.hpp:48,
                 from /path/to/modular-boost/boost/geometry.hpp:17,
                 from alias.cc:1:
/path/to/modular-boost/boost/geometry/geometries/point.hpp: In static
member function ‘static void
boost::geometry::index::detail::rtree::rstar::choose_split_axis_and_index_for_axis<Box,
AxisIndex, ElementIndexableTag>::apply
[...]
/path/to/modular-boost/boost/geometry/geometries/point.hpp:168:
warning: dereferencing pointer ‘<anonymous>’ does break
strict-aliasing rules
/path/to/modular-boost/boost/geometry/geometries/point.hpp:168:
warning: dereferencing pointer ‘<anonymous>’ does break
strict-aliasing rules
/path/to/modular-boost/boost/geometry/index/detail/rtree/rstar/redistribute_elements.hpp:121:
note: initialized from here
[etc.]

Any insight you could offer would be appreciated. Thanks!

 - Pat


#include <boost/geometry.hpp>
#include <boost/geometry/index/rtree.hpp>
#include <boost/geometry/geometries/point.hpp>
#include <boost/geometry/geometries/box.hpp>

namespace bg = boost::geometry;
namespace bgi = bg::index;

typedef bg::model::point<double, 2, bg::cs::cartesian> Point;
typedef bg::model::box<Point> Box;
typedef std::pair<Box, unsigned> Value;
typedef bgi::rtree<Value, bgi::rstar<16> > RTree;

void
foo()
{
  RTree rtree;
  Box b1(Point(0,0), Point(1,1));
  rtree.insert(Value(b1, 0));
}
_______________________________________________
Geometry mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/geometry
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: GCC 4.4.7 and strict aliasing warnings

Adam Wulkiewicz
Hi,

Patrick J. Lopresti wrote:
> (Using the develop branch)
>
> This is with Red Hat Enterprise 6.5, although I suspect it will happen
> with most RHEL 6 variants since they all use some variant of GCC
> 4.4.7. See the (short) program appended to this message.

Which version of Boost are you using? 1.56?

Is the compiler complaining about the line 121 in this file:
https://github.com/boostorg/geometry/blob/geometry-1.56.0/include/boost/geometry/index/detail/rtree/rstar/redistribute_elements.hpp 
?
So this:

     choosen_index=parameters.get_min_elements();

Here a static method is called (see line 139
https://github.com/boostorg/geometry/blob/geometry-1.56.0/include/boost/geometry/index/parameters.hpp)
If you wanted to play with it, you could remove static keywords in your
local copy and see if the warning was still there.

In the file
https://github.com/boostorg/geometry/blob/geometry-1.56.0/include/boost/geometry/geometries/point.hpp,
line 168:

     returnp.templateget<Dimension>();

Here a member function template instantiation is called.

If the compiler complains about the above it's probably a bug in the
compiler.

> Although I do not see how this even possible, since I do not see any
> pointer or reference casts at all... GCC bug, maybe?

Maybe related to this:
http://stackoverflow.com/questions/15520642/using-stdmap-gives-warning-dereferencing-pointer-anonymous-does-break-str
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39390

Regards,
Adam

> $ /usr/bin/g++ -I/path/to/modular-boost -O3 -Wall -S alias.cc
> In file included from
> /path/to/modular-boost/boost/geometry/index/detail/rtree/rstar/rstar.hpp:16,
>                   from /path/to/modular-boost/boost/geometry/index/rtree.hpp:72,
>                   from
> /path/to/modular-boost/boost/geometry/algorithms/detail/closest_feature/range_to_range.hpp:23,
>                   from
> /path/to/modular-boost/boost/geometry/algorithms/detail/distance/range_to_geometry_rtree.hpp:26,
>                   from
> /path/to/modular-boost/boost/geometry/algorithms/detail/distance/multipoint_to_geometry.hpp:26,
>                   from
> /path/to/modular-boost/boost/geometry/algorithms/detail/distance/implementation.hpp:25,
>                   from
> /path/to/modular-boost/boost/geometry/algorithms/detail/comparable_distance/implementation.hpp:22,
>                   from
> /path/to/modular-boost/boost/geometry/algorithms/comparable_distance.hpp:23,
>                   from
> /path/to/modular-boost/boost/geometry/algorithms/detail/buffer/turn_in_piece_visitor.hpp:24,
>                   from
> /path/to/modular-boost/boost/geometry/algorithms/detail/buffer/buffered_piece_collection.hpp:32,
>                   from
> /path/to/modular-boost/boost/geometry/algorithms/detail/buffer/buffer_inserter.hpp:27,
>                   from
> /path/to/modular-boost/boost/geometry/algorithms/buffer.hpp:32,
>                   from /path/to/modular-boost/boost/geometry/geometry.hpp:48,
>                   from /path/to/modular-boost/boost/geometry.hpp:17,
>                   from alias.cc:1:
> /path/to/modular-boost/boost/geometry/geometries/point.hpp: In static
> member function ‘static void
> boost::geometry::index::detail::rtree::rstar::choose_split_axis_and_index_for_axis<Box,
> AxisIndex, ElementIndexableTag>::apply
> [...]
> /path/to/modular-boost/boost/geometry/geometries/point.hpp:168:
> warning: dereferencing pointer ‘<anonymous>’ does break
> strict-aliasing rules
> /path/to/modular-boost/boost/geometry/geometries/point.hpp:168:
> warning: dereferencing pointer ‘<anonymous>’ does break
> strict-aliasing rules
> /path/to/modular-boost/boost/geometry/index/detail/rtree/rstar/redistribute_elements.hpp:121:
> note: initialized from here
> [etc.]
>
> Any insight you could offer would be appreciated. Thanks!
>
>   - Pat
>
>
> #include <boost/geometry.hpp>
> #include <boost/geometry/index/rtree.hpp>
> #include <boost/geometry/geometries/point.hpp>
> #include <boost/geometry/geometries/box.hpp>
>
> namespace bg = boost::geometry;
> namespace bgi = bg::index;
>
> typedef bg::model::point<double, 2, bg::cs::cartesian> Point;
> typedef bg::model::box<Point> Box;
> typedef std::pair<Box, unsigned> Value;
> typedef bgi::rtree<Value, bgi::rstar<16> > RTree;
>
> void
> foo()
> {
>    RTree rtree;
>    Box b1(Point(0,0), Point(1,1));
>    rtree.insert(Value(b1, 0));
> }
> _______________________________________________
> Geometry mailing list
> [hidden email]
> http://lists.boost.org/mailman/listinfo.cgi/geometry


_______________________________________________
Geometry mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/geometry
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: GCC 4.4.7 and strict aliasing warnings

Patrick J. LoPresti
Adam Wulkiewicz writes:

> Patrick J. Lopresti wrote:
>> (Using the develop branch)
>>
>
> Which version of Boost are you using? 1.56?

"the develop branch" :-)

> In the file
> https://github.com/boostorg/geometry/blob/geometry-1.56.0/include/boost/geometry/geometries/point.hpp,
> line 168:
>
>     return p.template get<Dimension>();
>
> Here a member function template instantiation is called.
>
> If the compiler complains about the above it's probably a bug in the
> compiler.

It certainly looks that way. Later versions of GCC do not warn.

The only hack I found around it is to create a local variable q,
memcpy() from p into q, then "return q.template
get<Dimension>()". Unfortunately, there are other instances of the
warning that are not so easy to hack around... Not to mention the
performance hit.

> Maybe related to this:
> http://stackoverflow.com/questions/15520642/using-stdmap-gives-warning-dereferencing-pointer-anonymous-does-break-str
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39390

Yes, it appears GCC 4.4 generates many bogus instances of this warning,
and nobody intends to fix it, even though this is the GCC in RHEL 6 (all
versions, all updates). Red Hat's own approach seems to be to add
"-fno-strict-aliasing" to the compiler options for all of their
packages.

Also GCC 4.4 does not have "#pragma GCC diagnostic [push/pop]", so there
is no clean way to disable the warning just around the Boost.Geometry
code. So I suppose I will disable it globally.

Thanks once again, Adam.

 - Pat
_______________________________________________
Geometry mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/geometry
Loading...