public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: c++/4486: incorrect evaluation of boolean expressions
@ 2001-12-15 10:54 nathan
0 siblings, 0 replies; 2+ messages in thread
From: nathan @ 2001-12-15 10:54 UTC (permalink / raw)
To: gcc-bugs, gcc-prs, mvishnu, nobody
Synopsis: incorrect evaluation of boolean expressions
State-Changed-From-To: open->closed
State-Changed-By: nathan
State-Changed-When: Sat Dec 15 10:54:36 2001
State-Changed-Why:
user error. Your synopsis does not match your code. The
code is
bool var = whatever;
for () {
bool var = var && somethingelse;
}
that is causing a read of an uninitalized variable.
with -Wall and -O you should get a warning about that.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=4486
^ permalink raw reply [flat|nested] 2+ messages in thread
* c++/4486: incorrect evaluation of boolean expressions
@ 2001-10-05 15:06 mvishnu
0 siblings, 0 replies; 2+ messages in thread
From: mvishnu @ 2001-10-05 15:06 UTC (permalink / raw)
To: gcc-gnats
>Number: 4486
>Category: c++
>Synopsis: incorrect evaluation of boolean expressions
>Confidential: no
>Severity: critical
>Priority: high
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Oct 05 15:06:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: Meenan Vishnu
>Release: unknown-1.0
>Organization:
>Environment:
Solaris and Linux
>Description:
The expression such as
bool a = <bool expression>
a = a && <another bool expression>
is evaluating to false when it should be true
in g++ (3 and 3.01) In the attached file, the assertion should not be asserted, but is asserted. (note that both
data() and is_set_port() are const member functions).
// make multicast requests to input ports with multicast
// cells destined to the output port.
void ARBITER::make_mc_requests( void )
{
for( int opi = 0; opi < NUM_PORTS; ++opi )
{
ARB_OUTPUT_PORT& op = output_port[ opi ];
// compute sum of the weights...
long sum_w = 0;
for( int ipi = 0; ipi < NUM_PORTS; ++ipi )
{
ARB_INPUT_PORT& ip = input_port[ ipi ];
ARB_INOUT_PORT& io = inout_port[ ipi ][ opi ];
// there should not have been any prior service.
assert( ip.s_i <= ip.a_i );
if( ( ip.enabled.data() ) &&
( ip.mc_fluid_q_len > 0 ) &&
( ip.current_rm.is_set_port( opi ) ) &&
( ip.s_i < ip.a_i ) )
{
sum_w += io.mc_weight;
}
}
// compute the requests to the inputs...
long f = op.a_o - op.s_o;
bool req_cond1 = op.enabled.data() &&
( sum_w > 0 );
#define COMPILER_CHECK
#ifdef COMPILER_CHECK
bool req_cond2 = op.enabled.data() &&
( sum_w > 0 );
#endif
for( int ipi = 0; ipi < NUM_PORTS; ++ipi )
{
ARB_INPUT_PORT& ip = input_port[ ipi ];
ARB_INOUT_PORT& io = inout_port[ ipi ][ opi ];
bool req_cond = req_cond1 &&
( ip.enabled.data() ) &&
( ip.mc_fluid_q_len > 0 ) &&
( ip.current_rm.is_set_port( opi ) ) &&
( ip.s_i < ip.a_i );
#ifdef COMPILER_CHECK
bool req_cond2 = req_cond2 &&
( ip.enabled.data() ) &&
( ip.mc_fluid_q_len > 0 ) &&
( ip.current_rm.is_set_port( opi ) ) &&
( ip.s_i < ip.a_i );
// This assertion is failing indicating a compiler problem
assert( req_cond == req_cond2 );
#endif
if( req_cond )
io.request = f * io.mc_weight / sum_w;
else
io.request = 0;
}
}
}
>How-To-Repeat:
>Fix:
A fix is to rewrite the expression as
bool a1 = <bool expression>
bool a = a1 && <another bool expression>
>Release-Note:
>Audit-Trail:
>Unformatted:
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2001-12-15 18:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-12-15 10:54 c++/4486: incorrect evaluation of boolean expressions nathan
-- strict thread matches above, loose matches on Subject: below --
2001-10-05 15:06 mvishnu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).