Warnings in gcc 4.4.1 with optimization

View: New views
4 Messages — Rating Filter:   Alert me  

Warnings in gcc 4.4.1 with optimization

by Norbert Wenzel-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

I've been pointed to this mailing list by the boost-users mailing list.
I've got some Spirit code, that issues warnings about pointer
dereferencing breaking strict-aliasing rules when built with
optimization enabled (>=2) and only in boost 1.40. The same code
compiles in 1.39 without any warnings.

I'm using Spirit.Classic at the moment. I'll post the full (test) code
after the text, since it's less than 30 lines.
The file is compiled with
g++ spiritExample.cpp -O3 -Wall -o spiritExample
and adding the include folder of either boost 1.39 or 1.40.

The output of the compiler gives the following two warnings, where the
first is for the action using bind and the second is for the action
using a standard function pointer:
../include/boost/bind/bind.hpp:311: warning: dereferencing pointer ‘val’
does break strict-aliasing rules
../include/boost/spirit/home/classic/core/composite/actions.hpp:110:
note: initialized from here
../include/boost/spirit/home/classic/core/scanner/scanner.hpp:132:
warning: dereferencing pointer ‘val’ does break strict-aliasing rules
../include/boost/spirit/home/classic/core/composite/actions.hpp:110:
note: initialized from here

My question is, if this is something I should care about and if I'm
doing something wrong here in using spirit. Is there anything I can do
to remove these warnings, except moving to the newer version of Spirit
(which had already been recommended as a general idea on boost-users)?

Thanks,
Norbert


<code>
#include "boost/spirit.hpp"
#include "boost/bind.hpp"

#include <string>

struct Object
{
    void obj_param(double param) {}
};

void get_param(double param) {}

int main(int argc, char **argv)
{
    Object theObj;
    std::string toParse;

    using namespace boost::spirit;
    using boost::bind;
    using boost::ref;

    parse(toParse.c_str(), real_p[bind(&Object::obj_param, ref(theObj),
_1)], space_p).full;
    parse(toParse.c_str(), real_p[&get_param], space_p).full;
       
    return 0;
}
</code>



------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Spirit-general mailing list
Spirit-general@...
https://lists.sourceforge.net/lists/listinfo/spirit-general

smime.p7s (4K) Download Attachment

Re: Warnings in gcc 4.4.1 with optimization

by Hartmut Kaiser :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

> I've been pointed to this mailing list by the boost-users mailing list.
> I've got some Spirit code, that issues warnings about pointer
> dereferencing breaking strict-aliasing rules when built with
> optimization enabled (>=2) and only in boost 1.40. The same code
> compiles in 1.39 without any warnings.
>
> I'm using Spirit.Classic at the moment. I'll post the full (test) code
> after the text, since it's less than 30 lines.
> The file is compiled with
> g++ spiritExample.cpp -O3 -Wall -o spiritExample
> and adding the include folder of either boost 1.39 or 1.40.
>
> The output of the compiler gives the following two warnings, where the
> first is for the action using bind and the second is for the action
> using a standard function pointer:
> ../include/boost/bind/bind.hpp:311: warning: dereferencing pointer
> ‘val’
> does break strict-aliasing rules
> ../include/boost/spirit/home/classic/core/composite/actions.hpp:110:
> note: initialized from here
> ../include/boost/spirit/home/classic/core/scanner/scanner.hpp:132:
> warning: dereferencing pointer ‘val’ does break strict-aliasing rules
> ../include/boost/spirit/home/classic/core/composite/actions.hpp:110:
> note: initialized from here

I'd say you can ignore it.

> My question is, if this is something I should care about and if I'm
> doing something wrong here in using spirit. Is there anything I can do
> to remove these warnings, except moving to the newer version of Spirit
> (which had already been recommended as a general idea on boost-users)?

FWIW, there isn't any difference between Spirit.Classic in V1.39 and V1.40. So it must have been introduced by some other change in Boost.

Regards Hartmut

-------------------
Meet me at BoostCon
http://boostcon.com

>
> Thanks,
> Norbert
>
>
> <code>
> #include "boost/spirit.hpp"
> #include "boost/bind.hpp"
>
> #include <string>
>
> struct Object
> {
>     void obj_param(double param) {}
> };
>
> void get_param(double param) {}
>
> int main(int argc, char **argv)
> {
>     Object theObj;
>     std::string toParse;
>
>     using namespace boost::spirit;
>     using boost::bind;
>     using boost::ref;
>
>     parse(toParse.c_str(), real_p[bind(&Object::obj_param, ref(theObj),
> _1)], space_p).full;
>     parse(toParse.c_str(), real_p[&get_param], space_p).full;
>
>     return 0;
> }
> </code>



------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Spirit-general mailing list
Spirit-general@...
https://lists.sourceforge.net/lists/listinfo/spirit-general

Re: Warnings in gcc 4.4.1 with optimization

by Norbert Wenzel-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 11/06/2009 01:16 AM, Hartmut Kaiser wrote:

>> The output of the compiler gives the following two warnings, where the
>> first is for the action using bind and the second is for the action
>> using a standard function pointer:
>> ../include/boost/bind/bind.hpp:311: warning: dereferencing pointer
>> ‘val’
>> does break strict-aliasing rules
>> ../include/boost/spirit/home/classic/core/composite/actions.hpp:110:
>> note: initialized from here
>> ../include/boost/spirit/home/classic/core/scanner/scanner.hpp:132:
>> warning: dereferencing pointer ‘val’ does break strict-aliasing rules
>> ../include/boost/spirit/home/classic/core/composite/actions.hpp:110:
>> note: initialized from here
>
> I'd say you can ignore it.

Thanks for your help.

>> My question is, if this is something I should care about and if I'm
>> doing something wrong here in using spirit. Is there anything I can do
>> to remove these warnings, except moving to the newer version of Spirit
>> (which had already been recommended as a general idea on boost-users)?
>
> FWIW, there isn't any difference between Spirit.Classic in V1.39 and V1.40. So it must have been introduced by some other change in Boost.

I had expected that for bind, but I was wondering about the same warning
when using the standard function pointer. Anyway, since the code didn't
change and the parsing is working fine, I'll ignore the warning.

thanks,
Norbert

>> <code>
>> #include "boost/spirit.hpp"
>> #include "boost/bind.hpp"
>>
>> #include<string>
>>
>> struct Object
>> {
>>      void obj_param(double param) {}
>> };
>>
>> void get_param(double param) {}
>>
>> int main(int argc, char **argv)
>> {
>>      Object theObj;
>>      std::string toParse;
>>
>>      using namespace boost::spirit;
>>      using boost::bind;
>>      using boost::ref;
>>
>>      parse(toParse.c_str(), real_p[bind(&Object::obj_param, ref(theObj),
>> _1)], space_p).full;
>>      parse(toParse.c_str(), real_p[&get_param], space_p).full;
>>
>>      return 0;
>> }
>> </code>

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Spirit-general mailing list
Spirit-general@...
https://lists.sourceforge.net/lists/listinfo/spirit-general

Re: Warnings in gcc 4.4.1 with optimization

by ben qhq :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have a similar problem with gcc 4.4 but not gcc 4.3
just add option -fno-ipa-cp is ok.

g++ -O2 -fno-ipa-cp