Archived issue #0024537
GCC compiler warnings in byte order reversion code
Description
GCC produces warnings on breakage of pointer aliasing rules in code related to conversion of data between low-endian and big-endian formats, see #0024252:
FSD_FileHeader.hxx:101: warning: dereferencing type-punned pointer will break strict-aliasing rules
BinObjMgt_Persistent.cxx:1109: warning: dereferencing type-punned pointer will break strict-aliasing rules
FSD_BinaryFile.cxx:417: warning: dereferencing type-punned pointer will break strict-aliasing rules
The code can be corrected to use unions for this conversion. The problem however is that that code is not tested now, as all currently supported platforms are based on Intel x86 architecture and thus are low-endian. Thus specific tests need to be created for this functionality.
It is also a question whether big-endian platforms need to be supported at all. As it seems, existing and potential target platforms for OCCT (including iOS and Android on ARM processors) all use little-endian convention (even if ARM is bi-endian).
FSD_FileHeader.hxx:101: warning: dereferencing type-punned pointer will break strict-aliasing rules
BinObjMgt_Persistent.cxx:1109: warning: dereferencing type-punned pointer will break strict-aliasing rules
FSD_BinaryFile.cxx:417: warning: dereferencing type-punned pointer will break strict-aliasing rules
The code can be corrected to use unions for this conversion. The problem however is that that code is not tested now, as all currently supported platforms are based on Intel x86 architecture and thus are low-endian. Thus specific tests need to be created for this functionality.
It is also a question whether big-endian platforms need to be supported at all. As it seems, existing and potential target platforms for OCCT (including iOS and Android on ARM processors) all use little-endian convention (even if ARM is bi-endian).
Steps to reproduce
test bugs fclasses bug24537
Public activity
18 archived notes
Participants are labeled by their role within this record.
Branch [archived branch] has been created by Participant.
[revision removed]
Detailed log of new commits:
Author: dln
Date: Tue Sep 9 14:54:08 2014 +0400
0024537: GCC compiler warnings in byte order reversion code
- preliminary version of the fix for test
[revision removed]
Detailed log of new commits:
Author: dln
Date: Tue Sep 9 14:54:08 2014 +0400
0024537: GCC compiler warnings in byte order reversion code
- preliminary version of the fix for test
Branch [archived branch] has been updated forcibly by Participant.
[revision removed]
[revision removed]
Branch [archived branch] has been updated forcibly by Participant.
[revision removed]
[revision removed]
Dear abv,
check it please
check it please
Branch [archived branch] has been created by Participant.
[revision removed]
Detailed log of new commits:
Author: dln
Date: Tue Sep 9 14:54:08 2014 +0400
0024537: GCC compiler warnings in byte order reversion code
- warnings in byte order inversion functionality is fixed with unions
- test case (simulation of conversion to big endian) is added
[revision removed]
Detailed log of new commits:
Author: dln
Date: Tue Sep 9 14:54:08 2014 +0400
0024537: GCC compiler warnings in byte order reversion code
- warnings in byte order inversion functionality is fixed with unions
- test case (simulation of conversion to big endian) is added
Please review again.
Sorry, the new test case fails on x64 platform. It needs to be reworked.
Branch [archived branch] has been updated forcibly by Participant.
[revision removed]
[revision removed]
The test case has been reworked. Now it is completely hard-coded inside the draw command OCC24537.
Andrey, please review the branch CR24537.
Andrey, please review the branch CR24537.
I suggest that some corrections should be made:
1. In FSD_FileHeader.hxx:
- it can be worth moving this code to cxx or separate header (in BinTools?), to avoid defining this stuff (very special and not used in practice) globally
- it can be worth renaming macro DO_INVERSE to something more specific, at least prefix it with "OCCT_"
- it can be worth adding Standard_StaticAssert to check that sizeof(ShortReal) == sizeof(Integer) and sizeof(Real) == 2 * sizeof(Integer) etc.; alternatively templated version can be used (just as for Size)
- InverseSizeSpecialized <4> can be just a call to InverseInt()
- InverseLong() is obviously not correct for 64-bit systems where long is 8 bytes in size; it can be removed as unused, or implemented in the same way as for Size
2. In BinObjMgt_Persistent.cxx:
- I believe this will not work as before on 32-bit systems, since before aData was double* (incremented by 8 bytes) and now &aWrapUnion.anAddrData is void** (incremented by 4 bytes):
- aPrevPtr = &aData[aLenInPiece / BP_REALSIZE];
+ aPrevPtr = (&aWrapUnion.anAddrData)[aLenInPiece / BP_REALSIZE];
- I deem that casting char* to double* is generally bad idea, since on some architectures this may cause alignment failure. Why not just to move along myData by 8-byte sequences, copying them to buffer, then converting and placing back?
3. In QABugs_19.cxx: I suggest using more disperse set of probing values, not just 1-2-3. For instance:
- int: -4000000, -1234, 0, 1, 1234, 4000000
- double: -1e300, -1e-9, 0., 1.e-9, 1., 3.1415296, 1e100
- float: -1e-9, 0., 1.e-9, 1., 3.1415
1. In FSD_FileHeader.hxx:
- it can be worth moving this code to cxx or separate header (in BinTools?), to avoid defining this stuff (very special and not used in practice) globally
- it can be worth renaming macro DO_INVERSE to something more specific, at least prefix it with "OCCT_"
- it can be worth adding Standard_StaticAssert to check that sizeof(ShortReal) == sizeof(Integer) and sizeof(Real) == 2 * sizeof(Integer) etc.; alternatively templated version can be used (just as for Size)
- InverseSizeSpecialized <4> can be just a call to InverseInt()
- InverseLong() is obviously not correct for 64-bit systems where long is 8 bytes in size; it can be removed as unused, or implemented in the same way as for Size
2. In BinObjMgt_Persistent.cxx:
- I believe this will not work as before on 32-bit systems, since before aData was double* (incremented by 8 bytes) and now &aWrapUnion.anAddrData is void** (incremented by 4 bytes):
- aPrevPtr = &aData[aLenInPiece / BP_REALSIZE];
+ aPrevPtr = (&aWrapUnion.anAddrData)[aLenInPiece / BP_REALSIZE];
- I deem that casting char* to double* is generally bad idea, since on some architectures this may cause alignment failure. Why not just to move along myData by 8-byte sequences, copying them to buffer, then converting and placing back?
3. In QABugs_19.cxx: I suggest using more disperse set of probing values, not just 1-2-3. For instance:
- int: -4000000, -1234, 0, 1, 1234, 4000000
- double: -1e300, -1e-9, 0., 1.e-9, 1., 3.1415296, 1e100
- float: -1e-9, 0., 1.e-9, 1., 3.1415
Branch [archived branch] has been updated forcibly by Participant.
[revision removed]
[revision removed]
I have considered some remarks. It is needed to continue the fix. The current version of the branch CR24537 must be re-based on current master before continuing. It can be not compilable.
Branch [archived branch] has been created by Participant.
[revision removed]
Detailed log of new commits:
Author: rkv
Date: Tue Sep 22 12:48:04 2015 +0300
0024537: GCC compiler warnings in byte order reversion code
- warnings in byte order inversion functionality is fixed with unions
- test case (simulation of conversion to big endian) is added
[revision removed]
Detailed log of new commits:
Author: rkv
Date: Tue Sep 22 12:48:04 2015 +0300
0024537: GCC compiler warnings in byte order reversion code
- warnings in byte order inversion functionality is fixed with unions
- test case (simulation of conversion to big endian) is added
Reviewed.
Dear Commenter 2,
Branch CR24537_3 from occt git-repository (and master from products git-repository) was compiled on Linux, MacOS and Windows platforms and tested on Release mode.
[revision removed]
Number of compiler warnings:
occt component :
Linux: 13 (15 on master)
Windows: 0 (0 on master)
products component :
Linux: 39 (39 on master)
Windows: 0 (0 on master)
There is new additional compilation warning on Linux platform:
There are compilation errors in Qt samples products on windows platform:
Regressions/Differences/Improvements:
No regressions/differences
Testing cases:
http://occt-tests/CR24537-3-master-occt-64/Debian70-64/bugs/fclasses/bug24537.html
http://occt-tests/CR24537-3-master-occt-64/Windows-64-VC10/bugs/fclasses/bug24537.html
bugs fclasses bug24537: OK
Testing on Linux:
occt component :
Total MEMORY difference: 92282120 / 92105726 [+0.19%]
Total CPU difference: 18763.229999999014 / 18665.439999998966 [+0.52%]
products component :
Total MEMORY difference: 25921386 / 25980951 [-0.23%]
Total CPU difference: 7418.7299999999905 / 7208.589999999996 [+2.92%]
Testing on Windows:
occt component :
Total MEMORY difference: 56806777 / 56823447 [-0.03%]
Total CPU difference: 18049.986504299017 / 16808.499346099128 [+7.39%]
products component :
Total MEMORY difference: 16785580 / 16790438 [-0.03%]
Total CPU difference: 5934.1844394 / 5526.49142599996 [+7.38%]
There are no differences in images found by testdiff.
Branch CR24537_3 from occt git-repository (and master from products git-repository) was compiled on Linux, MacOS and Windows platforms and tested on Release mode.
[revision removed]
Number of compiler warnings:
occt component :
Linux: 13 (15 on master)
Windows: 0 (0 on master)
products component :
Linux: 39 (39 on master)
Windows: 0 (0 on master)
There is new additional compilation warning on Linux platform:
There are compilation errors in Qt samples products on windows platform:
Regressions/Differences/Improvements:
No regressions/differences
Testing cases:
http://occt-tests/CR24537-3-master-occt-64/Debian70-64/bugs/fclasses/bug24537.html
http://occt-tests/CR24537-3-master-occt-64/Windows-64-VC10/bugs/fclasses/bug24537.html
bugs fclasses bug24537: OK
Testing on Linux:
occt component :
Total MEMORY difference: 92282120 / 92105726 [+0.19%]
Total CPU difference: 18763.229999999014 / 18665.439999998966 [+0.52%]
products component :
Total MEMORY difference: 25921386 / 25980951 [-0.23%]
Total CPU difference: 7418.7299999999905 / 7208.589999999996 [+2.92%]
Testing on Windows:
occt component :
Total MEMORY difference: 56806777 / 56823447 [-0.03%]
Total CPU difference: 18049.986504299017 / 16808.499346099128 [+7.39%]
products component :
Total MEMORY difference: 16785580 / 16790438 [-0.03%]
Total CPU difference: 5934.1844394 / 5526.49142599996 [+7.38%]
There are no differences in images found by testdiff.
Branch [archived branch] has been deleted by Commenter 1.
[revision removed]
[revision removed]
Branch [archived branch] has been deleted by Commenter 1.
[revision removed]
[revision removed]
Branch [archived branch] has been deleted by Commenter 1.
[revision removed]
[revision removed]
Related records