c++/7322: Code to Compute Numeric Limits "runs away" when -O<any> used

lprimak@hope.nyc.ny.us lprimak@hope.nyc.ny.us
Mon Jul 15 19:56:00 GMT 2002


>Number:         7322
>Category:       c++
>Synopsis:       Code to Compute Numeric Limits "runs away" when -O<any> used
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jul 15 19:56:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Lenny Primak
>Release:        gcc version 3.1
>Organization:
>Environment:
(the OS is probably irrelevant)
Solaris 8/x86, Oct. 01 release,
gcc 3.1 as posted on Sunfreeware.com

ash-2.03$ gcc -v
Reading specs from /usr/local/lib/gcc-lib/i386-pc-solaris2.8/3.1/specs
Configured with: ../configure --with-as=/usr/ccs/bin/as --with-ld=/usr/ccs/bin/ld --disable-nls
Thread model: posix
bash-2.03$ gcc -v
Reading specs from /usr/local/lib/gcc-lib/i386-pc-solaris2.8/3.1/specs
Configured with: ../configure --with-as=/usr/ccs/bin/as --with-ld=/usr/ccs/bin/ld --disable-nls
Thread model: posix
gcc version 3.1
>Description:
The code works correctly when not using the optimize (-O) switch.
Incorrect code is produced that causes the process
to "run away" and eats 100% of the cpu when any kind
of optimization switch is used.
>How-To-Repeat:
bash-2.03$ c++ -O1 limits.cpp 
bash-2.03$ ./a.out
:
#undef _LPLIM_LIMITS
#define _LPLIM_CHAR_BIT 8
#define _LPLIM_BOOL_MIN !!0 /* sizeof (bool) = 1 */
#define _LPLIM_BOOL_MAX !0
#define _LPLIM_CHAR_MAX 127 /* sizeof (char) = 1 */
#define _LPLIM_CHAR_MIN (-_LPLIM_CHAR_MAX - 1)
(hangs/runs away here) ^C
bash-2.03$ 
>Fix:
None Available
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="limits.cpp"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="limits.cpp"

Ly8gY29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woKICAgIGZvciAoOyBUIChtYXggKiAyKSA+IG1heDsgbWF4ICo9IDIpOwogICAgZm9yIChU
IG4gPSBtYXggLyA0OyBuOyApIHsKICAgICAgICBpZiAoVCAobWF4ICsgbikgPCBtYXgpIHsKICAg
ICAgICAgICAgaWYgKG4gPiAyKQogICAgICAgICAgICAgICAgbiAvPSAyOwogICAgICAgICAgICBl
bHNlIGlmIChUIChtYXggKyAxKSA+IG1heCkKICAgICAgICAgICAgICAgIG4gPSAxOwogICAgICAg
ICAgICBlbHNlCiAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgICAgZWxzZQog
ICAgICAgICAgICBtYXggKz0gbjsKICAgIH0KCiAgICBwcmludF9saW1pdCAobWF4LCBwZngsIHNm
eCwgdHJ1ZSwgdHlwZSk7CgogICAgbWluID0gLW1heDsKCiAgICAvLyBjb21wdXRlIGEgbWluaW11
bQogICAgZm9yICg7IFQgKG1pbiAqIDIpIDwgbWluOyBtaW4gKj0gMik7CgogICAgLy8gd29ya2lu
ZyBhcm91bmQgYSBnY2Mgb3B0aW1pemVyICJmZWF0dXJlIiAoUFIgIzI2MjExKQogICAgLy8gc2ln
bmVkIGludGVnZXIgb3ZlcmZsb3cgaXMgdW5kZWZpbmVkIGJlaGF2aW9yCiAgICAvLyBmb3IgKDsg
VCAobWluIC0gMSkgPCBtaW47IG1pbiAtPSAxKTsKICAgIG1pbiA9IGZvbyAob25lLCBtaW4pOwoK
ICAgIHByaW50X2xpbWl0PFQ+IChtaW4sIHBmeCwgc2Z4LCBmYWxzZSwgdHlwZSk7Cn0KCgp2b2lk
IGNvbXB1dGVfY2hhcl9iaXRzICgpCnsKICAgIHVuc2lnbmVkIGJpdHMgPSAwOwoKICAgIGZvciAo
dW5zaWduZWQgY2hhciBjID0gJ1wwMSc7IGM7IGMgPDw9IDEsICsrYml0cyk7CgogICAgcHJpbnRm
ICgiI2RlZmluZSBfTFBMSU1fQ0hBUl9CSVQgJWRcbiIsIGJpdHMpOw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