authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-01-29 19:10:56-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-01-29 19:10:56-05:00
logc75e58ffe6905c6a7d4e9f082726ea2cdcec514e
tree154dd3fc23953eab6273a7ff4481a6e155e5f969
parente0a422ae7e9716172ef316e88a1050f98fb7f1fa

fix behavior for comptime and runtime basic block phi


2 files changed, 29 insertions(+), 0 deletions(-)

src/ir.cpp+1
......@@ -5935,6 +5935,7 @@ static TypeTableEntry *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instru
59355935 return ir_unreach_error(ira);
59365936 }
59375937
5938 old_bb->other = ira->old_irb.current_basic_block->other;
59385939 ir_start_bb(ira, old_bb, ira->old_irb.current_basic_block);
59395940 return ira->codegen->builtin_types.entry_unreachable;
59405941}
test/cases/eval.zig+28
......@@ -191,3 +191,31 @@ fn testTryToTrickEvalWithRuntimeIf(b: bool) -> usize {
191191 return i;
192192 }
193193}
194
195fn max(comptime T: type, a: T, b: T) -> T {
196 if (T == bool) {
197 return a || b;
198 } else if (a > b) {
199 return a;
200 } else {
201 return b;
202 }
203}
204fn letsTryToCompareBools(a: bool, b: bool) -> bool {
205 max(bool, a, b)
206}
207fn inlinedBlockAndRuntimeBlockPhi() {
208 @setFnTest(this);
209
210 assert(letsTryToCompareBools(true, true));
211 assert(letsTryToCompareBools(true, false));
212 assert(letsTryToCompareBools(false, true));
213 assert(!letsTryToCompareBools(false, false));
214
215 comptime {
216 assert(letsTryToCompareBools(true, true));
217 assert(letsTryToCompareBools(true, false));
218 assert(letsTryToCompareBools(false, true));
219 assert(!letsTryToCompareBools(false, false));
220 }
221}