[LLVMdev] how to eliminate dead infinite loops?

Chris Lattner clattner at apple.com
Mon Nov 29 14:13:36 PST 2010


On Nov 29, 2010, at 1:52 PM, me22 wrote:

> On Sun, Nov 28, 2010 at 12:12, Chris Lattner <clattner at apple.com> wrote:
>> 
>> FWIW, this is currently a discussion in the C++ and C committees, and my understanding is that this has changed (or is changing soon) in the C'1x draft.  Assuming it happens, it will make it valid to assume that loops always terminate unless they are written with a condition that is an integer constant expression that folds to 1.
>> 
>> In addition to being able to delete noop loops that traverse over pointer-based data structures, this will also solve the:
>> 
>>  for (unsigned i = 0; i <= N; ++i)
>> 
>> class of problems.  I'm obviously strongly in favor of this, and I also think we should apply it to all C languages.  I don't see any reason for people to write infinite loops with non-trivial conditions.
>> 
> 
> Does that mean that
>    for (unsigned i = 0; i <= N; ++i) {}
> and
>    for (unsigned i = 0; ; ++i) { if (i <= N) break; }
> would then have different semantics?

I don't know the details of the proposal, sorry.  comp.lang.c[++] would be a good place to ask.

-Chris



More information about the llvm-dev mailing list