Keil Logo

ARMCLANG: Wrong result from (int&mask)<<shift when compiling with -O0


Information in this knowledgebase article applies to:

  • Arm Compiler 6.11

QUESTION

When compiling the following code snippet using Arm Compiler 6.11 with the optimization level -O0,

unsigned int fn(unsigned int arg) {
  return (arg & 0x0000FF00) << 8;
}

int main () {
  printf("0x%08X\n", fn(0x12345678));
}

I got the wrong result 0x00005600, instead of the correct result 0x00560000. 

How can I resolve this issue?

ANSWER

This is, unfortunately, a known bug in the Arm Compiler 6.11 to build code above when the optimization -O0 is used. 

RESOLUTION

Using Arm Compiler 6.11 with other optimization levels, such as -O1 etc. can resolve this issue.

The operation e.g. (int & mask) >> shift, is not affected by this bug. The older versions of the Arm Compiler 6, such as 6.10 etc. are not affected either.

This bug is fixed since the release of Arm Compiler 6.12.

Last Reviewed: Wednesday, November 4, 2020


Did this article provide the answer you needed?
 
Yes
No
Not Sure
 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.