QuantumLeaps / qpc

QP/C Real-Time Embedded Framework/RTOS based on asynchronous, event-driven Active Objects (Actors) and Hierarchical State Machines
https://www.state-machine.com/products/qp
980 stars 250 forks source link

Unused parameter 'x' in qv_port.c #32

Closed samuel-schuepbach closed 1 year ago

samuel-schuepbach commented 1 year ago

I am getting an error due to a unused parameter when compiling the arm-cm port with the gcc compiler (arm-none-eabi-gcc, 11.3.1)

/qpc/port/arm-cm/qv/gnu/qv_port.c: In function 'QF_qlog2':
/qpc/port/arm-cm/qv/gnu/qv_port.c:92:32: error: unused parameter 'x' [-Werror=unused-parameter]
   92 | uint_fast8_t QF_qlog2(uint32_t x) {
      |                       ~~~~~~~~~^

It complains about the variable 'x' not being used in the following function:

uint_fast8_t QF_qlog2(uint32_t x) {
__asm volatile (

If the variable is not used, it would be convenient to remove it or other wise suppress the error. Otherwise projects need to change the compiler flags to avoid this error or manually suppress the error in the code.

quantum-leaps commented 1 year ago

Hi Sam, You apparently are using the -Werror option that elevates warnings to errors. The parameter x is, of course, used in this case (as register r0 per the AAPCS), but this is done inside the optimized assembly code, which the compiler does not analyze. The preferred way to silence this warning (as in any other case of "unused parameters") is by means of the macro Q_UNUSED_PAR() specially created for that, as follows:

 __attribute__ ((naked, optimize("-fno-stack-protector")))
uint_fast8_t QF_qlog2(uint32_t x) {
    Q_UNUSED_PAR(x);
__asm volatile ( . . .

This fix is already used in our internal version and will be included in the next release.

On a side note, I'm glad to see that you're using the QV kernel. This simple kernel is a good choice for a surprisingly wide range of applications.

--MMS

samuel-schuepbach commented 1 year ago

Thanks for the quick explanation with r0, that absolutely makes sense. I have changed my code locally the same way (with (void)(x); for now, but that should do the same from what I can tell) and it works well. Happy to hear that it is already included!

I agree, QV is ideal for our use case. Its simple but does all that it needs to.

Thank you for the quick response and help. I will close the issue.