Hi everyone,
I am using RTI's C++ mapping with a recent gcc and g++ -O2
or -O3
. I am getting a lot of warnings because some of the RTI code breaks strict-aliasing rules:
/home/user/src/mycode/generated/Foo.cxx:323:14: note: in expansion of macro 'RTICdrStream_serializeFloat' if (!RTICdrStream_serializeFloat( ^ /opt/rti_connext_dds-5.2.0/include/ndds/cdr/cdr_stream_impl.h:472:55: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] *(RTICdr4Byte *)((me)->_currentPosition) = (*(in)), \ ^ /opt/rti_connext_dds-5.2.0/include/ndds/cdr/cdr_stream_impl.h:709:43: note: in expansion of macro 'RTICdrStream_serialize4ByteFastMacro' #define RTICdrStream_serialize4ByteFast RTICdrStream_serialize4ByteFastMacro ^ /opt/rti_connext_dds-5.2.0/include/ndds/cdr/cdr_stream_impl.h:1242:7: note: in expansion of macro 'RTICdrStream_serialize4ByteFast' (RTICdrStream_serialize4ByteFast((me), (const RTICdr4Byte *)(in)), \ ^ /opt/rti_connext_dds-5.2.0/include/ndds/cdr/cdr_stream_impl.h:1401:39: note: in expansion of macro 'RTICdrStream_serialize4Byte' #define RTICdrStream_serializeFloat RTICdrStream_serialize4Byte ^
This is a problem in several ways:
- With a lot of IDL files, there are a lot of these warnings cluttering up the compiler output.
- Breaking the strict-aliasing rules can turn out to be a huge problem in practice because the compiler may end up producing unsafe code optimizations.
So my questions are:
- Is there any sort of guarantee that this will notlead to any problems in practice? I.e., is it truly safe to disable the warning?
- Do you have any plans or suggestions to improve the code?
Thanks in advance.
Hi Jan,
There is an issue filed to fix these warnings in our generated code: CORE-6778. The resolution is scheduled for our next GAR.
So far I have not seen any reported alising problems in the generated code. However, as you well indicated, this does not mean that there will not be problems down the road.
To be safe, my recommnendation is to compile the generated code with the flag -fno-strict-aliasing. This will also suppress the warnings.
Best Regards,
- Fernando
Hi Fernando,
thanks very much for your information. I will switch to -fno-strict-aliasing for the time being.
Jan
Have this error been resolved? I'm using RTI 5.3.2 with gcc 6.2 and it geenerates the same error when coplining with -O2 and using float type in ILD structures.