.
--- generic/tclExecute.c
+++ generic/tclExecute.c
@@ -5074,8 +5074,11 @@
if (valuePtr->typePtr == &tclIntType) {
i = valuePtr->internalRep.longValue;
if (i < 0) {
- iResult = -i;
- if (iResult < 0) {
+ /* The casting hell below is needed to prevent GCC 4.1.0
+ * and newer from optimizing away the MIN_INT special case
+ * as dead code, which is allowed, according to the C
+ * standard. See bug #1241572. */
+ if ((unsigned long)(((signed long)iResult)-1) > 0) {
#ifdef TCL_WIDE_INT_IS_LONG
Tcl_SetObjResult(interp, Tcl_NewStringObj(
"integer value too large to represent", -1));
@@ -5094,6 +5097,7 @@
#endif
}
+ iResult = -i;
} else {
iResult = i;
}