Skip to content

Commit d6aaa23

Browse files
compudjshuahkh
authored andcommitted
selftests/rseq: Implement rseq_unqual_scalar_typeof
Allow defining variables and perform cast with a typeof which removes the volatile and const qualifiers. This prevents declaring a stack variable with a volatile qualifier within a macro, which would generate sub-optimal assembler. This is imported from the "librseq" project. Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent c0d87e4 commit d6aaa23

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tools/testing/selftests/rseq/compiler.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,30 @@
3333
#define RSEQ_COMBINE_TOKENS(_tokena, _tokenb) \
3434
RSEQ__COMBINE_TOKENS(_tokena, _tokenb)
3535

36+
#ifdef __cplusplus
37+
#define rseq_unqual_scalar_typeof(x) \
38+
std::remove_cv<std::remove_reference<decltype(x)>::type>::type
39+
#else
40+
#define rseq_scalar_type_to_expr(type) \
41+
unsigned type: (unsigned type)0, \
42+
signed type: (signed type)0
43+
44+
/*
45+
* Use C11 _Generic to express unqualified type from expression. This removes
46+
* volatile qualifier from expression type.
47+
*/
48+
#define rseq_unqual_scalar_typeof(x) \
49+
__typeof__( \
50+
_Generic((x), \
51+
char: (char)0, \
52+
rseq_scalar_type_to_expr(char), \
53+
rseq_scalar_type_to_expr(short), \
54+
rseq_scalar_type_to_expr(int), \
55+
rseq_scalar_type_to_expr(long), \
56+
rseq_scalar_type_to_expr(long long), \
57+
default: (x) \
58+
) \
59+
)
60+
#endif
61+
3662
#endif /* RSEQ_COMPILER_H_ */

0 commit comments

Comments
 (0)