aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-02-24 13:57:00 -0500
committerAndrew Kelley <superjoe30@gmail.com>2017-02-24 13:57:00 -0500
commit3b40aaa01fb15799cf27d662229597ac98e2ab77 (patch)
treedb9403afed5078fe795b07ce3d522b3f2a9d4343 /src/ir.cpp
parent4b99f5978f35e54d4b4f1bfae022f48f193e40fd (diff)
downloadzig-3b40aaa01fb15799cf27d662229597ac98e2ab77.tar.gz
zig-3b40aaa01fb15799cf27d662229597ac98e2ab77.zip
add compile error for control flow using comptime var at runtime
closes #266
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index 28ae1bd1ad..43040fd7a2 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -8601,6 +8601,15 @@ static TypeTableEntry *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr
return ir_inline_bb(ira, &br_instruction->base, old_dest_block);
IrBasicBlock *new_bb = ir_get_new_bb(ira, old_dest_block, &br_instruction->base);
+
+ if (new_bb->must_be_comptime_source_instr) {
+ ErrorMsg *msg = ir_add_error(ira, &br_instruction->base,
+ buf_sprintf("control flow attempts to use compile-time variable at runtime"));
+ add_error_note(ira->codegen, msg, new_bb->must_be_comptime_source_instr->source_node,
+ buf_sprintf("compile-time variable assigned here"));
+ return ir_unreach_error(ira);
+ }
+
ir_build_br_from(&ira->new_irb, &br_instruction->base, new_bb);
return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable);
}
@@ -9392,6 +9401,9 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru
ConstExprValue *dest_val = const_ptr_pointee(&ptr->value);
if (dest_val->special != ConstValSpecialRuntime) {
*dest_val = casted_value->value;
+ if (!ira->new_irb.current_basic_block->must_be_comptime_source_instr) {
+ ira->new_irb.current_basic_block->must_be_comptime_source_instr = &store_ptr_instruction->base;
+ }
return ir_analyze_void(ira, &store_ptr_instruction->base);
}
}