Fix overflow handling in plpgsql's integer FOR loops.
Fix overflow handling in plpgsql's integer FOR loops.

The test to exit the loop if the integer control value would overflow
an int32 turns out not to work on some ICC versions, as it's dependent
on the assumption that the compiler will execute the code as written
rather than "optimize" it.  ICC lacks any equivalent of gcc's -fwrapv
switch, so it was optimizing on the assumption of no integer overflow,
and that breaks this.  Rewrite into a form that in fact does not
do any overflowing computations.

Per Tomas Vondra and buildfarm member fulmar.  It's been like this
for a long time, although it was not till we added a regression test
case covering the behavior (in commit dd2243f2a) that the problem
became apparent.  Back-patch to all supported versions.

Discussion: 0aaf411fbf5872269cca913e5b4b15138506d9cf@2ndquadrant.com

greenplum-db/gpdb,ashwinstar/gpdb,adam8157/gpdb,jmcatamney/gpdb,greenplum-db/gpdb,50wu/gpdb,xinzweb/gpdb,xinzweb/gpdb,greenplum-db/gpdb,greenplum-db/gpdb,ashwinstar/gpdb,ashwinstar/gpdb,lisakowen/gpdb,adam8157/gpdb,xinzweb/gpdb,50wu/gpdb,jmcatamney/gpdb,lisakowen/gpdb,jmcatamney/gpdb,jmcatamney/gpdb,xinzweb/gpdb,lisakowen/gpdb,jmcatamney/gpdb,lisakowen/gpdb,lisakowen/gpdb,xinzweb/gpdb,jmcatamney/gpdb,ashwinstar/gpdb,adam8157/gpdb,greenplum-db/gpdb,ashwinstar/gpdb,xinzweb/gpdb,adam8157/gpdb,ashwinstar/gpdb,xinzweb/gpdb,50wu/gpdb,50wu/gpdb,greenplum-db/gpdb,ashwinstar/gpdb,adam8157/gpdb,xinzweb/gpdb,adam8157/gpdb,lisakowen/gpdb,adam8157/gpdb,greenplum-db/gpdb,lisakowen/gpdb,greenplum-db/gpdb,50wu/gpdb,jmcatamney/gpdb,50wu/gpdb,adam8157/gpdb,ashwinstar/gpdb,lisakowen/gpdb,jmcatamney/gpdb,50wu/gpdb,50wu/gpdb