Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Mathieu Desnoyers and committed by
Shuah Khan
d6aaa23a c0d87e43

+26
+26
tools/testing/selftests/rseq/compiler.h
··· 33 33 #define RSEQ_COMBINE_TOKENS(_tokena, _tokenb) \ 34 34 RSEQ__COMBINE_TOKENS(_tokena, _tokenb) 35 35 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 + 36 62 #endif /* RSEQ_COMPILER_H_ */