Skip to content

Commit db1406a

Browse files
Add -Werror mode and use it for testing
Enabled through -DXSIMD_ENABLE_WERROR, and used for validation to prevent further `regression` Fix #417
1 parent 830509d commit db1406a

File tree

12 files changed

+84
-56
lines changed

12 files changed

+84
-56
lines changed

.azure-pipelines/unix-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ steps:
3939
CMAKE_EXTRA_ARGS="$CMAKE_EXTRA_ARGS -DXSIMD_FORCE_X86_INSTR_SET=0 -DXSIMD_FORCE_X86_AMD_INSTR_SET=0";
4040
fi
4141
42-
cmake -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX $CMAKE_EXTRA_ARGS -DDOWNLOAD_GTEST=ON $(Build.SourcesDirectory)
42+
cmake -DCMAKE_INSTALL_PREFIX=$CONDA_PREFIX $CMAKE_EXTRA_ARGS -DDOWNLOAD_GTEST=ON -DXSIMD_ENABLE_WERROR=1 $(Build.SourcesDirectory)
4343
displayName: Configure xsimd
4444
workingDirectory: $(Build.BinariesDirectory)
4545

include/xsimd/config/xsimd_instruction_set.hpp

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,34 +52,42 @@
5252
#ifdef XSIMD_FORCE_X86_INSTR_SET
5353
#define XSIMD_X86_INSTR_SET XSIMD_FORCE_X86_INSTR_SET
5454
#define XSIMD_X86_INSTR_SET_AVAILABLE XSIMD_VERSION_NUMBER_AVAILABLE
55-
#ifdef _MSC_VER
56-
#pragma message("Warning: Forcing X86 instruction set")
57-
#else
58-
#warning "Forcing X86 instruction set"
55+
#ifndef XSIMD_SKIP_ON_WERROR
56+
#ifdef _MSC_VER
57+
#pragma message("Warning: Forcing X86 instruction set")
58+
#else
59+
#warning "Forcing X86 instruction set"
60+
#endif
5961
#endif
6062
#elif defined(XSIMD_FORCE_X86_AMD_INSTR_SET)
6163
#define XSIMD_X86_AMD_INSTR_SET XSIMD_FORCE_X86_AMD_INSTR_SET
6264
#define XSIMD_X86_AMD_INSTR_SET_AVAILABLE XSIMD_VERSION_NUMBER_AVAILABLE
63-
#ifdef _MSC_VER
64-
#pragma message("Warning: Forcing X86 AMD instruction set")
65-
#else
66-
#warning "Forcing X86 AMD instruction set"
65+
#ifndef XSIMD_SKIP_ON_WERROR
66+
#ifdef _MSC_VER
67+
#pragma message("Warning: Forcing X86 AMD instruction set")
68+
#else
69+
#warning "Forcing X86 AMD instruction set"
70+
#endif
6771
#endif
6872
#elif defined(XSIMD_FORCE_PPC_INSTR_SET)
6973
#define XSIMD_PPC_INSTR_SET XSIMD_FORCE_PPC_INSTR_SET
7074
#define XSIMD_PPC_INSTR_SET_AVAILABLE XSIMD_VERSION_NUMBER_AVAILABLE
71-
#ifdef _MSC_VER
72-
#pragma message("Warning: Forcing PPC instruction set")
73-
#else
74-
#warning "Forcing PPC instruction set"
75+
#ifndef XSIMD_SKIP_ON_WERROR
76+
#ifdef _MSC_VER
77+
#pragma message("Warning: Forcing PPC instruction set")
78+
#else
79+
#warning "Forcing PPC instruction set"
80+
#endif
7581
#endif
7682
#elif defined(XSIMD_FORCE_ARM_INSTR_SET)
7783
#define XSIMD_ARM_INSTR_SET XSIMD_FORCE_ARM_INSTR_SET
7884
#define XSIMD_ARM_INSTR_SET_AVAILABLE XSIMD_VERSION_NUMBER_AVAILABLE
79-
#ifdef _MSC_VER
80-
#pragma message("Warning: Forcing ARM instruction set")
81-
#else
82-
#warning "Forcing ARM instruction set"
85+
#ifndef XSIMD_SKIP_ON_WERROR
86+
#ifdef _MSC_VER
87+
#pragma message("Warning: Forcing ARM instruction set")
88+
#else
89+
#warning "Forcing ARM instruction set"
90+
#endif
8391
#endif
8492
#endif
8593

include/xsimd/types/xsimd_avx_float.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ namespace xsimd
707707
}
708708

709709
template<bool... Values>
710-
static batch_type select(const batch_bool_constant<value_type, Values...>& cond, const batch_type& a, const batch_type& b)
710+
static batch_type select(const batch_bool_constant<value_type, Values...>&, const batch_type& a, const batch_type& b)
711711
{
712712
constexpr int mask = batch_bool_constant<value_type, Values...>::mask();
713713
return _mm256_blend_ps(b, a, mask);

include/xsimd/types/xsimd_base_constant.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace xsimd
2929

3030
bool operator[](size_t i) const
3131
{
32-
return std::array<value_type, size>{Values...}[i];
32+
return std::array<value_type, size>{{Values...}}[i];
3333
}
3434
static constexpr int mask()
3535
{

include/xsimd/types/xsimd_fallback.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,8 @@ namespace xsimd
603603
{
604604
T res(0);
605605
using int_type = as_unsigned_integer_t<T>;
606-
*reinterpret_cast<int_type*>(&res) = ~int_type(0);
606+
int_type value(~int_type(0));
607+
std::memcpy(&res, &value, sizeof(int_type));
607608
return res;
608609
}
609610
};

include/xsimd/types/xsimd_sse_double.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ namespace xsimd
633633
static batch_type select(const batch_bool_constant<value_type, Values...>& cond, const batch_type& a, const batch_type& b)
634634
{
635635
#if XSIMD_X86_INSTR_SET >= XSIMD_X86_SSE4_1_VERSION
636+
(void)cond;
636637
constexpr int mask = batch_bool_constant<value_type, Values...>::mask();
637638
return _mm_blend_pd(b, a, mask);
638639
#else

include/xsimd/types/xsimd_types_include.hpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,21 @@
7070
#endif
7171

7272
#if !defined(XSIMD_INSTR_SET_AVAILABLE)
73-
#if defined(XSIMD_ENABLE_FALLBACK)
74-
#ifdef _MSC_VER
75-
#pragma message("Warning: No SIMD instructions set detected, using fallback mode.")
76-
#else
77-
#warning "No SIMD instructions set detected, using fallback mode."
78-
#endif
79-
#else
80-
#ifdef _MSC_VER
81-
#pragma message("Warning: No SIMD instructions set detected, please enable SIMD instructions or activate the fallback mode. (e.g. for x86 -march=native or for ARM -mfpu=neon)")
73+
#ifndef XSIMD_SKIP_ON_WERROR
74+
75+
#if defined(XSIMD_ENABLE_FALLBACK)
76+
#ifdef _MSC_VER
77+
#pragma message("Warning: No SIMD instructions set detected, using fallback mode.")
78+
#else
79+
#warning "No SIMD instructions set detected, using fallback mode."
80+
#endif
8281
#else
83-
#warning "No SIMD instructions set detected, please enable SIMD instructions or activate the fallback mode. (e.g. for x86 -march=native or for ARM -mfpu=neon)"
84-
#endif
82+
#ifdef _MSC_VER
83+
#pragma message("Warning: No SIMD instructions set detected, please enable SIMD instructions or activate the fallback mode. (e.g. for x86 -march=native or for ARM -mfpu=neon)")
84+
#else
85+
#warning "No SIMD instructions set detected, please enable SIMD instructions or activate the fallback mode. (e.g. for x86 -march=native or for ARM -mfpu=neon)"
86+
#endif
87+
#endif
8588
#endif
8689
#endif
8790

test/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ include(CheckCXXCompilerFlag)
3030

3131
string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE)
3232

33+
OPTION(XSIMD_ENABLE_WERROR "Turn on -Werror" OFF)
34+
3335
################
3436
# ARM SETTINGS #
3537
################
@@ -239,3 +241,7 @@ if (CROSS_COMPILE_ARM)
239241
else()
240242
add_custom_target(xtest COMMAND test_xsimd DEPENDS test_xsimd)
241243
endif()
244+
245+
if (XSIMD_ENABLE_WERROR)
246+
target_compile_options(test_xsimd PRIVATE -Werror -Wall -DXSIMD_SKIP_ON_WERROR)
247+
endif()

test/test_algorithms.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ TEST(algorithms, iterator)
263263
*cbegin = sin(*cbegin);
264264
*cbegin = sqrt(*cbegin);
265265
auto real_part = abs(*(cbegin));
266+
(void)real_part;
266267
#endif
267268

268269
}

test/test_basic_math.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ class basic_math_test : public testing::Test
9898
}
9999
// clip
100100
{
101-
value_type clip_lo = 0.5;
102-
value_type clip_hi = 1.;
101+
value_type clip_lo = static_cast<value_type>(0.5);
102+
value_type clip_hi = static_cast<value_type>(1.);
103103
array_type expected;
104104
std::transform(clip_input.cbegin(), clip_input.cend(), expected.begin(),
105105
[clip_lo, clip_hi](const value_type& l) {

0 commit comments

Comments
 (0)