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: -funsafe-loop-optimizations


> From: Robert Dewar <dewar@adacore.com>
>> Paul Schlie wrote:
>> Don't necessarily disagree, but wouldn't it be preferable if the ambiguity
>> were explicitly removed in the code
> 
> What do you mean by this?

Given the example (where n may be MAX_UNSIGNED yielding an infinite loop):

 void foo (unsigned n)
 {
   for (unsigned i = 0; i <= n; i++)
     bar ();
 }

If warnings were issued along the lines of:

 Warning: n == MAX_UNSIGNED will yield infinite loop.
 Warning: n == MAX_UNSIGNED inhibits loop optimization.

The code could be explicitly changed if desired to eliminate the
potential for an infinite loop if unintended to:

 void foo (unsigned n)
 {
   unsigned i = 0;
   do {
     bar ();
   while ( i++ < n );
 }

Or possibly if preferred:

 void foo (unsigned n)
 {
   for (long i = 0; i <= n; i++) /* assuming precision long > unsigned. */
     bar ();
 }

etc. ..., as it would seem desirable to explicitly specify in the language
the intent of the code, and not necessarily rely on alternative external
interpretations of it's intent when it's intent may be unambiguously
specified?





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