diff options
author | Josef Ahmad <josef.ahmad@mongodb.com> | 2022-09-15 06:14:58 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-09-19 23:04:49 +0000 |
commit | da082157917de5178828aae111b32c870f664852 (patch) | |
tree | e5523cd23a6a94160af387d7cef4ac1151a1096d | |
parent | 52940805f01b2599ed6ed3221094716766e347ac (diff) | |
download | mongo-da082157917de5178828aae111b32c870f664852.tar.gz |
SERVER-69611 Set the -ffp-contract=off compiler option by default
(cherry picked from commit d8901a2835d3f464d394631d85dc7aa9493fc095)
-rwxr-xr-x | SConstruct | 9 | ||||
-rw-r--r-- | jstests/noPassthrough/floating_point_exp_contraction_off.js | 47 |
2 files changed, 56 insertions, 0 deletions
diff --git a/SConstruct b/SConstruct index a0700af4f92..bd2fb097deb 100755 --- a/SConstruct +++ b/SConstruct @@ -2115,6 +2115,15 @@ for suboption in get_option('experimental-runtime-hardening'): elif suboption.startswith('+'): selected_experimental_runtime_hardenings.add(suboption[1:]) +# Disable floating-point contractions such as forming of fused multiply-add operations. +if env.ToolchainIs('clang', 'gcc'): + env.Append(CCFLAGS=["-ffp-contract=off"]) +else: + # msvc defaults to /fp:precise. Visual Studio 2022 does not emit floating-point contractions + # with /fp:precise, but previous versions can. Disable contractions altogether by using + # /fp:strict. + env.Append(CCFLAGS=["/fp:strict"]) + if env.TargetOSIs('linux'): env.Append( LIBS=["m"] ) if not env.TargetOSIs('android'): diff --git a/jstests/noPassthrough/floating_point_exp_contraction_off.js b/jstests/noPassthrough/floating_point_exp_contraction_off.js new file mode 100644 index 00000000000..601dcd20f0d --- /dev/null +++ b/jstests/noPassthrough/floating_point_exp_contraction_off.js @@ -0,0 +1,47 @@ +/** + * Validates that the server doesn't use fused multiply-add instructions (-ffp-contract=off). + * + * @tags: [ + * multiversion_incompatible, + * ] + */ + +(function() { +'use strict'; + +const conn = MongoRunner.runMongod(); + +const coll = conn.getDB('test').getCollection('c'); + +assert.commandWorked(coll.createIndex({loc: "2dsphere"})); +assert.commandWorked(coll.insertOne({ + "loc": { + "type": "Polygon", + "coordinates": [[ + [-85.0329458713531, 41.3677690255613], + [-85.0296092033386, 41.3677690255613], + [-85.0296092033386, 41.360594065847], + [-85.0329458713531, 41.360594065847], + [-85.0329458713531, 41.3677690255613] + ]] + } +})); + +// Assert that the query returns the document. If the query does not return any result, then +// this is likely because of different rounding due to fused multiply-add instructions on platforms +// that have native support, like arm64. +assert.eq( + 1, + coll.find({ + "loc": { + "$near": { + "$geometry": + {"type": "Point", "coordinates": [-85.031218528747559, 41.364586470348961]}, + "$maxDistance": 0 + } + } + }) + .itcount()); + +MongoRunner.stopMongod(conn); +}()); |