fsl_usdhc.c USDHC_ReceiveCommandResponse() miscompile

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

fsl_usdhc.c USDHC_ReceiveCommandResponse() miscompile

516 Views
buckfobb
Contributor II

I could be wrong but it seems gcc (any version) with -O3 enabled miscompiles fsl_usdhc.c USDHC_ReceiveCommandResponse(). This appears to be an issue with gcc. Gcc doesn't properly generate the asm code; gcc seems to only partially implement the function, and does not return, thus barging right into the next function that gcc places. At least on my builds.

However, it seems like NXP should refactor the function so that it doesn't cause gcc to barf on it.

I think you should be able to repro this with the sdmmc example projects.

Additionally, here's a link to a Compiler Explorer example: Compiler Explorer . It is the USDHC_ReceiveCommandResponse() function verbatim, with a contrived example, hoping to show what's going on. Once the assembly gets past "if (command->responseType == kCARD_ResponseTypeR2)" it doesn't return.

If you do come up with a refactor that works, please post/share it. I don't have a solution as yet.

Hope this helps.

PS: I should also point out that your implementation of the do-while loop in there is incorrect: since it is a post decrement, the do loop is executed with i = 0, which causes "command->response[i - 1U] <<= 8U;" to write out-of-bounds.

0 Kudos
1 Reply

454 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Buck Fobb,

  You said:  gcc (any version) with -O3 enabled miscompiles fsl_usdhc.c

Do you mean the O3 is the optimization level?

What's the RT chip you are using, please tell me the RT chip part number.

Do you test the SDK code on your side which can be downloaded from this link:

Welcome | MCUXpresso SDK Builder 

Whether you can reproduce the problems or not?


Have a great day,
Kerry

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos