| ... | ... | @@ -2372,7 +2372,10 @@ static Error resolve_union_alignment(CodeGen *g, ZigType *union_type) { |
| 2372 | 2372 | if (field->gen_index == UINT32_MAX) |
| 2373 | 2373 | continue; |
| 2374 | 2374 | |
| 2375 | | AstNode *align_expr = field->decl_node->data.struct_field.align_expr; |
| 2375 | AstNode *align_expr = nullptr; |
| 2376 | if (union_type->data.unionation.decl_node->type == NodeTypeContainerDecl) { |
| 2377 | align_expr = field->decl_node->data.struct_field.align_expr; |
| 2378 | } |
| 2376 | 2379 | if (align_expr != nullptr) { |
| 2377 | 2380 | if (!analyze_const_align(g, &union_type->data.unionation.decls_scope->base, align_expr, |
| 2378 | 2381 | &field->align)) |
| ... | ... | @@ -2468,9 +2471,6 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) { |
| 2468 | 2471 | |
| 2469 | 2472 | AstNode *decl_node = union_type->data.unionation.decl_node; |
| 2470 | 2473 | |
| 2471 | | |
| 2472 | | assert(decl_node->type == NodeTypeContainerDecl); |
| 2473 | | |
| 2474 | 2474 | uint32_t field_count = union_type->data.unionation.src_field_count; |
| 2475 | 2475 | TypeUnionField *most_aligned_union_member = union_type->data.unionation.most_aligned_union_member; |
| 2476 | 2476 | |
| ... | ... | @@ -3055,7 +3055,6 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { |
| 3055 | 3055 | return ErrorNone; |
| 3056 | 3056 | |
| 3057 | 3057 | AstNode *decl_node = union_type->data.unionation.decl_node; |
| 3058 | | assert(decl_node->type == NodeTypeContainerDecl); |
| 3059 | 3058 | |
| 3060 | 3059 | if (union_type->data.unionation.resolve_loop_flag_zero_bits) { |
| 3061 | 3060 | if (union_type->data.unionation.resolve_status != ResolveStatusInvalid) { |
| ... | ... | @@ -3069,30 +3068,50 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { |
| 3069 | 3068 | |
| 3070 | 3069 | union_type->data.unionation.resolve_loop_flag_zero_bits = true; |
| 3071 | 3070 | |
| 3072 | | assert(union_type->data.unionation.fields == nullptr); |
| 3073 | | uint32_t field_count = (uint32_t)decl_node->data.container_decl.fields.length; |
| 3074 | | if (field_count == 0) { |
| 3075 | | add_node_error(g, decl_node, buf_sprintf("unions must have 1 or more fields")); |
| 3071 | uint32_t field_count; |
| 3072 | if (decl_node->type == NodeTypeContainerDecl) { |
| 3073 | assert(union_type->data.unionation.fields == nullptr); |
| 3074 | field_count = (uint32_t)decl_node->data.container_decl.fields.length; |
| 3075 | if (field_count == 0) { |
| 3076 | add_node_error(g, decl_node, buf_sprintf("unions must have 1 or more fields")); |
| 3077 | union_type->data.unionation.src_field_count = field_count; |
| 3078 | union_type->data.unionation.resolve_status = ResolveStatusInvalid; |
| 3079 | return ErrorSemanticAnalyzeFail; |
| 3080 | } |
| 3076 | 3081 | union_type->data.unionation.src_field_count = field_count; |
| 3077 | | union_type->data.unionation.resolve_status = ResolveStatusInvalid; |
| 3078 | | return ErrorSemanticAnalyzeFail; |
| 3082 | union_type->data.unionation.fields = heap::c_allocator.allocate<TypeUnionField>(field_count); |
| 3083 | union_type->data.unionation.fields_by_name.init(field_count); |
| 3084 | } else { |
| 3085 | assert(union_type->data.unionation.fields != nullptr); |
| 3086 | field_count = union_type->data.unionation.src_field_count; |
| 3079 | 3087 | } |
| 3080 | | union_type->data.unionation.src_field_count = field_count; |
| 3081 | | union_type->data.unionation.fields = heap::c_allocator.allocate<TypeUnionField>(field_count); |
| 3082 | | union_type->data.unionation.fields_by_name.init(field_count); |
| 3083 | 3088 | |
| 3084 | 3089 | Scope *scope = &union_type->data.unionation.decls_scope->base; |
| 3085 | 3090 | |
| 3086 | 3091 | HashMap<BigInt, AstNode *, bigint_hash, bigint_eql> occupied_tag_values = {}; |
| 3087 | 3092 | |
| 3088 | | AstNode *enum_type_node = decl_node->data.container_decl.init_arg_expr; |
| 3089 | | union_type->data.unionation.have_explicit_tag_type = decl_node->data.container_decl.auto_enum || |
| 3090 | | enum_type_node != nullptr; |
| 3091 | | bool auto_layout = (union_type->data.unionation.layout == ContainerLayoutAuto); |
| 3092 | | bool want_safety = (field_count >= 2) && (auto_layout || enum_type_node != nullptr) && !(g->build_mode == BuildModeFastRelease || g->build_mode == BuildModeSmallRelease); |
| 3093 | bool is_auto_enum; // union(enum) or union(enum(expr)) |
| 3094 | bool is_explicit_enum; // union(expr) |
| 3095 | AstNode *enum_type_node; // expr in union(enum(expr)) or union(expr) |
| 3096 | if (decl_node->type == NodeTypeContainerDecl) { |
| 3097 | is_auto_enum = decl_node->data.container_decl.auto_enum; |
| 3098 | is_explicit_enum = decl_node->data.container_decl.init_arg_expr != nullptr; |
| 3099 | enum_type_node = decl_node->data.container_decl.init_arg_expr; |
| 3100 | } else { |
| 3101 | is_auto_enum = false; |
| 3102 | is_explicit_enum = union_type->data.unionation.tag_type != nullptr; |
| 3103 | enum_type_node = nullptr; |
| 3104 | } |
| 3105 | union_type->data.unionation.have_explicit_tag_type = is_auto_enum || is_explicit_enum; |
| 3106 | |
| 3107 | bool is_auto_layout = union_type->data.unionation.layout == ContainerLayoutAuto; |
| 3108 | bool want_safety = (field_count >= 2) |
| 3109 | && (is_auto_layout || is_explicit_enum) |
| 3110 | && !(g->build_mode == BuildModeFastRelease || g->build_mode == BuildModeSmallRelease); |
| 3093 | 3111 | ZigType *tag_type; |
| 3094 | | bool create_enum_type = decl_node->data.container_decl.auto_enum || (enum_type_node == nullptr && want_safety); |
| 3112 | bool create_enum_type = is_auto_enum || (!is_explicit_enum && want_safety); |
| 3095 | 3113 | bool *covered_enum_fields; |
| 3114 | bool *is_zero_bits = heap::c_allocator.allocate<bool>(field_count); |
| 3096 | 3115 | ZigLLVMDIEnumerator **di_enumerators; |
| 3097 | 3116 | if (create_enum_type) { |
| 3098 | 3117 | occupied_tag_values.init(field_count); |
| ... | ... | @@ -3150,105 +3169,111 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { |
| 3150 | 3169 | return err; |
| 3151 | 3170 | } |
| 3152 | 3171 | tag_type = enum_type; |
| 3153 | | covered_enum_fields = heap::c_allocator.allocate<bool>(enum_type->data.enumeration.src_field_count); |
| 3154 | 3172 | } else { |
| 3155 | | tag_type = nullptr; |
| 3173 | if (decl_node->type == NodeTypeContainerDecl) { |
| 3174 | tag_type = nullptr; |
| 3175 | } else { |
| 3176 | tag_type = union_type->data.unionation.tag_type; |
| 3177 | } |
| 3178 | } |
| 3179 | if (tag_type != nullptr) { |
| 3180 | covered_enum_fields = heap::c_allocator.allocate<bool>(tag_type->data.enumeration.src_field_count); |
| 3156 | 3181 | } |
| 3157 | 3182 | union_type->data.unionation.tag_type = tag_type; |
| 3158 | 3183 | |
| 3159 | | uint32_t gen_field_index = 0; |
| 3160 | 3184 | for (uint32_t i = 0; i < field_count; i += 1) { |
| 3161 | | AstNode *field_node = decl_node->data.container_decl.fields.at(i); |
| 3162 | | Buf *field_name = field_node->data.struct_field.name; |
| 3163 | 3185 | TypeUnionField *union_field = &union_type->data.unionation.fields[i]; |
| 3164 | | union_field->name = field_node->data.struct_field.name; |
| 3165 | | union_field->decl_node = field_node; |
| 3166 | | union_field->gen_index = UINT32_MAX; |
| 3167 | | |
| 3168 | | auto field_entry = union_type->data.unionation.fields_by_name.put_unique(union_field->name, union_field); |
| 3169 | | if (field_entry != nullptr) { |
| 3170 | | ErrorMsg *msg = add_node_error(g, field_node, |
| 3171 | | buf_sprintf("duplicate union field: '%s'", buf_ptr(union_field->name))); |
| 3172 | | add_error_note(g, msg, field_entry->value->decl_node, buf_sprintf("other field here")); |
| 3173 | | union_type->data.unionation.resolve_status = ResolveStatusInvalid; |
| 3174 | | return ErrorSemanticAnalyzeFail; |
| 3175 | | } |
| 3186 | if (decl_node->type == NodeTypeContainerDecl) { |
| 3187 | AstNode *field_node = decl_node->data.container_decl.fields.at(i); |
| 3188 | union_field->name = field_node->data.struct_field.name; |
| 3189 | union_field->decl_node = field_node; |
| 3190 | union_field->gen_index = UINT32_MAX; |
| 3191 | is_zero_bits[i] = false; |
| 3176 | 3192 | |
| 3177 | | bool field_is_zero_bits; |
| 3178 | | if (field_node->data.struct_field.type == nullptr) { |
| 3179 | | if (decl_node->data.container_decl.auto_enum || |
| 3180 | | decl_node->data.container_decl.init_arg_expr != nullptr) |
| 3181 | | { |
| 3182 | | union_field->type_entry = g->builtin_types.entry_void; |
| 3183 | | field_is_zero_bits = true; |
| 3184 | | } else { |
| 3185 | | add_node_error(g, field_node, buf_sprintf("union field missing type")); |
| 3186 | | union_type->data.unionation.resolve_status = ResolveStatusInvalid; |
| 3187 | | return ErrorSemanticAnalyzeFail; |
| 3188 | | } |
| 3189 | | } else { |
| 3190 | | ZigValue *field_type_val = analyze_const_value(g, scope, |
| 3191 | | field_node->data.struct_field.type, g->builtin_types.entry_type, nullptr, LazyOkNoUndef); |
| 3192 | | if (type_is_invalid(field_type_val->type)) { |
| 3193 | auto field_entry = union_type->data.unionation.fields_by_name.put_unique(union_field->name, union_field); |
| 3194 | if (field_entry != nullptr) { |
| 3195 | ErrorMsg *msg = add_node_error(g, union_field->decl_node, |
| 3196 | buf_sprintf("duplicate union field: '%s'", buf_ptr(union_field->name))); |
| 3197 | add_error_note(g, msg, field_entry->value->decl_node, buf_sprintf("other field here")); |
| 3193 | 3198 | union_type->data.unionation.resolve_status = ResolveStatusInvalid; |
| 3194 | 3199 | return ErrorSemanticAnalyzeFail; |
| 3195 | 3200 | } |
| 3196 | | assert(field_type_val->special != ConstValSpecialRuntime); |
| 3197 | | union_field->type_val = field_type_val; |
| 3198 | | if (union_type->data.unionation.resolve_status == ResolveStatusInvalid) |
| 3199 | | return ErrorSemanticAnalyzeFail; |
| 3200 | 3201 | |
| 3201 | | bool field_is_opaque_type; |
| 3202 | | if ((err = type_val_resolve_is_opaque_type(g, field_type_val, &field_is_opaque_type))) { |
| 3203 | | union_type->data.unionation.resolve_status = ResolveStatusInvalid; |
| 3204 | | return ErrorSemanticAnalyzeFail; |
| 3205 | | } |
| 3206 | | if (field_is_opaque_type) { |
| 3207 | | add_node_error(g, field_node, |
| 3208 | | buf_create_from_str( |
| 3209 | | "opaque types have unknown size and therefore cannot be directly embedded in unions")); |
| 3210 | | union_type->data.unionation.resolve_status = ResolveStatusInvalid; |
| 3211 | | return ErrorSemanticAnalyzeFail; |
| 3212 | | } |
| 3202 | if (field_node->data.struct_field.type == nullptr) { |
| 3203 | if (is_auto_enum || is_explicit_enum) { |
| 3204 | union_field->type_entry = g->builtin_types.entry_void; |
| 3205 | is_zero_bits[i] = true; |
| 3206 | } else { |
| 3207 | add_node_error(g, field_node, buf_sprintf("union field missing type")); |
| 3208 | union_type->data.unionation.resolve_status = ResolveStatusInvalid; |
| 3209 | return ErrorSemanticAnalyzeFail; |
| 3210 | } |
| 3211 | } else { |
| 3212 | ZigValue *field_type_val = analyze_const_value(g, scope, |
| 3213 | field_node->data.struct_field.type, g->builtin_types.entry_type, nullptr, LazyOkNoUndef); |
| 3214 | if (type_is_invalid(field_type_val->type)) { |
| 3215 | union_type->data.unionation.resolve_status = ResolveStatusInvalid; |
| 3216 | return ErrorSemanticAnalyzeFail; |
| 3217 | } |
| 3218 | assert(field_type_val->special != ConstValSpecialRuntime); |
| 3219 | union_field->type_val = field_type_val; |
| 3220 | if (union_type->data.unionation.resolve_status == ResolveStatusInvalid) |
| 3221 | return ErrorSemanticAnalyzeFail; |
| 3213 | 3222 | |
| 3214 | | switch (type_val_resolve_requires_comptime(g, field_type_val)) { |
| 3215 | | case ReqCompTimeInvalid: |
| 3216 | | if (g->trace_err != nullptr) { |
| 3217 | | g->trace_err = add_error_note(g, g->trace_err, field_node, |
| 3218 | | buf_create_from_str("while checking this field")); |
| 3219 | | } |
| 3223 | bool field_is_opaque_type; |
| 3224 | if ((err = type_val_resolve_is_opaque_type(g, field_type_val, &field_is_opaque_type))) { |
| 3220 | 3225 | union_type->data.unionation.resolve_status = ResolveStatusInvalid; |
| 3221 | 3226 | return ErrorSemanticAnalyzeFail; |
| 3222 | | case ReqCompTimeYes: |
| 3223 | | union_type->data.unionation.requires_comptime = true; |
| 3224 | | break; |
| 3225 | | case ReqCompTimeNo: |
| 3226 | | break; |
| 3227 | | } |
| 3227 | } |
| 3228 | if (field_is_opaque_type) { |
| 3229 | add_node_error(g, field_node, |
| 3230 | buf_create_from_str( |
| 3231 | "opaque types have unknown size and therefore cannot be directly embedded in unions")); |
| 3232 | union_type->data.unionation.resolve_status = ResolveStatusInvalid; |
| 3233 | return ErrorSemanticAnalyzeFail; |
| 3234 | } |
| 3228 | 3235 | |
| 3229 | | if ((err = type_val_resolve_zero_bits(g, field_type_val, union_type, nullptr, &field_is_zero_bits))) { |
| 3230 | | union_type->data.unionation.resolve_status = ResolveStatusInvalid; |
| 3231 | | return ErrorSemanticAnalyzeFail; |
| 3236 | switch (type_val_resolve_requires_comptime(g, field_type_val)) { |
| 3237 | case ReqCompTimeInvalid: |
| 3238 | if (g->trace_err != nullptr) { |
| 3239 | g->trace_err = add_error_note(g, g->trace_err, field_node, |
| 3240 | buf_create_from_str("while checking this field")); |
| 3241 | } |
| 3242 | union_type->data.unionation.resolve_status = ResolveStatusInvalid; |
| 3243 | return ErrorSemanticAnalyzeFail; |
| 3244 | case ReqCompTimeYes: |
| 3245 | union_type->data.unionation.requires_comptime = true; |
| 3246 | break; |
| 3247 | case ReqCompTimeNo: |
| 3248 | break; |
| 3249 | } |
| 3250 | |
| 3251 | if ((err = type_val_resolve_zero_bits(g, field_type_val, union_type, nullptr, &is_zero_bits[i]))) { |
| 3252 | union_type->data.unionation.resolve_status = ResolveStatusInvalid; |
| 3253 | return ErrorSemanticAnalyzeFail; |
| 3254 | } |
| 3232 | 3255 | } |
| 3233 | | } |
| 3234 | 3256 | |
| 3235 | | if (field_node->data.struct_field.value != nullptr && !decl_node->data.container_decl.auto_enum) { |
| 3236 | | ErrorMsg *msg = add_node_error(g, field_node->data.struct_field.value, |
| 3237 | | buf_create_from_str("untagged union field assignment")); |
| 3238 | | add_error_note(g, msg, decl_node, buf_create_from_str("consider 'union(enum)' here")); |
| 3257 | if (field_node->data.struct_field.value != nullptr && !is_auto_enum) { |
| 3258 | ErrorMsg *msg = add_node_error(g, field_node->data.struct_field.value, |
| 3259 | buf_create_from_str("untagged union field assignment")); |
| 3260 | add_error_note(g, msg, decl_node, buf_create_from_str("consider 'union(enum)' here")); |
| 3261 | } |
| 3239 | 3262 | } |
| 3240 | 3263 | |
| 3241 | 3264 | if (create_enum_type) { |
| 3242 | | di_enumerators[i] = ZigLLVMCreateDebugEnumerator(g->dbuilder, buf_ptr(field_name), i); |
| 3265 | di_enumerators[i] = ZigLLVMCreateDebugEnumerator(g->dbuilder, buf_ptr(union_field->name), i); |
| 3243 | 3266 | union_field->enum_field = &tag_type->data.enumeration.fields[i]; |
| 3244 | | union_field->enum_field->name = field_name; |
| 3267 | union_field->enum_field->name = union_field->name; |
| 3245 | 3268 | union_field->enum_field->decl_index = i; |
| 3246 | | union_field->enum_field->decl_node = field_node; |
| 3269 | union_field->enum_field->decl_node = union_field->decl_node; |
| 3247 | 3270 | |
| 3248 | 3271 | auto prev_entry = tag_type->data.enumeration.fields_by_name.put_unique(union_field->enum_field->name, union_field->enum_field); |
| 3249 | 3272 | assert(prev_entry == nullptr); // caught by union de-duplicator above |
| 3250 | 3273 | |
| 3251 | | AstNode *tag_value = field_node->data.struct_field.value; |
| 3274 | AstNode *tag_value = decl_node->type == NodeTypeContainerDecl |
| 3275 | ? union_field->decl_node->data.struct_field.value : nullptr; |
| 3276 | |
| 3252 | 3277 | // In this first pass we resolve explicit tag values. |
| 3253 | 3278 | // In a second pass we will fill in the unspecified ones. |
| 3254 | 3279 | if (tag_value != nullptr) { |
| ... | ... | @@ -3276,11 +3301,11 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { |
| 3276 | 3301 | return ErrorSemanticAnalyzeFail; |
| 3277 | 3302 | } |
| 3278 | 3303 | } |
| 3279 | | } else if (enum_type_node != nullptr) { |
| 3280 | | union_field->enum_field = find_enum_type_field(tag_type, field_name); |
| 3304 | } else if (tag_type != nullptr) { |
| 3305 | union_field->enum_field = find_enum_type_field(tag_type, union_field->name); |
| 3281 | 3306 | if (union_field->enum_field == nullptr) { |
| 3282 | | ErrorMsg *msg = add_node_error(g, field_node, |
| 3283 | | buf_sprintf("enum field not found: '%s'", buf_ptr(field_name))); |
| 3307 | ErrorMsg *msg = add_node_error(g, union_field->decl_node, |
| 3308 | buf_sprintf("enum field not found: '%s'", buf_ptr(union_field->name))); |
| 3284 | 3309 | add_error_note(g, msg, tag_type->data.enumeration.decl_node, |
| 3285 | 3310 | buf_sprintf("enum declared here")); |
| 3286 | 3311 | union_type->data.unionation.resolve_status = ResolveStatusInvalid; |
| ... | ... | @@ -3289,21 +3314,23 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { |
| 3289 | 3314 | covered_enum_fields[union_field->enum_field->decl_index] = true; |
| 3290 | 3315 | } else { |
| 3291 | 3316 | union_field->enum_field = heap::c_allocator.create<TypeEnumField>(); |
| 3292 | | union_field->enum_field->name = field_name; |
| 3317 | union_field->enum_field->name = union_field->name; |
| 3293 | 3318 | union_field->enum_field->decl_index = i; |
| 3294 | 3319 | bigint_init_unsigned(&union_field->enum_field->value, i); |
| 3295 | 3320 | } |
| 3296 | 3321 | assert(union_field->enum_field != nullptr); |
| 3322 | } |
| 3297 | 3323 | |
| 3298 | | if (field_is_zero_bits) |
| 3299 | | continue; |
| 3300 | | |
| 3301 | | union_field->gen_index = gen_field_index; |
| 3302 | | gen_field_index += 1; |
| 3324 | uint32_t gen_field_index = 0; |
| 3325 | for (uint32_t i = 0; i < field_count; i += 1) { |
| 3326 | TypeUnionField *union_field = &union_type->data.unionation.fields[i]; |
| 3327 | if (!is_zero_bits[i]) { |
| 3328 | union_field->gen_index = gen_field_index; |
| 3329 | gen_field_index += 1; |
| 3330 | } |
| 3303 | 3331 | } |
| 3304 | 3332 | |
| 3305 | | bool src_have_tag = decl_node->data.container_decl.auto_enum || |
| 3306 | | decl_node->data.container_decl.init_arg_expr != nullptr; |
| 3333 | bool src_have_tag = is_auto_enum || is_explicit_enum; |
| 3307 | 3334 | |
| 3308 | 3335 | if (src_have_tag && union_type->data.unionation.layout != ContainerLayoutAuto) { |
| 3309 | 3336 | const char *qual_str; |
| ... | ... | @@ -3317,8 +3344,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { |
| 3317 | 3344 | qual_str = "extern"; |
| 3318 | 3345 | break; |
| 3319 | 3346 | } |
| 3320 | | AstNode *source_node = (decl_node->data.container_decl.init_arg_expr != nullptr) ? |
| 3321 | | decl_node->data.container_decl.init_arg_expr : decl_node; |
| 3347 | AstNode *source_node = enum_type_node != nullptr ? enum_type_node : decl_node; |
| 3322 | 3348 | add_node_error(g, source_node, |
| 3323 | 3349 | buf_sprintf("%s union does not support enum tag type", qual_str)); |
| 3324 | 3350 | union_type->data.unionation.resolve_status = ResolveStatusInvalid; |
| ... | ... | @@ -3326,43 +3352,47 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { |
| 3326 | 3352 | } |
| 3327 | 3353 | |
| 3328 | 3354 | if (create_enum_type) { |
| 3329 | | // Now iterate again and populate the unspecified tag values |
| 3330 | | uint32_t next_maybe_unoccupied_index = 0; |
| 3355 | if (decl_node->type == NodeTypeContainerDecl) { |
| 3356 | // Now iterate again and populate the unspecified tag values |
| 3357 | uint32_t next_maybe_unoccupied_index = 0; |
| 3331 | 3358 | |
| 3332 | | for (uint32_t field_i = 0; field_i < field_count; field_i += 1) { |
| 3333 | | AstNode *field_node = decl_node->data.container_decl.fields.at(field_i); |
| 3334 | | TypeUnionField *union_field = &union_type->data.unionation.fields[field_i]; |
| 3335 | | AstNode *tag_value = field_node->data.struct_field.value; |
| 3359 | for (uint32_t field_i = 0; field_i < field_count; field_i += 1) { |
| 3360 | AstNode *field_node = decl_node->data.container_decl.fields.at(field_i); |
| 3361 | TypeUnionField *union_field = &union_type->data.unionation.fields[field_i]; |
| 3362 | AstNode *tag_value = field_node->data.struct_field.value; |
| 3336 | 3363 | |
| 3337 | | if (tag_value == nullptr) { |
| 3338 | | if (occupied_tag_values.size() == 0) { |
| 3339 | | bigint_init_unsigned(&union_field->enum_field->value, next_maybe_unoccupied_index); |
| 3340 | | next_maybe_unoccupied_index += 1; |
| 3341 | | } else { |
| 3342 | | BigInt proposed_value; |
| 3343 | | for (;;) { |
| 3344 | | bigint_init_unsigned(&proposed_value, next_maybe_unoccupied_index); |
| 3364 | if (tag_value == nullptr) { |
| 3365 | if (occupied_tag_values.size() == 0) { |
| 3366 | bigint_init_unsigned(&union_field->enum_field->value, next_maybe_unoccupied_index); |
| 3345 | 3367 | next_maybe_unoccupied_index += 1; |
| 3346 | | auto entry = occupied_tag_values.put_unique(proposed_value, field_node); |
| 3347 | | if (entry != nullptr) { |
| 3348 | | continue; |
| 3368 | } else { |
| 3369 | BigInt proposed_value; |
| 3370 | for (;;) { |
| 3371 | bigint_init_unsigned(&proposed_value, next_maybe_unoccupied_index); |
| 3372 | next_maybe_unoccupied_index += 1; |
| 3373 | auto entry = occupied_tag_values.put_unique(proposed_value, field_node); |
| 3374 | if (entry != nullptr) { |
| 3375 | continue; |
| 3376 | } |
| 3377 | break; |
| 3349 | 3378 | } |
| 3350 | | break; |
| 3379 | bigint_init_bigint(&union_field->enum_field->value, &proposed_value); |
| 3351 | 3380 | } |
| 3352 | | bigint_init_bigint(&union_field->enum_field->value, &proposed_value); |
| 3353 | 3381 | } |
| 3354 | 3382 | } |
| 3355 | 3383 | } |
| 3356 | | } else if (enum_type_node != nullptr) { |
| 3384 | } else if (tag_type != nullptr) { |
| 3357 | 3385 | for (uint32_t i = 0; i < tag_type->data.enumeration.src_field_count; i += 1) { |
| 3358 | 3386 | TypeEnumField *enum_field = &tag_type->data.enumeration.fields[i]; |
| 3359 | 3387 | if (!covered_enum_fields[i]) { |
| 3360 | | AstNode *enum_decl_node = tag_type->data.enumeration.decl_node; |
| 3361 | | AstNode *field_node = enum_decl_node->data.container_decl.fields.at(i); |
| 3362 | 3388 | ErrorMsg *msg = add_node_error(g, decl_node, |
| 3363 | 3389 | buf_sprintf("enum field missing: '%s'", buf_ptr(enum_field->name))); |
| 3364 | | add_error_note(g, msg, field_node, |
| 3365 | | buf_sprintf("declared here")); |
| 3390 | if (decl_node->type == NodeTypeContainerDecl) { |
| 3391 | AstNode *enum_decl_node = tag_type->data.enumeration.decl_node; |
| 3392 | AstNode *field_node = enum_decl_node->data.container_decl.fields.at(i); |
| 3393 | add_error_note(g, msg, field_node, |
| 3394 | buf_sprintf("declared here")); |
| 3395 | } |
| 3366 | 3396 | union_type->data.unionation.resolve_status = ResolveStatusInvalid; |
| 3367 | 3397 | } |
| 3368 | 3398 | } |
| ... | ... | @@ -8350,7 +8380,7 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS |
| 8350 | 8380 | ZigLLVMDIFile *di_file; |
| 8351 | 8381 | ZigLLVMDIScope *di_scope; |
| 8352 | 8382 | unsigned line; |
| 8353 | | if (decl_node != nullptr && !struct_type->data.structure.created_by_at_type) { |
| 8383 | if (decl_node != nullptr) { |
| 8354 | 8384 | Scope *scope = &struct_type->data.structure.decls_scope->base; |
| 8355 | 8385 | ZigType *import = get_scope_import(scope); |
| 8356 | 8386 | di_file = import->data.structure.root_struct->di_file; |
| ... | ... | @@ -8713,7 +8743,7 @@ static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveSta |
| 8713 | 8743 | |
| 8714 | 8744 | uint64_t store_size_in_bits = union_field->type_entry->size_in_bits; |
| 8715 | 8745 | uint64_t abi_align_in_bits = 8*union_field->type_entry->abi_align; |
| 8716 | | AstNode *field_node = decl_node->data.container_decl.fields.at(i); |
| 8746 | AstNode *field_node = union_field->decl_node; |
| 8717 | 8747 | union_inner_di_types[union_field->gen_index] = ZigLLVMCreateDebugMemberType(g->dbuilder, |
| 8718 | 8748 | ZigLLVMTypeToScope(union_type->llvm_di_type), buf_ptr(union_field->enum_field->name), |
| 8719 | 8749 | import->data.structure.root_struct->di_file, (unsigned)(field_node->line + 1), |