Archived issue #0024252

GCC warnings on breakage of strict-aliasing rules

Open CASCADEOCCT:Codingclosed3 public notes

Search issues

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

Steps to reproduce

Public activity

3 archived notes

Participants are labeled by their role within this record.

01Commenter 1
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
02Commenter 2
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.
03Commenter 3
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.

Related records