stdcxx-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Colin Lee (JIRA)" <>
Subject [jira] Created: (STDCXX-264) LIMITS.cpp WCHAR test causes infinite loop with IPA, nonstandard code
Date Mon, 31 Jul 2006 20:26:13 GMT
LIMITS.cpp WCHAR test causes infinite loop with IPA, nonstandard code

                 Key: STDCXX-264
             Project: C++ Standard Library
          Issue Type: Bug
          Components: Configuration
    Affects Versions: 4.1.3
         Environment: > uname -a && CC -V
UNICOS/mp sn702 3.0.62 07230830 crayx1
Cray C++ : Version  Mon Jul 31, 2006  14:38:56
            Reporter: Colin Lee
            Priority: Minor

With any compiler that uses interprocedural analysis including leaf node inlining, this WCHAR
test in etc/config/src/LIMITS.cpp invokes undefined behavior from signed integer overflow
and can result in an infinite loop.  Our compiler inlines the greater() function and invokes
undefined behavior, so the loop never exits.  One workaround is to disable optimization and
run the code by hand, but since this code is hidden within the build process, a portable solution
is needed.  Here's a code snippet:

template <class T>
T greater (T lhs, T rhs)
    // prevents overzealous gcc optimizer from invoking
    // undefined behavior on signed integer over/underflow
    return lhs > rhs;

template <class T>
T compute_limits (T, const char *pfx, const char *sfx, const char *type)
    T max  = T (1);
    T one  = T (1);

    for (; T (max * 2) > max; max *= 2);
    for (T n = max / 4; n; ) {
        if (T (max + n) < max) {
            if (n > 2)
                n /= 2;
            else if (greater (T (max + one), max))
                n = 1;
            max += n;
    return max;

int main(void) {
    compute_limits ((wchar_t)0, "WCHAR_T", suffix, "wchar_t");
    return 0;

This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators:
For more information on JIRA, see:


View raw message