diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-01-29 19:10:56 -0500 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-01-29 19:10:56 -0500 |
| commit | c75e58ffe6905c6a7d4e9f082726ea2cdcec514e (patch) | |
| tree | 154dd3fc23953eab6273a7ff4481a6e155e5f969 | |
| parent | e0a422ae7e9716172ef316e88a1050f98fb7f1fa (diff) | |
| download | zig-c75e58ffe6905c6a7d4e9f082726ea2cdcec514e.tar.gz zig-c75e58ffe6905c6a7d4e9f082726ea2cdcec514e.zip | |
fix behavior for comptime and runtime basic block phi
| -rw-r--r-- | src/ir.cpp | 1 | ||||
| -rw-r--r-- | test/cases/eval.zig | 28 |
2 files changed, 29 insertions, 0 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index 34654760a4..3793418972 100644 --- a/src/ir.cpp +++ b/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; } diff --git a/test/cases/eval.zig b/test/cases/eval.zig index 31901edca0..8e6f1dd096 100644 --- a/test/cases/eval.zig +++ b/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)); + } +} |
