Skip to main content
Morty Morty
Associate III
March 11, 2019
Question

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

  • March 11, 2019
  • 2 replies
  • 699 views

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

This topic has been closed for replies.

2 replies

Technical Moderator
March 13, 2019

Hello Morty,

Thanks for reports this issue.

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

Kind Regards,

Imen

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks
Technical Moderator
August 20, 2019

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

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks