1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*******************************************************************************
* Copyright 2020 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
#ifndef COMMON_COMPILER_WORKAROUNDS_HPP
#define COMMON_COMPILER_WORKAROUNDS_HPP
// Workaround 01: clang.
//
// Clang has an issue [1] with `#pragma omp simd` that might lead to segfault.
// The essential conditions are:
// 1. Optimization level is O1 or O2. Surprisingly, O3 is fine.
// 2. Conditional check inside the vectorization loop.
// Since there is no reliable way to determine the first condition, we disable
// vectorization for clang altogether for now.
//
// [1] https://bugs.llvm.org/show_bug.cgi?id=48104
#if (defined __clang_major__) && (__clang_major__ < 13)
#define CLANG_WA_01_SAFE_TO_USE_OMP_SIMD 0
#else
#define CLANG_WA_01_SAFE_TO_USE_OMP_SIMD 1
#endif
// Workaround 02: clang.
//
// Clang generates incorrect code with OMP_SIMD in some particular cases.
// Unlike CLANG_WA_01_SAFE_TO_USE_OMP_SIMD, the issue happens even with -O3.
#if (defined __clang_major__) && (__clang_major__ < 13)
#define CLANG_WA_02_SAFE_TO_USE_OMP_SIMD 0
#else
#define CLANG_WA_02_SAFE_TO_USE_OMP_SIMD 1
#endif
// Workaround 03: MSVC c++17 vs c++20
//
// C++17/20 are contradictory w.r.t. capturing `this` and using the default '='
// capture.
// - C++17 and before returns a warning for the `[=, this]` capture as explicit
// `this` capture is redundant (so [=] should be used).
// - C++20 does not capture this with the default `[=]` capture and mandates
// using `[=, this]` explicitly.
// As a workaround, newer versions of GCC and clang emit the warning in the
// first case only under -pedantic and/or -Wc++20-extensions
//
// (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100493)
#if (defined(_MSVC_LANG) && (_MSVC_LANG >= 202002L)) \
|| (defined(__cplusplus) && (__cplusplus >= 202002L))
#define COMPAT_THIS_CAPTURE , this
#else
#define COMPAT_THIS_CAPTURE
#endif
#endif // COMMON_COMPILER_WORKAROUNDS_HPP