Fix supported autotools versions in README.md
[librseq.git] / include / rseq / compiler.h
CommitLineData
90702366 1/* SPDX-License-Identifier: MIT */
f2d7b530
MJ
2/* SPDX-FileCopyrightText: 2021 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> */
3
dd76f2d6
MD
4/*
5 * rseq/compiler.h
6 *
7 * Work-around asm goto compiler bugs.
dd76f2d6
MD
8 */
9
10#ifndef RSEQ_COMPILER_H
11#define RSEQ_COMPILER_H
12
d292e9e1
MD
13#if defined __cplusplus
14# include <type_traits> /* for std::remove_cv */
15#endif
16
dd76f2d6
MD
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 */
6a5fa598 32#define rseq_after_asm_goto() __asm__ __volatile__ ("" : : : "memory")
dd76f2d6 33
809f5ee3
MD
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
eb5d1cbe
MD
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
d292e9e1
MD
48#ifdef __cplusplus
49#define rseq_unqual_scalar_typeof(x) \
96d67c89 50 std::remove_cv<std::remove_reference<decltype(x)>::type>::type
d292e9e1 51#else
a95cabb3
MD
52#define rseq_scalar_type_to_expr(type) \
53 unsigned type: (unsigned type)0, \
54 signed type: (signed type)0
55
d292e9e1
MD
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, \
a95cabb3
MD
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), \
d292e9e1
MD
69 default: (x) \
70 ) \
71 )
72#endif
73
dd76f2d6 74#endif /* RSEQ_COMPILER_H_ */
This page took 0.035459 seconds and 4 git commands to generate.