1 /* SPDX-License-Identifier: MIT */
2 /* SPDX-FileCopyrightText: 2021 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> */
7 * Work-around asm goto compiler bugs.
10 #ifndef RSEQ_COMPILER_H
11 #define RSEQ_COMPILER_H
13 #if defined __cplusplus
14 # include <type_traits> /* for std::remove_cv */
18 * gcc prior to 4.8.2 miscompiles asm goto.
19 * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670
21 * gcc prior to 8.1.0 miscompiles asm goto at O1.
22 * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103908
24 * clang prior to version 13.0.1 miscompiles asm goto at O2.
25 * https://github.com/llvm/llvm-project/issues/52735
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.
32 #define rseq_after_asm_goto() __asm__ __volatile__ ("" : : : "memory")
34 /* Combine two tokens. */
35 #define RSEQ__COMBINE_TOKENS(_tokena, _tokenb) \
37 #define RSEQ_COMBINE_TOKENS(_tokena, _tokenb) \
38 RSEQ__COMBINE_TOKENS(_tokena, _tokenb)
40 #if defined(__SIZEOF_LONG__)
41 #define RSEQ_BITS_PER_LONG (__SIZEOF_LONG__ * 8)
43 #define RSEQ_BITS_PER_LONG 64
45 #define RSEQ_BITS_PER_LONG 32
49 #define rseq_unqual_scalar_typeof(x) \
50 std::remove_cv<std::remove_reference<decltype(x)>::type>::type
52 #define rseq_scalar_type_to_expr(type) \
53 unsigned type: (unsigned type)0, \
54 signed type: (signed type)0
57 * Use C11 _Generic to express unqualified type from expression. This removes
58 * volatile qualifier from expression type.
60 #define rseq_unqual_scalar_typeof(x) \
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), \
74 #endif /* RSEQ_COMPILER_H_ */
This page took 0.075583 seconds and 4 git commands to generate.