7.8 Infinite Loops

armclang considers infinite loops with no side-effects to be undefined behavior, as stated in the C11 and C++11 standards. In certain situations armclang deletes or moves infinite loops, resulting in a program that eventually terminates, or does not behave as expected.

How to write an infinite loop in armclang

To ensure that a loop executes for an infinite length of time, Arm recommends writing infinite loops in the following way:

void infinite_loop(void) {
  while (1)
    asm volatile("");	// this line is considered to have side-effects
}

armclang does not delete or move the loop, because it has side-effects.

Non-ConfidentialPDF file icon PDF versionDUI0773J
Copyright © 2014–2017, 2019 Arm Limited or its affiliates. All rights reserved.