mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
add void arrays test
This commit is contained in:
parent
0311b35a21
commit
86f55bce53
@ -514,7 +514,7 @@ static LLVMValueRef gen_array_base_ptr(CodeGen *g, AstNode *node) {
|
||||
array_ptr = gen_expr(g, node);
|
||||
}
|
||||
|
||||
assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMPointerTypeKind);
|
||||
assert(!array_ptr || LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMPointerTypeKind);
|
||||
|
||||
return array_ptr;
|
||||
}
|
||||
@ -530,6 +530,10 @@ static LLVMValueRef gen_array_ptr(CodeGen *g, AstNode *node) {
|
||||
LLVMValueRef subscript_value = gen_expr(g, node->data.array_access_expr.subscript);
|
||||
assert(subscript_value);
|
||||
|
||||
if (type_entry->size_in_bits == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (type_entry->id == TypeTableEntryIdArray) {
|
||||
LLVMValueRef indices[] = {
|
||||
LLVMConstNull(g->builtin_types.entry_usize->type_ref),
|
||||
@ -670,7 +674,7 @@ static LLVMValueRef gen_array_access_expr(CodeGen *g, AstNode *node, bool is_lva
|
||||
|
||||
LLVMValueRef ptr = gen_array_ptr(g, node);
|
||||
|
||||
if (is_lvalue) {
|
||||
if (is_lvalue || !ptr) {
|
||||
return ptr;
|
||||
} else {
|
||||
add_debug_source_node(g, node);
|
||||
@ -1189,6 +1193,10 @@ static LLVMValueRef gen_assign_expr(CodeGen *g, AstNode *node) {
|
||||
|
||||
LLVMValueRef value = gen_expr(g, node->data.bin_op_expr.op2);
|
||||
|
||||
if (op1_type->size_in_bits == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return gen_assign_raw(g, node, node->data.bin_op_expr.bin_op, target_ref, value, op1_type, op2_type);
|
||||
}
|
||||
|
||||
@ -1723,7 +1731,7 @@ static LLVMValueRef gen_var_decl_raw(CodeGen *g, AstNode *source_node, AstNodeVa
|
||||
if (var_decl->expr) {
|
||||
*init_value = gen_expr(g, var_decl->expr);
|
||||
}
|
||||
if (variable->type->id == TypeTableEntryIdVoid) {
|
||||
if (variable->type->size_in_bits == 0) {
|
||||
return nullptr;
|
||||
} else {
|
||||
if (var_decl->expr) {
|
||||
@ -1788,7 +1796,7 @@ static LLVMValueRef gen_symbol(CodeGen *g, AstNode *node) {
|
||||
get_resolved_expr(node)->block_context,
|
||||
&node->data.symbol_expr.symbol);
|
||||
assert(variable);
|
||||
if (variable->type->id == TypeTableEntryIdVoid) {
|
||||
if (variable->type->size_in_bits == 0) {
|
||||
return nullptr;
|
||||
} else if (variable->is_ptr) {
|
||||
assert(variable->value_ref);
|
||||
@ -2122,8 +2130,9 @@ static void do_code_gen(CodeGen *g) {
|
||||
break;
|
||||
|
||||
VariableTableEntry *var = entry->value;
|
||||
if (var->type->id == TypeTableEntryIdVoid)
|
||||
if (var->type->size_in_bits == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
unsigned tag;
|
||||
unsigned arg_no;
|
||||
@ -2732,7 +2741,9 @@ void codegen_add_root_code(CodeGen *g, Buf *src_dir, Buf *src_basename, Buf *sou
|
||||
g->bootstrap_import = add_special_code(g, "bootstrap.zig");
|
||||
}
|
||||
|
||||
add_special_code(g, "builtin.zig");
|
||||
if (g->out_type == OutTypeExe) {
|
||||
add_special_code(g, "builtin.zig");
|
||||
}
|
||||
}
|
||||
|
||||
if (g->verbose) {
|
||||
|
||||
@ -59,7 +59,7 @@ pub struct Rand {
|
||||
|
||||
while (true) {
|
||||
r.get_bytes_aligned(rand_val_array);
|
||||
const rand_val = *((&u64)(rand_val_array.ptr));
|
||||
const rand_val = *(&u64)(rand_val_array.ptr);
|
||||
if (rand_val < upper_bound) {
|
||||
return start + (rand_val % range);
|
||||
}
|
||||
|
||||
@ -351,6 +351,25 @@ pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
||||
|
||||
)SOURCE", "OK\n");
|
||||
|
||||
add_simple_case("void arrays", R"SOURCE(
|
||||
use "std.zig";
|
||||
|
||||
pub fn main(argc: isize, argv: &&u8, env: &&u8) i32 => {
|
||||
var array: [4]void;
|
||||
array[0] = void{};
|
||||
array[1] = array[2];
|
||||
if (@sizeof(@typeof(array)) != 0) {
|
||||
print_str("BAD\n");
|
||||
}
|
||||
if (array.len != 4) {
|
||||
print_str("BAD\n");
|
||||
}
|
||||
print_str("OK\n");
|
||||
return 0;
|
||||
}
|
||||
)SOURCE", "OK\n");
|
||||
|
||||
|
||||
add_simple_case("mutable local variables", R"SOURCE(
|
||||
use "std.zig";
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user