This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Infinite loop in dcraw with current GCC versions


On 27 February 2015 at 19:12, Manuel López-Ibáñez <lopezibanez@gmail.com> wrote:
>>      This sounds like a compiler bug to me.  A statement
>> of the form:
>>
>>     for (i=0; i < 12; i++) {
>>       <code that doesn't change "i">
>>     }
>>
>>      should never generate an infinite loop.
>
> If there is undefined behavior, then not only can generate an infinite
> loop but many kinds of nasty effects. The reasons are difficult to
> explain, but you just have to think that at some moment the code has
> to be converted to something like:
>
> if(x) goto Y
> else goto Z
>
> and some optimization may decide that x is always false or always true
> (because of something that goes inside the for-loop that cannot happen
> ever has started a possibly long chain of transformations that
> ultimately leads to that conclusion) Voilá: infinite loop.

And the above should also explain why this kind of arguments:

* It was working before
* It only happens with a particular optimization
* It only happens with a particular version of GCC
* It works in every machine and every compiler I have tested it
* "I ran my last full test (over 2000 raw photos) with
GCC 4.9.1" and it doesn't happen

are not useful. Maybe by chance, at some step in the long chain of
events, the UB did not have any bad effect, but something seemingly
unrelated changed within that chain and suddenly you get an infinite
loop, and this does not mean that the compiler had a bug before or has
a bug now, only that the chain of events was and is valid as long as
your program does not have UB.

For those interested in UB, I will strongly recommend reading:
http://www.eskimo.com/~scs/readings/undef.950321.html

Cheers,

Manuel.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]