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: GCC optimizes integer overflow: bug or feature?


* Andrew Pinski:

> A simple loop like:
> int foo ()
> {
>   int a[N];
>   int i;
>   int n;
>
>   for (i = 0; i <= n; i++)
>       ca[i] = 2;
> }
>
> we cannot find how many iterations it runs without knowing that signed
> types overflow.

In this case, the assumption is not needed because the lack of
overflow can be inferred from the validity of the expression ca[i] for
all relevant i.  However, in the general case, such information might
not be available.  I wonder if it is feasible to duplicate the loop
code, once for positive n, and once for negative, or if this would
lead to too much code bloat in real-world applications.

By the way, as I've tried to describe here:
<http://cert.uni-stuttgart.de/advisories/c-integer-overflow.php>
variable range tracking can result in reintroduction of
supposedly-fixed security vulnerabilities. 8-(


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