Files
swift-mirror/test/SIL/verify_reducible_loops.sil
Meghana Gupta d8dda2d3ff Add optional verification to ensure reducible loops
Add a -verify-reducible-loops flag that checks SIL functions do not
contain irreducible loops
2026-07-15 15:09:40 -07:00

33 lines
712 B
Plaintext

// RUN: %empty-directory(%t)
// RUN: not --crash %target-sil-opt -verify-reducible-loops %s 2> %t/err.txt
// RUN: %FileCheck %s < %t/err.txt
// REQUIRES: asserts
// This test contains an irreducible loop and should fail verification
// when -sil-verify-reducible-loops is enabled.
sil_stage canonical
import Builtin
// CHECK: Irreducible loop detected in function irreducible_loop
sil @irreducible_loop : $@convention(thin) (Builtin.Int1) -> () {
bb0(%0 : $Builtin.Int1):
cond_br %0, bb1, bb2
// bb1 and bb2 form an irreducible loop: both are entry points
// from outside and both branch to each other.
bb1:
cond_br %0, bb2, bb3
bb2:
cond_br %0, bb1, bb3
bb3:
%r = tuple ()
return %r : $()
}