[SERVER-19340] Vendored wiredtiger rand.c fails to compile without -fno-strict-aliasing Created: 09/Jul/15  Updated: 31/Aug/15  Resolved: 12/Aug/15

Status: Closed
Project: Core Server
Component/s: Build, Internal Code, WiredTiger
Affects Version/s: None
Fix Version/s: 3.1.7

Type: Bug Priority: Major - P3
Reporter: Andrew Morrow (Inactive) Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Ubuntu 15.04, GCC 4.9.2


Issue Links:
Depends
is depended on by WT-1973 MongoDB changes for WiredTiger 2.7.0 Closed
is depended on by SERVER-19744 WiredTiger changes for MongoDB 3.0.6 Closed
Related
is related to SERVER-19338 Evaluate feasibility and impact of no... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

Remove -fno-strict-aliasing from the top level SConstruct and build with a modern GCC.

Participants:

 Description   

If the -fno-strict-aliasing flag is removed from the top level SConstruct, the vendored WiredTiger sources in src/third_party/wiredtiger do not compile. In particular, the rand.c file generates strict aliasing errors:

src/third_party/wiredtiger/src/support/rand.c: In function '__wt_random_init':
src/third_party/wiredtiger/src/support/rand.c:57:2: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  M_W(rnd) = 521288629;
  ^
src/third_party/wiredtiger/src/support/rand.c: In function '__wt_random':
src/third_party/wiredtiger/src/support/rand.c:78:2: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  w = M_W(rnd);
  ^
src/third_party/wiredtiger/src/support/rand.c:91:2: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  M_W(rnd) = w = 18000 * (w & 65535) + (w >> 16);
  ^
cc1: all warnings being treated as errors



 Comments   
Comment by Githook User [ 04/Aug/15 ]

Author:

{u'username': u'daveh86', u'name': u'David Hows', u'email': u'howsdav@gmail.com'}

Message: Merge pull request #2088 from wiredtiger/rand-strict-alias

SERVER-19340 Avoid type aliasing in the random number generator.
(cherry picked from commit 3ec45a7204e01a5ac176550fdfef30a7402046e8)
Branch: mongodb-3.0
https://github.com/wiredtiger/wiredtiger/commit/69819d42bbe625ddef576939e112cf4e1e745948

Comment by Githook User [ 28/Jul/15 ]

Author:

{u'username': u'daveh86', u'name': u'David Hows', u'email': u'howsdav@gmail.com'}

Message: Merge pull request #2088 from wiredtiger/rand-strict-alias

SERVER-19340 Avoid type aliasing in the random number generator.
Branch: develop
https://github.com/wiredtiger/wiredtiger/commit/3ec45a7204e01a5ac176550fdfef30a7402046e8

Comment by Githook User [ 28/Jul/15 ]

Author:

{u'username': u'michaelcahill', u'name': u'Michael Cahill', u'email': u'michael.cahill@mongodb.com'}

Message: SERVER-19340 Fix the random state union.
Branch: develop
https://github.com/wiredtiger/wiredtiger/commit/24569ab8457df6a07cd65866a560f6967a51d5fc

Comment by Githook User [ 28/Jul/15 ]

Author:

{u'username': u'michaelcahill', u'name': u'Michael Cahill', u'email': u'michael.cahill@mongodb.com'}

Message: SERVER-19340 Avoid type aliasing in the random number generator.
Branch: develop
https://github.com/wiredtiger/wiredtiger/commit/7063f8b6e80b130f9a682991203384bd05c58f24

Comment by Alexander Gorrod [ 27/Jul/15 ]

david.hows GCC 5.2.0 is not yet supported. There is another ticket covering the warning you report:
https://jira.mongodb.org/browse/SERVER-19353

Comment by David Hows [ 27/Jul/15 ]

I tried to reproduce this on my arch box w/ GCC 5.2.0 but could not get to the point where you failed;

First I hit the following:

src/mongo/base/global_initializer.cpp:44:14: error: 'mongo::{anonymous}::_theGlobalInitializer' defined but not used [-Werror=unused-variable]
 Initializer* _theGlobalInitializer = &getGlobalInitializer();

With that resolved, I hit the following:

In file included from src/mongo/bson/bsonobj.h:48:0,
                 from src/mongo/db/jsobj.h:50,
                 from src/mongo/db/exec/plan_stats.h:37,
                 from src/mongo/db/query/plan_cache.h:34,
                 from src/mongo/db/catalog/collection_info_cache.h:34,
                 from src/mongo/db/catalog/collection.h:41,
                 from src/mongo/db/exec/multi_iterator.h:34,
                 from src/mongo/db/exec/multi_iterator.cpp:31:
src/mongo/util/shared_buffer.h: In member function 'virtual mongo::PlanStage::StageState mongo::MultiIteratorStage::work(mongo::WorkingSetID*)':
src/mongo/util/shared_buffer.h:98:24: error: '*((void*)(& record)+32).boost::intrusive_ptr<mongo::SharedBuffer::Holder>::px' may be used uninitialized in this function [-Werror=maybe-uninitialized]
                 free(h);
                        ^
src/mongo/db/exec/multi_iterator.cpp:66:29: note: '*((void*)(& record)+32).boost::intrusive_ptr<mongo::SharedBuffer::Holder>::px' was declared here
     boost::optional<Record> record;

In file included from src/mongo/db/pipeline/document.h:31:0,
                 from src/mongo/db/pipeline/document_source.h:48,
                 from src/mongo/db/exec/pipeline_proxy.cpp:34:
src/mongo/db/pipeline/document_internal.h: In static member function 'static const mongo::DocumentStorage& mongo::DocumentStorage::emptyDoc()':
src/mongo/db/pipeline/document_internal.h:205:68: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
         return *reinterpret_cast<const DocumentStorage*>(emptyBytes);

Generated at Thu Feb 08 03:50:38 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.