Commit c75e58ffe6
src/ir.cpp
@@ -5935,6 +5935,7 @@ static TypeTableEntry *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instru
return ir_unreach_error(ira);
}
+ old_bb->other = ira->old_irb.current_basic_block->other;
ir_start_bb(ira, old_bb, ira->old_irb.current_basic_block);
return ira->codegen->builtin_types.entry_unreachable;
}
test/cases/eval.zig
@@ -191,3 +191,31 @@ fn testTryToTrickEvalWithRuntimeIf(b: bool) -> usize {
return i;
}
}
+
+fn max(comptime T: type, a: T, b: T) -> T {
+ if (T == bool) {
+ return a || b;
+ } else if (a > b) {
+ return a;
+ } else {
+ return b;
+ }
+}
+fn letsTryToCompareBools(a: bool, b: bool) -> bool {
+ max(bool, a, b)
+}
+fn inlinedBlockAndRuntimeBlockPhi() {
+ @setFnTest(this);
+
+ assert(letsTryToCompareBools(true, true));
+ assert(letsTryToCompareBools(true, false));
+ assert(letsTryToCompareBools(false, true));
+ assert(!letsTryToCompareBools(false, false));
+
+ comptime {
+ assert(letsTryToCompareBools(true, true));
+ assert(letsTryToCompareBools(true, false));
+ assert(letsTryToCompareBools(false, true));
+ assert(!letsTryToCompareBools(false, false));
+ }
+}