This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/4486: incorrect evaluation of boolean expressions
- To: gcc-gnats at gcc dot gnu dot org
- Subject: c++/4486: incorrect evaluation of boolean expressions
- From: mvishnu at calix dot com
- Date: 5 Oct 2001 22:03:42 -0000
- Reply-To: mvishnu at calix dot com
>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: