Handle optional condition/step when evaluating for loops at compile time.
This fixes the compiler segfault seen in issue #1143.
This commit is contained in:
parent
a204af04a5
commit
82a122372b
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2012-2022 Stephen Williams (steve@icarus.com)
|
||||
* Copyright (c) 2012-2024 Stephen Williams (steve@icarus.com)
|
||||
*
|
||||
* This source code is free software; you can redistribute it
|
||||
* and/or modify it in source code form under the terms of the GNU
|
||||
|
|
@ -834,24 +834,26 @@ bool NetForLoop::evaluate_function(const LineInfo&loc,
|
|||
}
|
||||
|
||||
while (flag && !disable) {
|
||||
// Evaluate the condition expression to try and get the
|
||||
// condition for the loop.
|
||||
NetExpr*cond = condition_->evaluate_function(loc, context_map);
|
||||
if (cond == nullptr) {
|
||||
flag = false;
|
||||
break;
|
||||
if (condition_) {
|
||||
// Evaluate the condition expression to try and get the
|
||||
// condition for the loop.
|
||||
NetExpr*cond = condition_->evaluate_function(loc, context_map);
|
||||
if (cond == nullptr) {
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
|
||||
NetEConst*cond_const = dynamic_cast<NetEConst*> (cond);
|
||||
ivl_assert(loc, cond_const);
|
||||
|
||||
long val = cond_const->value().as_long();
|
||||
delete cond;
|
||||
|
||||
// If the condition is false, then break;
|
||||
if (val == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
NetEConst*cond_const = dynamic_cast<NetEConst*> (cond);
|
||||
ivl_assert(loc, cond_const);
|
||||
|
||||
long val = cond_const->value().as_long();
|
||||
delete cond;
|
||||
|
||||
// If the condition is false, then break;
|
||||
if (val == 0)
|
||||
break;
|
||||
|
||||
bool tmp_flag = statement_->evaluate_function(loc, context_map);
|
||||
flag &= tmp_flag;
|
||||
|
||||
|
|
@ -865,8 +867,10 @@ bool NetForLoop::evaluate_function(const LineInfo&loc,
|
|||
|
||||
loop_continue = false;
|
||||
|
||||
tmp_flag = step_statement_->evaluate_function(loc, context_map);
|
||||
flag &= tmp_flag;
|
||||
if (step_statement_) {
|
||||
tmp_flag = step_statement_->evaluate_function(loc, context_map);
|
||||
flag &= tmp_flag;
|
||||
}
|
||||
}
|
||||
|
||||
if (debug_eval_tree) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue