View Issue Details

IDProjectCategoryView StatusLast Update
0029825Open CASCADEOCCT:Foundation Classespublic2018-07-21 20:02
Reporterkgv Assigned Tobugmaster  
PrioritynormalSeverityminor 
Status closedResolutionfixed 
Product Version7.2.0 
Target Version7.4.0Fixed in Version7.4.0 
Summary0029825: Foundation Classes, NCollection_Vec4 - workaround gcc optimizer issues with xyz() method
Descriptiongcc (of some old versions, like gcc 4.7, 4.8, 7.2.0) has known issue with xyz() method returning a reference to vector of smaller size like this:
  //! @return XYZ-components modifiable vector
  NCollection_Vec3<Element_t>& xyz()
  {
    return *((NCollection_Vec3<Element_t>* )&v[0]);

The problem is that gcc considers method as "dereferencing type-punned pointer will break strict aliasing", and following strict aliasing rules it might remove essential code lines.
Steps To Reproduce
  NCollection_Mat4<float> aMatrix;
  aMatrix.Translate (NCollection_Vec3<float> (4.0f, 3.0f, 1.0f));

  NCollection_Vec4<float> aPoints1[8];
  for (int aX = 0; aX < 2; ++aX)
  {
    for (int aY = 0; aY < 2; ++aY)
    {
      for (int aZ = 0; aZ < 2; ++aZ)
      {
        aPoints1[aX * 2 * 2 + aY * 2 + aZ] =
          NCollection_Vec4<float> (-1.0f + 2.0f * float(aX),
                                   -1.0f + 2.0f * float(aY),
                                   -1.0f + 2.0f * float(aZ),
                                    1.0f);
      }
    }
  }

  NCollection_Vec3<float> aPoints2[8];
  for (int aPntIdx = 0; aPntIdx < 8; ++aPntIdx)
  {
    // bug, the evaluation of line below can be dropped by optimizer
    // while retrieving xyz() value the line after
    aPoints1[aPntIdx] = aMatrix * aPoints1[aPntIdx];
    aPoints2[aPntIdx] = aPoints1[aPntIdx].xyz() / aPoints1[aPntIdx].w();
    //aPoints2[aPntIdx] = NCollection_Vec3<float> (aPoints1[aPntIdx].x(),
                                                   aPoints1[aPntIdx].y(),
                                                   aPoints1[aPntIdx].z())
                        / aPoints1[aPntIdx].w();
  }
TagsNo tags attached.
Test case numbercollections/n/vec4

Relationships

related to 0029826 closedbugmaster Open CASCADE Tests - test case perf/fclasses/strtod is unstable 

Activities

git

2018-05-30 13:54

administrator   ~0076436

Branch CR29825 has been created by kgv.

SHA-1: 24ee470b4f8629c931665e609f5e09dcb7ef95bf


Detailed log of new commits:

Author: kgv
Date: Wed May 30 13:54:02 2018 +0300

    0029825: Foundation Classes, NCollection_Vec4 - workaround gcc optimizer issues with xyz() method

git

2018-05-30 18:59

administrator   ~0076454

Branch CR29825 has been updated forcibly by kgv.

SHA-1: 100b940b254d0200468e5f8ba8f92b432eec8d94

git

2018-05-30 21:01

administrator   ~0076458

Branch CR29825 has been updated by kgv.

SHA-1: e97d95e5c5a017441c4cb71e3535244816d70889


Detailed log of new commits:

Author: kgv
Date: Wed May 30 21:01:26 2018 +0300

    Define proxy structures NCollection_Vec2Ref/NCollection_Vec3Ref
    for returning modifiable entities from methods like NCollection_Vec4::xyz().

git

2018-05-30 21:53

administrator   ~0076459

Branch CR29825 has been updated forcibly by kgv.

SHA-1: d04beea68345b8ef4f10889757f6fae25b56048e

git

2018-05-30 21:57

administrator   ~0076460

Branch CR29825 has been updated forcibly by kgv.

SHA-1: e44e39e96fc9991f7ff4e6fbff65436512df7656

git

2018-05-30 23:08

administrator   ~0076461

Branch CR29825 has been updated forcibly by kgv.

SHA-1: 2eeca5883916860d617103903dd9e0ffe1f2e0fc

git

2018-05-30 23:18

administrator   ~0076462

Branch CR29825 has been updated forcibly by kgv.

SHA-1: 3ee8f2941c3aaed772ee19c60978506a72336a1c

git

2018-05-30 23:29

administrator   ~0076463

Branch CR29825 has been updated forcibly by kgv.

SHA-1: bd68da72cee9c6162c35ed48e490a4f3529bb4c1

git

2018-05-31 00:58

administrator   ~0076464

Branch CR29825 has been updated forcibly by kgv.

SHA-1: 907bb316328c7025ab3b8113a70910ed226d7032

kgv

2018-05-31 01:01

developer   ~0076465

Last edited: 2018-05-31 08:13

Patch is ready for review.

http://jenkins-test-11.nnov.opencascade.com/view/CR29825-master-KGV/

git

2018-05-31 13:04

administrator   ~0076478

Branch CR29825 has been updated by kgv.

SHA-1: cabbf3bf0835fcdfa764012ce19da31e79453753


Detailed log of new commits:

Author: kgv
Date: Thu May 31 13:04:29 2018 +0300

    # workaround crash of SWIG prepocessor

git

2018-05-31 13:19

administrator   ~0076479

Branch CR29825 has been updated by kgv.

SHA-1: 0ed443c465cce0998b992d9e9575bc0cca19364b


Detailed log of new commits:

Author: kgv
Date: Thu May 31 13:18:55 2018 +0300

    # extend description of proxy classes

git

2018-06-02 16:05

administrator   ~0076547

Branch CR29825_del_xyz has been created by kgv.

SHA-1: 82cc66a6c77b27d21bf3bf2c804b624a613709d9


Detailed log of new commits:

Author: kgv
Date: Sat Jun 2 16:05:11 2018 +0300

    Eliminate NCollection_Vec4::xyz() returning a reference to NCollection_Vec3

Author: kgv
Date: Wed May 30 18:59:12 2018 +0300

    0029825: Foundation Classes, NCollection_Vec4 - workaround gcc optimizer issues with xyz() method

git

2018-06-05 12:24

administrator   ~0076610

Branch CR29825_2 has been created by abv.

SHA-1: 928d9f666c8e98e2e99581a34ab3cf6b3e2a8e14


Detailed log of new commits:

Author: kgv
Date: Wed May 30 18:59:12 2018 +0300

    0029825: Foundation Classes, NCollection_Vec4 - workaround gcc optimizer issues with xyz() method
    
    Methods of NCollection_Vec3 and NCollection_Vec3 that returned reference to internal buffer as vector of lower dimension (non-const xy(), xyz() etc.) are eliminated.
    Use of these methods could led to generation of incorrect binary code by GCC.
    Instead added new method SetValues() accepting vector of lower dimension and additional value.
    
    DRAW test command QANColTestVec4 reproducing one situation where the bug occurs is added, along with a test case.

abv

2018-06-05 16:33

manager   ~0076621

Reviewed with amendments and tested, see branch CR29825_2 and Jenkins job CR29825-master-KGV

bugmaster

2018-06-06 12:12

administrator   ~0076632

Combination -
OCCT branch : CR29825_2 SHA - 928d9f666c8e98e2e99581a34ab3cf6b3e2a8e14
Products branch : master SHA - 82570c1f4b0e27eb09789f573087eef089260f59
was compiled on Linux, MacOS and Windows platforms and tested in optimize mode.

Number of compiler warnings:
No new/fixed warnings

Regressions/Differences/Improvements:
No regressions/differences

CPU differences:
Debian70-64:
OCCT
Total CPU difference: 17047.97000000008 / 17011.039999999866 [+0.22%]
Products
Total CPU difference: 7454.750000000047 / 7518.500000000041 [-0.85%]
Windows-64-VC10:
OCCT
Total CPU difference: 16828.4986742986 / 16821.806231398525 [+0.04%]
Products
Total CPU difference: 8237.14920189988 / 8177.369618699882 [+0.73%]


Image differences :
No differences that require special attention

Memory differences :
No differences that require special attention

git

2018-06-23 13:57

administrator   ~0076969

Branch CR29825_2 has been deleted by kgv.

SHA-1: 928d9f666c8e98e2e99581a34ab3cf6b3e2a8e14

git

2018-06-23 13:57

administrator   ~0076970

Branch CR29825_del_xyz has been deleted by kgv.

SHA-1: 82cc66a6c77b27d21bf3bf2c804b624a613709d9

git

2018-06-30 13:34

administrator   ~0077140

Branch CR29825 has been deleted by inv.

SHA-1: 0ed443c465cce0998b992d9e9575bc0cca19364b

git

2018-06-30 14:17

administrator   ~0077170

Branch CR29825 has been created by kgv.

SHA-1: cc5fa75f2b903d0b6a84e7374ad35136fc2af6e8


Detailed log of new commits:

Author: kgv
Date: Wed Jun 6 22:42:11 2018 +0300

    0029847: Visualization, Image_Diff - Tolerance is not effective for 24/32bit image formats
    
    Image_Color - removed semibroken summ/difference operators.
    Image_Diff now uses signed integer for computing differnce between ubyte3 components.

Author: kgv
Date: Thu May 31 13:18:55 2018 +0300

    # extend description of proxy classes

Author: kgv
Date: Thu May 31 13:04:29 2018 +0300

    # workaround crash of SWIG prepocessor

Author: kgv
Date: Thu May 31 00:58:06 2018 +0300

    Define proxy structures NCollection_Vec2Ref/NCollection_Vec3Ref
    for returning modifiable entities from methods like NCollection_Vec4::xyz().

Author: kgv
Date: Wed May 30 18:59:12 2018 +0300

    0029825: Foundation Classes, NCollection_Vec4 - workaround gcc optimizer issues with xyz() method

git

2018-07-08 12:00

administrator   ~0077366

Branch CR29825 has been deleted by inv.

SHA-1: cc5fa75f2b903d0b6a84e7374ad35136fc2af6e8

git

2018-07-08 13:10

administrator   ~0077375

Branch CR29825 has been created by kgv.

SHA-1: cc5fa75f2b903d0b6a84e7374ad35136fc2af6e8


Detailed log of new commits:

Author: kgv
Date: Wed Jun 6 22:42:11 2018 +0300

    0029847: Visualization, Image_Diff - Tolerance is not effective for 24/32bit image formats
    
    Image_Color - removed semibroken summ/difference operators.
    Image_Diff now uses signed integer for computing differnce between ubyte3 components.

Author: kgv
Date: Thu May 31 13:18:55 2018 +0300

    # extend description of proxy classes

Author: kgv
Date: Thu May 31 13:04:29 2018 +0300

    # workaround crash of SWIG prepocessor

Author: kgv
Date: Thu May 31 00:58:06 2018 +0300

    Define proxy structures NCollection_Vec2Ref/NCollection_Vec3Ref
    for returning modifiable entities from methods like NCollection_Vec4::xyz().

Author: kgv
Date: Wed May 30 18:59:12 2018 +0300

    0029825: Foundation Classes, NCollection_Vec4 - workaround gcc optimizer issues with xyz() method

git

2018-07-14 12:42

administrator   ~0077624

Branch CR29825 has been deleted by inv.

SHA-1: cc5fa75f2b903d0b6a84e7374ad35136fc2af6e8

git

2018-07-14 12:58

administrator   ~0077627

Branch CR29825 has been created by kgv.

SHA-1: cc5fa75f2b903d0b6a84e7374ad35136fc2af6e8


Detailed log of new commits:

Author: kgv
Date: Wed Jun 6 22:42:11 2018 +0300

    0029847: Visualization, Image_Diff - Tolerance is not effective for 24/32bit image formats
    
    Image_Color - removed semibroken summ/difference operators.
    Image_Diff now uses signed integer for computing differnce between ubyte3 components.

Author: kgv
Date: Thu May 31 13:18:55 2018 +0300

    # extend description of proxy classes

Author: kgv
Date: Thu May 31 13:04:29 2018 +0300

    # workaround crash of SWIG prepocessor

Author: kgv
Date: Thu May 31 00:58:06 2018 +0300

    Define proxy structures NCollection_Vec2Ref/NCollection_Vec3Ref
    for returning modifiable entities from methods like NCollection_Vec4::xyz().

Author: kgv
Date: Wed May 30 18:59:12 2018 +0300

    0029825: Foundation Classes, NCollection_Vec4 - workaround gcc optimizer issues with xyz() method

git

2018-07-21 20:02

administrator   ~0077894

Branch CR29825 has been deleted by inv.

SHA-1: cc5fa75f2b903d0b6a84e7374ad35136fc2af6e8

Related Changesets

occt: master bc379358

2018-05-30 15:59:12

kgv


Committer: bugmaster Details Diff
0029825: Foundation Classes, NCollection_Vec4 - workaround gcc optimizer issues with xyz() method

Methods of NCollection_Vec3 and NCollection_Vec3 that returned reference to internal buffer as vector of lower dimension (non-const xy(), xyz() etc.) are eliminated.
Use of these methods could led to generation of incorrect binary code by GCC.
Instead added new method SetValues() accepting vector of lower dimension and additional value.

DRAW test command QANColTestVec4 reproducing one situation where the bug occurs is added, along with a test case.
Affected Issues
0029825
mod - src/NCollection/NCollection_Vec3.hxx Diff File
mod - src/NCollection/NCollection_Vec4.hxx Diff File
mod - src/OpenGl/OpenGl_BackgroundArray.cxx Diff File
mod - src/OpenGl/OpenGl_Context.cxx Diff File
mod - src/OpenGl/OpenGl_Material.hxx Diff File
mod - src/OpenGl/OpenGl_Text.cxx Diff File
mod - src/QANCollection/QANCollection_Test.cxx Diff File
mod - src/Select3D/Select3D_SensitivePrimitiveArray.cxx Diff File
add - tests/collections/n/vec4 Diff File

Issue History

Date Modified Username Field Change
2018-05-30 12:49 kgv New Issue
2018-05-30 12:49 kgv Assigned To => kgv
2018-05-30 13:54 git Note Added: 0076436
2018-05-30 18:59 git Note Added: 0076454
2018-05-30 19:02 kgv Description Updated
2018-05-30 19:04 kgv Description Updated
2018-05-30 19:04 kgv Steps to Reproduce Updated
2018-05-30 21:01 git Note Added: 0076458
2018-05-30 21:53 git Note Added: 0076459
2018-05-30 21:57 git Note Added: 0076460
2018-05-30 23:08 git Note Added: 0076461
2018-05-30 23:18 git Note Added: 0076462
2018-05-30 23:29 git Note Added: 0076463
2018-05-31 00:58 git Note Added: 0076464
2018-05-31 01:01 kgv Note Added: 0076465
2018-05-31 01:01 kgv Assigned To kgv => abv
2018-05-31 01:01 kgv Status new => resolved
2018-05-31 08:13 kgv Note Edited: 0076465
2018-05-31 08:24 kgv Relationship added related to 0029826
2018-05-31 13:04 git Note Added: 0076478
2018-05-31 13:19 git Note Added: 0076479
2018-06-02 14:40 kgv Description Updated
2018-06-02 16:05 git Note Added: 0076547
2018-06-05 12:24 git Note Added: 0076610
2018-06-05 16:33 abv Note Added: 0076621
2018-06-05 16:33 abv Assigned To abv => bugmaster
2018-06-05 16:33 abv Status resolved => reviewed
2018-06-06 12:08 bugmaster Status reviewed => tested
2018-06-06 12:09 bugmaster Test case number => collections/n/vec4
2018-06-06 12:12 bugmaster Note Added: 0076632
2018-06-14 18:20 bugmaster Changeset attached => occt master bc379358
2018-06-14 18:20 bugmaster Status tested => verified
2018-06-14 18:20 bugmaster Resolution open => fixed
2018-06-23 13:57 git Note Added: 0076969
2018-06-23 13:57 git Note Added: 0076970
2018-06-30 13:34 git Note Added: 0077140
2018-06-30 14:17 git Note Added: 0077170
2018-07-08 12:00 git Note Added: 0077366
2018-07-08 13:10 git Note Added: 0077375
2018-07-14 12:42 git Note Added: 0077624
2018-07-14 12:58 git Note Added: 0077627
2018-07-21 20:02 git Note Added: 0077894