cancel
Showing results for 
Search instead for 
Did you mean: 

[Bug] Undefined behavior in LL_ADC_SetChannelSingleDiff causes it to alway set bits in gcc and clang

Morty Morty
Associate III

From LL_ADC_SetChannelSingleDiff:

 /* Bits of channels in single or differential mode are set only for        */

 /* differential mode (for single mode, mask of bits allowed to be set is   */

 /* shifted out of range of bits of channels in single or differential mode. */

The assumption that it is ok to shift the bits out of the register is wrong, because it is undefined bahviour: C11 6.5.7 / http://c0x.coding-guidelines.com/6.5.7.html

This causes gcc (https://godbolt.org/z/eH-T_m), as well as clang (and therefore probably armcc, too), to replace the bic-instruction with an orr-instruction; inverting the intent.

The reasoning why they do that can be found here:

https://gcc.gnu.org/ml/gcc/2019-03/msg00077.html

2 REPLIES 2
Imen.D
ST Employee

Hello Morty,

Thanks for reports this issue.

We will look on this issue, then we will keep you updated.

Kind Regards,

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Imen.D
ST Employee

Hello @Moritz Strübe​ ,

This issue will be fixed on the coming release of all relevant STM32 series.

Thank you for your contribution.

Best Regards,

Imen

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen