[LLVMdev] Is infinite empty loop dead code?

Óscar Fuentes ofv at wanadoo.es
Wed Nov 14 14:00:59 PST 2012


Joshua Cranmer <pidgeot18 at gmail.com> writes:

> The C++11 standard explicitly allows compilers to assume that all
> loops will eventually terminate:
>
> [intro.multithread] 24:
> The implementation may assume that any thread will eventually do one
> of the following:
> — terminate,
> — make a call to a library I/O function,
> — access or modify a volatile object, or
> — perform a synchronization operation or an atomic operation.
> [ Note: This is intended to allow compiler transformations such as
> removal of empty loops, even when
> termination cannot be proven. —end note ]

In embedded, single-threaded systems, sometimes you use an infinite
empty loop when the purpose is to wait and handle hardware interrupts
forever. Those interrupts may or may not happen. I wonder how this fits
into the note above.

> I don't know if C11 has a similar statement, but C99 has a statement
> which is ambiguous in this regard (it only refers to a requirement
> upon program termination).
>
> There's a blog post by John Regehr on this topic:
> <http://blog.regehr.org/archives/161>.

I agree with that blog post about the C++ Standard's text quoted above.




More information about the llvm-dev mailing list