[LLVMdev] Is infinite empty loop dead code?

Dan Gohman dan433584 at gmail.com
Wed Nov 14 11:44:34 PST 2012


On Tue, Nov 13, 2012 at 11:23 PM, Shuxin Yang <shuxin.llvm at gmail.com> wrote:

> Hi, All:
>
>     Is it legal to delete empty infinite loop like this : "while(1) {}"?
> It is interesting that both llvm and gcc keep the loop, however Open64
> delete it.
>

Well, LLVM *sometimes* keeps infinite loops. Compile this with -O2, for
example:

 void bar(void) {
  for (;;) {}
}

void foo(void) {
  bar();
}

Infinite loops really are special, and infinite loops containing no side
effects really are especially special. People will probably say that LLVM
and Open64 and other compilers have bugs here, and they're probably right.
There is room for sympathy though, both because of the unique havoc
infinite loops play on compiler theory, and because of how rarely empty
loops are actually an advisable idiom in the real world.

Dan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121114/afab49a5/attachment.html>


More information about the llvm-dev mailing list