stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r589913 - /incubator/stdcxx/trunk/etc/config/src/NO_INT_TRAPS.cpp
Date Mon, 29 Oct 2007 23:41:54 GMT
Author: sebor
Date: Mon Oct 29 16:41:53 2007
New Revision: 589913

URL: http://svn.apache.org/viewvc?rev=589913&view=rev
Log:
2007-10-29  Martin Sebor  <sebor@roguewave.com>

	Merged rev 589912 (fix for STDCXX-624) from branches/4.2.x.
	* NO_INT_TRAPS.cpp (main): Worked even harder to foil optimizers
	and trigger a trap (such as SIGFPE) for integer arithmetic.

Modified:
    incubator/stdcxx/trunk/etc/config/src/NO_INT_TRAPS.cpp

Modified: incubator/stdcxx/trunk/etc/config/src/NO_INT_TRAPS.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/etc/config/src/NO_INT_TRAPS.cpp?rev=589913&r1=589912&r2=589913&view=diff
==============================================================================
--- incubator/stdcxx/trunk/etc/config/src/NO_INT_TRAPS.cpp (original)
+++ incubator/stdcxx/trunk/etc/config/src/NO_INT_TRAPS.cpp Mon Oct 29 16:41:53 2007
@@ -34,30 +34,49 @@
 #endif   // _WIN{32,64}
 
 
-int get_int ();
+int get_int (int);
+
+
+volatile int int_zero;
+volatile int int_one;
+
 
 int main (int argc, char*[])
 {
-    int int_zero = get_int ();
-    int int_one  = get_int ();
+    // test expects to be called with no command line arguments
+    // i.e., (argc < 2) is expected to hold
+
+    // argc used to try to foil optimizers
+    int_zero = get_int (argc);
+    int_one  = get_int (argc);
 
-    int result;
+    int result [2];
 
     TRY {
-        result = int_one / int_zero;
+        // use both division and modulo to try to foil optimizers
+        result [0] = int_one / int_zero;
+        result [1] = int_one % int_zero;
     }
     EXCEPT (1) {
         return 1;
     }
 
     // NEGATIVE test: successful exit status indicates a failure
-    return argc < 2 ? 0 : result;
+    return argc < 2 ? result [0] : result [1];
 }
 
-// foil optimizers
-volatile int int_value = 0;
+// use volatile to try to foil optimizers
+volatile int int_value;
 
-int get_int ()
+// use recursion to try to foil optimizers
+int get_int (int arg)
 {
-    return int_value++;
+    if (1 < arg)
+        return get_int (arg - 1) + get_int (arg - 2);
+
+    const int value = int_value;
+
+    ++int_value;
+
+    return value;
 }



Mime
View raw message