diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2019-12-08 12:27:02 -0500 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2019-12-08 12:27:02 -0500 |
| commit | d57370d3ca28db17a183157b0497c0ab25e22c19 (patch) | |
| tree | 0dfbe27beb71eabdce5add8e423f5ad5d50f8b09 /src/analyze.cpp | |
| parent | 19c1b5a33a21bdddfbbca3c65b1c0e6419c4629f (diff) | |
| parent | 64d700bfa6cea1d9a440a7431ec8d64964cdd6c1 (diff) | |
| download | zig-d57370d3ca28db17a183157b0497c0ab25e22c19.tar.gz zig-d57370d3ca28db17a183157b0497c0ab25e22c19.zip | |
Merge branch 'comptime-fields'
closes #3677
Diffstat (limited to 'src/analyze.cpp')
| -rw-r--r-- | src/analyze.cpp | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp index c3e24ecb46..cf7296a9f8 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -2736,6 +2736,16 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) { field_node = decl_node->data.container_decl.fields.at(i); type_struct_field->name = field_node->data.struct_field.name; type_struct_field->decl_node = field_node; + if (field_node->data.struct_field.comptime_token != nullptr) { + if (field_node->data.struct_field.value == nullptr) { + add_token_error(g, field_node->owner, + field_node->data.struct_field.comptime_token, + buf_sprintf("comptime struct field missing initialization value")); + struct_type->data.structure.resolve_status = ResolveStatusInvalid; + return ErrorSemanticAnalyzeFail; + } + type_struct_field->is_comptime = true; + } if (field_node->data.struct_field.type == nullptr) { add_node_error(g, field_node, buf_sprintf("struct field missing type")); @@ -2788,6 +2798,9 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) { type_struct_field->src_index = i; type_struct_field->gen_index = SIZE_MAX; + if (type_struct_field->is_comptime) + continue; + switch (type_val_resolve_requires_comptime(g, field_type_val)) { case ReqCompTimeYes: struct_type->data.structure.requires_comptime = true; @@ -7987,8 +8000,9 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS // inserting padding bytes where LLVM would do it automatically. size_t llvm_struct_abi_align = 0; for (size_t i = 0; i < field_count; i += 1) { - ZigType *field_type = struct_type->data.structure.fields[i]->type_entry; - if (!type_has_bits(field_type)) + TypeStructField *field = struct_type->data.structure.fields[i]; + ZigType *field_type = field->type_entry; + if (field->is_comptime || !type_has_bits(field_type)) continue; LLVMTypeRef field_llvm_type = get_llvm_type(g, field_type); size_t llvm_field_abi_align = LLVMABIAlignmentOfType(g->target_data_ref, field_llvm_type); @@ -7999,7 +8013,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS TypeStructField *field = struct_type->data.structure.fields[i]; ZigType *field_type = field->type_entry; - if (!type_has_bits(field_type)) { + if (field->is_comptime || !type_has_bits(field_type)) { field->gen_index = SIZE_MAX; continue; } |
