You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stdcxx.apache.org by se...@apache.org on 2007/07/11 00:51:20 UTC

svn commit: r555106 - /incubator/stdcxx/trunk/etc/config/src/LIMITS.cpp

Author: sebor
Date: Tue Jul 10 15:51:19 2007
New Revision: 555106

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

	STDCXX-482
	* LIMITS.cpp (compute_limits): Used the first argument to pass in
	a pointer to a value for the function to use in integer arithmetic
	involving (signed) overflow which with some aggressive optimizers
	such as Sun Studio 12 aka Sun C++ 5.9 leads to undefined behavior.
	(main): Introduced MKLIMITS() macro for convenience.

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

Modified: incubator/stdcxx/trunk/etc/config/src/LIMITS.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/etc/config/src/LIMITS.cpp?view=diff&rev=555106&r1=555105&r2=555106
==============================================================================
--- incubator/stdcxx/trunk/etc/config/src/LIMITS.cpp (original)
+++ incubator/stdcxx/trunk/etc/config/src/LIMITS.cpp Tue Jul 10 15:51:19 2007
@@ -155,7 +155,7 @@
 
 
 template <class T>
-T compute_limits (T, const char *pfx, const char *sfx, const char *type)
+T compute_limits (T *pval, const char *pfx, const char *sfx, const char *type)
 {
     T min = T (-one);
     T max = T (one);
@@ -167,17 +167,17 @@
 
     // compute the maximum representable value
     for (; T (max * two) > max; max *= two);
-    for (T n = max / (two + two); n; ) {
-        if (T (max + n) < max) {
-            if (n > T (two))
-                n /= two;
+    for (*pval = max / (two + two); *pval; ) {
+        if (T (max + *pval) < max) {
+            if (*pval > T (two))
+                *pval /= two;
             else if (max < T (max + one))
-                n = one;
+                *pval = one;
             else
                 break;
         }
         else
-            max += n;
+            max += *pval;
     }
 
     // print the maximum representable value
@@ -281,18 +281,24 @@
     }
     printf ("#define _RWSTD_NO_TWOS_COMPLEMENT\n");
 
-    compute_limits ((char)0, "CHAR", "", "char");
-    compute_limits ((signed char)0, "SCHAR", "", "signed char");
-    compute_limits ((unsigned char)0, "UCHAR", "U", "unsigned char");
+#define MKLIMITS(T, pfx, sfx, type)            \
+    do {                                       \
+        T buf = 0;                             \
+        compute_limits (&buf, pfx, sfx, type); \
+    } while (0)
+
+    MKLIMITS (char, "CHAR", "", "char");
+    MKLIMITS (signed char, "SCHAR", "", "signed char");
+    MKLIMITS (unsigned char, "UCHAR", "U", "unsigned char");
 
-    compute_limits ((short)0, "SHRT", "", "short");
-    compute_limits ((unsigned short)0, "USHRT", "U", "unsigned short");
+    MKLIMITS (short, "SHRT", "", "short");
+    MKLIMITS (unsigned short, "USHRT", "U", "unsigned short");
 
-    compute_limits ((int)0, "INT", "", "int");
-    compute_limits ((unsigned int)0, "UINT", "U", "unsigned int");
+    MKLIMITS (int, "INT", "", "int");
+    MKLIMITS (unsigned int, "UINT", "U", "unsigned int");
 
-    compute_limits ((long)0, "LONG", "L", "long");
-    compute_limits ((unsigned long)0, "ULONG", "UL", "unsigned long");
+    MKLIMITS (long, "LONG", "L", "long");
+    MKLIMITS (unsigned long, "ULONG", "UL", "unsigned long");
 
 #ifndef _RWSTD_NO_LONG_LONG
 
@@ -302,8 +308,8 @@
 
     const char llong_name[] = "long long";
 
-    compute_limits ((LLong)0, "LLONG", "LL", "long long");
-    compute_limits ((unsigned LLong)0, "ULLONG", "ULL", "unsigned long long");
+    MKLIMITS (LLong, "LLONG", "LL", "long long");
+    MKLIMITS (unsigned LLong, "ULLONG", "ULL", "unsigned long long");
 
 #else   // if defined (_RWSTD_NO_LONG_LONG)
 
@@ -315,9 +321,8 @@
 
     const char llong_name[] = "__int64";
 
-    compute_limits ((LLong)0, "LLONG", "L", "__int64");
-    compute_limits ((unsigned LLong)0, "ULLONG", "UL",
-                    "unsigned __int64");
+    MKLIMITS (LLong, "LLONG", "L", "__int64");
+    MKLIMITS (unsigned LLong, "ULLONG", "UL", "unsigned __int64");
 
 #    else
 
@@ -338,7 +343,7 @@
     if ((wchar_t)~0 < (wchar_t)0)
         suffix = "";
     
-    compute_limits ((wchar_t)0, "WCHAR", suffix, "wchar_t");
+    MKLIMITS (wchar_t, "WCHAR", suffix, "wchar_t");
 
 #endif   // _RWSTD_NO_WCHAR_T
 



Re: svn commit: r555106 - /incubator/stdcxx/trunk/etc/config/src/LIMITS.cpp

Posted by Martin Sebor <se...@roguewave.com>.
Andrew Black wrote:
> Greetings Martin
> 
> I'm not certain, but I suspect this change has lead to a breakage with
> aCC 3.73 and aCC 3.76.  In particular, I see the following failure while
> building the library (remarks trimmed out)
>> aCC -c -I$(TOPDIR)/include/ansi -I/usr/include     -I$(TOPDIR)/include -I$(BUILDDIR)/include  -Aa +nostl +W2193 +W2261 +W2340 +W2401 +W2487 +W4263 +W4264 +W4297 +O2  +DD64 +w +W392 +W655 +W684 +W818 +W819 +W849  +Z  $(TOPDIR)/src/time_put.cpp
>> "$(TOPDIR)/src/time_put.cpp", line 2811: error #2167: argument of type "unsigned long" is incompatible with parameter of type "const wchar_t *"
>>                           bufsize,
>>                           ^
> 
> The failure is a fairly new (less than a week old), and I believe this
> to be the most likely culprit.

Thanks for pointing it out! Yes, this is my bad. It's a fallout
from http://svn.apache.org/viewvc?view=rev&revision=554281. I
believe I fixed it along with another problems caused by yours
truly with the following two changes:

   http://svn.apache.org/viewvc?view=rev&rev=555408
   http://svn.apache.org/viewvc?view=rev&rev=555427

Martin


Re: svn commit: r555106 - /incubator/stdcxx/trunk/etc/config/src/LIMITS.cpp

Posted by Andrew Black <ab...@roguewave.com>.
Greetings Martin

I'm not certain, but I suspect this change has lead to a breakage with
aCC 3.73 and aCC 3.76.  In particular, I see the following failure while
building the library (remarks trimmed out)
> aCC -c -I$(TOPDIR)/include/ansi -I/usr/include     -I$(TOPDIR)/include -I$(BUILDDIR)/include  -Aa +nostl +W2193 +W2261 +W2340 +W2401 +W2487 +W4263 +W4264 +W4297 +O2  +DD64 +w +W392 +W655 +W684 +W818 +W819 +W849  +Z  $(TOPDIR)/src/time_put.cpp
> "$(TOPDIR)/src/time_put.cpp", line 2811: error #2167: argument of type "unsigned long" is incompatible with parameter of type "const wchar_t *"
>                           bufsize,
>                           ^

The failure is a fairly new (less than a week old), and I believe this
to be the most likely culprit.

--Andrew Black

sebor@apache.org wrote:
> Author: sebor
> Date: Tue Jul 10 15:51:19 2007
> New Revision: 555106
> 
> URL: http://svn.apache.org/viewvc?view=rev&rev=555106
> Log:
> 2007-07-10  Martin Sebor  <se...@roguewave.com>
> 
> 	STDCXX-482
> 	* LIMITS.cpp (compute_limits): Used the first argument to pass in
> 	a pointer to a value for the function to use in integer arithmetic
> 	involving (signed) overflow which with some aggressive optimizers
> 	such as Sun Studio 12 aka Sun C++ 5.9 leads to undefined behavior.
> 	(main): Introduced MKLIMITS() macro for convenience.
> 
> Modified:
>     incubator/stdcxx/trunk/etc/config/src/LIMITS.cpp