Message118139
See the example above: suppose that a compiler is looking at a (p >= q) comparison of pointers. Suppose furthermore that in a particular case that compiler is smart enough to figure out that q is a pointer to the start of an array. Then the compiler is *permitted to assume* that p also points into the same array, since if it didn't then the code would introduce undefined behaviour. And since q is the start of the array, and p is (by assumption) a pointer into the same array, p >= q will automatically be true, so the compiler is free to replace the expression with the integer '1' (i.e., true).
gcc does similar things with checks like (x + 1 > x): if x is a (signed) int, then gcc can and will optimize (x + 1 > x) to 'true', on the basis that x + 1 can never overflow, because such overflow would be undefined behaviour and therefore can't occur in a valid C program. |
|
Date |
User |
Action |
Args |
2010-10-07 21:22:03 | mark.dickinson | set | recipients:
+ mark.dickinson, rhettinger, amaury.forgeotdarc, pitrou, eric.smith, stutzbach |
2010-10-07 21:22:03 | mark.dickinson | set | messageid: <1286486523.86.0.587248442341.issue10044@psf.upfronthosting.co.za> |
2010-10-07 21:22:02 | mark.dickinson | link | issue10044 messages |
2010-10-07 21:22:02 | mark.dickinson | create | |
|