This is the mail archive of the gcc-patches@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: [PATCH] Document arithmetic overflow semantics


>> Are you really claiming that a program with an uninitialized variable
>> must be compiled in such a way that it produces the same result
>> independent of optimization?

> No one claims this, but it is useful to observe that the problem of
> uninitialized variables causing different results in unoptimized and
> optimized code is a severe one in practice that causes a lot of grief,
> especially in large systems where tracking down the difference can be a
> lot of work. However, in this case, the cure would be very expensive,
> and the gain from "optimizing" (which typically comes from putting stuff
> in registers) is so great as to be worth the pain.

That's not really true... a straight-forward way to "fix" this problem is
to simply initialize all variables to, for example, zero.  In almost all
cases, optimization would DCE this initialization anyway, so there is
really very little cost.  The only major cases I can think of that the
initialization would not be killed would be something like this:

int X;

if (predicate) {
...
  X = 6;
}

...

if (predicate) {
  = X;
}

In this case, X is always initialized before being used, but it's unlikely
an optimizer would know that, and thus it would have to insert an
initialization for X on the first !predicate path...

Despite the small cost, this could be a real help to some people...

-Chris

-- 
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/


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