Fix supported autotools versions in README.md
[librseq.git] / include / rseq / compiler.h
1 /* SPDX-License-Identifier: MIT */
2 /* SPDX-FileCopyrightText: 2021 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> */
3
4 /*
5 * rseq/compiler.h
6 *
7 * Work-around asm goto compiler bugs.
8 */
9
10 #ifndef RSEQ_COMPILER_H
11 #define RSEQ_COMPILER_H
12
13 #if defined __cplusplus
14 # include <type_traits> /* for std::remove_cv */
15 #endif
16
17 /*
18 * gcc prior to 4.8.2 miscompiles asm goto.
19 * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670
20 *
21 * gcc prior to 8.1.0 miscompiles asm goto at O1.
22 * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103908
23 *
24 * clang prior to version 13.0.1 miscompiles asm goto at O2.
25 * https://github.com/llvm/llvm-project/issues/52735
26 *
27 * Work around these issues by adding a volatile inline asm with
28 * memory clobber in the fallthrough after the asm goto and at each
29 * label target. Emit this for all compilers in case other similar
30 * issues are found in the future.
31 */
32 #define rseq_after_asm_goto() __asm__ __volatile__ ("" : : : "memory")
33
34 /* Combine two tokens. */
35 #define RSEQ__COMBINE_TOKENS(_tokena, _tokenb) \
36 _tokena##_tokenb
37 #define RSEQ_COMBINE_TOKENS(_tokena, _tokenb) \
38 RSEQ__COMBINE_TOKENS(_tokena, _tokenb)
39
40 #if defined(__SIZEOF_LONG__)
41 #define RSEQ_BITS_PER_LONG (__SIZEOF_LONG__ * 8)
42 #elif defined(_LP64)
43 #define RSEQ_BITS_PER_LONG 64
44 #else
45 #define RSEQ_BITS_PER_LONG 32
46 #endif
47
48 #ifdef __cplusplus
49 #define rseq_unqual_scalar_typeof(x) \
50 std::remove_cv<std::remove_reference<decltype(x)>::type>::type
51 #else
52 #define rseq_scalar_type_to_expr(type) \
53 unsigned type: (unsigned type)0, \
54 signed type: (signed type)0
55
56 /*
57 * Use C11 _Generic to express unqualified type from expression. This removes
58 * volatile qualifier from expression type.
59 */
60 #define rseq_unqual_scalar_typeof(x) \
61 __typeof__( \
62 _Generic((x), \
63 char: (char)0, \
64 rseq_scalar_type_to_expr(char), \
65 rseq_scalar_type_to_expr(short), \
66 rseq_scalar_type_to_expr(int), \
67 rseq_scalar_type_to_expr(long), \
68 rseq_scalar_type_to_expr(long long), \
69 default: (x) \
70 ) \
71 )
72 #endif
73
74 #endif /* RSEQ_COMPILER_H_ */
This page took 0.075583 seconds and 4 git commands to generate.