Archived issue #0024252
GCC warnings on breakage of strict-aliasing rules
Description
When building OCCT on Linux platforms, GCC reports multiple warnings on breakage of strict-aliasing rules (about 100 cases in total), for instance:
NCollection_DataMap.hxx:175: dereferencing type-punned pointer will break strict-aliasing rules
TopoDS_Shape.hxx:54: dereferencing pointer ‘E’ does break strict-aliasing rules
NCollection_DataMap.hxx:175: dereferencing type-punned pointer will break strict-aliasing rules
TopoDS_Shape.hxx:54: dereferencing pointer ‘E’ does break strict-aliasing rules
Steps to reproduce
Public activity
3 archived notes
Participants are labeled by their role within this record.
The branch CR24252 is created.
Violation of strict aliasing rules can lead to undefined behaviour when optimization mode is -O2 or higher.
One of possible solutions is usage of union to reference to an object using different types.
Please read
http://www.cyberforum.ru/c/thread802307.html
http://dbp-consulting.com/tutorials/StrictAliasing.html
http://cellperformance.beyond3d.com/articles/2006/06/understanding-strict-aliasing.html
Violation of strict aliasing rules can lead to undefined behaviour when optimization mode is -O2 or higher.
One of possible solutions is usage of union to reference to an object using different types.
Please read
http://www.cyberforum.ru/c/thread802307.html
http://dbp-consulting.com/tutorials/StrictAliasing.html
http://cellperformance.beyond3d.com/articles/2006/06/understanding-strict-aliasing.html
The patch is reviewed; the part which consists in elimination of unnecessary type casts is pushed to branch CR24252_extract; please test. Other remaining problems will be registered as separate issues.
Dear Commenter 1,
Branch CR24252_extract (and products from GIT master) was compiled on Linux and Windows platforms and tested.
[revision removed]
Number of compiler warnings:
occt component :
Linux: 38 (55 on master)
Windows: 1 (1 on master)
products component :
Linux: 12 (20 on master)
Windows: 2 (2 on master)
Regressions/Differences:
No regressions/differences
Testing cases:
Not needed
Testing on Linux:
Total MEMORY difference: 358283328 / 357072508
Total CPU difference: 44045.470000000154 / 42990.139999999854
Testing on Windows:
Total MEMORY difference: 409959504 / 412885964
Total CPU difference: 29722.703125 / 31989.96875
There are not differences in images found by testdiff.
Branch CR24252_extract (and products from GIT master) was compiled on Linux and Windows platforms and tested.
[revision removed]
Number of compiler warnings:
occt component :
Linux: 38 (55 on master)
Windows: 1 (1 on master)
products component :
Linux: 12 (20 on master)
Windows: 2 (2 on master)
Regressions/Differences:
No regressions/differences
Testing cases:
Not needed
Testing on Linux:
Total MEMORY difference: 358283328 / 357072508
Total CPU difference: 44045.470000000154 / 42990.139999999854
Testing on Windows:
Total MEMORY difference: 409959504 / 412885964
Total CPU difference: 29722.703125 / 31989.96875
There are not differences in images found by testdiff.
Related records
- #0024489 · parent of · closedAvoid type casts in call to Standard::Free()
- #0024534 · parent of · closedImprove design of Image_PixMap class
- #0024536 · parent of · closedGCC compiler warning on breakage of pointer aliasing rules in BRepFill_Evolved.cxx
- #0024535 · parent of · closedBad type cast in TDocStd_Document::Update()
- #0024537 · parent of · closedGCC compiler warnings in byte order reversion code