You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stdcxx.apache.org by "Colin Lee (JIRA)" <ji...@apache.org> on 2006/07/31 22:26:13 UTC

[jira] Created: (STDCXX-264) LIMITS.cpp WCHAR test causes infinite loop with IPA, nonstandard code

LIMITS.cpp WCHAR test causes infinite loop with IPA, nonstandard code
---------------------------------------------------------------------

                 Key: STDCXX-264
                 URL: http://issues.apache.org/jira/browse/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 5.6.0.0.57  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;
            else
                break;
        }
        else
            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: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (STDCXX-264) LIMITS.cpp WCHAR test causes infinite loop with IPA, nonstandard code

Posted by "Colin Lee (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/STDCXX-264?page=comments#action_12424686 ] 
            
Colin Lee commented on STDCXX-264:
----------------------------------

It seems the volatiles fixed the problem.  Thanks again.

> LIMITS.cpp WCHAR test causes infinite loop with IPA, nonstandard code
> ---------------------------------------------------------------------
>
>                 Key: STDCXX-264
>                 URL: http://issues.apache.org/jira/browse/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 5.6.0.0.57  Mon Jul 31, 2006  14:38:56
>            Reporter: Colin Lee
>         Assigned To: Martin Sebor
>            Priority: Minor
>             Fix For: 4.2
>
>
> 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;
>             else
>                 break;
>         }
>         else
>             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: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (STDCXX-264) LIMITS.cpp WCHAR test causes infinite loop with IPA, nonstandard code

Posted by "Colin Lee (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/STDCXX-264?page=comments#action_12424681 ] 
            
Colin Lee commented on STDCXX-264:
----------------------------------

Thanks, you have a very fast response rate!  I'll look at it soon.

> LIMITS.cpp WCHAR test causes infinite loop with IPA, nonstandard code
> ---------------------------------------------------------------------
>
>                 Key: STDCXX-264
>                 URL: http://issues.apache.org/jira/browse/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 5.6.0.0.57  Mon Jul 31, 2006  14:38:56
>            Reporter: Colin Lee
>         Assigned To: Martin Sebor
>            Priority: Minor
>             Fix For: 4.2
>
>
> 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;
>             else
>                 break;
>         }
>         else
>             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: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Assigned: (STDCXX-264) LIMITS.cpp WCHAR test causes infinite loop with IPA, nonstandard code

Posted by "Martin Sebor (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/STDCXX-264?page=all ]

Martin Sebor reassigned STDCXX-264:
-----------------------------------

    Assignee: Martin Sebor

> LIMITS.cpp WCHAR test causes infinite loop with IPA, nonstandard code
> ---------------------------------------------------------------------
>
>                 Key: STDCXX-264
>                 URL: http://issues.apache.org/jira/browse/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 5.6.0.0.57  Mon Jul 31, 2006  14:38:56
>            Reporter: Colin Lee
>         Assigned To: Martin Sebor
>            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;
>             else
>                 break;
>         }
>         else
>             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: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Closed: (STDCXX-264) LIMITS.cpp WCHAR test causes infinite loop with IPA, nonstandard code

Posted by "Martin Sebor (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/STDCXX-264?page=all ]

Martin Sebor closed STDCXX-264.
-------------------------------


Great, thanks for the confirmation (and the report itself)!

> LIMITS.cpp WCHAR test causes infinite loop with IPA, nonstandard code
> ---------------------------------------------------------------------
>
>                 Key: STDCXX-264
>                 URL: http://issues.apache.org/jira/browse/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 5.6.0.0.57  Mon Jul 31, 2006  14:38:56
>            Reporter: Colin Lee
>         Assigned To: Martin Sebor
>            Priority: Minor
>             Fix For: 4.2
>
>
> 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;
>             else
>                 break;
>         }
>         else
>             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: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Resolved: (STDCXX-264) LIMITS.cpp WCHAR test causes infinite loop with IPA, nonstandard code

Posted by "Martin Sebor (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/STDCXX-264?page=all ]

Martin Sebor resolved STDCXX-264.
---------------------------------

    Fix Version/s: 4.2
       Resolution: Fixed

The referenced patch should fix it. Colin -- please let us know if the problem persists.

> LIMITS.cpp WCHAR test causes infinite loop with IPA, nonstandard code
> ---------------------------------------------------------------------
>
>                 Key: STDCXX-264
>                 URL: http://issues.apache.org/jira/browse/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 5.6.0.0.57  Mon Jul 31, 2006  14:38:56
>            Reporter: Colin Lee
>         Assigned To: Martin Sebor
>            Priority: Minor
>             Fix For: 4.2
>
>
> 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;
>             else
>                 break;
>         }
>         else
>             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: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira