From e9208a9d03a6e06e80a6cc9335d9886c90d776f2 Mon Sep 17 00:00:00 2001 From: Balazs Varga Date: Wed, 10 Apr 2024 17:48:20 +0100 Subject: tdf#160616 - Fix SUMPRODUCT calculation is broken in some cases Double refs with operators only trimmable in case of one root paramater. Follow up of: ba0ec4a5d2b025b675410cd18890d1cca3bc5a2f Change-Id: If61fb39696d9539ffc9d32a6ecad79bfa1bf92e5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165957 Tested-by: Gabor Kelemen Tested-by: Jenkins Reviewed-by: Gabor Kelemen (cherry picked from commit 2af433f11cf24db655677bdf26e39fabaf3611fc) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165932 Tested-by: allotropia jenkins Reviewed-by: Thorsten Behrens --- sc/qa/unit/ucalc_formula.cxx | 2 +- sc/source/core/tool/compiler.cxx | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/sc/qa/unit/ucalc_formula.cxx b/sc/qa/unit/ucalc_formula.cxx index 153096d6a434..feb0e8fef22a 100644 --- a/sc/qa/unit/ucalc_formula.cxx +++ b/sc/qa/unit/ucalc_formula.cxx @@ -1464,7 +1464,7 @@ CPPUNIT_TEST_FIXTURE(TestFormula, testFormulaAnnotateTrimOnDoubleRefs) { "=SUMPRODUCT(A:A=$C$1; 1-(A:A=$C$1))", - ScRange(0, 0, 0, 0, 1048575, 0), + ScRange(-1, -1, -1, -1, -1, -1), // Has no trimmable double-ref. 0.0, false // Not in matrix mode. }, diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx index 451956922c29..7e1fa777bfec 100644 --- a/sc/source/core/tool/compiler.cxx +++ b/sc/source/core/tool/compiler.cxx @@ -6477,6 +6477,8 @@ void ScCompiler::AnnotateTrimOnDoubleRefs() // OpCode of the "root" operator (which is already in RPN array). OpCode eOpCode = (*(pCode - 1))->GetOpCode(); + // Param number of the "root" operator (which is already in RPN array). + sal_uInt8 nRootParam = (*(pCode - 1))->GetByte(); // eOpCode can be some operator which does not change with operands with or contains zero values. if (eOpCode == ocSum) { @@ -6569,7 +6571,8 @@ void ScCompiler::AnnotateTrimOnDoubleRefs() // such that one of the operands of ocEqual is a double-ref. // Examples of formula that matches this are: // SUMPRODUCT(IF($A:$A=$L12;$D:$D*G:G)) - // Also in case of DoubleRef arguments around other Binary operators can be trimmable: + // Also in case of DoubleRef arguments around other Binary operators can be trimmable inside one parameter + // of the root operator: // SUMPRODUCT(($D:$D>M47:M47)*($D:$DIsInForceArray()) + // tdf#160616: Double refs with these operators only + // trimmable in case of one paramater + if (!pTok->IsInForceArray() || nRootParam > 1) break; FormulaToken* pLHS = *(ppTok - 1); FormulaToken* pRHS = *(ppTok - 2); -- cgit