side_robust/overlay: GCC -ffp-contract=fast on x86-64-v3 breaks adaptive predicates (ST_SymDifference loses polygons)
I maintainer di solito rispondono entro 2 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 57/100
Direzione di ricerca
Begin in util/precise_math.hpp: read two_diff/two_product and confirm that only the explicit std::fma may fuse; the pragma added by PR #1453 in index/detail/algorithms/content.hpp is the precedent to mirror. First reproduce: build the ST_SymDifference WKT from st_symdifference.test with -O3 -DNDEBUG -march=x86-64-v3 and check the first geometry's area is 7.93333 rather than 76.1482. Done when that build returns the three polygons (68.2149, 5, 2.93333) with contraction left on and the geometry tests still pass.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Environment
- Boost.Geometry 1.84.0 (bundled with MySQL 8.4.11)
- GCC 15.2.0, Ubuntu 26.04, x86-64 (
-march=x86-64-v3, FMA available) - Flags:
-O3 -DNDEBUG - Compiler defaults: GCC
-ffp-contract=fast(contracts across statements);
Clang defaults to-ffp-contract=onand is not affected. - Affected path:
strategies/relate/cartesian.hppselects
strategy::side::side_robust, which usesutil/precise_math.hpp
(two_diff,two_productviastd::fma).strategy/cartesian/precise_area.hpp
uses the same helpers.
Summary
With GCC's default -ffp-contract=fast, expressions inside the adaptive
predicates can be fused into FMA across statements. precise_math.hpp
implements Shewchuk-style error-free transformations that are only correct if
every +, -, * rounds exactly as written and only the explicit
std::fma is fused. Once a product or a tail is contracted, the returned
"rounding error" is no longer exact, the filter's error bound is violated, and
side_robust can return the wrong sign for near-degenerate configurations.
Overlay then selects the wrong topology and output polygons disappear.
Reproducer (deterministic, MySQL SQL)
WKT from mysql-test/suite/gis/t/st_symdifference.test:
SET @a = 'MULTIPOLYGON(((5 0,15 5,25 0,22 10,30 15,19 15,5 0)),((19 15,15 25,11 15,19 15)))';
SET @b = 'GEOMETRYCOLLECTION(MULTIPOLYGON(((5 0,15 5,25 0,22 10,30 15,19 15,5 0)),((19 15,15 25,11 15,19 15))),POLYGON((5 0,7 10,0 15,10 15,15 25,20 15,30 15,22 10,25 0,15 5,5 0),(10 6,10 10,7 12,13 13,15 18,17 13,21 13,18 10,20 6,15 8,10 6)),MULTILINESTRING((25 0,0 15,15 30,0 5)),LINESTRING(15 25,15 10),MULTIPOINT(5 0,25 0),POINT(15 25))';
SELECT ST_Area(ST_GeometryN(
ST_SymDifference(ST_GeomFromText(@a), ST_GeomFromText(@b)), 1));
Results:
| build | area |
|---|---|
-O3 -DNDEBUG -march=x86-64-v3 (FMA contracted) |
7.9333333333333229 |
same + -ffp-contract=off |
76.148226950354598 (3 polygons) |
same + -mno-fma or -ffp-contract=on |
76.148226950354598 |
The correct result is three polygons with areas 68.2149, 5, and 2.93333.
The broken value 7.93333 is exactly 5 + 2.93333: the large piece is dropped
by a wrong side/orientation decision, not by a rounding difference in the area.
Debug (-O0), ARM, and the same code compiled with Clang all pass, which is
consistent with the contraction hypothesis.
Relation to #1452 / #1453
#1452/#1453 added
#pragma GCC optimize("fp-contract=off")
only around index/detail/algorithms/content.hpp. The overlay path
(strategy/cartesian/side_robust.hpp and strategy/cartesian/precise_area.hpp
through util/precise_math.hpp) has no equivalent protection, so the same
failure mode still applies there.
Suggested fix
Disable contraction around the error-free transformations in
util/precise_math.hpp (for GCC), e.g. push/pop
#pragma GCC optimize("fp-contract=off") around the helper definitions, or
document/enforce that TUs using side_robust/precise_area must be compiled
with -ffp-contract=off. A portable #pragma STDC FP_CONTRACT OFF is not
reliably honoured for C++ by GCC, which is why #1453 used the GCC pragma.
Workaround
Compile the affected translation units / target with -ffp-contract=off
(preferred) or -mno-fma. This is what MySQL-derived builds have started doing
for their sql_gis target.
References
- Related: #1452, PR #1453, PR #1455
- Full report, CI job, and reduced C++ repro (MySQL Cartesian types):
https://github.com/Shannon-Data/ShannonBase/issues/1042 - MySQL bugs #79031 / #77372 cover other numerical-robustness aspects of
ST_SymDifference, not FMA contraction.
- Lingua principale
- C++
- Stelle
- 519
- Fork
- 241
- Merge medio
- 4g 15h
- PR unite (30g)
- 9
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di boostorg/geometry
-
LLM generated regression case in differenceForse già presa @barendgehrels l’ha presa 11 giorni fa. Apertabug
boostorg/geometry#1511 · 1 reazione · 1 assegnatario ·
I maintainer di solito rispondono entro 2 giorni
-
union_ of two valid polygons sharing an edge returns empty (argument order dependent)Forse già presa @barendgehrels l’ha presa 16 giorni fa. Aperta
boostorg/geometry#1506 · 1 commento · 1 reazione · 1 assegnatario ·
I maintainer di solito rispondono entro 2 giorni
-
difference() produces invalid (self-intersecting) result for valid polygon-with-hole inputForse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 70/100
boostorg/geometry#1490 · 1 commento · 1 reazione ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
boostorg/geometry#1476 · 6 commenti ·
I maintainer di solito rispondono entro 2 giorni
-
I cannot get Dissolve to compile in version 1.91Forse di nuovo libera @barendgehrels l’ha presa 160 giorni fa e non c’è nessuna pull request aperta. Aperta
boostorg/geometry#1472 · 8 commenti · 1 assegnatario ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di boostorg/geometry
Issue simili
-
agent:WSL code-review linux pri:medium refactoring
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 1 giorno
-
kind/enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 82/100
psi29a/d2decomped#691 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
CachyOS/packageinstaller#144 ·
I maintainer di solito rispondono entro 1 giorno
-
(S1 - Need confirmation)
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
CleverRaven/Cataclysm-DDA#89715 ·
I maintainer di solito rispondono entro 1 giorno