2
0
mirror of https://github.com/boostorg/build.git synced 2026-02-20 02:32:13 +00:00

Fix a subtle problem in the result of if statements.

[SVN r75944]
This commit is contained in:
Steven Watanabe
2011-12-14 21:33:26 +00:00
parent 929e2872a7
commit c88679cd52
2 changed files with 58 additions and 5 deletions

View File

@@ -2167,19 +2167,18 @@ static void compile_parse( PARSE * parse, compiler * c, int result_location )
}
else if( parse->type == PARSE_IF )
{
int nested_result = result_location == RESULT_NONE? RESULT_NONE : RESULT_RETURN;
int f = compile_new_label( c );
/* Emit the condition */
compile_condition( parse->left, c, 0, f );
/* Emit the if block */
compile_parse( parse->right, c, nested_result );
if ( parse->third->type != PARSE_NULL )
compile_parse( parse->right, c, result_location );
if ( parse->third->type != PARSE_NULL || result_location != RESULT_NONE )
{
/* Emit the else block */
int end = compile_new_label( c );
compile_emit_branch( c, INSTR_JUMP, end );
compile_set_label( c, f );
compile_parse( parse->third, c, nested_result );
compile_parse( parse->third, c, result_location );
compile_set_label( c, end );
}
else
@@ -2187,7 +2186,6 @@ static void compile_parse( PARSE * parse, compiler * c, int result_location )
compile_set_label( c, f );
}
adjust_result( c, nested_result, result_location);
}
else if( parse->type == PARSE_WHILE )
{

View File

@@ -359,6 +359,61 @@ else
check-order if-else-false : r2 ;
rule test-rule
{
if true
{
return result ;
}
}
check-equal if-true-result : [ test-rule ] : result ;
rule test-rule
{
local idx = 1 2 ;
local values = true ;
while $(idx)
{
local v = $(values[$(idx[1])]) ;
idx = $(idx[2-]) ;
if $(v)
{
return result ;
}
}
}
check-equal if-false-result : [ test-rule ] : ;
rule test-rule
{
if true
{
return r1 ;
}
else
{
return r2 ;
}
}
check-equal if-else-true-result : [ test-rule ] : r1 ;
rule test-rule
{
if $(false)
{
return r1 ;
}
else
{
return r2 ;
}
}
check-equal if-else-false-result : [ test-rule ] : r2 ;
}
# Check the evaluation of conditions