OpenAMP / open-amp

The main OpenAMP library implementing RPMSG, Virtio, and Remoteproc for RTOS etc
https://www.openampproject.org/
Other
706 stars 288 forks source link

atomic_flag func error when compile with clang #471

Closed mzyx-hnu closed 1 year ago

mzyx-hnu commented 1 year ago

Error when compile with clang on AArch64

/usr1/openeuler/build/arm64_standard_llvm/tmp/work/aarch64-openeuler-linux/openamp/2022.04.0-r0/openamp-2022.04.0/lib/proxy/rpmsg_retarget.c:49:4: error: member reference base type 'atomic_int' (aka '_Atomic(int)') is not a structure or union

The error is reported every time the atomic_flag function is called.

https://github.com/OpenAMP/open-amp/blob/7513776e35225ce604773b6d42316a93ef544c60/lib/proxy/rpmsg_retarget.c#L49

The reason is that the usage of atomic_flag-related functions in some codes does not comply with the language standard(The parameter &rpc->nacked is a atomic_int while the function requires a atomic_flag). The Clang function library has stricter input type restrictions (clang gets the _Value subitem of the input atomic_flag parameter, gcc does not) , then preceding error occurs.

clang version of atomic_flag

image

gcc version

image

Therefore, the input parameter type should be changed from atomic_int to atomic_flag, and the corresponding initialization function atomic_init() should be changed to atomic_flag_test_and_set().

Related description in the C11 standard: https://en.cppreference.com/w/cpp/atomic/atomic_flag_clear https://en.cppreference.com/w/cpp/atomic/atomic_flag_test_and_set

mzyx-hnu commented 1 year ago

related pr #472