This is the mail archive of the gcc@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: basic VRP min/max range overflow question







Paul Schlie wrote on 20/06/2005 08:55:20:
>   y = z ? z + x;    // y == [INT_MIN+1, INT_MAX+2]

Invalid syntax, what did you mean?

> I guess I simply believe that optimizations should never alter the
logical
> behavior of a specified program relative to it's un-optimized form unless
> explicitly granted permission to do so, therefore such optimizations
should
> never be considered enabled at any level of optimization by default.

As a user I sympathize with this wish. As someone who spent a whole
day wading through assembly to analyze a bug (undefined
behavior), I can tell you that I don't like it either.

Yet, as a developer of another system with strict semantics I can
say that, in general, your requirements are impossible to follow,
unless very carefully worded.

This requirement for "never alter the logical behavior" implicitly
forbids all optimizations in a language like C.
For example consider:

1: void foo()
2: {
3:     int a;
4:     printf("%d\n", a); /* undefined behavior */
5: }
6: void bar()
7: {
8:     do something;
9: }
10:int main()
11:{
12:    bar();
13:    foo();
14:    return 0;
15:}

Almost any optimization over line 8 will change the
behavior of line 4. I believe that you did not intend to
cover this case in your requirement. Maybe you would
like to narrow the requirement such that it enumerates
all the cases you consider to "alter the logical behavior".
And even if you do, you'll have to be very careful to
define a consistent semantics for each case.



   Michael


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