Fix: change method used by _rcu_dereference to strip type constness
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 17 Aug 2022 15:24:25 +0000 (11:24 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 17 Aug 2022 17:50:02 +0000 (13:50 -0400)
commit2d466a6397dbc7af397d0fc10e327cc6cac76a5a
treeb8249dff957852c419c60d2a2ad54aba55109cff
parent06326a94ac233064654c7100b6384b2833f7b898
Fix: change method used by _rcu_dereference to strip type constness

Commit 1e41ec3b07e4 ("Make temporary variable in _rcu_dereference
non-const") used the trick to add 0 to the pointer passed as a parameter
to the macro to get rid of its constness, should it be const (with the
end goal of avoiding compiler warnings).  This is problematic (as shown
in [1]) if it is a pointer to an opaque type though, as the compiler
cannot perform pointer arithmetic on such a pointer (even though it
wouldn't really need to here, as we add 0).

Change it to use another trick to strip away the constness, that
shouldn't hit this problem.  It was found in the same stackoverflow post
as the original trick [2].  It consists of using a statement expression
like so:

    __typeof__(({ const int foo; foo; }))

The statement expression yields a value of type `int`.  Statement
expressions are extensions to the C language, but we already use them
here.

The test_build* binaries now need to be linked against the urcu library,
otherwise they would be missing the rcu_dereference_sym symbol.

[1] https://lists.lttng.org/pipermail/lttng-dev/2022-August/030247.html
[2] https://stackoverflow.com/a/54016713

Change-Id: Ic73590ef4beaa1832161aa05a6df37e467f85116
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/urcu/static/pointer.h
tests/unit/Makefile.am
tests/unit/test_build.c
This page took 0.025685 seconds and 4 git commands to generate.