IR: pass genericMallocFree test

master
Andrew Kelley 2016-12-26 03:02:20 -05:00
parent 110a6f39ca
commit 3ef6663b72
4 changed files with 18 additions and 26 deletions

View File

@ -2839,7 +2839,6 @@ bool type_requires_comptime(TypeTableEntry *type_entry) {
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefLit:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNullLit:
case TypeTableEntryIdMetaType: case TypeTableEntryIdMetaType:
case TypeTableEntryIdVoid:
case TypeTableEntryIdNamespace: case TypeTableEntryIdNamespace:
case TypeTableEntryIdBlock: case TypeTableEntryIdBlock:
case TypeTableEntryIdBoundFn: case TypeTableEntryIdBoundFn:
@ -2857,6 +2856,7 @@ bool type_requires_comptime(TypeTableEntry *type_entry) {
case TypeTableEntryIdFloat: case TypeTableEntryIdFloat:
case TypeTableEntryIdPointer: case TypeTableEntryIdPointer:
case TypeTableEntryIdEnumTag: case TypeTableEntryIdEnumTag:
case TypeTableEntryIdVoid:
return false; return false;
} }
zig_unreachable(); zig_unreachable();

View File

@ -6350,13 +6350,13 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node
if (casted_arg->value.type->id == TypeTableEntryIdInvalid) if (casted_arg->value.type->id == TypeTableEntryIdInvalid)
return false; return false;
ConstExprValue *first_arg_val = ir_resolve_const(ira, casted_arg, UndefBad); ConstExprValue *arg_val = ir_resolve_const(ira, casted_arg, UndefBad);
if (!first_arg_val) if (!arg_val)
return false; return false;
Buf *param_name = param_decl_node->data.param_decl.name; Buf *param_name = param_decl_node->data.param_decl.name;
VariableTableEntry *var = add_variable(ira->codegen, param_decl_node, VariableTableEntry *var = add_variable(ira->codegen, param_decl_node,
*exec_scope, param_name, true, first_arg_val); *exec_scope, param_name, true, arg_val);
*exec_scope = var->child_scope; *exec_scope = var->child_scope;
*next_proto_i += 1; *next_proto_i += 1;

View File

@ -278,6 +278,20 @@ fn explicitCastMaybePointers() {
const b: ?&f32 = (?&f32)(a); const b: ?&f32 = (?&f32)(a);
} }
fn genericMallocFree() {
@setFnTest(this);
const a = %%memAlloc(u8, 10);
memFree(u8, a);
}
const some_mem : [100]u8 = undefined;
fn memAlloc(inline T: type, n: usize) -> %[]T {
return (&T)(&some_mem[0])[0...n];
}
fn memFree(inline T: type, mem: []T) { }
// TODO import from std.str // TODO import from std.str
pub fn memeql(a: []const u8, b: []const u8) -> bool { pub fn memeql(a: []const u8, b: []const u8) -> bool {

View File

@ -4,28 +4,6 @@ const str = std.str;
const cstr = std.cstr; const cstr = std.cstr;
fn explicitCastMaybePointers() {
@setFnTest(this);
const a: ?&i32 = undefined;
const b: ?&f32 = (?&f32)(a);
}
fn genericMallocFree() {
@setFnTest(this, true);
const a = %%memAlloc(u8, 10);
memFree(u8, a);
}
const some_mem : [100]u8 = undefined;
fn memAlloc(inline T: type, n: usize) -> %[]T {
@setFnStaticEval(this, false);
return (&T)(&some_mem[0])[0...n];
}
fn memFree(inline T: type, mem: []T) { }
fn castUndefined() { fn castUndefined() {
@setFnTest(this, true); @setFnTest(this, true);