Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions xls/dslx/ir_convert/function_converter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1650,8 +1650,10 @@ absl::StatusOr<BValue> FunctionConverter::HandleForBody(

XLS_ASSIGN_OR_RETURN(BValue init, Use(node->init()));
if (implicit_token_data_.has_value()) {
BValue activated = trip_count == 0 ? function_builder_->Literal(UBits(0, 1))
: implicit_token_data_->activated;
BValue activated = trip_count == 0
? function_builder_->Literal(UBits(0, 1))
: implicit_token_data_->create_control_predicate();

init = function_builder_->Tuple(
{implicit_token_data_->entry_token, activated, init});
}
Expand Down
10 changes: 10 additions & 0 deletions xls/dslx/tests/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,16 @@ dslx_lang_test(
test_ir_equivalence = False,
)

dslx_lang_test(
name = "assert_in_for_under_inactive_conditional",
compare = "interpreter",
# Don't convert to IR because we want to compare the IR interpreter and
# DSL interpreter. convert_to_ir=True disables comparison.
convert_to_ir = False,
# IR asserts are software-only; skip z3 equivalence.
test_ir_equivalence = False,
)

dslx_lang_test(
name = "quickcheck_fn_with_fail",
# Primarily a #[quickcheck] function.
Expand Down
28 changes: 28 additions & 0 deletions xls/dslx/tests/assert_in_for_under_inactive_conditional.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2025 The XLS Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

fn main() -> () { () }

fn bar() -> () { assert!(false, "Should not happen."); }

fn foo(x: bool) -> () {
if x {
for (_, ()) in u32:0..u32:4 {
bar()
}(())
}
}

#[test]
fn test_main_no_assert_when_false() { foo(false) }