aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2017-01-16 16:07:03 -0500
committerAndrew Kelley <superjoe30@gmail.com>2017-01-16 16:07:03 -0500
commit867686af420bab965f63359499a526f35e875c9a (patch)
tree081d9129e01e9dd3953a3a65c9856cf56b77cbcd /src
parentfdbc2d8da1c707859af8f8bb42a27ae9d3a62159 (diff)
downloadzig-867686af420bab965f63359499a526f35e875c9a.tar.gz
zig-867686af420bab965f63359499a526f35e875c9a.zip
equality comparison of void types is known at compile time
closes #56
Diffstat (limited to 'src')
-rw-r--r--src/ir.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index f6b932a9e7..5e7f00c306 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -94,8 +94,12 @@ static Buf *exec_c_import_buf(IrExecutable *exec) {
return exec->c_import_buf;
}
+static bool value_is_comptime(ConstExprValue *const_val) {
+ return const_val->special != ConstValSpecialRuntime;
+}
+
static bool instr_is_comptime(IrInstruction *instruction) {
- return instruction->value.special != ConstValSpecialRuntime;
+ return value_is_comptime(&instruction->value);
}
static bool instr_is_unreachable(IrInstruction *instruction) {
@@ -6907,7 +6911,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
ConstExprValue *op1_val = &casted_op1->value;
ConstExprValue *op2_val = &casted_op2->value;
- if (op1_val->special != ConstValSpecialRuntime && op2_val->special != ConstValSpecialRuntime) {
+ if ((value_is_comptime(op1_val) && value_is_comptime(op2_val)) || resolved_type->id == TypeTableEntryIdVoid) {
bool type_can_gt_lt_cmp = (resolved_type->id == TypeTableEntryIdNumLitFloat ||
resolved_type->id == TypeTableEntryIdNumLitInt ||
resolved_type->id == TypeTableEntryIdFloat ||
@@ -6933,7 +6937,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
answer = bignum_cmp(&op1_val->data.x_bignum, &op2_val->data.x_bignum);
} else {
- bool are_equal = const_values_equal(op1_val, op2_val);
+ bool are_equal = resolved_type->id == TypeTableEntryIdVoid || const_values_equal(op1_val, op2_val);
if (op_id == IrBinOpCmpEq) {
answer = are_equal;
} else if (op_id == IrBinOpCmpNotEq) {