include/tools/cpuid.hxx                                     |   10 +++++++++
 tools/qa/cppunit/test_cpu_runtime_detection_AVX2_check.cxx  |   10 ++++-----
 tools/qa/cppunit/test_cpu_runtime_detection_SSE2_check.cxx  |   13 ++++++------
 tools/qa/cppunit/test_cpu_runtime_detection_SSSE3_check.cxx |    9 +++-----
 4 files changed, 26 insertions(+), 16 deletions(-)

New commits:
commit ed43620c007e7fa8eb3a4ea49a90d2171b8de594
Author:     Luboš Luňák <l.lu...@collabora.com>
AuthorDate: Wed Oct 27 10:09:31 2021 +0200
Commit:     Luboš Luňák <l.lu...@collabora.com>
CommitDate: Wed Oct 27 18:36:59 2021 +0200

    CPU-specific files should not include templates or inlines
    
    Otherwise the possible copy emitted compiled with CPU-specific
    instructions might be chosen as the copy to keep and would be
    used by generic code. See history for the Calc Kahan code.
    
    Change-Id: Ifc1bbd8d9720d9effe05b8ff8ee5e804363939df
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124257
    Tested-by: Jenkins
    Reviewed-by: Luboš Luňák <l.lu...@collabora.com>

diff --git a/include/tools/cpuid.hxx b/include/tools/cpuid.hxx
index 0fb1d5b8e965..1be897e84a4e 100644
--- a/include/tools/cpuid.hxx
+++ b/include/tools/cpuid.hxx
@@ -15,6 +15,16 @@
 #include <o3tl/typed_flags_set.hxx>
 #include <rtl/ustring.hxx>
 
+/*
+
+Do NOT include this header in source files compiled with CPU-specific code.
+TODO: For the header to be safe that way, it should be free of any templates
+or inline functions, otherwise their possibly emitted copies compiled
+with the CPU-specific instructions might be chosen by the linker as the copy
+to keep.
+
+*/
+
 namespace cpuid {
 
 enum class InstructionSetFlags
diff --git a/tools/qa/cppunit/test_cpu_runtime_detection_AVX2_check.cxx 
b/tools/qa/cppunit/test_cpu_runtime_detection_AVX2_check.cxx
index b5948223752c..39c18e5314e0 100644
--- a/tools/qa/cppunit/test_cpu_runtime_detection_AVX2_check.cxx
+++ b/tools/qa/cppunit/test_cpu_runtime_detection_AVX2_check.cxx
@@ -10,17 +10,17 @@
 #include <sal/types.h>
 #include <tools/simdsupport.hxx>
 
-#include <cppunit/TestAssert.h>
-#include <cppunit/TestFixture.h>
-#include <cppunit/extensions/HelperMacros.h>
-#include <cppunit/plugin/TestPlugIn.h>
+#include <stdlib.h>
 
 #include "test_cpu_runtime_detection_x86_checks.hxx"
 
 /* WARNING: This file is compiled with AVX2 support, don't call
  * any function without checking cpuid to check the CPU can actually
- * handle it.
+ * handle it, and don't include any headers that contain templates
+ * or inline functions, which includes cppunit.
  */
+#define CPPUNIT_ASSERT_EQUAL(a, b) ((a) == (b) ? (void)0 : abort())
+
 void CpuRuntimeDetectionX86Checks::checkAVX2()
 {
 #ifdef LO_AVX2_AVAILABLE
diff --git a/tools/qa/cppunit/test_cpu_runtime_detection_SSE2_check.cxx 
b/tools/qa/cppunit/test_cpu_runtime_detection_SSE2_check.cxx
index 14bcc78717d8..4b706cd5c1de 100644
--- a/tools/qa/cppunit/test_cpu_runtime_detection_SSE2_check.cxx
+++ b/tools/qa/cppunit/test_cpu_runtime_detection_SSE2_check.cxx
@@ -10,15 +10,16 @@
 #include <sal/types.h>
 #include <tools/simdsupport.hxx>
 
-#include <cppunit/TestAssert.h>
-#include <cppunit/TestFixture.h>
-#include <cppunit/extensions/HelperMacros.h>
-#include <cppunit/plugin/TestPlugIn.h>
-
-#include <tools/cpuid.hxx>
+#include <stdlib.h>
 
 #include "test_cpu_runtime_detection_x86_checks.hxx"
 
+/* WARNING: This file is compiled with SSE2 support, don't call
+ * any function without checking cpuid to check the CPU can actually
+ * handle it, and don't include any headers that contain templates
+ * or inline functions, which includes cppunit.
+ */
+#define CPPUNIT_ASSERT_EQUAL(a, b) ((a) == (b) ? (void)0 : abort())
 void CpuRuntimeDetectionX86Checks::checkSSE2()
 {
 #ifdef LO_SSE2_AVAILABLE
diff --git a/tools/qa/cppunit/test_cpu_runtime_detection_SSSE3_check.cxx 
b/tools/qa/cppunit/test_cpu_runtime_detection_SSSE3_check.cxx
index 5fd46e62c185..5e7c0b3e2a75 100644
--- a/tools/qa/cppunit/test_cpu_runtime_detection_SSSE3_check.cxx
+++ b/tools/qa/cppunit/test_cpu_runtime_detection_SSSE3_check.cxx
@@ -10,17 +10,16 @@
 #include <sal/types.h>
 #include <tools/simdsupport.hxx>
 
-#include <cppunit/TestAssert.h>
-#include <cppunit/TestFixture.h>
-#include <cppunit/extensions/HelperMacros.h>
-#include <cppunit/plugin/TestPlugIn.h>
+#include <stdlib.h>
 
 #include "test_cpu_runtime_detection_x86_checks.hxx"
 
 /* WARNING: This file is compiled with SSSE3 support, don't call
  * any function without checking cpuid to check the CPU can actually
- * handle it.
+ * handle it, and don't include any headers that contain templates
+ * or inline functions, which includes cppunit.
  */
+#define CPPUNIT_ASSERT_EQUAL(a, b) ((a) == (b) ? (void)0 : abort())
 void CpuRuntimeDetectionX86Checks::checkSSSE3()
 {
 #ifdef LO_SSSE3_AVAILABLE

Reply via email to