| ... | ... | @@ -19,7 +19,7 @@ |
| 19 | 19 | #include <errno.h> |
| 20 | 20 | |
| 21 | 21 | struct IrExecContext { |
| 22 | | ZigList<ConstExprValue *> mem_slot_list; |
| 22 | ZigList<ZigValue *> mem_slot_list; |
| 23 | 23 | }; |
| 24 | 24 | |
| 25 | 25 | struct IrBuilder { |
| ... | ... | @@ -204,14 +204,14 @@ static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction * |
| 204 | 204 | static IrInstruction *ir_expr_wrap(IrBuilder *irb, Scope *scope, IrInstruction *inst, ResultLoc *result_loc); |
| 205 | 205 | static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align); |
| 206 | 206 | static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new_align); |
| 207 | | static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf, ConstExprValue *val); |
| 208 | | static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val); |
| 207 | static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf, ZigValue *val); |
| 208 | static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ZigValue *val); |
| 209 | 209 | static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, |
| 210 | | ConstExprValue *out_val, ConstExprValue *ptr_val); |
| 210 | ZigValue *out_val, ZigValue *ptr_val); |
| 211 | 211 | static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *ptr, |
| 212 | 212 | ZigType *dest_type, IrInstruction *dest_type_src, bool safety_check_on); |
| 213 | | static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed); |
| 214 | | static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_global_refs); |
| 213 | static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed); |
| 214 | static void copy_const_val(ZigValue *dest, ZigValue *src, bool same_global_refs); |
| 215 | 215 | static Error resolve_ptr_align(IrAnalyze *ira, ZigType *ty, uint32_t *result_align); |
| 216 | 216 | static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target, |
| 217 | 217 | ZigType *ptr_type); |
| ... | ... | @@ -244,10 +244,10 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n |
| 244 | 244 | IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type); |
| 245 | 245 | static ResultLoc *no_result_loc(void); |
| 246 | 246 | |
| 247 | | static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *const_val) { |
| 247 | static ZigValue *const_ptr_pointee_unchecked(CodeGen *g, ZigValue *const_val) { |
| 248 | 248 | assert(get_src_ptr_type(const_val->type) != nullptr); |
| 249 | 249 | assert(const_val->special == ConstValSpecialStatic); |
| 250 | | ConstExprValue *result; |
| 250 | ZigValue *result; |
| 251 | 251 | |
| 252 | 252 | switch (type_has_one_possible_value(g, const_val->type->data.pointer.child_type)) { |
| 253 | 253 | case OnePossibleValueInvalid: |
| ... | ... | @@ -265,7 +265,7 @@ static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *c |
| 265 | 265 | result = const_val->data.x_ptr.data.ref.pointee; |
| 266 | 266 | break; |
| 267 | 267 | case ConstPtrSpecialBaseArray: { |
| 268 | | ConstExprValue *array_val = const_val->data.x_ptr.data.base_array.array_val; |
| 268 | ZigValue *array_val = const_val->data.x_ptr.data.base_array.array_val; |
| 269 | 269 | if (const_val->data.x_ptr.data.base_array.elem_index == array_val->type->data.array.len) { |
| 270 | 270 | result = array_val->type->data.array.sentinel; |
| 271 | 271 | } else { |
| ... | ... | @@ -275,7 +275,7 @@ static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *c |
| 275 | 275 | break; |
| 276 | 276 | } |
| 277 | 277 | case ConstPtrSpecialBaseStruct: { |
| 278 | | ConstExprValue *struct_val = const_val->data.x_ptr.data.base_struct.struct_val; |
| 278 | ZigValue *struct_val = const_val->data.x_ptr.data.base_struct.struct_val; |
| 279 | 279 | expand_undef_struct(g, struct_val); |
| 280 | 280 | result = struct_val->data.x_struct.fields[const_val->data.x_ptr.data.base_struct.field_index]; |
| 281 | 281 | break; |
| ... | ... | @@ -317,7 +317,7 @@ static bool slice_is_const(ZigType *type) { |
| 317 | 317 | return type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const; |
| 318 | 318 | } |
| 319 | 319 | |
| 320 | | // This function returns true when you can change the type of a ConstExprValue and the |
| 320 | // This function returns true when you can change the type of a ZigValue and the |
| 321 | 321 | // value remains meaningful. |
| 322 | 322 | static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expected, ZigType *actual) { |
| 323 | 323 | if (expected == actual) |
| ... | ... | @@ -416,16 +416,16 @@ static Buf *exec_c_import_buf(IrExecutable *exec) { |
| 416 | 416 | return exec->c_import_buf; |
| 417 | 417 | } |
| 418 | 418 | |
| 419 | | static bool value_is_comptime(ConstExprValue *const_val) { |
| 419 | static bool value_is_comptime(ZigValue *const_val) { |
| 420 | 420 | return const_val->special != ConstValSpecialRuntime; |
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | static bool instr_is_comptime(IrInstruction *instruction) { |
| 424 | | return value_is_comptime(&instruction->value); |
| 424 | return value_is_comptime(instruction->value); |
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | static bool instr_is_unreachable(IrInstruction *instruction) { |
| 428 | | return instruction->value.type && instruction->value.type->id == ZigTypeIdUnreachable; |
| 428 | return instruction->value->type && instruction->value->type->id == ZigTypeIdUnreachable; |
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | static void ir_link_new_bb(IrBasicBlock *new_bb, IrBasicBlock *old_bb) { |
| ... | ... | @@ -449,7 +449,7 @@ static void ir_ref_var(ZigVar *var) { |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | ZigType *ir_analyze_type_expr(IrAnalyze *ira, Scope *scope, AstNode *node) { |
| 452 | | ConstExprValue *result = ir_eval_const_value(ira->codegen, scope, node, ira->codegen->builtin_types.entry_type, |
| 452 | ZigValue *result = ir_eval_const_value(ira->codegen, scope, node, ira->codegen->builtin_types.entry_type, |
| 453 | 453 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr, nullptr, |
| 454 | 454 | node, nullptr, ira->new_irb.exec, nullptr, UndefBad); |
| 455 | 455 | |
| ... | ... | @@ -1156,7 +1156,24 @@ static T *ir_create_instruction(IrBuilder *irb, Scope *scope, AstNode *source_no |
| 1156 | 1156 | special_instruction->base.source_node = source_node; |
| 1157 | 1157 | special_instruction->base.debug_id = exec_next_debug_id(irb->exec); |
| 1158 | 1158 | special_instruction->base.owner_bb = irb->current_basic_block; |
| 1159 | | special_instruction->base.value.global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs"); |
| 1159 | special_instruction->base.value = allocate<ZigValue>(1, "ZigValue"); |
| 1160 | special_instruction->base.value->global_refs = allocate<ConstGlobalRefs>(1, "ConstGlobalRefs"); |
| 1161 | return special_instruction; |
| 1162 | } |
| 1163 | |
| 1164 | template<typename T> |
| 1165 | static T *ir_create_instruction_noval(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 1166 | const char *name = nullptr; |
| 1167 | #ifdef ZIG_ENABLE_MEM_PROFILE |
| 1168 | T *dummy = nullptr; |
| 1169 | name = ir_instruction_type_str(ir_instruction_id(dummy)); |
| 1170 | #endif |
| 1171 | T *special_instruction = allocate<T>(1, name); |
| 1172 | special_instruction->base.id = ir_instruction_id(special_instruction); |
| 1173 | special_instruction->base.scope = scope; |
| 1174 | special_instruction->base.source_node = source_node; |
| 1175 | special_instruction->base.debug_id = exec_next_debug_id(irb->exec); |
| 1176 | special_instruction->base.owner_bb = irb->current_basic_block; |
| 1160 | 1177 | return special_instruction; |
| 1161 | 1178 | } |
| 1162 | 1179 | |
| ... | ... | @@ -1184,8 +1201,8 @@ static IrInstruction *ir_build_cond_br(IrBuilder *irb, Scope *scope, AstNode *so |
| 1184 | 1201 | IrBasicBlock *then_block, IrBasicBlock *else_block, IrInstruction *is_comptime) |
| 1185 | 1202 | { |
| 1186 | 1203 | IrInstructionCondBr *cond_br_instruction = ir_build_instruction<IrInstructionCondBr>(irb, scope, source_node); |
| 1187 | | cond_br_instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable; |
| 1188 | | cond_br_instruction->base.value.special = ConstValSpecialStatic; |
| 1204 | cond_br_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable; |
| 1205 | cond_br_instruction->base.value->special = ConstValSpecialStatic; |
| 1189 | 1206 | cond_br_instruction->condition = condition; |
| 1190 | 1207 | cond_br_instruction->then_block = then_block; |
| 1191 | 1208 | cond_br_instruction->else_block = else_block; |
| ... | ... | @@ -1203,8 +1220,8 @@ static IrInstruction *ir_build_return(IrBuilder *irb, Scope *scope, AstNode *sou |
| 1203 | 1220 | IrInstruction *operand) |
| 1204 | 1221 | { |
| 1205 | 1222 | IrInstructionReturn *return_instruction = ir_build_instruction<IrInstructionReturn>(irb, scope, source_node); |
| 1206 | | return_instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable; |
| 1207 | | return_instruction->base.value.special = ConstValSpecialStatic; |
| 1223 | return_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable; |
| 1224 | return_instruction->base.value->special = ConstValSpecialStatic; |
| 1208 | 1225 | return_instruction->operand = operand; |
| 1209 | 1226 | |
| 1210 | 1227 | if (operand != nullptr) ir_ref_instruction(operand, irb->current_basic_block); |
| ... | ... | @@ -1213,55 +1230,64 @@ static IrInstruction *ir_build_return(IrBuilder *irb, Scope *scope, AstNode *sou |
| 1213 | 1230 | } |
| 1214 | 1231 | |
| 1215 | 1232 | static IrInstruction *ir_build_const_void(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 1216 | | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1217 | | const_instruction->base.value.type = irb->codegen->builtin_types.entry_void; |
| 1218 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 1233 | #ifdef ZIG_ENABLE_MEM_PROFILE |
| 1234 | memprof_intern_count.x_void += 1; |
| 1235 | #endif |
| 1236 | IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(irb, scope, source_node); |
| 1237 | ir_instruction_append(irb->current_basic_block, &const_instruction->base); |
| 1238 | const_instruction->base.value = &irb->codegen->intern_values.x_void; |
| 1219 | 1239 | return &const_instruction->base; |
| 1220 | 1240 | } |
| 1221 | 1241 | |
| 1222 | 1242 | static IrInstruction *ir_build_const_undefined(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 1223 | | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1224 | | const_instruction->base.value.special = ConstValSpecialUndef; |
| 1225 | | const_instruction->base.value.type = irb->codegen->builtin_types.entry_undef; |
| 1243 | #ifdef ZIG_ENABLE_MEM_PROFILE |
| 1244 | memprof_intern_count.x_undefined += 1; |
| 1245 | #endif |
| 1246 | IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(irb, scope, source_node); |
| 1247 | ir_instruction_append(irb->current_basic_block, &const_instruction->base); |
| 1248 | const_instruction->base.value = &irb->codegen->intern_values.x_undefined; |
| 1226 | 1249 | return &const_instruction->base; |
| 1227 | 1250 | } |
| 1228 | 1251 | |
| 1229 | 1252 | static IrInstruction *ir_build_const_uint(IrBuilder *irb, Scope *scope, AstNode *source_node, uint64_t value) { |
| 1230 | 1253 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1231 | | const_instruction->base.value.type = irb->codegen->builtin_types.entry_num_lit_int; |
| 1232 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 1233 | | bigint_init_unsigned(&const_instruction->base.value.data.x_bigint, value); |
| 1254 | const_instruction->base.value->type = irb->codegen->builtin_types.entry_num_lit_int; |
| 1255 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 1256 | bigint_init_unsigned(&const_instruction->base.value->data.x_bigint, value); |
| 1234 | 1257 | return &const_instruction->base; |
| 1235 | 1258 | } |
| 1236 | 1259 | |
| 1237 | 1260 | static IrInstruction *ir_build_const_bigint(IrBuilder *irb, Scope *scope, AstNode *source_node, BigInt *bigint) { |
| 1238 | 1261 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1239 | | const_instruction->base.value.type = irb->codegen->builtin_types.entry_num_lit_int; |
| 1240 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 1241 | | bigint_init_bigint(&const_instruction->base.value.data.x_bigint, bigint); |
| 1262 | const_instruction->base.value->type = irb->codegen->builtin_types.entry_num_lit_int; |
| 1263 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 1264 | bigint_init_bigint(&const_instruction->base.value->data.x_bigint, bigint); |
| 1242 | 1265 | return &const_instruction->base; |
| 1243 | 1266 | } |
| 1244 | 1267 | |
| 1245 | 1268 | static IrInstruction *ir_build_const_bigfloat(IrBuilder *irb, Scope *scope, AstNode *source_node, BigFloat *bigfloat) { |
| 1246 | 1269 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1247 | | const_instruction->base.value.type = irb->codegen->builtin_types.entry_num_lit_float; |
| 1248 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 1249 | | bigfloat_init_bigfloat(&const_instruction->base.value.data.x_bigfloat, bigfloat); |
| 1270 | const_instruction->base.value->type = irb->codegen->builtin_types.entry_num_lit_float; |
| 1271 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 1272 | bigfloat_init_bigfloat(&const_instruction->base.value->data.x_bigfloat, bigfloat); |
| 1250 | 1273 | return &const_instruction->base; |
| 1251 | 1274 | } |
| 1252 | 1275 | |
| 1253 | 1276 | static IrInstruction *ir_build_const_null(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 1254 | | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1255 | | const_instruction->base.value.type = irb->codegen->builtin_types.entry_null; |
| 1256 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 1277 | #ifdef ZIG_ENABLE_MEM_PROFILE |
| 1278 | memprof_intern_count.x_null += 1; |
| 1279 | #endif |
| 1280 | IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(irb, scope, source_node); |
| 1281 | ir_instruction_append(irb->current_basic_block, &const_instruction->base); |
| 1282 | const_instruction->base.value = &irb->codegen->intern_values.x_null; |
| 1257 | 1283 | return &const_instruction->base; |
| 1258 | 1284 | } |
| 1259 | 1285 | |
| 1260 | 1286 | static IrInstruction *ir_build_const_usize(IrBuilder *irb, Scope *scope, AstNode *source_node, uint64_t value) { |
| 1261 | 1287 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1262 | | const_instruction->base.value.type = irb->codegen->builtin_types.entry_usize; |
| 1263 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 1264 | | bigint_init_unsigned(&const_instruction->base.value.data.x_bigint, value); |
| 1288 | const_instruction->base.value->type = irb->codegen->builtin_types.entry_usize; |
| 1289 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 1290 | bigint_init_unsigned(&const_instruction->base.value->data.x_bigint, value); |
| 1265 | 1291 | return &const_instruction->base; |
| 1266 | 1292 | } |
| 1267 | 1293 | |
| ... | ... | @@ -1269,9 +1295,9 @@ static IrInstruction *ir_create_const_type(IrBuilder *irb, Scope *scope, AstNode |
| 1269 | 1295 | ZigType *type_entry) |
| 1270 | 1296 | { |
| 1271 | 1297 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1272 | | const_instruction->base.value.type = irb->codegen->builtin_types.entry_type; |
| 1273 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 1274 | | const_instruction->base.value.data.x_type = type_entry; |
| 1298 | const_instruction->base.value->type = irb->codegen->builtin_types.entry_type; |
| 1299 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 1300 | const_instruction->base.value->data.x_type = type_entry; |
| 1275 | 1301 | return &const_instruction->base; |
| 1276 | 1302 | } |
| 1277 | 1303 | |
| ... | ... | @@ -1285,35 +1311,35 @@ static IrInstruction *ir_build_const_type(IrBuilder *irb, Scope *scope, AstNode |
| 1285 | 1311 | |
| 1286 | 1312 | static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigFn *fn_entry) { |
| 1287 | 1313 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1288 | | const_instruction->base.value.type = fn_entry->type_entry; |
| 1289 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 1290 | | const_instruction->base.value.data.x_ptr.data.fn.fn_entry = fn_entry; |
| 1291 | | const_instruction->base.value.data.x_ptr.mut = ConstPtrMutComptimeConst; |
| 1292 | | const_instruction->base.value.data.x_ptr.special = ConstPtrSpecialFunction; |
| 1314 | const_instruction->base.value->type = fn_entry->type_entry; |
| 1315 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 1316 | const_instruction->base.value->data.x_ptr.data.fn.fn_entry = fn_entry; |
| 1317 | const_instruction->base.value->data.x_ptr.mut = ConstPtrMutComptimeConst; |
| 1318 | const_instruction->base.value->data.x_ptr.special = ConstPtrSpecialFunction; |
| 1293 | 1319 | return &const_instruction->base; |
| 1294 | 1320 | } |
| 1295 | 1321 | |
| 1296 | 1322 | static IrInstruction *ir_build_const_import(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigType *import) { |
| 1297 | 1323 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1298 | | const_instruction->base.value.type = irb->codegen->builtin_types.entry_type; |
| 1299 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 1300 | | const_instruction->base.value.data.x_type = import; |
| 1324 | const_instruction->base.value->type = irb->codegen->builtin_types.entry_type; |
| 1325 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 1326 | const_instruction->base.value->data.x_type = import; |
| 1301 | 1327 | return &const_instruction->base; |
| 1302 | 1328 | } |
| 1303 | 1329 | |
| 1304 | 1330 | static IrInstruction *ir_build_const_bool(IrBuilder *irb, Scope *scope, AstNode *source_node, bool value) { |
| 1305 | 1331 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1306 | | const_instruction->base.value.type = irb->codegen->builtin_types.entry_bool; |
| 1307 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 1308 | | const_instruction->base.value.data.x_bool = value; |
| 1332 | const_instruction->base.value->type = irb->codegen->builtin_types.entry_bool; |
| 1333 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 1334 | const_instruction->base.value->data.x_bool = value; |
| 1309 | 1335 | return &const_instruction->base; |
| 1310 | 1336 | } |
| 1311 | 1337 | |
| 1312 | 1338 | static IrInstruction *ir_build_const_enum_literal(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *name) { |
| 1313 | 1339 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1314 | | const_instruction->base.value.type = irb->codegen->builtin_types.entry_enum_literal; |
| 1315 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 1316 | | const_instruction->base.value.data.x_enum_literal = name; |
| 1340 | const_instruction->base.value->type = irb->codegen->builtin_types.entry_enum_literal; |
| 1341 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 1342 | const_instruction->base.value->data.x_enum_literal = name; |
| 1317 | 1343 | return &const_instruction->base; |
| 1318 | 1344 | } |
| 1319 | 1345 | |
| ... | ... | @@ -1321,19 +1347,20 @@ static IrInstruction *ir_build_const_bound_fn(IrBuilder *irb, Scope *scope, AstN |
| 1321 | 1347 | ZigFn *fn_entry, IrInstruction *first_arg) |
| 1322 | 1348 | { |
| 1323 | 1349 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1324 | | const_instruction->base.value.type = get_bound_fn_type(irb->codegen, fn_entry); |
| 1325 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 1326 | | const_instruction->base.value.data.x_bound_fn.fn = fn_entry; |
| 1327 | | const_instruction->base.value.data.x_bound_fn.first_arg = first_arg; |
| 1350 | const_instruction->base.value->type = get_bound_fn_type(irb->codegen, fn_entry); |
| 1351 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 1352 | const_instruction->base.value->data.x_bound_fn.fn = fn_entry; |
| 1353 | const_instruction->base.value->data.x_bound_fn.first_arg = first_arg; |
| 1328 | 1354 | return &const_instruction->base; |
| 1329 | 1355 | } |
| 1330 | 1356 | |
| 1331 | 1357 | static IrInstruction *ir_create_const_str_lit(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *str) { |
| 1332 | 1358 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(irb, scope, source_node); |
| 1333 | | init_const_str_lit(irb->codegen, &const_instruction->base.value, str); |
| 1359 | init_const_str_lit(irb->codegen, const_instruction->base.value, str); |
| 1334 | 1360 | |
| 1335 | 1361 | return &const_instruction->base; |
| 1336 | 1362 | } |
| 1363 | |
| 1337 | 1364 | static IrInstruction *ir_build_const_str_lit(IrBuilder *irb, Scope *scope, AstNode *source_node, Buf *str) { |
| 1338 | 1365 | IrInstruction *instruction = ir_create_const_str_lit(irb, scope, source_node, str); |
| 1339 | 1366 | ir_instruction_append(irb->current_basic_block, instruction); |
| ... | ... | @@ -1388,7 +1415,7 @@ static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *so |
| 1388 | 1415 | static IrInstruction *ir_build_return_ptr(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) { |
| 1389 | 1416 | IrInstructionReturnPtr *instruction = ir_build_instruction<IrInstructionReturnPtr>(&ira->new_irb, |
| 1390 | 1417 | source_instruction->scope, source_instruction->source_node); |
| 1391 | | instruction->base.value.type = ty; |
| 1418 | instruction->base.value->type = ty; |
| 1392 | 1419 | return &instruction->base; |
| 1393 | 1420 | } |
| 1394 | 1421 | |
| ... | ... | @@ -1513,7 +1540,7 @@ static IrInstructionCallGen *ir_build_call_gen(IrAnalyze *ira, IrInstruction *so |
| 1513 | 1540 | { |
| 1514 | 1541 | IrInstructionCallGen *call_instruction = ir_build_instruction<IrInstructionCallGen>(&ira->new_irb, |
| 1515 | 1542 | source_instruction->scope, source_instruction->source_node); |
| 1516 | | call_instruction->base.value.type = return_type; |
| 1543 | call_instruction->base.value->type = return_type; |
| 1517 | 1544 | call_instruction->fn_entry = fn_entry; |
| 1518 | 1545 | call_instruction->fn_ref = fn_ref; |
| 1519 | 1546 | call_instruction->fn_inline = fn_inline; |
| ... | ... | @@ -1558,8 +1585,8 @@ static IrInstruction *ir_create_br(IrBuilder *irb, Scope *scope, AstNode *source |
| 1558 | 1585 | IrBasicBlock *dest_block, IrInstruction *is_comptime) |
| 1559 | 1586 | { |
| 1560 | 1587 | IrInstructionBr *br_instruction = ir_create_instruction<IrInstructionBr>(irb, scope, source_node); |
| 1561 | | br_instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable; |
| 1562 | | br_instruction->base.value.special = ConstValSpecialStatic; |
| 1588 | br_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable; |
| 1589 | br_instruction->base.value->special = ConstValSpecialStatic; |
| 1563 | 1590 | br_instruction->dest_block = dest_block; |
| 1564 | 1591 | br_instruction->is_comptime = is_comptime; |
| 1565 | 1592 | |
| ... | ... | @@ -1659,8 +1686,8 @@ static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scop |
| 1659 | 1686 | static IrInstruction *ir_build_unreachable(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 1660 | 1687 | IrInstructionUnreachable *unreachable_instruction = |
| 1661 | 1688 | ir_build_instruction<IrInstructionUnreachable>(irb, scope, source_node); |
| 1662 | | unreachable_instruction->base.value.special = ConstValSpecialStatic; |
| 1663 | | unreachable_instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable; |
| 1689 | unreachable_instruction->base.value->special = ConstValSpecialStatic; |
| 1690 | unreachable_instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable; |
| 1664 | 1691 | return &unreachable_instruction->base; |
| 1665 | 1692 | } |
| 1666 | 1693 | |
| ... | ... | @@ -1668,8 +1695,8 @@ static IrInstructionStorePtr *ir_build_store_ptr(IrBuilder *irb, Scope *scope, A |
| 1668 | 1695 | IrInstruction *ptr, IrInstruction *value) |
| 1669 | 1696 | { |
| 1670 | 1697 | IrInstructionStorePtr *instruction = ir_build_instruction<IrInstructionStorePtr>(irb, scope, source_node); |
| 1671 | | instruction->base.value.special = ConstValSpecialStatic; |
| 1672 | | instruction->base.value.type = irb->codegen->builtin_types.entry_void; |
| 1698 | instruction->base.value->special = ConstValSpecialStatic; |
| 1699 | instruction->base.value->type = irb->codegen->builtin_types.entry_void; |
| 1673 | 1700 | instruction->ptr = ptr; |
| 1674 | 1701 | instruction->value = value; |
| 1675 | 1702 | |
| ... | ... | @@ -1684,7 +1711,7 @@ static IrInstruction *ir_build_vector_store_elem(IrAnalyze *ira, IrInstruction * |
| 1684 | 1711 | { |
| 1685 | 1712 | IrInstructionVectorStoreElem *inst = ir_build_instruction<IrInstructionVectorStoreElem>( |
| 1686 | 1713 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 1687 | | inst->base.value.type = ira->codegen->builtin_types.entry_void; |
| 1714 | inst->base.value->type = ira->codegen->builtin_types.entry_void; |
| 1688 | 1715 | inst->vector_ptr = vector_ptr; |
| 1689 | 1716 | inst->index = index; |
| 1690 | 1717 | inst->value = value; |
| ... | ... | @@ -1700,8 +1727,8 @@ static IrInstruction *ir_build_var_decl_src(IrBuilder *irb, Scope *scope, AstNod |
| 1700 | 1727 | ZigVar *var, IrInstruction *align_value, IrInstruction *ptr) |
| 1701 | 1728 | { |
| 1702 | 1729 | IrInstructionDeclVarSrc *decl_var_instruction = ir_build_instruction<IrInstructionDeclVarSrc>(irb, scope, source_node); |
| 1703 | | decl_var_instruction->base.value.special = ConstValSpecialStatic; |
| 1704 | | decl_var_instruction->base.value.type = irb->codegen->builtin_types.entry_void; |
| 1730 | decl_var_instruction->base.value->special = ConstValSpecialStatic; |
| 1731 | decl_var_instruction->base.value->type = irb->codegen->builtin_types.entry_void; |
| 1705 | 1732 | decl_var_instruction->var = var; |
| 1706 | 1733 | decl_var_instruction->align_value = align_value; |
| 1707 | 1734 | decl_var_instruction->ptr = ptr; |
| ... | ... | @@ -1717,8 +1744,8 @@ static IrInstruction *ir_build_var_decl_gen(IrAnalyze *ira, IrInstruction *sourc |
| 1717 | 1744 | { |
| 1718 | 1745 | IrInstructionDeclVarGen *decl_var_instruction = ir_build_instruction<IrInstructionDeclVarGen>(&ira->new_irb, |
| 1719 | 1746 | source_instruction->scope, source_instruction->source_node); |
| 1720 | | decl_var_instruction->base.value.special = ConstValSpecialStatic; |
| 1721 | | decl_var_instruction->base.value.type = ira->codegen->builtin_types.entry_void; |
| 1747 | decl_var_instruction->base.value->special = ConstValSpecialStatic; |
| 1748 | decl_var_instruction->base.value->type = ira->codegen->builtin_types.entry_void; |
| 1722 | 1749 | decl_var_instruction->var = var; |
| 1723 | 1750 | decl_var_instruction->var_ptr = var_ptr; |
| 1724 | 1751 | |
| ... | ... | @@ -1732,7 +1759,7 @@ static IrInstruction *ir_build_resize_slice(IrAnalyze *ira, IrInstruction *sourc |
| 1732 | 1759 | { |
| 1733 | 1760 | IrInstructionResizeSlice *instruction = ir_build_instruction<IrInstructionResizeSlice>(&ira->new_irb, |
| 1734 | 1761 | source_instruction->scope, source_instruction->source_node); |
| 1735 | | instruction->base.value.type = ty; |
| 1762 | instruction->base.value->type = ty; |
| 1736 | 1763 | instruction->operand = operand; |
| 1737 | 1764 | instruction->result_loc = result_loc; |
| 1738 | 1765 | |
| ... | ... | @@ -1747,8 +1774,8 @@ static IrInstruction *ir_build_export(IrBuilder *irb, Scope *scope, AstNode *sou |
| 1747 | 1774 | { |
| 1748 | 1775 | IrInstructionExport *export_instruction = ir_build_instruction<IrInstructionExport>( |
| 1749 | 1776 | irb, scope, source_node); |
| 1750 | | export_instruction->base.value.special = ConstValSpecialStatic; |
| 1751 | | export_instruction->base.value.type = irb->codegen->builtin_types.entry_void; |
| 1777 | export_instruction->base.value->special = ConstValSpecialStatic; |
| 1778 | export_instruction->base.value->type = irb->codegen->builtin_types.entry_void; |
| 1752 | 1779 | export_instruction->name = name; |
| 1753 | 1780 | export_instruction->target = target; |
| 1754 | 1781 | export_instruction->linkage = linkage; |
| ... | ... | @@ -1925,7 +1952,7 @@ static IrInstruction *ir_build_optional_wrap(IrAnalyze *ira, IrInstruction *sour |
| 1925 | 1952 | { |
| 1926 | 1953 | IrInstructionOptionalWrap *instruction = ir_build_instruction<IrInstructionOptionalWrap>( |
| 1927 | 1954 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 1928 | | instruction->base.value.type = result_ty; |
| 1955 | instruction->base.value->type = result_ty; |
| 1929 | 1956 | instruction->operand = operand; |
| 1930 | 1957 | instruction->result_loc = result_loc; |
| 1931 | 1958 | |
| ... | ... | @@ -1940,7 +1967,7 @@ static IrInstruction *ir_build_err_wrap_payload(IrAnalyze *ira, IrInstruction *s |
| 1940 | 1967 | { |
| 1941 | 1968 | IrInstructionErrWrapPayload *instruction = ir_build_instruction<IrInstructionErrWrapPayload>( |
| 1942 | 1969 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 1943 | | instruction->base.value.type = result_type; |
| 1970 | instruction->base.value->type = result_type; |
| 1944 | 1971 | instruction->operand = operand; |
| 1945 | 1972 | instruction->result_loc = result_loc; |
| 1946 | 1973 | |
| ... | ... | @@ -1955,7 +1982,7 @@ static IrInstruction *ir_build_err_wrap_code(IrAnalyze *ira, IrInstruction *sour |
| 1955 | 1982 | { |
| 1956 | 1983 | IrInstructionErrWrapCode *instruction = ir_build_instruction<IrInstructionErrWrapCode>( |
| 1957 | 1984 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 1958 | | instruction->base.value.type = result_type; |
| 1985 | instruction->base.value->type = result_type; |
| 1959 | 1986 | instruction->operand = operand; |
| 1960 | 1987 | instruction->result_loc = result_loc; |
| 1961 | 1988 | |
| ... | ... | @@ -2025,8 +2052,8 @@ static IrInstructionSwitchBr *ir_build_switch_br(IrBuilder *irb, Scope *scope, A |
| 2025 | 2052 | IrInstruction *switch_prongs_void) |
| 2026 | 2053 | { |
| 2027 | 2054 | IrInstructionSwitchBr *instruction = ir_build_instruction<IrInstructionSwitchBr>(irb, scope, source_node); |
| 2028 | | instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable; |
| 2029 | | instruction->base.value.special = ConstValSpecialStatic; |
| 2055 | instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable; |
| 2056 | instruction->base.value->special = ConstValSpecialStatic; |
| 2030 | 2057 | instruction->target_value = target_value; |
| 2031 | 2058 | instruction->else_block = else_block; |
| 2032 | 2059 | instruction->case_count = case_count; |
| ... | ... | @@ -2122,7 +2149,7 @@ static IrInstruction *ir_build_ref_gen(IrAnalyze *ira, IrInstruction *source_ins |
| 2122 | 2149 | { |
| 2123 | 2150 | IrInstructionRefGen *instruction = ir_build_instruction<IrInstructionRefGen>(&ira->new_irb, |
| 2124 | 2151 | source_instruction->scope, source_instruction->source_node); |
| 2125 | | instruction->base.value.type = result_type; |
| 2152 | instruction->base.value->type = result_type; |
| 2126 | 2153 | instruction->operand = operand; |
| 2127 | 2154 | instruction->result_loc = result_loc; |
| 2128 | 2155 | |
| ... | ... | @@ -2237,7 +2264,7 @@ static IrInstruction *ir_build_cmpxchg_gen(IrAnalyze *ira, IrInstruction *source |
| 2237 | 2264 | { |
| 2238 | 2265 | IrInstructionCmpxchgGen *instruction = ir_build_instruction<IrInstructionCmpxchgGen>(&ira->new_irb, |
| 2239 | 2266 | source_instruction->scope, source_instruction->source_node); |
| 2240 | | instruction->base.value.type = result_type; |
| 2267 | instruction->base.value->type = result_type; |
| 2241 | 2268 | instruction->ptr = ptr; |
| 2242 | 2269 | instruction->cmp_value = cmp_value; |
| 2243 | 2270 | instruction->new_value = new_value; |
| ... | ... | @@ -2482,7 +2509,7 @@ static IrInstruction *ir_build_splat_gen(IrAnalyze *ira, IrInstruction *source_i |
| 2482 | 2509 | { |
| 2483 | 2510 | IrInstructionSplatGen *instruction = ir_build_instruction<IrInstructionSplatGen>( |
| 2484 | 2511 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 2485 | | instruction->base.value.type = result_type; |
| 2512 | instruction->base.value->type = result_type; |
| 2486 | 2513 | instruction->scalar = scalar; |
| 2487 | 2514 | |
| 2488 | 2515 | ir_ref_instruction(scalar, ira->new_irb.current_basic_block); |
| ... | ... | @@ -2495,7 +2522,7 @@ static IrInstruction *ir_build_slice_gen(IrAnalyze *ira, IrInstruction *source_i |
| 2495 | 2522 | { |
| 2496 | 2523 | IrInstructionSliceGen *instruction = ir_build_instruction<IrInstructionSliceGen>( |
| 2497 | 2524 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 2498 | | instruction->base.value.type = slice_type; |
| 2525 | instruction->base.value->type = slice_type; |
| 2499 | 2526 | instruction->ptr = ptr; |
| 2500 | 2527 | instruction->start = start; |
| 2501 | 2528 | instruction->end = end; |
| ... | ... | @@ -2709,7 +2736,7 @@ static IrInstruction *ir_build_test_err_gen(IrAnalyze *ira, IrInstruction *sourc |
| 2709 | 2736 | { |
| 2710 | 2737 | IrInstructionTestErrGen *instruction = ir_build_instruction<IrInstructionTestErrGen>( |
| 2711 | 2738 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 2712 | | instruction->base.value.type = ira->codegen->builtin_types.entry_bool; |
| 2739 | instruction->base.value->type = ira->codegen->builtin_types.entry_bool; |
| 2713 | 2740 | instruction->err_union = err_union; |
| 2714 | 2741 | |
| 2715 | 2742 | ir_ref_instruction(err_union, ira->new_irb.current_basic_block); |
| ... | ... | @@ -2792,7 +2819,7 @@ static IrInstruction *ir_build_ptr_cast_gen(IrAnalyze *ira, IrInstruction *sourc |
| 2792 | 2819 | { |
| 2793 | 2820 | IrInstructionPtrCastGen *instruction = ir_build_instruction<IrInstructionPtrCastGen>( |
| 2794 | 2821 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 2795 | | instruction->base.value.type = ptr_type; |
| 2822 | instruction->base.value->type = ptr_type; |
| 2796 | 2823 | instruction->ptr = ptr; |
| 2797 | 2824 | instruction->safety_check_on = safety_check_on; |
| 2798 | 2825 | |
| ... | ... | @@ -2806,7 +2833,7 @@ static IrInstruction *ir_build_load_ptr_gen(IrAnalyze *ira, IrInstruction *sourc |
| 2806 | 2833 | { |
| 2807 | 2834 | IrInstructionLoadPtrGen *instruction = ir_build_instruction<IrInstructionLoadPtrGen>( |
| 2808 | 2835 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 2809 | | instruction->base.value.type = ty; |
| 2836 | instruction->base.value->type = ty; |
| 2810 | 2837 | instruction->ptr = ptr; |
| 2811 | 2838 | instruction->result_loc = result_loc; |
| 2812 | 2839 | |
| ... | ... | @@ -2845,7 +2872,7 @@ static IrInstruction *ir_build_bit_cast_gen(IrAnalyze *ira, IrInstruction *sourc |
| 2845 | 2872 | { |
| 2846 | 2873 | IrInstructionBitCastGen *instruction = ir_build_instruction<IrInstructionBitCastGen>( |
| 2847 | 2874 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 2848 | | instruction->base.value.type = ty; |
| 2875 | instruction->base.value->type = ty; |
| 2849 | 2876 | instruction->operand = operand; |
| 2850 | 2877 | |
| 2851 | 2878 | ir_ref_instruction(operand, ira->new_irb.current_basic_block); |
| ... | ... | @@ -2997,8 +3024,8 @@ static IrInstruction *ir_build_decl_ref(IrBuilder *irb, Scope *scope, AstNode *s |
| 2997 | 3024 | |
| 2998 | 3025 | static IrInstruction *ir_build_panic(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *msg) { |
| 2999 | 3026 | IrInstructionPanic *instruction = ir_build_instruction<IrInstructionPanic>(irb, scope, source_node); |
| 3000 | | instruction->base.value.special = ConstValSpecialStatic; |
| 3001 | | instruction->base.value.type = irb->codegen->builtin_types.entry_unreachable; |
| 3027 | instruction->base.value->special = ConstValSpecialStatic; |
| 3028 | instruction->base.value->type = irb->codegen->builtin_types.entry_unreachable; |
| 3002 | 3029 | instruction->msg = msg; |
| 3003 | 3030 | |
| 3004 | 3031 | ir_ref_instruction(msg, irb->current_basic_block); |
| ... | ... | @@ -3328,7 +3355,7 @@ static IrInstruction *ir_build_vector_to_array(IrAnalyze *ira, IrInstruction *so |
| 3328 | 3355 | { |
| 3329 | 3356 | IrInstructionVectorToArray *instruction = ir_build_instruction<IrInstructionVectorToArray>(&ira->new_irb, |
| 3330 | 3357 | source_instruction->scope, source_instruction->source_node); |
| 3331 | | instruction->base.value.type = result_type; |
| 3358 | instruction->base.value->type = result_type; |
| 3332 | 3359 | instruction->vector = vector; |
| 3333 | 3360 | instruction->result_loc = result_loc; |
| 3334 | 3361 | |
| ... | ... | @@ -3343,7 +3370,7 @@ static IrInstruction *ir_build_ptr_of_array_to_slice(IrAnalyze *ira, IrInstructi |
| 3343 | 3370 | { |
| 3344 | 3371 | IrInstructionPtrOfArrayToSlice *instruction = ir_build_instruction<IrInstructionPtrOfArrayToSlice>(&ira->new_irb, |
| 3345 | 3372 | source_instruction->scope, source_instruction->source_node); |
| 3346 | | instruction->base.value.type = result_type; |
| 3373 | instruction->base.value->type = result_type; |
| 3347 | 3374 | instruction->operand = operand; |
| 3348 | 3375 | instruction->result_loc = result_loc; |
| 3349 | 3376 | |
| ... | ... | @@ -3358,7 +3385,7 @@ static IrInstruction *ir_build_array_to_vector(IrAnalyze *ira, IrInstruction *so |
| 3358 | 3385 | { |
| 3359 | 3386 | IrInstructionArrayToVector *instruction = ir_build_instruction<IrInstructionArrayToVector>(&ira->new_irb, |
| 3360 | 3387 | source_instruction->scope, source_instruction->source_node); |
| 3361 | | instruction->base.value.type = result_type; |
| 3388 | instruction->base.value->type = result_type; |
| 3362 | 3389 | instruction->array = array; |
| 3363 | 3390 | |
| 3364 | 3391 | ir_ref_instruction(array, ira->new_irb.current_basic_block); |
| ... | ... | @@ -3371,7 +3398,7 @@ static IrInstruction *ir_build_assert_zero(IrAnalyze *ira, IrInstruction *source |
| 3371 | 3398 | { |
| 3372 | 3399 | IrInstructionAssertZero *instruction = ir_build_instruction<IrInstructionAssertZero>(&ira->new_irb, |
| 3373 | 3400 | source_instruction->scope, source_instruction->source_node); |
| 3374 | | instruction->base.value.type = ira->codegen->builtin_types.entry_void; |
| 3401 | instruction->base.value->type = ira->codegen->builtin_types.entry_void; |
| 3375 | 3402 | instruction->target = target; |
| 3376 | 3403 | |
| 3377 | 3404 | ir_ref_instruction(target, ira->new_irb.current_basic_block); |
| ... | ... | @@ -3384,7 +3411,7 @@ static IrInstruction *ir_build_assert_non_null(IrAnalyze *ira, IrInstruction *so |
| 3384 | 3411 | { |
| 3385 | 3412 | IrInstructionAssertNonNull *instruction = ir_build_instruction<IrInstructionAssertNonNull>(&ira->new_irb, |
| 3386 | 3413 | source_instruction->scope, source_instruction->source_node); |
| 3387 | | instruction->base.value.type = ira->codegen->builtin_types.entry_void; |
| 3414 | instruction->base.value->type = ira->codegen->builtin_types.entry_void; |
| 3388 | 3415 | instruction->target = target; |
| 3389 | 3416 | |
| 3390 | 3417 | ir_ref_instruction(target, ira->new_irb.current_basic_block); |
| ... | ... | @@ -3433,7 +3460,7 @@ static IrInstruction *ir_build_end_expr(IrBuilder *irb, Scope *scope, AstNode *s |
| 3433 | 3460 | |
| 3434 | 3461 | static IrInstructionSuspendBegin *ir_build_suspend_begin(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 3435 | 3462 | IrInstructionSuspendBegin *instruction = ir_build_instruction<IrInstructionSuspendBegin>(irb, scope, source_node); |
| 3436 | | instruction->base.value.type = irb->codegen->builtin_types.entry_void; |
| 3463 | instruction->base.value->type = irb->codegen->builtin_types.entry_void; |
| 3437 | 3464 | |
| 3438 | 3465 | return instruction; |
| 3439 | 3466 | } |
| ... | ... | @@ -3442,7 +3469,7 @@ static IrInstruction *ir_build_suspend_finish(IrBuilder *irb, Scope *scope, AstN |
| 3442 | 3469 | IrInstructionSuspendBegin *begin) |
| 3443 | 3470 | { |
| 3444 | 3471 | IrInstructionSuspendFinish *instruction = ir_build_instruction<IrInstructionSuspendFinish>(irb, scope, source_node); |
| 3445 | | instruction->base.value.type = irb->codegen->builtin_types.entry_void; |
| 3472 | instruction->base.value->type = irb->codegen->builtin_types.entry_void; |
| 3446 | 3473 | instruction->begin = begin; |
| 3447 | 3474 | |
| 3448 | 3475 | ir_ref_instruction(&begin->base, irb->current_basic_block); |
| ... | ... | @@ -3467,7 +3494,7 @@ static IrInstructionAwaitGen *ir_build_await_gen(IrAnalyze *ira, IrInstruction * |
| 3467 | 3494 | { |
| 3468 | 3495 | IrInstructionAwaitGen *instruction = ir_build_instruction<IrInstructionAwaitGen>(&ira->new_irb, |
| 3469 | 3496 | source_instruction->scope, source_instruction->source_node); |
| 3470 | | instruction->base.value.type = result_type; |
| 3497 | instruction->base.value->type = result_type; |
| 3471 | 3498 | instruction->frame = frame; |
| 3472 | 3499 | instruction->result_loc = result_loc; |
| 3473 | 3500 | |
| ... | ... | @@ -3479,7 +3506,7 @@ static IrInstructionAwaitGen *ir_build_await_gen(IrAnalyze *ira, IrInstruction * |
| 3479 | 3506 | |
| 3480 | 3507 | static IrInstruction *ir_build_resume(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction *frame) { |
| 3481 | 3508 | IrInstructionResume *instruction = ir_build_instruction<IrInstructionResume>(irb, scope, source_node); |
| 3482 | | instruction->base.value.type = irb->codegen->builtin_types.entry_void; |
| 3509 | instruction->base.value->type = irb->codegen->builtin_types.entry_void; |
| 3483 | 3510 | instruction->frame = frame; |
| 3484 | 3511 | |
| 3485 | 3512 | ir_ref_instruction(frame, irb->current_basic_block); |
| ... | ... | @@ -3491,8 +3518,8 @@ static IrInstructionSpillBegin *ir_build_spill_begin(IrBuilder *irb, Scope *scop |
| 3491 | 3518 | IrInstruction *operand, SpillId spill_id) |
| 3492 | 3519 | { |
| 3493 | 3520 | IrInstructionSpillBegin *instruction = ir_build_instruction<IrInstructionSpillBegin>(irb, scope, source_node); |
| 3494 | | instruction->base.value.special = ConstValSpecialStatic; |
| 3495 | | instruction->base.value.type = irb->codegen->builtin_types.entry_void; |
| 3521 | instruction->base.value->special = ConstValSpecialStatic; |
| 3522 | instruction->base.value->type = irb->codegen->builtin_types.entry_void; |
| 3496 | 3523 | instruction->operand = operand; |
| 3497 | 3524 | instruction->spill_id = spill_id; |
| 3498 | 3525 | |
| ... | ... | @@ -3517,7 +3544,7 @@ static IrInstruction *ir_build_vector_extract_elem(IrAnalyze *ira, IrInstruction |
| 3517 | 3544 | { |
| 3518 | 3545 | IrInstructionVectorExtractElem *instruction = ir_build_instruction<IrInstructionVectorExtractElem>( |
| 3519 | 3546 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); |
| 3520 | | instruction->base.value.type = vector->value.type->data.vector.elem_type; |
| 3547 | instruction->base.value->type = vector->value->type->data.vector.elem_type; |
| 3521 | 3548 | instruction->vector = vector; |
| 3522 | 3549 | instruction->index = index; |
| 3523 | 3550 | |
| ... | ... | @@ -3588,8 +3615,8 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o |
| 3588 | 3615 | Scope *defer_expr_scope = defer_node->data.defer.expr_scope; |
| 3589 | 3616 | IrInstruction *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope); |
| 3590 | 3617 | if (defer_expr_value != irb->codegen->invalid_instruction) { |
| 3591 | | if (defer_expr_value->value.type != nullptr && |
| 3592 | | defer_expr_value->value.type->id == ZigTypeIdUnreachable) |
| 3618 | if (defer_expr_value->value->type != nullptr && |
| 3619 | defer_expr_value->value->type->id == ZigTypeIdUnreachable) |
| 3593 | 3620 | { |
| 3594 | 3621 | is_noreturn = true; |
| 3595 | 3622 | } else { |
| ... | ... | @@ -4411,7 +4438,7 @@ static void populate_invalid_variable_in_scope(CodeGen *g, Scope *scope, AstNode |
| 4411 | 4438 | init_tld(&tld_var->base, TldIdVar, var_name, VisibModPub, node, &scope_decls->base); |
| 4412 | 4439 | tld_var->base.resolution = TldResolutionInvalid; |
| 4413 | 4440 | tld_var->var = add_variable(g, node, &scope_decls->base, var_name, false, |
| 4414 | | &g->invalid_instruction->value, &tld_var->base, g->builtin_types.entry_invalid); |
| 4441 | g->invalid_instruction->value, &tld_var->base, g->builtin_types.entry_invalid); |
| 4415 | 4442 | scope_decls->decl_table.put(var_name, &tld_var->base); |
| 4416 | 4443 | } |
| 4417 | 4444 | |
| ... | ... | @@ -4424,10 +4451,10 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, |
| 4424 | 4451 | if (buf_eql_str(variable_name, "_")) { |
| 4425 | 4452 | if (lval == LValPtr) { |
| 4426 | 4453 | IrInstructionConst *const_instruction = ir_build_instruction<IrInstructionConst>(irb, scope, node); |
| 4427 | | const_instruction->base.value.type = get_pointer_to_type(irb->codegen, |
| 4454 | const_instruction->base.value->type = get_pointer_to_type(irb->codegen, |
| 4428 | 4455 | irb->codegen->builtin_types.entry_void, false); |
| 4429 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 4430 | | const_instruction->base.value.data.x_ptr.special = ConstPtrSpecialDiscard; |
| 4456 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 4457 | const_instruction->base.value->data.x_ptr.special = ConstPtrSpecialDiscard; |
| 4431 | 4458 | return &const_instruction->base; |
| 4432 | 4459 | } else { |
| 4433 | 4460 | add_node_error(irb->codegen, node, buf_sprintf("`_` may only be used to assign things to")); |
| ... | ... | @@ -8698,26 +8725,26 @@ static void ir_assert(bool ok, IrInstruction *source_instruction) { |
| 8698 | 8725 | // This function takes a comptime ptr and makes the child const value conform to the type |
| 8699 | 8726 | // described by the pointer. |
| 8700 | 8727 | static Error eval_comptime_ptr_reinterpret(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, |
| 8701 | | ConstExprValue *ptr_val) |
| 8728 | ZigValue *ptr_val) |
| 8702 | 8729 | { |
| 8703 | 8730 | Error err; |
| 8704 | 8731 | assert(ptr_val->type->id == ZigTypeIdPointer); |
| 8705 | 8732 | assert(ptr_val->special == ConstValSpecialStatic); |
| 8706 | | ConstExprValue tmp = {}; |
| 8733 | ZigValue tmp = {}; |
| 8707 | 8734 | tmp.special = ConstValSpecialStatic; |
| 8708 | 8735 | tmp.type = ptr_val->type->data.pointer.child_type; |
| 8709 | 8736 | if ((err = ir_read_const_ptr(ira, codegen, source_node, &tmp, ptr_val))) |
| 8710 | 8737 | return err; |
| 8711 | | ConstExprValue *child_val = const_ptr_pointee_unchecked(codegen, ptr_val); |
| 8738 | ZigValue *child_val = const_ptr_pointee_unchecked(codegen, ptr_val); |
| 8712 | 8739 | copy_const_val(child_val, &tmp, false); |
| 8713 | 8740 | return ErrorNone; |
| 8714 | 8741 | } |
| 8715 | 8742 | |
| 8716 | | ConstExprValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ConstExprValue *const_val, |
| 8743 | ZigValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ZigValue *const_val, |
| 8717 | 8744 | AstNode *source_node) |
| 8718 | 8745 | { |
| 8719 | 8746 | Error err; |
| 8720 | | ConstExprValue *val = const_ptr_pointee_unchecked(codegen, const_val); |
| 8747 | ZigValue *val = const_ptr_pointee_unchecked(codegen, const_val); |
| 8721 | 8748 | assert(val != nullptr); |
| 8722 | 8749 | assert(const_val->type->id == ZigTypeIdPointer); |
| 8723 | 8750 | ZigType *expected_type = const_val->type->data.pointer.child_type; |
| ... | ... | @@ -8740,19 +8767,19 @@ ConstExprValue *const_ptr_pointee(IrAnalyze *ira, CodeGen *codegen, ConstExprVal |
| 8740 | 8767 | return val; |
| 8741 | 8768 | } |
| 8742 | 8769 | |
| 8743 | | static ConstExprValue *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) { |
| 8770 | static ZigValue *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec) { |
| 8744 | 8771 | IrBasicBlock *bb = exec->basic_block_list.at(0); |
| 8745 | 8772 | for (size_t i = 0; i < bb->instruction_list.length; i += 1) { |
| 8746 | 8773 | IrInstruction *instruction = bb->instruction_list.at(i); |
| 8747 | 8774 | if (instruction->id == IrInstructionIdReturn) { |
| 8748 | 8775 | IrInstructionReturn *ret_inst = (IrInstructionReturn *)instruction; |
| 8749 | 8776 | IrInstruction *operand = ret_inst->operand; |
| 8750 | | if (operand->value.special == ConstValSpecialRuntime) { |
| 8777 | if (operand->value->special == ConstValSpecialRuntime) { |
| 8751 | 8778 | exec_add_error_node(codegen, exec, operand->source_node, |
| 8752 | 8779 | buf_sprintf("unable to evaluate constant expression")); |
| 8753 | | return &codegen->invalid_instruction->value; |
| 8780 | return codegen->invalid_instruction->value; |
| 8754 | 8781 | } |
| 8755 | | return &operand->value; |
| 8782 | return operand->value; |
| 8756 | 8783 | } else if (ir_has_side_effects(instruction)) { |
| 8757 | 8784 | if (instr_is_comptime(instruction)) { |
| 8758 | 8785 | switch (instruction->id) { |
| ... | ... | @@ -8769,7 +8796,7 @@ static ConstExprValue *ir_exec_const_result(CodeGen *codegen, IrExecutable *exec |
| 8769 | 8796 | } |
| 8770 | 8797 | exec_add_error_node(codegen, exec, instruction->source_node, |
| 8771 | 8798 | buf_sprintf("unable to evaluate constant expression")); |
| 8772 | | return &codegen->invalid_instruction->value; |
| 8799 | return codegen->invalid_instruction->value; |
| 8773 | 8800 | } |
| 8774 | 8801 | } |
| 8775 | 8802 | zig_unreachable(); |
| ... | ... | @@ -8783,14 +8810,14 @@ static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstruction *so |
| 8783 | 8810 | return true; |
| 8784 | 8811 | } |
| 8785 | 8812 | |
| 8786 | | static bool const_val_fits_in_num_lit(ConstExprValue *const_val, ZigType *num_lit_type) { |
| 8813 | static bool const_val_fits_in_num_lit(ZigValue *const_val, ZigType *num_lit_type) { |
| 8787 | 8814 | return ((num_lit_type->id == ZigTypeIdComptimeFloat && |
| 8788 | 8815 | (const_val->type->id == ZigTypeIdFloat || const_val->type->id == ZigTypeIdComptimeFloat)) || |
| 8789 | 8816 | (num_lit_type->id == ZigTypeIdComptimeInt && |
| 8790 | 8817 | (const_val->type->id == ZigTypeIdInt || const_val->type->id == ZigTypeIdComptimeInt))); |
| 8791 | 8818 | } |
| 8792 | 8819 | |
| 8793 | | static bool float_has_fraction(ConstExprValue *const_val) { |
| 8820 | static bool float_has_fraction(ZigValue *const_val) { |
| 8794 | 8821 | if (const_val->type->id == ZigTypeIdComptimeFloat) { |
| 8795 | 8822 | return bigfloat_has_fraction(&const_val->data.x_bigfloat); |
| 8796 | 8823 | } else if (const_val->type->id == ZigTypeIdFloat) { |
| ... | ... | @@ -8818,7 +8845,7 @@ static bool float_has_fraction(ConstExprValue *const_val) { |
| 8818 | 8845 | } |
| 8819 | 8846 | } |
| 8820 | 8847 | |
| 8821 | | static void float_append_buf(Buf *buf, ConstExprValue *const_val) { |
| 8848 | static void float_append_buf(Buf *buf, ZigValue *const_val) { |
| 8822 | 8849 | if (const_val->type->id == ZigTypeIdComptimeFloat) { |
| 8823 | 8850 | bigfloat_append_buf(buf, &const_val->data.x_bigfloat); |
| 8824 | 8851 | } else if (const_val->type->id == ZigTypeIdFloat) { |
| ... | ... | @@ -8856,7 +8883,7 @@ static void float_append_buf(Buf *buf, ConstExprValue *const_val) { |
| 8856 | 8883 | } |
| 8857 | 8884 | } |
| 8858 | 8885 | |
| 8859 | | static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) { |
| 8886 | static void float_init_bigint(BigInt *bigint, ZigValue *const_val) { |
| 8860 | 8887 | if (const_val->type->id == ZigTypeIdComptimeFloat) { |
| 8861 | 8888 | bigint_init_bigfloat(bigint, &const_val->data.x_bigfloat); |
| 8862 | 8889 | } else if (const_val->type->id == ZigTypeIdFloat) { |
| ... | ... | @@ -8903,7 +8930,7 @@ static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) { |
| 8903 | 8930 | } |
| 8904 | 8931 | } |
| 8905 | 8932 | |
| 8906 | | static void float_init_bigfloat(ConstExprValue *dest_val, BigFloat *bigfloat) { |
| 8933 | static void float_init_bigfloat(ZigValue *dest_val, BigFloat *bigfloat) { |
| 8907 | 8934 | if (dest_val->type->id == ZigTypeIdComptimeFloat) { |
| 8908 | 8935 | bigfloat_init_bigfloat(&dest_val->data.x_bigfloat, bigfloat); |
| 8909 | 8936 | } else if (dest_val->type->id == ZigTypeIdFloat) { |
| ... | ... | @@ -8930,7 +8957,7 @@ static void float_init_bigfloat(ConstExprValue *dest_val, BigFloat *bigfloat) { |
| 8930 | 8957 | } |
| 8931 | 8958 | } |
| 8932 | 8959 | |
| 8933 | | static void float_init_f16(ConstExprValue *dest_val, float16_t x) { |
| 8960 | static void float_init_f16(ZigValue *dest_val, float16_t x) { |
| 8934 | 8961 | if (dest_val->type->id == ZigTypeIdComptimeFloat) { |
| 8935 | 8962 | bigfloat_init_16(&dest_val->data.x_bigfloat, x); |
| 8936 | 8963 | } else if (dest_val->type->id == ZigTypeIdFloat) { |
| ... | ... | @@ -8955,7 +8982,7 @@ static void float_init_f16(ConstExprValue *dest_val, float16_t x) { |
| 8955 | 8982 | } |
| 8956 | 8983 | } |
| 8957 | 8984 | |
| 8958 | | static void float_init_f32(ConstExprValue *dest_val, float x) { |
| 8985 | static void float_init_f32(ZigValue *dest_val, float x) { |
| 8959 | 8986 | if (dest_val->type->id == ZigTypeIdComptimeFloat) { |
| 8960 | 8987 | bigfloat_init_32(&dest_val->data.x_bigfloat, x); |
| 8961 | 8988 | } else if (dest_val->type->id == ZigTypeIdFloat) { |
| ... | ... | @@ -8984,7 +9011,7 @@ static void float_init_f32(ConstExprValue *dest_val, float x) { |
| 8984 | 9011 | } |
| 8985 | 9012 | } |
| 8986 | 9013 | |
| 8987 | | static void float_init_f64(ConstExprValue *dest_val, double x) { |
| 9014 | static void float_init_f64(ZigValue *dest_val, double x) { |
| 8988 | 9015 | if (dest_val->type->id == ZigTypeIdComptimeFloat) { |
| 8989 | 9016 | bigfloat_init_64(&dest_val->data.x_bigfloat, x); |
| 8990 | 9017 | } else if (dest_val->type->id == ZigTypeIdFloat) { |
| ... | ... | @@ -9013,7 +9040,7 @@ static void float_init_f64(ConstExprValue *dest_val, double x) { |
| 9013 | 9040 | } |
| 9014 | 9041 | } |
| 9015 | 9042 | |
| 9016 | | static void float_init_f128(ConstExprValue *dest_val, float128_t x) { |
| 9043 | static void float_init_f128(ZigValue *dest_val, float128_t x) { |
| 9017 | 9044 | if (dest_val->type->id == ZigTypeIdComptimeFloat) { |
| 9018 | 9045 | bigfloat_init_128(&dest_val->data.x_bigfloat, x); |
| 9019 | 9046 | } else if (dest_val->type->id == ZigTypeIdFloat) { |
| ... | ... | @@ -9046,7 +9073,7 @@ static void float_init_f128(ConstExprValue *dest_val, float128_t x) { |
| 9046 | 9073 | } |
| 9047 | 9074 | } |
| 9048 | 9075 | |
| 9049 | | static void float_init_float(ConstExprValue *dest_val, ConstExprValue *src_val) { |
| 9076 | static void float_init_float(ZigValue *dest_val, ZigValue *src_val) { |
| 9050 | 9077 | if (src_val->type->id == ZigTypeIdComptimeFloat) { |
| 9051 | 9078 | float_init_bigfloat(dest_val, &src_val->data.x_bigfloat); |
| 9052 | 9079 | } else if (src_val->type->id == ZigTypeIdFloat) { |
| ... | ... | @@ -9071,7 +9098,7 @@ static void float_init_float(ConstExprValue *dest_val, ConstExprValue *src_val) |
| 9071 | 9098 | } |
| 9072 | 9099 | } |
| 9073 | 9100 | |
| 9074 | | static bool float_is_nan(ConstExprValue *op) { |
| 9101 | static bool float_is_nan(ZigValue *op) { |
| 9075 | 9102 | if (op->type->id == ZigTypeIdComptimeFloat) { |
| 9076 | 9103 | return bigfloat_is_nan(&op->data.x_bigfloat); |
| 9077 | 9104 | } else if (op->type->id == ZigTypeIdFloat) { |
| ... | ... | @@ -9092,7 +9119,7 @@ static bool float_is_nan(ConstExprValue *op) { |
| 9092 | 9119 | } |
| 9093 | 9120 | } |
| 9094 | 9121 | |
| 9095 | | static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) { |
| 9122 | static Cmp float_cmp(ZigValue *op1, ZigValue *op2) { |
| 9096 | 9123 | assert(op1->type == op2->type); |
| 9097 | 9124 | if (op1->type->id == ZigTypeIdComptimeFloat) { |
| 9098 | 9125 | return bigfloat_cmp(&op1->data.x_bigfloat, &op2->data.x_bigfloat); |
| ... | ... | @@ -9138,7 +9165,7 @@ static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) { |
| 9138 | 9165 | } |
| 9139 | 9166 | } |
| 9140 | 9167 | |
| 9141 | | static Cmp float_cmp_zero(ConstExprValue *op) { |
| 9168 | static Cmp float_cmp_zero(ZigValue *op) { |
| 9142 | 9169 | if (op->type->id == ZigTypeIdComptimeFloat) { |
| 9143 | 9170 | return bigfloat_cmp_zero(&op->data.x_bigfloat); |
| 9144 | 9171 | } else if (op->type->id == ZigTypeIdFloat) { |
| ... | ... | @@ -9188,7 +9215,7 @@ static Cmp float_cmp_zero(ConstExprValue *op) { |
| 9188 | 9215 | } |
| 9189 | 9216 | } |
| 9190 | 9217 | |
| 9191 | | static void float_add(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { |
| 9218 | static void float_add(ZigValue *out_val, ZigValue *op1, ZigValue *op2) { |
| 9192 | 9219 | assert(op1->type == op2->type); |
| 9193 | 9220 | out_val->type = op1->type; |
| 9194 | 9221 | if (op1->type->id == ZigTypeIdComptimeFloat) { |
| ... | ... | @@ -9215,7 +9242,7 @@ static void float_add(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal |
| 9215 | 9242 | } |
| 9216 | 9243 | } |
| 9217 | 9244 | |
| 9218 | | static void float_sub(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { |
| 9245 | static void float_sub(ZigValue *out_val, ZigValue *op1, ZigValue *op2) { |
| 9219 | 9246 | assert(op1->type == op2->type); |
| 9220 | 9247 | out_val->type = op1->type; |
| 9221 | 9248 | if (op1->type->id == ZigTypeIdComptimeFloat) { |
| ... | ... | @@ -9242,7 +9269,7 @@ static void float_sub(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal |
| 9242 | 9269 | } |
| 9243 | 9270 | } |
| 9244 | 9271 | |
| 9245 | | static void float_mul(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { |
| 9272 | static void float_mul(ZigValue *out_val, ZigValue *op1, ZigValue *op2) { |
| 9246 | 9273 | assert(op1->type == op2->type); |
| 9247 | 9274 | out_val->type = op1->type; |
| 9248 | 9275 | if (op1->type->id == ZigTypeIdComptimeFloat) { |
| ... | ... | @@ -9269,7 +9296,7 @@ static void float_mul(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal |
| 9269 | 9296 | } |
| 9270 | 9297 | } |
| 9271 | 9298 | |
| 9272 | | static void float_div(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { |
| 9299 | static void float_div(ZigValue *out_val, ZigValue *op1, ZigValue *op2) { |
| 9273 | 9300 | assert(op1->type == op2->type); |
| 9274 | 9301 | out_val->type = op1->type; |
| 9275 | 9302 | if (op1->type->id == ZigTypeIdComptimeFloat) { |
| ... | ... | @@ -9296,7 +9323,7 @@ static void float_div(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal |
| 9296 | 9323 | } |
| 9297 | 9324 | } |
| 9298 | 9325 | |
| 9299 | | static void float_div_trunc(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { |
| 9326 | static void float_div_trunc(ZigValue *out_val, ZigValue *op1, ZigValue *op2) { |
| 9300 | 9327 | assert(op1->type == op2->type); |
| 9301 | 9328 | out_val->type = op1->type; |
| 9302 | 9329 | if (op1->type->id == ZigTypeIdComptimeFloat) { |
| ... | ... | @@ -9325,7 +9352,7 @@ static void float_div_trunc(ConstExprValue *out_val, ConstExprValue *op1, ConstE |
| 9325 | 9352 | } |
| 9326 | 9353 | } |
| 9327 | 9354 | |
| 9328 | | static void float_div_floor(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { |
| 9355 | static void float_div_floor(ZigValue *out_val, ZigValue *op1, ZigValue *op2) { |
| 9329 | 9356 | assert(op1->type == op2->type); |
| 9330 | 9357 | out_val->type = op1->type; |
| 9331 | 9358 | if (op1->type->id == ZigTypeIdComptimeFloat) { |
| ... | ... | @@ -9354,7 +9381,7 @@ static void float_div_floor(ConstExprValue *out_val, ConstExprValue *op1, ConstE |
| 9354 | 9381 | } |
| 9355 | 9382 | } |
| 9356 | 9383 | |
| 9357 | | static void float_rem(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { |
| 9384 | static void float_rem(ZigValue *out_val, ZigValue *op1, ZigValue *op2) { |
| 9358 | 9385 | assert(op1->type == op2->type); |
| 9359 | 9386 | out_val->type = op1->type; |
| 9360 | 9387 | if (op1->type->id == ZigTypeIdComptimeFloat) { |
| ... | ... | @@ -9399,7 +9426,7 @@ static void zig_f128M_mod(const float128_t* a, const float128_t* b, float128_t* |
| 9399 | 9426 | f128M_sub(a, c, c); |
| 9400 | 9427 | } |
| 9401 | 9428 | |
| 9402 | | static void float_mod(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { |
| 9429 | static void float_mod(ZigValue *out_val, ZigValue *op1, ZigValue *op2) { |
| 9403 | 9430 | assert(op1->type == op2->type); |
| 9404 | 9431 | out_val->type = op1->type; |
| 9405 | 9432 | if (op1->type->id == ZigTypeIdComptimeFloat) { |
| ... | ... | @@ -9426,7 +9453,7 @@ static void float_mod(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal |
| 9426 | 9453 | } |
| 9427 | 9454 | } |
| 9428 | 9455 | |
| 9429 | | static void float_negate(ConstExprValue *out_val, ConstExprValue *op) { |
| 9456 | static void float_negate(ZigValue *out_val, ZigValue *op) { |
| 9430 | 9457 | out_val->type = op->type; |
| 9431 | 9458 | if (op->type->id == ZigTypeIdComptimeFloat) { |
| 9432 | 9459 | bigfloat_negate(&out_val->data.x_bigfloat, &op->data.x_bigfloat); |
| ... | ... | @@ -9457,7 +9484,7 @@ static void float_negate(ConstExprValue *out_val, ConstExprValue *op) { |
| 9457 | 9484 | } |
| 9458 | 9485 | } |
| 9459 | 9486 | |
| 9460 | | void float_write_ieee597(ConstExprValue *op, uint8_t *buf, bool is_big_endian) { |
| 9487 | void float_write_ieee597(ZigValue *op, uint8_t *buf, bool is_big_endian) { |
| 9461 | 9488 | if (op->type->id == ZigTypeIdFloat) { |
| 9462 | 9489 | switch (op->type->data.floating.bit_count) { |
| 9463 | 9490 | case 16: |
| ... | ... | @@ -9480,7 +9507,7 @@ void float_write_ieee597(ConstExprValue *op, uint8_t *buf, bool is_big_endian) { |
| 9480 | 9507 | } |
| 9481 | 9508 | } |
| 9482 | 9509 | |
| 9483 | | void float_read_ieee597(ConstExprValue *val, uint8_t *buf, bool is_big_endian) { |
| 9510 | void float_read_ieee597(ZigValue *val, uint8_t *buf, bool is_big_endian) { |
| 9484 | 9511 | if (val->type->id == ZigTypeIdFloat) { |
| 9485 | 9512 | switch (val->type->data.floating.bit_count) { |
| 9486 | 9513 | case 16: |
| ... | ... | @@ -9510,7 +9537,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc |
| 9510 | 9537 | return false; |
| 9511 | 9538 | } |
| 9512 | 9539 | |
| 9513 | | ConstExprValue *const_val = ir_resolve_const(ira, instruction, LazyOkNoUndef); |
| 9540 | ZigValue *const_val = ir_resolve_const(ira, instruction, LazyOkNoUndef); |
| 9514 | 9541 | if (const_val == nullptr) |
| 9515 | 9542 | return false; |
| 9516 | 9543 | |
| ... | ... | @@ -10217,13 +10244,13 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 10217 | 10244 | size_t i = 0; |
| 10218 | 10245 | for (;;) { |
| 10219 | 10246 | prev_inst = instructions[i]; |
| 10220 | | if (type_is_invalid(prev_inst->value.type)) { |
| 10247 | if (type_is_invalid(prev_inst->value->type)) { |
| 10221 | 10248 | return ira->codegen->builtin_types.entry_invalid; |
| 10222 | 10249 | } |
| 10223 | | if (prev_inst->value.type->id == ZigTypeIdUnreachable) { |
| 10250 | if (prev_inst->value->type->id == ZigTypeIdUnreachable) { |
| 10224 | 10251 | i += 1; |
| 10225 | 10252 | if (i == instruction_count) { |
| 10226 | | return prev_inst->value.type; |
| 10253 | return prev_inst->value->type; |
| 10227 | 10254 | } |
| 10228 | 10255 | continue; |
| 10229 | 10256 | } |
| ... | ... | @@ -10232,14 +10259,14 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 10232 | 10259 | ErrorTableEntry **errors = nullptr; |
| 10233 | 10260 | size_t errors_count = 0; |
| 10234 | 10261 | ZigType *err_set_type = nullptr; |
| 10235 | | if (prev_inst->value.type->id == ZigTypeIdErrorSet) { |
| 10236 | | if (!resolve_inferred_error_set(ira->codegen, prev_inst->value.type, prev_inst->source_node)) { |
| 10262 | if (prev_inst->value->type->id == ZigTypeIdErrorSet) { |
| 10263 | if (!resolve_inferred_error_set(ira->codegen, prev_inst->value->type, prev_inst->source_node)) { |
| 10237 | 10264 | return ira->codegen->builtin_types.entry_invalid; |
| 10238 | 10265 | } |
| 10239 | | if (type_is_global_error_set(prev_inst->value.type)) { |
| 10266 | if (type_is_global_error_set(prev_inst->value->type)) { |
| 10240 | 10267 | err_set_type = ira->codegen->builtin_types.entry_global_error_set; |
| 10241 | 10268 | } else { |
| 10242 | | err_set_type = prev_inst->value.type; |
| 10269 | err_set_type = prev_inst->value->type; |
| 10243 | 10270 | update_errors_helper(ira->codegen, &errors, &errors_count); |
| 10244 | 10271 | |
| 10245 | 10272 | for (uint32_t i = 0; i < err_set_type->data.error_set.err_count; i += 1) { |
| ... | ... | @@ -10250,12 +10277,12 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 10250 | 10277 | } |
| 10251 | 10278 | } |
| 10252 | 10279 | |
| 10253 | | bool any_are_null = (prev_inst->value.type->id == ZigTypeIdNull); |
| 10280 | bool any_are_null = (prev_inst->value->type->id == ZigTypeIdNull); |
| 10254 | 10281 | bool convert_to_const_slice = false; |
| 10255 | 10282 | for (; i < instruction_count; i += 1) { |
| 10256 | 10283 | IrInstruction *cur_inst = instructions[i]; |
| 10257 | | ZigType *cur_type = cur_inst->value.type; |
| 10258 | | ZigType *prev_type = prev_inst->value.type; |
| 10284 | ZigType *cur_type = cur_inst->value->type; |
| 10285 | ZigType *prev_type = prev_inst->value->type; |
| 10259 | 10286 | |
| 10260 | 10287 | if (type_is_invalid(cur_type)) { |
| 10261 | 10288 | return cur_type; |
| ... | ... | @@ -10559,20 +10586,20 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 10559 | 10586 | } |
| 10560 | 10587 | |
| 10561 | 10588 | if (prev_type->id == ZigTypeIdEnum && cur_type->id == ZigTypeIdEnumLiteral) { |
| 10562 | | TypeEnumField *field = find_enum_type_field(prev_type, cur_inst->value.data.x_enum_literal); |
| 10589 | TypeEnumField *field = find_enum_type_field(prev_type, cur_inst->value->data.x_enum_literal); |
| 10563 | 10590 | if (field != nullptr) { |
| 10564 | 10591 | continue; |
| 10565 | 10592 | } |
| 10566 | 10593 | } |
| 10567 | 10594 | if (is_tagged_union(prev_type) && cur_type->id == ZigTypeIdEnumLiteral) { |
| 10568 | | TypeUnionField *field = find_union_type_field(prev_type, cur_inst->value.data.x_enum_literal); |
| 10595 | TypeUnionField *field = find_union_type_field(prev_type, cur_inst->value->data.x_enum_literal); |
| 10569 | 10596 | if (field != nullptr) { |
| 10570 | 10597 | continue; |
| 10571 | 10598 | } |
| 10572 | 10599 | } |
| 10573 | 10600 | |
| 10574 | 10601 | if (cur_type->id == ZigTypeIdEnum && prev_type->id == ZigTypeIdEnumLiteral) { |
| 10575 | | TypeEnumField *field = find_enum_type_field(cur_type, prev_inst->value.data.x_enum_literal); |
| 10602 | TypeEnumField *field = find_enum_type_field(cur_type, prev_inst->value->data.x_enum_literal); |
| 10576 | 10603 | if (field != nullptr) { |
| 10577 | 10604 | prev_inst = cur_inst; |
| 10578 | 10605 | continue; |
| ... | ... | @@ -10580,7 +10607,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 10580 | 10607 | } |
| 10581 | 10608 | |
| 10582 | 10609 | if (is_tagged_union(cur_type) && prev_type->id == ZigTypeIdEnumLiteral) { |
| 10583 | | TypeUnionField *field = find_union_type_field(cur_type, prev_inst->value.data.x_enum_literal); |
| 10610 | TypeUnionField *field = find_union_type_field(cur_type, prev_inst->value->data.x_enum_literal); |
| 10584 | 10611 | if (field != nullptr) { |
| 10585 | 10612 | prev_inst = cur_inst; |
| 10586 | 10613 | continue; |
| ... | ... | @@ -10906,9 +10933,9 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 10906 | 10933 | free(errors); |
| 10907 | 10934 | |
| 10908 | 10935 | if (convert_to_const_slice) { |
| 10909 | | if (prev_inst->value.type->id == ZigTypeIdArray) { |
| 10936 | if (prev_inst->value->type->id == ZigTypeIdArray) { |
| 10910 | 10937 | ZigType *ptr_type = get_pointer_to_type_extra( |
| 10911 | | ira->codegen, prev_inst->value.type->data.array.child_type, |
| 10938 | ira->codegen, prev_inst->value->type->data.array.child_type, |
| 10912 | 10939 | true, false, PtrLenUnknown, |
| 10913 | 10940 | 0, 0, 0, false); |
| 10914 | 10941 | ZigType *slice_type = get_slice_type(ira->codegen, ptr_type); |
| ... | ... | @@ -10917,12 +10944,12 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 10917 | 10944 | } else { |
| 10918 | 10945 | return slice_type; |
| 10919 | 10946 | } |
| 10920 | | } else if (prev_inst->value.type->id == ZigTypeIdPointer) { |
| 10921 | | ZigType *array_type = prev_inst->value.type->data.pointer.child_type; |
| 10947 | } else if (prev_inst->value->type->id == ZigTypeIdPointer) { |
| 10948 | ZigType *array_type = prev_inst->value->type->data.pointer.child_type; |
| 10922 | 10949 | src_assert(array_type->id == ZigTypeIdArray, source_node); |
| 10923 | 10950 | ZigType *ptr_type = get_pointer_to_type_extra2( |
| 10924 | 10951 | ira->codegen, array_type->data.array.child_type, |
| 10925 | | prev_inst->value.type->data.pointer.is_const, false, |
| 10952 | prev_inst->value->type->data.pointer.is_const, false, |
| 10926 | 10953 | PtrLenUnknown, |
| 10927 | 10954 | 0, 0, 0, false, |
| 10928 | 10955 | VECTOR_INDEX_NONE, nullptr, array_type->data.array.sentinel); |
| ... | ... | @@ -10936,10 +10963,10 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 10936 | 10963 | zig_unreachable(); |
| 10937 | 10964 | } |
| 10938 | 10965 | } else if (err_set_type != nullptr) { |
| 10939 | | if (prev_inst->value.type->id == ZigTypeIdErrorSet) { |
| 10966 | if (prev_inst->value->type->id == ZigTypeIdErrorSet) { |
| 10940 | 10967 | return err_set_type; |
| 10941 | | } else if (prev_inst->value.type->id == ZigTypeIdErrorUnion) { |
| 10942 | | ZigType *payload_type = prev_inst->value.type->data.error_union.payload_type; |
| 10968 | } else if (prev_inst->value->type->id == ZigTypeIdErrorUnion) { |
| 10969 | ZigType *payload_type = prev_inst->value->type->data.error_union.payload_type; |
| 10943 | 10970 | if ((err = type_resolve(ira->codegen, payload_type, ResolveStatusSizeKnown))) |
| 10944 | 10971 | return ira->codegen->builtin_types.entry_invalid; |
| 10945 | 10972 | return get_error_union_type(ira->codegen, err_set_type, payload_type); |
| ... | ... | @@ -10949,44 +10976,44 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT |
| 10949 | 10976 | return ira->codegen->builtin_types.entry_invalid; |
| 10950 | 10977 | return get_error_union_type(ira->codegen, err_set_type, payload_type); |
| 10951 | 10978 | } else { |
| 10952 | | if (prev_inst->value.type->id == ZigTypeIdComptimeInt || |
| 10953 | | prev_inst->value.type->id == ZigTypeIdComptimeFloat) |
| 10979 | if (prev_inst->value->type->id == ZigTypeIdComptimeInt || |
| 10980 | prev_inst->value->type->id == ZigTypeIdComptimeFloat) |
| 10954 | 10981 | { |
| 10955 | 10982 | ir_add_error_node(ira, source_node, |
| 10956 | 10983 | buf_sprintf("unable to make error union out of number literal")); |
| 10957 | 10984 | return ira->codegen->builtin_types.entry_invalid; |
| 10958 | | } else if (prev_inst->value.type->id == ZigTypeIdNull) { |
| 10985 | } else if (prev_inst->value->type->id == ZigTypeIdNull) { |
| 10959 | 10986 | ir_add_error_node(ira, source_node, |
| 10960 | 10987 | buf_sprintf("unable to make error union out of null literal")); |
| 10961 | 10988 | return ira->codegen->builtin_types.entry_invalid; |
| 10962 | 10989 | } else { |
| 10963 | | if ((err = type_resolve(ira->codegen, prev_inst->value.type, ResolveStatusSizeKnown))) |
| 10990 | if ((err = type_resolve(ira->codegen, prev_inst->value->type, ResolveStatusSizeKnown))) |
| 10964 | 10991 | return ira->codegen->builtin_types.entry_invalid; |
| 10965 | | return get_error_union_type(ira->codegen, err_set_type, prev_inst->value.type); |
| 10992 | return get_error_union_type(ira->codegen, err_set_type, prev_inst->value->type); |
| 10966 | 10993 | } |
| 10967 | 10994 | } |
| 10968 | | } else if (any_are_null && prev_inst->value.type->id != ZigTypeIdNull) { |
| 10969 | | if (prev_inst->value.type->id == ZigTypeIdComptimeInt || |
| 10970 | | prev_inst->value.type->id == ZigTypeIdComptimeFloat) |
| 10995 | } else if (any_are_null && prev_inst->value->type->id != ZigTypeIdNull) { |
| 10996 | if (prev_inst->value->type->id == ZigTypeIdComptimeInt || |
| 10997 | prev_inst->value->type->id == ZigTypeIdComptimeFloat) |
| 10971 | 10998 | { |
| 10972 | 10999 | ir_add_error_node(ira, source_node, |
| 10973 | 11000 | buf_sprintf("unable to make maybe out of number literal")); |
| 10974 | 11001 | return ira->codegen->builtin_types.entry_invalid; |
| 10975 | | } else if (prev_inst->value.type->id == ZigTypeIdOptional) { |
| 10976 | | return prev_inst->value.type; |
| 11002 | } else if (prev_inst->value->type->id == ZigTypeIdOptional) { |
| 11003 | return prev_inst->value->type; |
| 10977 | 11004 | } else { |
| 10978 | | if ((err = type_resolve(ira->codegen, prev_inst->value.type, ResolveStatusSizeKnown))) |
| 11005 | if ((err = type_resolve(ira->codegen, prev_inst->value->type, ResolveStatusSizeKnown))) |
| 10979 | 11006 | return ira->codegen->builtin_types.entry_invalid; |
| 10980 | | return get_optional_type(ira->codegen, prev_inst->value.type); |
| 11007 | return get_optional_type(ira->codegen, prev_inst->value->type); |
| 10981 | 11008 | } |
| 10982 | 11009 | } else { |
| 10983 | | return prev_inst->value.type; |
| 11010 | return prev_inst->value->type; |
| 10984 | 11011 | } |
| 10985 | 11012 | } |
| 10986 | 11013 | |
| 10987 | | static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_global_refs) { |
| 11014 | static void copy_const_val(ZigValue *dest, ZigValue *src, bool same_global_refs) { |
| 10988 | 11015 | ConstGlobalRefs *global_refs = dest->global_refs; |
| 10989 | | memcpy(dest, src, sizeof(ConstExprValue)); |
| 11016 | memcpy(dest, src, sizeof(ZigValue)); |
| 10990 | 11017 | if (!same_global_refs) { |
| 10991 | 11018 | dest->global_refs = global_refs; |
| 10992 | 11019 | if (src->special != ConstValSpecialStatic) |
| ... | ... | @@ -11002,8 +11029,8 @@ static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_ |
| 11002 | 11029 | |
| 11003 | 11030 | static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_instr, |
| 11004 | 11031 | CastOp cast_op, |
| 11005 | | ConstExprValue *other_val, ZigType *other_type, |
| 11006 | | ConstExprValue *const_val, ZigType *new_type) |
| 11032 | ZigValue *other_val, ZigType *other_type, |
| 11033 | ZigValue *const_val, ZigType *new_type) |
| 11007 | 11034 | { |
| 11008 | 11035 | const_val->special = other_val->special; |
| 11009 | 11036 | |
| ... | ... | @@ -11106,25 +11133,31 @@ static IrInstruction *ir_const(IrAnalyze *ira, IrInstruction *old_instruction, Z |
| 11106 | 11133 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, |
| 11107 | 11134 | old_instruction->scope, old_instruction->source_node); |
| 11108 | 11135 | IrInstruction *new_instruction = &const_instruction->base; |
| 11109 | | new_instruction->value.type = ty; |
| 11110 | | new_instruction->value.special = ConstValSpecialStatic; |
| 11136 | new_instruction->value->type = ty; |
| 11137 | new_instruction->value->special = ConstValSpecialStatic; |
| 11111 | 11138 | return new_instruction; |
| 11112 | 11139 | } |
| 11113 | 11140 | |
| 11141 | static IrInstruction *ir_const_noval(IrAnalyze *ira, IrInstruction *old_instruction) { |
| 11142 | IrInstructionConst *const_instruction = ir_create_instruction_noval<IrInstructionConst>(&ira->new_irb, |
| 11143 | old_instruction->scope, old_instruction->source_node); |
| 11144 | return &const_instruction->base; |
| 11145 | } |
| 11146 | |
| 11114 | 11147 | static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, |
| 11115 | 11148 | ZigType *wanted_type, CastOp cast_op) |
| 11116 | 11149 | { |
| 11117 | 11150 | if (instr_is_comptime(value) || !type_has_bits(wanted_type)) { |
| 11118 | 11151 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 11119 | | if (!eval_const_expr_implicit_cast(ira, source_instr, cast_op, &value->value, value->value.type, |
| 11120 | | &result->value, wanted_type)) |
| 11152 | if (!eval_const_expr_implicit_cast(ira, source_instr, cast_op, value->value, value->value->type, |
| 11153 | result->value, wanted_type)) |
| 11121 | 11154 | { |
| 11122 | 11155 | return ira->codegen->invalid_instruction; |
| 11123 | 11156 | } |
| 11124 | 11157 | return result; |
| 11125 | 11158 | } else { |
| 11126 | 11159 | IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type, value, cast_op); |
| 11127 | | result->value.type = wanted_type; |
| 11160 | result->value->type = wanted_type; |
| 11128 | 11161 | return result; |
| 11129 | 11162 | } |
| 11130 | 11163 | } |
| ... | ... | @@ -11132,35 +11165,35 @@ static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 11132 | 11165 | static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrInstruction *source_instr, |
| 11133 | 11166 | IrInstruction *value, ZigType *wanted_type) |
| 11134 | 11167 | { |
| 11135 | | assert(value->value.type->id == ZigTypeIdPointer); |
| 11168 | assert(value->value->type->id == ZigTypeIdPointer); |
| 11136 | 11169 | |
| 11137 | 11170 | Error err; |
| 11138 | 11171 | |
| 11139 | | if ((err = type_resolve(ira->codegen, value->value.type->data.pointer.child_type, |
| 11172 | if ((err = type_resolve(ira->codegen, value->value->type->data.pointer.child_type, |
| 11140 | 11173 | ResolveStatusAlignmentKnown))) |
| 11141 | 11174 | { |
| 11142 | 11175 | return ira->codegen->invalid_instruction; |
| 11143 | 11176 | } |
| 11144 | 11177 | |
| 11145 | | wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, value->value.type)); |
| 11178 | wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, value->value->type)); |
| 11146 | 11179 | |
| 11147 | 11180 | if (instr_is_comptime(value)) { |
| 11148 | | ConstExprValue *pointee = const_ptr_pointee(ira, ira->codegen, &value->value, source_instr->source_node); |
| 11181 | ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, value->value, source_instr->source_node); |
| 11149 | 11182 | if (pointee == nullptr) |
| 11150 | 11183 | return ira->codegen->invalid_instruction; |
| 11151 | 11184 | if (pointee->special != ConstValSpecialRuntime) { |
| 11152 | 11185 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 11153 | | result->value.data.x_ptr.special = ConstPtrSpecialBaseArray; |
| 11154 | | result->value.data.x_ptr.mut = value->value.data.x_ptr.mut; |
| 11155 | | result->value.data.x_ptr.data.base_array.array_val = pointee; |
| 11156 | | result->value.data.x_ptr.data.base_array.elem_index = 0; |
| 11186 | result->value->data.x_ptr.special = ConstPtrSpecialBaseArray; |
| 11187 | result->value->data.x_ptr.mut = value->value->data.x_ptr.mut; |
| 11188 | result->value->data.x_ptr.data.base_array.array_val = pointee; |
| 11189 | result->value->data.x_ptr.data.base_array.elem_index = 0; |
| 11157 | 11190 | return result; |
| 11158 | 11191 | } |
| 11159 | 11192 | } |
| 11160 | 11193 | |
| 11161 | 11194 | IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, |
| 11162 | 11195 | wanted_type, value, CastOpBitCast); |
| 11163 | | result->value.type = wanted_type; |
| 11196 | result->value->type = wanted_type; |
| 11164 | 11197 | return result; |
| 11165 | 11198 | } |
| 11166 | 11199 | |
| ... | ... | @@ -11169,28 +11202,28 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc |
| 11169 | 11202 | { |
| 11170 | 11203 | Error err; |
| 11171 | 11204 | |
| 11172 | | if ((err = type_resolve(ira->codegen, array_ptr->value.type->data.pointer.child_type, |
| 11205 | if ((err = type_resolve(ira->codegen, array_ptr->value->type->data.pointer.child_type, |
| 11173 | 11206 | ResolveStatusAlignmentKnown))) |
| 11174 | 11207 | { |
| 11175 | 11208 | return ira->codegen->invalid_instruction; |
| 11176 | 11209 | } |
| 11177 | 11210 | |
| 11178 | | wanted_type = adjust_slice_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, array_ptr->value.type)); |
| 11211 | wanted_type = adjust_slice_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, array_ptr->value->type)); |
| 11179 | 11212 | |
| 11180 | 11213 | if (instr_is_comptime(array_ptr)) { |
| 11181 | | ConstExprValue *pointee = const_ptr_pointee(ira, ira->codegen, &array_ptr->value, source_instr->source_node); |
| 11214 | ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, array_ptr->value, source_instr->source_node); |
| 11182 | 11215 | if (pointee == nullptr) |
| 11183 | 11216 | return ira->codegen->invalid_instruction; |
| 11184 | 11217 | if (pointee->special != ConstValSpecialRuntime) { |
| 11185 | | assert(array_ptr->value.type->id == ZigTypeIdPointer); |
| 11186 | | ZigType *array_type = array_ptr->value.type->data.pointer.child_type; |
| 11218 | assert(array_ptr->value->type->id == ZigTypeIdPointer); |
| 11219 | ZigType *array_type = array_ptr->value->type->data.pointer.child_type; |
| 11187 | 11220 | assert(is_slice(wanted_type)); |
| 11188 | 11221 | bool is_const = wanted_type->data.structure.fields[slice_ptr_index]->type_entry->data.pointer.is_const; |
| 11189 | 11222 | |
| 11190 | 11223 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 11191 | | init_const_slice(ira->codegen, &result->value, pointee, 0, array_type->data.array.len, is_const); |
| 11192 | | result->value.data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = array_ptr->value.data.x_ptr.mut; |
| 11193 | | result->value.type = wanted_type; |
| 11224 | init_const_slice(ira->codegen, result->value, pointee, 0, array_type->data.array.len, is_const); |
| 11225 | result->value->data.x_struct.fields[slice_ptr_index]->data.x_ptr.mut = array_ptr->value->data.x_ptr.mut; |
| 11226 | result->value->type = wanted_type; |
| 11194 | 11227 | return result; |
| 11195 | 11228 | } |
| 11196 | 11229 | } |
| ... | ... | @@ -11198,7 +11231,7 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc |
| 11198 | 11231 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 11199 | 11232 | IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, |
| 11200 | 11233 | false, true); |
| 11201 | | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { |
| 11234 | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { |
| 11202 | 11235 | return result_loc_inst; |
| 11203 | 11236 | } |
| 11204 | 11237 | return ir_build_ptr_of_array_to_slice(ira, source_instr, wanted_type, array_ptr, result_loc_inst); |
| ... | ... | @@ -11403,53 +11436,61 @@ static IrInstruction *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instruc |
| 11403 | 11436 | } |
| 11404 | 11437 | |
| 11405 | 11438 | static IrInstruction *ir_finish_anal(IrAnalyze *ira, IrInstruction *instruction) { |
| 11406 | | if (instruction->value.type->id == ZigTypeIdUnreachable) |
| 11439 | if (instruction->value->type->id == ZigTypeIdUnreachable) |
| 11407 | 11440 | ir_finish_bb(ira); |
| 11408 | 11441 | return instruction; |
| 11409 | 11442 | } |
| 11410 | 11443 | |
| 11411 | 11444 | static IrInstruction *ir_const_type(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) { |
| 11412 | 11445 | IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_type); |
| 11413 | | result->value.data.x_type = ty; |
| 11446 | result->value->data.x_type = ty; |
| 11414 | 11447 | return result; |
| 11415 | 11448 | } |
| 11416 | 11449 | |
| 11417 | 11450 | static IrInstruction *ir_const_bool(IrAnalyze *ira, IrInstruction *source_instruction, bool value) { |
| 11418 | 11451 | IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_bool); |
| 11419 | | result->value.data.x_bool = value; |
| 11452 | result->value->data.x_bool = value; |
| 11420 | 11453 | return result; |
| 11421 | 11454 | } |
| 11422 | 11455 | |
| 11423 | 11456 | static IrInstruction *ir_const_undef(IrAnalyze *ira, IrInstruction *source_instruction, ZigType *ty) { |
| 11424 | 11457 | IrInstruction *result = ir_const(ira, source_instruction, ty); |
| 11425 | | result->value.special = ConstValSpecialUndef; |
| 11458 | result->value->special = ConstValSpecialUndef; |
| 11426 | 11459 | return result; |
| 11427 | 11460 | } |
| 11428 | 11461 | |
| 11429 | 11462 | static IrInstruction *ir_const_unreachable(IrAnalyze *ira, IrInstruction *source_instruction) { |
| 11430 | | IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_unreachable); |
| 11431 | | result->value.special = ConstValSpecialStatic; |
| 11463 | #ifdef ZIG_ENABLE_MEM_PROFILE |
| 11464 | memprof_intern_count.x_unreachable += 1; |
| 11465 | #endif |
| 11466 | IrInstruction *result = ir_const_noval(ira, source_instruction); |
| 11467 | result->value = &ira->codegen->intern_values.x_unreachable; |
| 11432 | 11468 | return result; |
| 11433 | 11469 | } |
| 11434 | 11470 | |
| 11435 | 11471 | static IrInstruction *ir_const_void(IrAnalyze *ira, IrInstruction *source_instruction) { |
| 11436 | | return ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_void); |
| 11472 | #ifdef ZIG_ENABLE_MEM_PROFILE |
| 11473 | memprof_intern_count.x_void += 1; |
| 11474 | #endif |
| 11475 | IrInstruction *result = ir_const_noval(ira, source_instruction); |
| 11476 | result->value = &ira->codegen->intern_values.x_void; |
| 11477 | return result; |
| 11437 | 11478 | } |
| 11438 | 11479 | |
| 11439 | 11480 | static IrInstruction *ir_const_unsigned(IrAnalyze *ira, IrInstruction *source_instruction, uint64_t value) { |
| 11440 | 11481 | IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_num_lit_int); |
| 11441 | | bigint_init_unsigned(&result->value.data.x_bigint, value); |
| 11482 | bigint_init_unsigned(&result->value->data.x_bigint, value); |
| 11442 | 11483 | return result; |
| 11443 | 11484 | } |
| 11444 | 11485 | |
| 11445 | 11486 | static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 11446 | | ConstExprValue *pointee, ZigType *pointee_type, |
| 11487 | ZigValue *pointee, ZigType *pointee_type, |
| 11447 | 11488 | ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align) |
| 11448 | 11489 | { |
| 11449 | 11490 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type, |
| 11450 | 11491 | ptr_is_const, ptr_is_volatile, PtrLenSingle, ptr_align, 0, 0, false); |
| 11451 | 11492 | IrInstruction *const_instr = ir_const(ira, instruction, ptr_type); |
| 11452 | | ConstExprValue *const_val = &const_instr->value; |
| 11493 | ZigValue *const_val = const_instr->value; |
| 11453 | 11494 | const_val->data.x_ptr.special = ConstPtrSpecialRef; |
| 11454 | 11495 | const_val->data.x_ptr.mut = ptr_mut; |
| 11455 | 11496 | const_val->data.x_ptr.data.ref.pointee = pointee; |
| ... | ... | @@ -11457,7 +11498,7 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio |
| 11457 | 11498 | } |
| 11458 | 11499 | |
| 11459 | 11500 | static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, |
| 11460 | | ConstExprValue *val, UndefAllowed undef_allowed) |
| 11501 | ZigValue *val, UndefAllowed undef_allowed) |
| 11461 | 11502 | { |
| 11462 | 11503 | Error err; |
| 11463 | 11504 | for (;;) { |
| ... | ... | @@ -11490,17 +11531,17 @@ static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode |
| 11490 | 11531 | } |
| 11491 | 11532 | } |
| 11492 | 11533 | |
| 11493 | | static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed) { |
| 11534 | static ZigValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed) { |
| 11494 | 11535 | Error err; |
| 11495 | 11536 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, value->source_node, |
| 11496 | | &value->value, undef_allowed))) |
| 11537 | value->value, undef_allowed))) |
| 11497 | 11538 | { |
| 11498 | 11539 | return nullptr; |
| 11499 | 11540 | } |
| 11500 | | return &value->value; |
| 11541 | return value->value; |
| 11501 | 11542 | } |
| 11502 | 11543 | |
| 11503 | | ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, |
| 11544 | ZigValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, |
| 11504 | 11545 | ZigType *expected_type, size_t *backward_branch_count, size_t *backward_branch_quota, |
| 11505 | 11546 | ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name, |
| 11506 | 11547 | IrExecutable *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef_allowed) |
| ... | ... | @@ -11508,7 +11549,7 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod |
| 11508 | 11549 | Error err; |
| 11509 | 11550 | |
| 11510 | 11551 | if (expected_type != nullptr && type_is_invalid(expected_type)) |
| 11511 | | return &codegen->invalid_instruction->value; |
| 11552 | return codegen->invalid_instruction->value; |
| 11512 | 11553 | |
| 11513 | 11554 | IrExecutable *ir_executable = allocate<IrExecutable>(1); |
| 11514 | 11555 | ir_executable->source_node = source_node; |
| ... | ... | @@ -11522,7 +11563,7 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod |
| 11522 | 11563 | |
| 11523 | 11564 | if (ir_executable->first_err_trace_msg != nullptr) { |
| 11524 | 11565 | codegen->trace_err = ir_executable->first_err_trace_msg; |
| 11525 | | return &codegen->invalid_instruction->value; |
| 11566 | return codegen->invalid_instruction->value; |
| 11526 | 11567 | } |
| 11527 | 11568 | |
| 11528 | 11569 | if (codegen->verbose_ir) { |
| ... | ... | @@ -11545,7 +11586,7 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod |
| 11545 | 11586 | analyzed_executable->begin_scope = scope; |
| 11546 | 11587 | ZigType *result_type = ir_analyze(codegen, ir_executable, analyzed_executable, expected_type, expected_type_source_node); |
| 11547 | 11588 | if (type_is_invalid(result_type)) { |
| 11548 | | return &codegen->invalid_instruction->value; |
| 11589 | return codegen->invalid_instruction->value; |
| 11549 | 11590 | } |
| 11550 | 11591 | |
| 11551 | 11592 | if (codegen->verbose_ir) { |
| ... | ... | @@ -11554,27 +11595,27 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod |
| 11554 | 11595 | fprintf(stderr, "}\n"); |
| 11555 | 11596 | } |
| 11556 | 11597 | |
| 11557 | | ConstExprValue *result = ir_exec_const_result(codegen, analyzed_executable); |
| 11598 | ZigValue *result = ir_exec_const_result(codegen, analyzed_executable); |
| 11558 | 11599 | if (type_is_invalid(result->type)) |
| 11559 | | return &codegen->invalid_instruction->value; |
| 11600 | return codegen->invalid_instruction->value; |
| 11560 | 11601 | |
| 11561 | 11602 | if ((err = ir_resolve_const_val(codegen, analyzed_executable, node, result, undef_allowed))) |
| 11562 | | return &codegen->invalid_instruction->value; |
| 11603 | return codegen->invalid_instruction->value; |
| 11563 | 11604 | |
| 11564 | 11605 | return result; |
| 11565 | 11606 | } |
| 11566 | 11607 | |
| 11567 | 11608 | static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstruction *err_value) { |
| 11568 | | if (type_is_invalid(err_value->value.type)) |
| 11609 | if (type_is_invalid(err_value->value->type)) |
| 11569 | 11610 | return nullptr; |
| 11570 | 11611 | |
| 11571 | | if (err_value->value.type->id != ZigTypeIdErrorSet) { |
| 11612 | if (err_value->value->type->id != ZigTypeIdErrorSet) { |
| 11572 | 11613 | ir_add_error(ira, err_value, |
| 11573 | | buf_sprintf("expected error, found '%s'", buf_ptr(&err_value->value.type->name))); |
| 11614 | buf_sprintf("expected error, found '%s'", buf_ptr(&err_value->value->type->name))); |
| 11574 | 11615 | return nullptr; |
| 11575 | 11616 | } |
| 11576 | 11617 | |
| 11577 | | ConstExprValue *const_val = ir_resolve_const(ira, err_value, UndefBad); |
| 11618 | ZigValue *const_val = ir_resolve_const(ira, err_value, UndefBad); |
| 11578 | 11619 | if (!const_val) |
| 11579 | 11620 | return nullptr; |
| 11580 | 11621 | |
| ... | ... | @@ -11583,7 +11624,7 @@ static ErrorTableEntry *ir_resolve_error(IrAnalyze *ira, IrInstruction *err_valu |
| 11583 | 11624 | } |
| 11584 | 11625 | |
| 11585 | 11626 | static ZigType *ir_resolve_const_type(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, |
| 11586 | | ConstExprValue *val) |
| 11627 | ZigValue *val) |
| 11587 | 11628 | { |
| 11588 | 11629 | Error err; |
| 11589 | 11630 | if ((err = ir_resolve_const_val(codegen, exec, source_node, val, UndefBad))) |
| ... | ... | @@ -11593,28 +11634,28 @@ static ZigType *ir_resolve_const_type(CodeGen *codegen, IrExecutable *exec, AstN |
| 11593 | 11634 | return val->data.x_type; |
| 11594 | 11635 | } |
| 11595 | 11636 | |
| 11596 | | static ConstExprValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstruction *type_value) { |
| 11597 | | if (type_is_invalid(type_value->value.type)) |
| 11637 | static ZigValue *ir_resolve_type_lazy(IrAnalyze *ira, IrInstruction *type_value) { |
| 11638 | if (type_is_invalid(type_value->value->type)) |
| 11598 | 11639 | return nullptr; |
| 11599 | 11640 | |
| 11600 | | if (type_value->value.type->id != ZigTypeIdMetaType) { |
| 11641 | if (type_value->value->type->id != ZigTypeIdMetaType) { |
| 11601 | 11642 | ir_add_error(ira, type_value, |
| 11602 | | buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value.type->name))); |
| 11643 | buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value->type->name))); |
| 11603 | 11644 | return nullptr; |
| 11604 | 11645 | } |
| 11605 | 11646 | |
| 11606 | 11647 | Error err; |
| 11607 | 11648 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, type_value->source_node, |
| 11608 | | &type_value->value, LazyOk))) |
| 11649 | type_value->value, LazyOk))) |
| 11609 | 11650 | { |
| 11610 | 11651 | return nullptr; |
| 11611 | 11652 | } |
| 11612 | 11653 | |
| 11613 | | return &type_value->value; |
| 11654 | return type_value->value; |
| 11614 | 11655 | } |
| 11615 | 11656 | |
| 11616 | 11657 | static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) { |
| 11617 | | ConstExprValue *val = ir_resolve_type_lazy(ira, type_value); |
| 11658 | ZigValue *val = ir_resolve_type_lazy(ira, type_value); |
| 11618 | 11659 | if (val == nullptr) |
| 11619 | 11660 | return ira->codegen->builtin_types.entry_invalid; |
| 11620 | 11661 | |
| ... | ... | @@ -11663,18 +11704,18 @@ static ZigType *ir_resolve_int_type(IrAnalyze *ira, IrInstruction *type_value) { |
| 11663 | 11704 | } |
| 11664 | 11705 | |
| 11665 | 11706 | static ZigType *ir_resolve_error_set_type(IrAnalyze *ira, IrInstruction *op_source, IrInstruction *type_value) { |
| 11666 | | if (type_is_invalid(type_value->value.type)) |
| 11707 | if (type_is_invalid(type_value->value->type)) |
| 11667 | 11708 | return ira->codegen->builtin_types.entry_invalid; |
| 11668 | 11709 | |
| 11669 | | if (type_value->value.type->id != ZigTypeIdMetaType) { |
| 11710 | if (type_value->value->type->id != ZigTypeIdMetaType) { |
| 11670 | 11711 | ErrorMsg *msg = ir_add_error(ira, type_value, |
| 11671 | | buf_sprintf("expected error set type, found '%s'", buf_ptr(&type_value->value.type->name))); |
| 11712 | buf_sprintf("expected error set type, found '%s'", buf_ptr(&type_value->value->type->name))); |
| 11672 | 11713 | add_error_note(ira->codegen, msg, op_source->source_node, |
| 11673 | 11714 | buf_sprintf("`||` merges error sets; `or` performs boolean OR")); |
| 11674 | 11715 | return ira->codegen->builtin_types.entry_invalid; |
| 11675 | 11716 | } |
| 11676 | 11717 | |
| 11677 | | ConstExprValue *const_val = ir_resolve_const(ira, type_value, UndefBad); |
| 11718 | ZigValue *const_val = ir_resolve_const(ira, type_value, UndefBad); |
| 11678 | 11719 | if (!const_val) |
| 11679 | 11720 | return ira->codegen->builtin_types.entry_invalid; |
| 11680 | 11721 | |
| ... | ... | @@ -11694,16 +11735,16 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) { |
| 11694 | 11735 | if (fn_value == ira->codegen->invalid_instruction) |
| 11695 | 11736 | return nullptr; |
| 11696 | 11737 | |
| 11697 | | if (type_is_invalid(fn_value->value.type)) |
| 11738 | if (type_is_invalid(fn_value->value->type)) |
| 11698 | 11739 | return nullptr; |
| 11699 | 11740 | |
| 11700 | | if (fn_value->value.type->id != ZigTypeIdFn) { |
| 11741 | if (fn_value->value->type->id != ZigTypeIdFn) { |
| 11701 | 11742 | ir_add_error_node(ira, fn_value->source_node, |
| 11702 | | buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->value.type->name))); |
| 11743 | buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->value->type->name))); |
| 11703 | 11744 | return nullptr; |
| 11704 | 11745 | } |
| 11705 | 11746 | |
| 11706 | | ConstExprValue *const_val = ir_resolve_const(ira, fn_value, UndefBad); |
| 11747 | ZigValue *const_val = ir_resolve_const(ira, fn_value, UndefBad); |
| 11707 | 11748 | if (!const_val) |
| 11708 | 11749 | return nullptr; |
| 11709 | 11750 | |
| ... | ... | @@ -11722,22 +11763,22 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so |
| 11722 | 11763 | if (instr_is_comptime(value)) { |
| 11723 | 11764 | ZigType *payload_type = wanted_type->data.maybe.child_type; |
| 11724 | 11765 | IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type); |
| 11725 | | if (type_is_invalid(casted_payload->value.type)) |
| 11766 | if (type_is_invalid(casted_payload->value->type)) |
| 11726 | 11767 | return ira->codegen->invalid_instruction; |
| 11727 | 11768 | |
| 11728 | | ConstExprValue *val = ir_resolve_const(ira, casted_payload, UndefOk); |
| 11769 | ZigValue *val = ir_resolve_const(ira, casted_payload, UndefOk); |
| 11729 | 11770 | if (!val) |
| 11730 | 11771 | return ira->codegen->invalid_instruction; |
| 11731 | 11772 | |
| 11732 | 11773 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, |
| 11733 | 11774 | source_instr->scope, source_instr->source_node); |
| 11734 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 11775 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 11735 | 11776 | if (types_have_same_zig_comptime_repr(ira->codegen, wanted_type, payload_type)) { |
| 11736 | | copy_const_val(&const_instruction->base.value, val, val->data.x_ptr.mut == ConstPtrMutComptimeConst); |
| 11777 | copy_const_val(const_instruction->base.value, val, val->data.x_ptr.mut == ConstPtrMutComptimeConst); |
| 11737 | 11778 | } else { |
| 11738 | | const_instruction->base.value.data.x_optional = val; |
| 11779 | const_instruction->base.value->data.x_optional = val; |
| 11739 | 11780 | } |
| 11740 | | const_instruction->base.value.type = wanted_type; |
| 11781 | const_instruction->base.value->type = wanted_type; |
| 11741 | 11782 | return &const_instruction->base; |
| 11742 | 11783 | } |
| 11743 | 11784 | |
| ... | ... | @@ -11747,12 +11788,12 @@ static IrInstruction *ir_analyze_optional_wrap(IrAnalyze *ira, IrInstruction *so |
| 11747 | 11788 | IrInstruction *result_loc_inst = nullptr; |
| 11748 | 11789 | if (result_loc != nullptr) { |
| 11749 | 11790 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true); |
| 11750 | | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { |
| 11791 | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { |
| 11751 | 11792 | return result_loc_inst; |
| 11752 | 11793 | } |
| 11753 | 11794 | } |
| 11754 | 11795 | IrInstruction *result = ir_build_optional_wrap(ira, source_instr, wanted_type, value, result_loc_inst); |
| 11755 | | result->value.data.rh_maybe = RuntimeHintOptionalNonNull; |
| 11796 | result->value->data.rh_maybe = RuntimeHintOptionalNonNull; |
| 11756 | 11797 | return result; |
| 11757 | 11798 | } |
| 11758 | 11799 | |
| ... | ... | @@ -11765,24 +11806,24 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction |
| 11765 | 11806 | ZigType *err_set_type = wanted_type->data.error_union.err_set_type; |
| 11766 | 11807 | if (instr_is_comptime(value)) { |
| 11767 | 11808 | IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type); |
| 11768 | | if (type_is_invalid(casted_payload->value.type)) |
| 11809 | if (type_is_invalid(casted_payload->value->type)) |
| 11769 | 11810 | return ira->codegen->invalid_instruction; |
| 11770 | 11811 | |
| 11771 | | ConstExprValue *val = ir_resolve_const(ira, casted_payload, UndefBad); |
| 11812 | ZigValue *val = ir_resolve_const(ira, casted_payload, UndefBad); |
| 11772 | 11813 | if (!val) |
| 11773 | 11814 | return ira->codegen->invalid_instruction; |
| 11774 | 11815 | |
| 11775 | | ConstExprValue *err_set_val = create_const_vals(1); |
| 11816 | ZigValue *err_set_val = create_const_vals(1); |
| 11776 | 11817 | err_set_val->type = err_set_type; |
| 11777 | 11818 | err_set_val->special = ConstValSpecialStatic; |
| 11778 | 11819 | err_set_val->data.x_err_set = nullptr; |
| 11779 | 11820 | |
| 11780 | 11821 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, |
| 11781 | 11822 | source_instr->scope, source_instr->source_node); |
| 11782 | | const_instruction->base.value.type = wanted_type; |
| 11783 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 11784 | | const_instruction->base.value.data.x_err_union.error_set = err_set_val; |
| 11785 | | const_instruction->base.value.data.x_err_union.payload = val; |
| 11823 | const_instruction->base.value->type = wanted_type; |
| 11824 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 11825 | const_instruction->base.value->data.x_err_union.error_set = err_set_val; |
| 11826 | const_instruction->base.value->data.x_err_union.payload = val; |
| 11786 | 11827 | return &const_instruction->base; |
| 11787 | 11828 | } |
| 11788 | 11829 | |
| ... | ... | @@ -11790,7 +11831,7 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction |
| 11790 | 11831 | if (handle_is_ptr(wanted_type)) { |
| 11791 | 11832 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 11792 | 11833 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true); |
| 11793 | | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { |
| 11834 | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { |
| 11794 | 11835 | return result_loc_inst; |
| 11795 | 11836 | } |
| 11796 | 11837 | } else { |
| ... | ... | @@ -11798,18 +11839,18 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction |
| 11798 | 11839 | } |
| 11799 | 11840 | |
| 11800 | 11841 | IrInstruction *result = ir_build_err_wrap_payload(ira, source_instr, wanted_type, value, result_loc_inst); |
| 11801 | | result->value.data.rh_error_union = RuntimeHintErrorUnionNonError; |
| 11842 | result->value->data.rh_error_union = RuntimeHintErrorUnionNonError; |
| 11802 | 11843 | return result; |
| 11803 | 11844 | } |
| 11804 | 11845 | |
| 11805 | 11846 | static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, |
| 11806 | 11847 | ZigType *wanted_type) |
| 11807 | 11848 | { |
| 11808 | | assert(value->value.type->id == ZigTypeIdErrorSet); |
| 11849 | assert(value->value->type->id == ZigTypeIdErrorSet); |
| 11809 | 11850 | assert(wanted_type->id == ZigTypeIdErrorSet); |
| 11810 | 11851 | |
| 11811 | 11852 | if (instr_is_comptime(value)) { |
| 11812 | | ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); |
| 11853 | ZigValue *val = ir_resolve_const(ira, value, UndefBad); |
| 11813 | 11854 | if (!val) |
| 11814 | 11855 | return ira->codegen->invalid_instruction; |
| 11815 | 11856 | |
| ... | ... | @@ -11834,14 +11875,14 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou |
| 11834 | 11875 | |
| 11835 | 11876 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, |
| 11836 | 11877 | source_instr->scope, source_instr->source_node); |
| 11837 | | const_instruction->base.value.type = wanted_type; |
| 11838 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 11839 | | const_instruction->base.value.data.x_err_set = val->data.x_err_set; |
| 11878 | const_instruction->base.value->type = wanted_type; |
| 11879 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 11880 | const_instruction->base.value->data.x_err_set = val->data.x_err_set; |
| 11840 | 11881 | return &const_instruction->base; |
| 11841 | 11882 | } |
| 11842 | 11883 | |
| 11843 | 11884 | IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type, value, CastOpErrSet); |
| 11844 | | result->value.type = wanted_type; |
| 11885 | result->value->type = wanted_type; |
| 11845 | 11886 | return result; |
| 11846 | 11887 | } |
| 11847 | 11888 | |
| ... | ... | @@ -11849,7 +11890,7 @@ static IrInstruction *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInstruc |
| 11849 | 11890 | IrInstruction *frame_ptr, ZigType *wanted_type) |
| 11850 | 11891 | { |
| 11851 | 11892 | if (instr_is_comptime(frame_ptr)) { |
| 11852 | | ConstExprValue *ptr_val = ir_resolve_const(ira, frame_ptr, UndefBad); |
| 11893 | ZigValue *ptr_val = ir_resolve_const(ira, frame_ptr, UndefBad); |
| 11853 | 11894 | if (ptr_val == nullptr) |
| 11854 | 11895 | return ira->codegen->invalid_instruction; |
| 11855 | 11896 | |
| ... | ... | @@ -11861,7 +11902,7 @@ static IrInstruction *ir_analyze_frame_ptr_to_anyframe(IrAnalyze *ira, IrInstruc |
| 11861 | 11902 | |
| 11862 | 11903 | IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, |
| 11863 | 11904 | wanted_type, frame_ptr, CastOpBitCast); |
| 11864 | | result->value.type = wanted_type; |
| 11905 | result->value->type = wanted_type; |
| 11865 | 11906 | return result; |
| 11866 | 11907 | } |
| 11867 | 11908 | |
| ... | ... | @@ -11874,7 +11915,7 @@ static IrInstruction *ir_analyze_anyframe_to_anyframe(IrAnalyze *ira, IrInstruct |
| 11874 | 11915 | |
| 11875 | 11916 | IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, source_instr->source_node, |
| 11876 | 11917 | wanted_type, value, CastOpBitCast); |
| 11877 | | result->value.type = wanted_type; |
| 11918 | result->value->type = wanted_type; |
| 11878 | 11919 | return result; |
| 11879 | 11920 | } |
| 11880 | 11921 | |
| ... | ... | @@ -11887,21 +11928,21 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so |
| 11887 | 11928 | IrInstruction *casted_value = ir_implicit_cast(ira, value, wanted_type->data.error_union.err_set_type); |
| 11888 | 11929 | |
| 11889 | 11930 | if (instr_is_comptime(casted_value)) { |
| 11890 | | ConstExprValue *val = ir_resolve_const(ira, casted_value, UndefBad); |
| 11931 | ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad); |
| 11891 | 11932 | if (!val) |
| 11892 | 11933 | return ira->codegen->invalid_instruction; |
| 11893 | 11934 | |
| 11894 | | ConstExprValue *err_set_val = create_const_vals(1); |
| 11935 | ZigValue *err_set_val = create_const_vals(1); |
| 11895 | 11936 | err_set_val->special = ConstValSpecialStatic; |
| 11896 | 11937 | err_set_val->type = wanted_type->data.error_union.err_set_type; |
| 11897 | 11938 | err_set_val->data.x_err_set = val->data.x_err_set; |
| 11898 | 11939 | |
| 11899 | 11940 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, |
| 11900 | 11941 | source_instr->scope, source_instr->source_node); |
| 11901 | | const_instruction->base.value.type = wanted_type; |
| 11902 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 11903 | | const_instruction->base.value.data.x_err_union.error_set = err_set_val; |
| 11904 | | const_instruction->base.value.data.x_err_union.payload = nullptr; |
| 11942 | const_instruction->base.value->type = wanted_type; |
| 11943 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 11944 | const_instruction->base.value->data.x_err_union.error_set = err_set_val; |
| 11945 | const_instruction->base.value->data.x_err_union.payload = nullptr; |
| 11905 | 11946 | return &const_instruction->base; |
| 11906 | 11947 | } |
| 11907 | 11948 | |
| ... | ... | @@ -11909,7 +11950,7 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so |
| 11909 | 11950 | if (handle_is_ptr(wanted_type)) { |
| 11910 | 11951 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 11911 | 11952 | result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, true, false, true); |
| 11912 | | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { |
| 11953 | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { |
| 11913 | 11954 | return result_loc_inst; |
| 11914 | 11955 | } |
| 11915 | 11956 | } else { |
| ... | ... | @@ -11918,7 +11959,7 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so |
| 11918 | 11959 | |
| 11919 | 11960 | |
| 11920 | 11961 | IrInstruction *result = ir_build_err_wrap_code(ira, source_instr, wanted_type, value, result_loc_inst); |
| 11921 | | result->value.data.rh_error_union = RuntimeHintErrorUnionError; |
| 11962 | result->value->data.rh_error_union = RuntimeHintErrorUnionError; |
| 11922 | 11963 | return result; |
| 11923 | 11964 | } |
| 11924 | 11965 | |
| ... | ... | @@ -11926,17 +11967,17 @@ static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *so |
| 11926 | 11967 | assert(wanted_type->id == ZigTypeIdOptional); |
| 11927 | 11968 | assert(instr_is_comptime(value)); |
| 11928 | 11969 | |
| 11929 | | ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); |
| 11970 | ZigValue *val = ir_resolve_const(ira, value, UndefBad); |
| 11930 | 11971 | assert(val != nullptr); |
| 11931 | 11972 | |
| 11932 | 11973 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 11933 | | result->value.special = ConstValSpecialStatic; |
| 11974 | result->value->special = ConstValSpecialStatic; |
| 11934 | 11975 | if (get_codegen_ptr_type(wanted_type) != nullptr) { |
| 11935 | | result->value.data.x_ptr.special = ConstPtrSpecialNull; |
| 11976 | result->value->data.x_ptr.special = ConstPtrSpecialNull; |
| 11936 | 11977 | } else if (is_opt_err_set(wanted_type)) { |
| 11937 | | result->value.data.x_err_set = nullptr; |
| 11978 | result->value->data.x_err_set = nullptr; |
| 11938 | 11979 | } else { |
| 11939 | | result->value.data.x_optional = nullptr; |
| 11980 | result->value->data.x_optional = nullptr; |
| 11940 | 11981 | } |
| 11941 | 11982 | return result; |
| 11942 | 11983 | } |
| ... | ... | @@ -11948,12 +11989,12 @@ static IrInstruction *ir_analyze_null_to_c_pointer(IrAnalyze *ira, IrInstruction |
| 11948 | 11989 | assert(wanted_type->data.pointer.ptr_len == PtrLenC); |
| 11949 | 11990 | assert(instr_is_comptime(value)); |
| 11950 | 11991 | |
| 11951 | | ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); |
| 11992 | ZigValue *val = ir_resolve_const(ira, value, UndefBad); |
| 11952 | 11993 | assert(val != nullptr); |
| 11953 | 11994 | |
| 11954 | 11995 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 11955 | | result->value.data.x_ptr.special = ConstPtrSpecialNull; |
| 11956 | | result->value.data.x_ptr.mut = ConstPtrMutComptimeConst; |
| 11996 | result->value->data.x_ptr.special = ConstPtrSpecialNull; |
| 11997 | result->value->data.x_ptr.mut = ConstPtrMutComptimeConst; |
| 11957 | 11998 | return result; |
| 11958 | 11999 | } |
| 11959 | 12000 | |
| ... | ... | @@ -11962,36 +12003,36 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi |
| 11962 | 12003 | { |
| 11963 | 12004 | Error err; |
| 11964 | 12005 | |
| 11965 | | if (type_is_invalid(value->value.type)) |
| 12006 | if (type_is_invalid(value->value->type)) |
| 11966 | 12007 | return ira->codegen->invalid_instruction; |
| 11967 | 12008 | |
| 11968 | | if ((err = type_resolve(ira->codegen, value->value.type, ResolveStatusZeroBitsKnown))) |
| 12009 | if ((err = type_resolve(ira->codegen, value->value->type, ResolveStatusZeroBitsKnown))) |
| 11969 | 12010 | return ira->codegen->invalid_instruction; |
| 11970 | 12011 | |
| 11971 | 12012 | if (instr_is_comptime(value)) { |
| 11972 | | ConstExprValue *val = ir_resolve_const(ira, value, LazyOk); |
| 12013 | ZigValue *val = ir_resolve_const(ira, value, LazyOk); |
| 11973 | 12014 | if (!val) |
| 11974 | 12015 | return ira->codegen->invalid_instruction; |
| 11975 | | return ir_get_const_ptr(ira, source_instruction, val, value->value.type, |
| 12016 | return ir_get_const_ptr(ira, source_instruction, val, value->value->type, |
| 11976 | 12017 | ConstPtrMutComptimeConst, is_const, is_volatile, 0); |
| 11977 | 12018 | } |
| 11978 | 12019 | |
| 11979 | | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value->value.type, |
| 12020 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value->value->type, |
| 11980 | 12021 | is_const, is_volatile, PtrLenSingle, 0, 0, 0, false); |
| 11981 | 12022 | |
| 11982 | 12023 | if ((err = type_resolve(ira->codegen, ptr_type, ResolveStatusZeroBitsKnown))) |
| 11983 | 12024 | return ira->codegen->invalid_instruction; |
| 11984 | 12025 | |
| 11985 | 12026 | IrInstruction *result_loc; |
| 11986 | | if (type_has_bits(ptr_type) && !handle_is_ptr(value->value.type)) { |
| 11987 | | result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), value->value.type, nullptr, true, |
| 12027 | if (type_has_bits(ptr_type) && !handle_is_ptr(value->value->type)) { |
| 12028 | result_loc = ir_resolve_result(ira, source_instruction, no_result_loc(), value->value->type, nullptr, true, |
| 11988 | 12029 | false, true); |
| 11989 | 12030 | } else { |
| 11990 | 12031 | result_loc = nullptr; |
| 11991 | 12032 | } |
| 11992 | 12033 | |
| 11993 | 12034 | IrInstruction *new_instruction = ir_build_ref_gen(ira, source_instruction, ptr_type, value, result_loc); |
| 11994 | | new_instruction->value.data.rh_ptr = RuntimeHintPtrStack; |
| 12035 | new_instruction->value->data.rh_ptr = RuntimeHintPtrStack; |
| 11995 | 12036 | return new_instruction; |
| 11996 | 12037 | } |
| 11997 | 12038 | |
| ... | ... | @@ -12004,39 +12045,39 @@ static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *s |
| 12004 | 12045 | |
| 12005 | 12046 | IrInstruction *array_ptr = nullptr; |
| 12006 | 12047 | IrInstruction *array; |
| 12007 | | if (array_arg->value.type->id == ZigTypeIdPointer) { |
| 12048 | if (array_arg->value->type->id == ZigTypeIdPointer) { |
| 12008 | 12049 | array = ir_get_deref(ira, source_instr, array_arg, nullptr); |
| 12009 | 12050 | array_ptr = array_arg; |
| 12010 | 12051 | } else { |
| 12011 | 12052 | array = array_arg; |
| 12012 | 12053 | } |
| 12013 | | ZigType *array_type = array->value.type; |
| 12054 | ZigType *array_type = array->value->type; |
| 12014 | 12055 | assert(array_type->id == ZigTypeIdArray); |
| 12015 | 12056 | |
| 12016 | 12057 | if (instr_is_comptime(array) || array_type->data.array.len == 0) { |
| 12017 | 12058 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 12018 | | init_const_slice(ira->codegen, &result->value, &array->value, 0, array_type->data.array.len, true); |
| 12019 | | result->value.type = wanted_type; |
| 12059 | init_const_slice(ira->codegen, result->value, array->value, 0, array_type->data.array.len, true); |
| 12060 | result->value->type = wanted_type; |
| 12020 | 12061 | return result; |
| 12021 | 12062 | } |
| 12022 | 12063 | |
| 12023 | 12064 | IrInstruction *start = ir_const(ira, source_instr, ira->codegen->builtin_types.entry_usize); |
| 12024 | | init_const_usize(ira->codegen, &start->value, 0); |
| 12065 | init_const_usize(ira->codegen, start->value, 0); |
| 12025 | 12066 | |
| 12026 | 12067 | IrInstruction *end = ir_const(ira, source_instr, ira->codegen->builtin_types.entry_usize); |
| 12027 | | init_const_usize(ira->codegen, &end->value, array_type->data.array.len); |
| 12068 | init_const_usize(ira->codegen, end->value, array_type->data.array.len); |
| 12028 | 12069 | |
| 12029 | 12070 | if (!array_ptr) array_ptr = ir_get_ref(ira, source_instr, array, true, false); |
| 12030 | 12071 | |
| 12031 | 12072 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 12032 | 12073 | IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, wanted_type, nullptr, |
| 12033 | 12074 | true, false, true); |
| 12034 | | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { |
| 12075 | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { |
| 12035 | 12076 | return result_loc_inst; |
| 12036 | 12077 | } |
| 12037 | 12078 | IrInstruction *result = ir_build_slice_gen(ira, source_instr, wanted_type, array_ptr, start, end, false, result_loc_inst); |
| 12038 | | result->value.data.rh_slice.id = RuntimeHintSliceIdLen; |
| 12039 | | result->value.data.rh_slice.len = array_type->data.array.len; |
| 12079 | result->value->data.rh_slice.id = RuntimeHintSliceIdLen; |
| 12080 | result->value->data.rh_slice.len = array_type->data.array.len; |
| 12040 | 12081 | |
| 12041 | 12082 | return result; |
| 12042 | 12083 | } |
| ... | ... | @@ -12065,19 +12106,19 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour |
| 12065 | 12106 | |
| 12066 | 12107 | IrInstruction *enum_target; |
| 12067 | 12108 | ZigType *enum_type; |
| 12068 | | if (target->value.type->id == ZigTypeIdUnion) { |
| 12069 | | enum_type = ir_resolve_union_tag_type(ira, target, target->value.type); |
| 12109 | if (target->value->type->id == ZigTypeIdUnion) { |
| 12110 | enum_type = ir_resolve_union_tag_type(ira, target, target->value->type); |
| 12070 | 12111 | if (type_is_invalid(enum_type)) |
| 12071 | 12112 | return ira->codegen->invalid_instruction; |
| 12072 | 12113 | enum_target = ir_implicit_cast(ira, target, enum_type); |
| 12073 | | if (type_is_invalid(enum_target->value.type)) |
| 12114 | if (type_is_invalid(enum_target->value->type)) |
| 12074 | 12115 | return ira->codegen->invalid_instruction; |
| 12075 | | } else if (target->value.type->id == ZigTypeIdEnum) { |
| 12116 | } else if (target->value->type->id == ZigTypeIdEnum) { |
| 12076 | 12117 | enum_target = target; |
| 12077 | | enum_type = target->value.type; |
| 12118 | enum_type = target->value->type; |
| 12078 | 12119 | } else { |
| 12079 | 12120 | ir_add_error(ira, target, |
| 12080 | | buf_sprintf("expected enum, found type '%s'", buf_ptr(&target->value.type->name))); |
| 12121 | buf_sprintf("expected enum, found type '%s'", buf_ptr(&target->value->type->name))); |
| 12081 | 12122 | return ira->codegen->invalid_instruction; |
| 12082 | 12123 | } |
| 12083 | 12124 | |
| ... | ... | @@ -12092,41 +12133,41 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour |
| 12092 | 12133 | enum_type->data.enumeration.src_field_count == 1) |
| 12093 | 12134 | { |
| 12094 | 12135 | IrInstruction *result = ir_const(ira, source_instr, tag_type); |
| 12095 | | init_const_bigint(&result->value, tag_type, |
| 12136 | init_const_bigint(result->value, tag_type, |
| 12096 | 12137 | &enum_type->data.enumeration.fields[0].value); |
| 12097 | 12138 | return result; |
| 12098 | 12139 | } |
| 12099 | 12140 | |
| 12100 | 12141 | if (instr_is_comptime(enum_target)) { |
| 12101 | | ConstExprValue *val = ir_resolve_const(ira, enum_target, UndefBad); |
| 12142 | ZigValue *val = ir_resolve_const(ira, enum_target, UndefBad); |
| 12102 | 12143 | if (!val) |
| 12103 | 12144 | return ira->codegen->invalid_instruction; |
| 12104 | 12145 | IrInstruction *result = ir_const(ira, source_instr, tag_type); |
| 12105 | | init_const_bigint(&result->value, tag_type, &val->data.x_enum_tag); |
| 12146 | init_const_bigint(result->value, tag_type, &val->data.x_enum_tag); |
| 12106 | 12147 | return result; |
| 12107 | 12148 | } |
| 12108 | 12149 | |
| 12109 | 12150 | IrInstruction *result = ir_build_widen_or_shorten(&ira->new_irb, source_instr->scope, |
| 12110 | 12151 | source_instr->source_node, enum_target); |
| 12111 | | result->value.type = tag_type; |
| 12152 | result->value->type = tag_type; |
| 12112 | 12153 | return result; |
| 12113 | 12154 | } |
| 12114 | 12155 | |
| 12115 | 12156 | static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *source_instr, |
| 12116 | 12157 | IrInstruction *target, ZigType *wanted_type) |
| 12117 | 12158 | { |
| 12118 | | assert(target->value.type->id == ZigTypeIdUnion); |
| 12159 | assert(target->value->type->id == ZigTypeIdUnion); |
| 12119 | 12160 | assert(wanted_type->id == ZigTypeIdEnum); |
| 12120 | | assert(wanted_type == target->value.type->data.unionation.tag_type); |
| 12161 | assert(wanted_type == target->value->type->data.unionation.tag_type); |
| 12121 | 12162 | |
| 12122 | 12163 | if (instr_is_comptime(target)) { |
| 12123 | | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); |
| 12164 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 12124 | 12165 | if (!val) |
| 12125 | 12166 | return ira->codegen->invalid_instruction; |
| 12126 | 12167 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 12127 | | result->value.special = ConstValSpecialStatic; |
| 12128 | | result->value.type = wanted_type; |
| 12129 | | bigint_init_bigint(&result->value.data.x_enum_tag, &val->data.x_union.tag); |
| 12168 | result->value->special = ConstValSpecialStatic; |
| 12169 | result->value->type = wanted_type; |
| 12170 | bigint_init_bigint(&result->value->data.x_enum_tag, &val->data.x_union.tag); |
| 12130 | 12171 | return result; |
| 12131 | 12172 | } |
| 12132 | 12173 | |
| ... | ... | @@ -12135,16 +12176,16 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou |
| 12135 | 12176 | wanted_type->data.enumeration.src_field_count == 1) |
| 12136 | 12177 | { |
| 12137 | 12178 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 12138 | | result->value.special = ConstValSpecialStatic; |
| 12139 | | result->value.type = wanted_type; |
| 12140 | | TypeEnumField *enum_field = target->value.type->data.unionation.fields[0].enum_field; |
| 12141 | | bigint_init_bigint(&result->value.data.x_enum_tag, &enum_field->value); |
| 12179 | result->value->special = ConstValSpecialStatic; |
| 12180 | result->value->type = wanted_type; |
| 12181 | TypeEnumField *enum_field = target->value->type->data.unionation.fields[0].enum_field; |
| 12182 | bigint_init_bigint(&result->value->data.x_enum_tag, &enum_field->value); |
| 12142 | 12183 | return result; |
| 12143 | 12184 | } |
| 12144 | 12185 | |
| 12145 | 12186 | IrInstruction *result = ir_build_union_tag(&ira->new_irb, source_instr->scope, |
| 12146 | 12187 | source_instr->source_node, target); |
| 12147 | | result->value.type = wanted_type; |
| 12188 | result->value->type = wanted_type; |
| 12148 | 12189 | return result; |
| 12149 | 12190 | } |
| 12150 | 12191 | |
| ... | ... | @@ -12152,7 +12193,7 @@ static IrInstruction *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInstruc |
| 12152 | 12193 | IrInstruction *target, ZigType *wanted_type) |
| 12153 | 12194 | { |
| 12154 | 12195 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 12155 | | result->value.special = ConstValSpecialUndef; |
| 12196 | result->value->special = ConstValSpecialUndef; |
| 12156 | 12197 | return result; |
| 12157 | 12198 | } |
| 12158 | 12199 | |
| ... | ... | @@ -12166,11 +12207,11 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so |
| 12166 | 12207 | return ira->codegen->invalid_instruction; |
| 12167 | 12208 | |
| 12168 | 12209 | IrInstruction *target = ir_implicit_cast(ira, uncasted_target, wanted_type->data.unionation.tag_type); |
| 12169 | | if (type_is_invalid(target->value.type)) |
| 12210 | if (type_is_invalid(target->value->type)) |
| 12170 | 12211 | return ira->codegen->invalid_instruction; |
| 12171 | 12212 | |
| 12172 | 12213 | if (instr_is_comptime(target)) { |
| 12173 | | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); |
| 12214 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 12174 | 12215 | if (!val) |
| 12175 | 12216 | return ira->codegen->invalid_instruction; |
| 12176 | 12217 | TypeUnionField *union_field = find_union_field_by_tag(wanted_type, &val->data.x_enum_tag); |
| ... | ... | @@ -12201,12 +12242,12 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so |
| 12201 | 12242 | } |
| 12202 | 12243 | |
| 12203 | 12244 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 12204 | | result->value.special = ConstValSpecialStatic; |
| 12205 | | result->value.type = wanted_type; |
| 12206 | | bigint_init_bigint(&result->value.data.x_union.tag, &val->data.x_enum_tag); |
| 12207 | | result->value.data.x_union.payload = create_const_vals(1); |
| 12208 | | result->value.data.x_union.payload->special = ConstValSpecialStatic; |
| 12209 | | result->value.data.x_union.payload->type = field_type; |
| 12245 | result->value->special = ConstValSpecialStatic; |
| 12246 | result->value->type = wanted_type; |
| 12247 | bigint_init_bigint(&result->value->data.x_union.tag, &val->data.x_enum_tag); |
| 12248 | result->value->data.x_union.payload = create_const_vals(1); |
| 12249 | result->value->data.x_union.payload->special = ConstValSpecialStatic; |
| 12250 | result->value->data.x_union.payload->type = field_type; |
| 12210 | 12251 | return result; |
| 12211 | 12252 | } |
| 12212 | 12253 | |
| ... | ... | @@ -12214,7 +12255,7 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so |
| 12214 | 12255 | // and in fact it's a noop cast because the union value is just the enum value |
| 12215 | 12256 | if (wanted_type->data.unionation.gen_field_count == 0) { |
| 12216 | 12257 | IrInstruction *result = ir_build_cast(&ira->new_irb, target->scope, target->source_node, wanted_type, target, CastOpNoop); |
| 12217 | | result->value.type = wanted_type; |
| 12258 | result->value->type = wanted_type; |
| 12218 | 12259 | return result; |
| 12219 | 12260 | } |
| 12220 | 12261 | |
| ... | ... | @@ -12245,7 +12286,7 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction |
| 12245 | 12286 | assert(wanted_type->id == ZigTypeIdInt || wanted_type->id == ZigTypeIdFloat); |
| 12246 | 12287 | |
| 12247 | 12288 | if (instr_is_comptime(target)) { |
| 12248 | | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); |
| 12289 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 12249 | 12290 | if (!val) |
| 12250 | 12291 | return ira->codegen->invalid_instruction; |
| 12251 | 12292 | if (wanted_type->id == ZigTypeIdInt) { |
| ... | ... | @@ -12259,16 +12300,16 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction |
| 12259 | 12300 | { |
| 12260 | 12301 | ir_add_error(ira, source_instr, |
| 12261 | 12302 | buf_sprintf("cast from '%s' to '%s' truncates bits", |
| 12262 | | buf_ptr(&target->value.type->name), buf_ptr(&wanted_type->name))); |
| 12303 | buf_ptr(&target->value->type->name), buf_ptr(&wanted_type->name))); |
| 12263 | 12304 | return ira->codegen->invalid_instruction; |
| 12264 | 12305 | } |
| 12265 | 12306 | } |
| 12266 | 12307 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 12267 | | result->value.type = wanted_type; |
| 12308 | result->value->type = wanted_type; |
| 12268 | 12309 | if (wanted_type->id == ZigTypeIdInt) { |
| 12269 | | bigint_init_bigint(&result->value.data.x_bigint, &val->data.x_bigint); |
| 12310 | bigint_init_bigint(&result->value->data.x_bigint, &val->data.x_bigint); |
| 12270 | 12311 | } else { |
| 12271 | | float_init_float(&result->value, val); |
| 12312 | float_init_float(result->value, val); |
| 12272 | 12313 | } |
| 12273 | 12314 | return result; |
| 12274 | 12315 | } |
| ... | ... | @@ -12278,16 +12319,16 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction |
| 12278 | 12319 | // the target is zero. |
| 12279 | 12320 | if (!type_has_bits(wanted_type)) { |
| 12280 | 12321 | assert(wanted_type->id == ZigTypeIdInt); |
| 12281 | | assert(type_has_bits(target->value.type)); |
| 12322 | assert(type_has_bits(target->value->type)); |
| 12282 | 12323 | ir_build_assert_zero(ira, source_instr, target); |
| 12283 | 12324 | IrInstruction *result = ir_const_unsigned(ira, source_instr, 0); |
| 12284 | | result->value.type = wanted_type; |
| 12325 | result->value->type = wanted_type; |
| 12285 | 12326 | return result; |
| 12286 | 12327 | } |
| 12287 | 12328 | |
| 12288 | 12329 | IrInstruction *result = ir_build_widen_or_shorten(&ira->new_irb, source_instr->scope, |
| 12289 | 12330 | source_instr->source_node, target); |
| 12290 | | result->value.type = wanted_type; |
| 12331 | result->value->type = wanted_type; |
| 12291 | 12332 | return result; |
| 12292 | 12333 | } |
| 12293 | 12334 | |
| ... | ... | @@ -12297,7 +12338,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour |
| 12297 | 12338 | Error err; |
| 12298 | 12339 | assert(wanted_type->id == ZigTypeIdEnum); |
| 12299 | 12340 | |
| 12300 | | ZigType *actual_type = target->value.type; |
| 12341 | ZigType *actual_type = target->value->type; |
| 12301 | 12342 | |
| 12302 | 12343 | if ((err = type_resolve(ira->codegen, wanted_type, ResolveStatusSizeKnown))) |
| 12303 | 12344 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -12313,7 +12354,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour |
| 12313 | 12354 | assert(actual_type->id == ZigTypeIdInt || actual_type->id == ZigTypeIdComptimeInt); |
| 12314 | 12355 | |
| 12315 | 12356 | if (instr_is_comptime(target)) { |
| 12316 | | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); |
| 12357 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 12317 | 12358 | if (!val) |
| 12318 | 12359 | return ira->codegen->invalid_instruction; |
| 12319 | 12360 | |
| ... | ... | @@ -12330,28 +12371,28 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour |
| 12330 | 12371 | } |
| 12331 | 12372 | |
| 12332 | 12373 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 12333 | | bigint_init_bigint(&result->value.data.x_enum_tag, &val->data.x_bigint); |
| 12374 | bigint_init_bigint(&result->value->data.x_enum_tag, &val->data.x_bigint); |
| 12334 | 12375 | return result; |
| 12335 | 12376 | } |
| 12336 | 12377 | |
| 12337 | 12378 | IrInstruction *result = ir_build_int_to_enum(&ira->new_irb, source_instr->scope, |
| 12338 | 12379 | source_instr->source_node, nullptr, target); |
| 12339 | | result->value.type = wanted_type; |
| 12380 | result->value->type = wanted_type; |
| 12340 | 12381 | return result; |
| 12341 | 12382 | } |
| 12342 | 12383 | |
| 12343 | 12384 | static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction *source_instr, |
| 12344 | 12385 | IrInstruction *target, ZigType *wanted_type) |
| 12345 | 12386 | { |
| 12346 | | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); |
| 12387 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 12347 | 12388 | if (!val) |
| 12348 | 12389 | return ira->codegen->invalid_instruction; |
| 12349 | 12390 | |
| 12350 | 12391 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 12351 | 12392 | if (wanted_type->id == ZigTypeIdComptimeFloat) { |
| 12352 | | float_init_float(&result->value, val); |
| 12393 | float_init_float(result->value, val); |
| 12353 | 12394 | } else if (wanted_type->id == ZigTypeIdComptimeInt) { |
| 12354 | | bigint_init_bigint(&result->value.data.x_bigint, &val->data.x_bigint); |
| 12395 | bigint_init_bigint(&result->value->data.x_bigint, &val->data.x_bigint); |
| 12355 | 12396 | } else { |
| 12356 | 12397 | zig_unreachable(); |
| 12357 | 12398 | } |
| ... | ... | @@ -12361,12 +12402,12 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction |
| 12361 | 12402 | static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target, |
| 12362 | 12403 | ZigType *wanted_type) |
| 12363 | 12404 | { |
| 12364 | | assert(target->value.type->id == ZigTypeIdInt); |
| 12365 | | assert(!target->value.type->data.integral.is_signed); |
| 12405 | assert(target->value->type->id == ZigTypeIdInt); |
| 12406 | assert(!target->value->type->data.integral.is_signed); |
| 12366 | 12407 | assert(wanted_type->id == ZigTypeIdErrorSet); |
| 12367 | 12408 | |
| 12368 | 12409 | if (instr_is_comptime(target)) { |
| 12369 | | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); |
| 12410 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 12370 | 12411 | if (!val) |
| 12371 | 12412 | return ira->codegen->invalid_instruction; |
| 12372 | 12413 | |
| ... | ... | @@ -12389,7 +12430,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc |
| 12389 | 12430 | } |
| 12390 | 12431 | |
| 12391 | 12432 | size_t index = bigint_as_usize(&val->data.x_bigint); |
| 12392 | | result->value.data.x_err_set = ira->codegen->errors_by_index.at(index); |
| 12433 | result->value->data.x_err_set = ira->codegen->errors_by_index.at(index); |
| 12393 | 12434 | return result; |
| 12394 | 12435 | } else { |
| 12395 | 12436 | ErrorTableEntry *err = nullptr; |
| ... | ... | @@ -12412,13 +12453,13 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc |
| 12412 | 12453 | return ira->codegen->invalid_instruction; |
| 12413 | 12454 | } |
| 12414 | 12455 | |
| 12415 | | result->value.data.x_err_set = err; |
| 12456 | result->value->data.x_err_set = err; |
| 12416 | 12457 | return result; |
| 12417 | 12458 | } |
| 12418 | 12459 | } |
| 12419 | 12460 | |
| 12420 | 12461 | IrInstruction *result = ir_build_int_to_err(&ira->new_irb, source_instr->scope, source_instr->source_node, target); |
| 12421 | | result->value.type = wanted_type; |
| 12462 | result->value->type = wanted_type; |
| 12422 | 12463 | return result; |
| 12423 | 12464 | } |
| 12424 | 12465 | |
| ... | ... | @@ -12427,10 +12468,10 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc |
| 12427 | 12468 | { |
| 12428 | 12469 | assert(wanted_type->id == ZigTypeIdInt); |
| 12429 | 12470 | |
| 12430 | | ZigType *err_type = target->value.type; |
| 12471 | ZigType *err_type = target->value->type; |
| 12431 | 12472 | |
| 12432 | 12473 | if (instr_is_comptime(target)) { |
| 12433 | | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); |
| 12474 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 12434 | 12475 | if (!val) |
| 12435 | 12476 | return ira->codegen->invalid_instruction; |
| 12436 | 12477 | |
| ... | ... | @@ -12444,11 +12485,11 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc |
| 12444 | 12485 | } else { |
| 12445 | 12486 | zig_unreachable(); |
| 12446 | 12487 | } |
| 12447 | | result->value.type = wanted_type; |
| 12488 | result->value->type = wanted_type; |
| 12448 | 12489 | uint64_t err_value = err ? err->value : 0; |
| 12449 | | bigint_init_unsigned(&result->value.data.x_bigint, err_value); |
| 12490 | bigint_init_unsigned(&result->value->data.x_bigint, err_value); |
| 12450 | 12491 | |
| 12451 | | if (!bigint_fits_in_bits(&result->value.data.x_bigint, |
| 12492 | if (!bigint_fits_in_bits(&result->value->data.x_bigint, |
| 12452 | 12493 | wanted_type->data.integral.bit_count, wanted_type->data.integral.is_signed)) |
| 12453 | 12494 | { |
| 12454 | 12495 | ir_add_error_node(ira, source_instr->source_node, |
| ... | ... | @@ -12474,12 +12515,12 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc |
| 12474 | 12515 | } |
| 12475 | 12516 | if (err_set_type->data.error_set.err_count == 0) { |
| 12476 | 12517 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 12477 | | bigint_init_unsigned(&result->value.data.x_bigint, 0); |
| 12518 | bigint_init_unsigned(&result->value->data.x_bigint, 0); |
| 12478 | 12519 | return result; |
| 12479 | 12520 | } else if (err_set_type->data.error_set.err_count == 1) { |
| 12480 | 12521 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 12481 | 12522 | ErrorTableEntry *err = err_set_type->data.error_set.errors[0]; |
| 12482 | | bigint_init_unsigned(&result->value.data.x_bigint, err->value); |
| 12523 | bigint_init_unsigned(&result->value->data.x_bigint, err->value); |
| 12483 | 12524 | return result; |
| 12484 | 12525 | } |
| 12485 | 12526 | } |
| ... | ... | @@ -12493,7 +12534,7 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc |
| 12493 | 12534 | } |
| 12494 | 12535 | |
| 12495 | 12536 | IrInstruction *result = ir_build_err_to_int(&ira->new_irb, source_instr->scope, source_instr->source_node, target); |
| 12496 | | result->value.type = wanted_type; |
| 12537 | result->value->type = wanted_type; |
| 12497 | 12538 | return result; |
| 12498 | 12539 | } |
| 12499 | 12540 | |
| ... | ... | @@ -12502,25 +12543,25 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou |
| 12502 | 12543 | { |
| 12503 | 12544 | assert(wanted_type->id == ZigTypeIdPointer); |
| 12504 | 12545 | Error err; |
| 12505 | | if ((err = type_resolve(ira->codegen, target->value.type->data.pointer.child_type, ResolveStatusAlignmentKnown))) |
| 12546 | if ((err = type_resolve(ira->codegen, target->value->type->data.pointer.child_type, ResolveStatusAlignmentKnown))) |
| 12506 | 12547 | return ira->codegen->invalid_instruction; |
| 12507 | | assert((wanted_type->data.pointer.is_const && target->value.type->data.pointer.is_const) || !target->value.type->data.pointer.is_const); |
| 12508 | | wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, target->value.type)); |
| 12548 | assert((wanted_type->data.pointer.is_const && target->value->type->data.pointer.is_const) || !target->value->type->data.pointer.is_const); |
| 12549 | wanted_type = adjust_ptr_align(ira->codegen, wanted_type, get_ptr_align(ira->codegen, target->value->type)); |
| 12509 | 12550 | ZigType *array_type = wanted_type->data.pointer.child_type; |
| 12510 | 12551 | assert(array_type->id == ZigTypeIdArray); |
| 12511 | 12552 | assert(array_type->data.array.len == 1); |
| 12512 | 12553 | |
| 12513 | 12554 | if (instr_is_comptime(target)) { |
| 12514 | | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); |
| 12555 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 12515 | 12556 | if (!val) |
| 12516 | 12557 | return ira->codegen->invalid_instruction; |
| 12517 | 12558 | |
| 12518 | 12559 | assert(val->type->id == ZigTypeIdPointer); |
| 12519 | | ConstExprValue *pointee = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node); |
| 12560 | ZigValue *pointee = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node); |
| 12520 | 12561 | if (pointee == nullptr) |
| 12521 | 12562 | return ira->codegen->invalid_instruction; |
| 12522 | 12563 | if (pointee->special != ConstValSpecialRuntime) { |
| 12523 | | ConstExprValue *array_val = create_const_vals(1); |
| 12564 | ZigValue *array_val = create_const_vals(1); |
| 12524 | 12565 | array_val->special = ConstValSpecialStatic; |
| 12525 | 12566 | array_val->type = array_type; |
| 12526 | 12567 | array_val->data.x_array.special = ConstArraySpecialNone; |
| ... | ... | @@ -12530,11 +12571,11 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou |
| 12530 | 12571 | |
| 12531 | 12572 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, |
| 12532 | 12573 | source_instr->scope, source_instr->source_node); |
| 12533 | | const_instruction->base.value.type = wanted_type; |
| 12534 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 12535 | | const_instruction->base.value.data.x_ptr.special = ConstPtrSpecialRef; |
| 12536 | | const_instruction->base.value.data.x_ptr.data.ref.pointee = array_val; |
| 12537 | | const_instruction->base.value.data.x_ptr.mut = val->data.x_ptr.mut; |
| 12574 | const_instruction->base.value->type = wanted_type; |
| 12575 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 12576 | const_instruction->base.value->data.x_ptr.special = ConstPtrSpecialRef; |
| 12577 | const_instruction->base.value->data.x_ptr.data.ref.pointee = array_val; |
| 12578 | const_instruction->base.value->data.x_ptr.mut = val->data.x_ptr.mut; |
| 12538 | 12579 | return &const_instruction->base; |
| 12539 | 12580 | } |
| 12540 | 12581 | } |
| ... | ... | @@ -12542,7 +12583,7 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou |
| 12542 | 12583 | // pointer to array and pointer to single item are represented the same way at runtime |
| 12543 | 12584 | IrInstruction *result = ir_build_cast(&ira->new_irb, target->scope, target->source_node, |
| 12544 | 12585 | wanted_type, target, CastOpBitCast); |
| 12545 | | result->value.type = wanted_type; |
| 12586 | result->value->type = wanted_type; |
| 12546 | 12587 | return result; |
| 12547 | 12588 | } |
| 12548 | 12589 | |
| ... | ... | @@ -12724,10 +12765,10 @@ static IrInstruction *ir_analyze_array_to_vector(IrAnalyze *ira, IrInstruction * |
| 12724 | 12765 | IrInstruction *array, ZigType *vector_type) |
| 12725 | 12766 | { |
| 12726 | 12767 | if (instr_is_comptime(array)) { |
| 12727 | | // arrays and vectors have the same ConstExprValue representation |
| 12768 | // arrays and vectors have the same ZigValue representation |
| 12728 | 12769 | IrInstruction *result = ir_const(ira, source_instr, vector_type); |
| 12729 | | copy_const_val(&result->value, &array->value, false); |
| 12730 | | result->value.type = vector_type; |
| 12770 | copy_const_val(result->value, array->value, false); |
| 12771 | result->value->type = vector_type; |
| 12731 | 12772 | return result; |
| 12732 | 12773 | } |
| 12733 | 12774 | return ir_build_array_to_vector(ira, source_instr, array, vector_type); |
| ... | ... | @@ -12737,10 +12778,10 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction * |
| 12737 | 12778 | IrInstruction *vector, ZigType *array_type, ResultLoc *result_loc) |
| 12738 | 12779 | { |
| 12739 | 12780 | if (instr_is_comptime(vector)) { |
| 12740 | | // arrays and vectors have the same ConstExprValue representation |
| 12781 | // arrays and vectors have the same ZigValue representation |
| 12741 | 12782 | IrInstruction *result = ir_const(ira, source_instr, array_type); |
| 12742 | | copy_const_val(&result->value, &vector->value, false); |
| 12743 | | result->value.type = array_type; |
| 12783 | copy_const_val(result->value, vector->value, false); |
| 12784 | result->value->type = array_type; |
| 12744 | 12785 | return result; |
| 12745 | 12786 | } |
| 12746 | 12787 | if (result_loc == nullptr) { |
| ... | ... | @@ -12748,7 +12789,7 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction * |
| 12748 | 12789 | } |
| 12749 | 12790 | IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, array_type, nullptr, |
| 12750 | 12791 | true, false, true); |
| 12751 | | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { |
| 12792 | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { |
| 12752 | 12793 | return result_loc_inst; |
| 12753 | 12794 | } |
| 12754 | 12795 | return ir_build_vector_to_array(ira, source_instr, array_type, vector, result_loc_inst); |
| ... | ... | @@ -12761,23 +12802,23 @@ static IrInstruction *ir_analyze_int_to_c_ptr(IrAnalyze *ira, IrInstruction *sou |
| 12761 | 12802 | if (instr_is_comptime(integer)) { |
| 12762 | 12803 | unsigned_integer = integer; |
| 12763 | 12804 | } else { |
| 12764 | | assert(integer->value.type->id == ZigTypeIdInt); |
| 12805 | assert(integer->value->type->id == ZigTypeIdInt); |
| 12765 | 12806 | |
| 12766 | | if (integer->value.type->data.integral.bit_count > |
| 12807 | if (integer->value->type->data.integral.bit_count > |
| 12767 | 12808 | ira->codegen->builtin_types.entry_usize->data.integral.bit_count) |
| 12768 | 12809 | { |
| 12769 | 12810 | ir_add_error(ira, source_instr, |
| 12770 | 12811 | buf_sprintf("integer type '%s' too big for implicit @intToPtr to type '%s'", |
| 12771 | | buf_ptr(&integer->value.type->name), |
| 12812 | buf_ptr(&integer->value->type->name), |
| 12772 | 12813 | buf_ptr(&dest_type->name))); |
| 12773 | 12814 | return ira->codegen->invalid_instruction; |
| 12774 | 12815 | } |
| 12775 | 12816 | |
| 12776 | | if (integer->value.type->data.integral.is_signed) { |
| 12817 | if (integer->value->type->data.integral.is_signed) { |
| 12777 | 12818 | ZigType *unsigned_int_type = get_int_type(ira->codegen, false, |
| 12778 | | integer->value.type->data.integral.bit_count); |
| 12819 | integer->value->type->data.integral.bit_count); |
| 12779 | 12820 | unsigned_integer = ir_analyze_bit_cast(ira, source_instr, integer, unsigned_int_type); |
| 12780 | | if (type_is_invalid(unsigned_integer->value.type)) |
| 12821 | if (type_is_invalid(unsigned_integer->value->type)) |
| 12781 | 12822 | return ira->codegen->invalid_instruction; |
| 12782 | 12823 | } else { |
| 12783 | 12824 | unsigned_integer = integer; |
| ... | ... | @@ -12807,16 +12848,16 @@ static IrInstruction *ir_analyze_enum_literal(IrAnalyze *ira, IrInstruction *sou |
| 12807 | 12848 | if ((err = type_resolve(ira->codegen, enum_type, ResolveStatusZeroBitsKnown))) |
| 12808 | 12849 | return ira->codegen->invalid_instruction; |
| 12809 | 12850 | |
| 12810 | | TypeEnumField *field = find_enum_type_field(enum_type, value->value.data.x_enum_literal); |
| 12851 | TypeEnumField *field = find_enum_type_field(enum_type, value->value->data.x_enum_literal); |
| 12811 | 12852 | if (field == nullptr) { |
| 12812 | 12853 | ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("enum '%s' has no field named '%s'", |
| 12813 | | buf_ptr(&enum_type->name), buf_ptr(value->value.data.x_enum_literal))); |
| 12854 | buf_ptr(&enum_type->name), buf_ptr(value->value->data.x_enum_literal))); |
| 12814 | 12855 | add_error_note(ira->codegen, msg, enum_type->data.enumeration.decl_node, |
| 12815 | 12856 | buf_sprintf("'%s' declared here", buf_ptr(&enum_type->name))); |
| 12816 | 12857 | return ira->codegen->invalid_instruction; |
| 12817 | 12858 | } |
| 12818 | 12859 | IrInstruction *result = ir_const(ira, source_instr, enum_type); |
| 12819 | | bigint_init_bigint(&result->value.data.x_enum_tag, &field->value); |
| 12860 | bigint_init_bigint(&result->value->data.x_enum_tag, &field->value); |
| 12820 | 12861 | |
| 12821 | 12862 | return result; |
| 12822 | 12863 | } |
| ... | ... | @@ -12885,7 +12926,7 @@ static IrInstruction *ir_analyze_struct_value_field_value(IrAnalyze *ira, IrInst |
| 12885 | 12926 | { |
| 12886 | 12927 | IrInstruction *struct_ptr = ir_get_ref(ira, source_instr, struct_operand, true, false); |
| 12887 | 12928 | IrInstruction *field_ptr = ir_analyze_struct_field_ptr(ira, source_instr, field, struct_ptr, |
| 12888 | | struct_operand->value.type, false); |
| 12929 | struct_operand->value->type, false); |
| 12889 | 12930 | return ir_get_deref(ira, source_instr, field_ptr, nullptr); |
| 12890 | 12931 | } |
| 12891 | 12932 | |
| ... | ... | @@ -12893,7 +12934,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 12893 | 12934 | ZigType *wanted_type, IrInstruction *value) |
| 12894 | 12935 | { |
| 12895 | 12936 | Error err; |
| 12896 | | ZigType *actual_type = value->value.type; |
| 12937 | ZigType *actual_type = value->value->type; |
| 12897 | 12938 | AstNode *source_node = source_instr->source_node; |
| 12898 | 12939 | |
| 12899 | 12940 | if (type_is_invalid(wanted_type) || type_is_invalid(actual_type)) { |
| ... | ... | @@ -12915,13 +12956,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 12915 | 12956 | } |
| 12916 | 12957 | |
| 12917 | 12958 | if (const_cast_result.id == ConstCastResultIdFnCC) { |
| 12918 | | ir_assert(value->value.type->id == ZigTypeIdFn, source_instr); |
| 12959 | ir_assert(value->value->type->id == ZigTypeIdFn, source_instr); |
| 12919 | 12960 | // ConstCastResultIdFnCC is guaranteed to be the last one reported, meaning everything else is ok. |
| 12920 | 12961 | if (wanted_type->data.fn.fn_type_id.cc == CallingConventionAsync && |
| 12921 | 12962 | actual_type->data.fn.fn_type_id.cc == CallingConventionUnspecified) |
| 12922 | 12963 | { |
| 12923 | | ir_assert(value->value.data.x_ptr.special == ConstPtrSpecialFunction, source_instr); |
| 12924 | | ZigFn *fn = value->value.data.x_ptr.data.fn.fn_entry; |
| 12964 | ir_assert(value->value->data.x_ptr.special == ConstPtrSpecialFunction, source_instr); |
| 12965 | ZigFn *fn = value->value->data.x_ptr.data.fn.fn_entry; |
| 12925 | 12966 | if (fn->inferred_async_node == nullptr) { |
| 12926 | 12967 | fn->inferred_async_node = source_instr->source_node; |
| 12927 | 12968 | } |
| ... | ... | @@ -12963,7 +13004,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 12963 | 13004 | { |
| 12964 | 13005 | IrInstruction *cast1 = ir_resolve_ptr_of_array_to_unknown_len_ptr(ira, source_instr, value, |
| 12965 | 13006 | wanted_child_type); |
| 12966 | | if (type_is_invalid(cast1->value.type)) |
| 13007 | if (type_is_invalid(cast1->value->type)) |
| 12967 | 13008 | return ira->codegen->invalid_instruction; |
| 12968 | 13009 | return ir_analyze_optional_wrap(ira, source_instr, cast1, wanted_type, nullptr); |
| 12969 | 13010 | } |
| ... | ... | @@ -12999,11 +13040,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 12999 | 13040 | actual_type->id == ZigTypeIdComptimeFloat) |
| 13000 | 13041 | { |
| 13001 | 13042 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value); |
| 13002 | | if (type_is_invalid(cast1->value.type)) |
| 13043 | if (type_is_invalid(cast1->value->type)) |
| 13003 | 13044 | return ira->codegen->invalid_instruction; |
| 13004 | 13045 | |
| 13005 | 13046 | IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); |
| 13006 | | if (type_is_invalid(cast2->value.type)) |
| 13047 | if (type_is_invalid(cast2->value->type)) |
| 13007 | 13048 | return ira->codegen->invalid_instruction; |
| 13008 | 13049 | |
| 13009 | 13050 | return cast2; |
| ... | ... | @@ -13018,29 +13059,29 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13018 | 13059 | (wanted_type->id == ZigTypeIdInt || wanted_type->id == ZigTypeIdComptimeInt || |
| 13019 | 13060 | wanted_type->id == ZigTypeIdFloat || wanted_type->id == ZigTypeIdComptimeFloat)) |
| 13020 | 13061 | { |
| 13021 | | if (value->value.special == ConstValSpecialUndef) { |
| 13062 | if (value->value->special == ConstValSpecialUndef) { |
| 13022 | 13063 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 13023 | | result->value.special = ConstValSpecialUndef; |
| 13064 | result->value->special = ConstValSpecialUndef; |
| 13024 | 13065 | return result; |
| 13025 | 13066 | } |
| 13026 | 13067 | if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) { |
| 13027 | 13068 | if (wanted_type->id == ZigTypeIdComptimeInt || wanted_type->id == ZigTypeIdInt) { |
| 13028 | 13069 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 13029 | 13070 | if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) { |
| 13030 | | copy_const_val(&result->value, &value->value, false); |
| 13031 | | result->value.type = wanted_type; |
| 13071 | copy_const_val(result->value, value->value, false); |
| 13072 | result->value->type = wanted_type; |
| 13032 | 13073 | } else { |
| 13033 | | float_init_bigint(&result->value.data.x_bigint, &value->value); |
| 13074 | float_init_bigint(&result->value->data.x_bigint, value->value); |
| 13034 | 13075 | } |
| 13035 | 13076 | return result; |
| 13036 | 13077 | } else if (wanted_type->id == ZigTypeIdComptimeFloat || wanted_type->id == ZigTypeIdFloat) { |
| 13037 | 13078 | IrInstruction *result = ir_const(ira, source_instr, wanted_type); |
| 13038 | 13079 | if (actual_type->id == ZigTypeIdComptimeInt || actual_type->id == ZigTypeIdInt) { |
| 13039 | 13080 | BigFloat bf; |
| 13040 | | bigfloat_init_bigint(&bf, &value->value.data.x_bigint); |
| 13041 | | float_init_bigfloat(&result->value, &bf); |
| 13081 | bigfloat_init_bigint(&bf, &value->value->data.x_bigint); |
| 13082 | float_init_bigfloat(result->value, &bf); |
| 13042 | 13083 | } else { |
| 13043 | | float_init_float(&result->value, &value->value); |
| 13084 | float_init_float(result->value, value->value); |
| 13044 | 13085 | } |
| 13045 | 13086 | return result; |
| 13046 | 13087 | } |
| ... | ... | @@ -13102,11 +13143,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13102 | 13143 | source_node, false).id == ConstCastResultIdOk) |
| 13103 | 13144 | { |
| 13104 | 13145 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value); |
| 13105 | | if (type_is_invalid(cast1->value.type)) |
| 13146 | if (type_is_invalid(cast1->value->type)) |
| 13106 | 13147 | return ira->codegen->invalid_instruction; |
| 13107 | 13148 | |
| 13108 | 13149 | IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); |
| 13109 | | if (type_is_invalid(cast2->value.type)) |
| 13150 | if (type_is_invalid(cast2->value->type)) |
| 13110 | 13151 | return ira->codegen->invalid_instruction; |
| 13111 | 13152 | |
| 13112 | 13153 | return cast2; |
| ... | ... | @@ -13121,11 +13162,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13121 | 13162 | actual_type->data.pointer.child_type->id == ZigTypeIdArray) |
| 13122 | 13163 | { |
| 13123 | 13164 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value); |
| 13124 | | if (type_is_invalid(cast1->value.type)) |
| 13165 | if (type_is_invalid(cast1->value->type)) |
| 13125 | 13166 | return ira->codegen->invalid_instruction; |
| 13126 | 13167 | |
| 13127 | 13168 | IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); |
| 13128 | | if (type_is_invalid(cast2->value.type)) |
| 13169 | if (type_is_invalid(cast2->value->type)) |
| 13129 | 13170 | return ira->codegen->invalid_instruction; |
| 13130 | 13171 | |
| 13131 | 13172 | return cast2; |
| ... | ... | @@ -13202,11 +13243,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13202 | 13243 | if (ok_align) { |
| 13203 | 13244 | if (wanted_type->id == ZigTypeIdErrorUnion) { |
| 13204 | 13245 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, slice_type, value); |
| 13205 | | if (type_is_invalid(cast1->value.type)) |
| 13246 | if (type_is_invalid(cast1->value->type)) |
| 13206 | 13247 | return ira->codegen->invalid_instruction; |
| 13207 | 13248 | |
| 13208 | 13249 | IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); |
| 13209 | | if (type_is_invalid(cast2->value.type)) |
| 13250 | if (type_is_invalid(cast2->value->type)) |
| 13210 | 13251 | return ira->codegen->invalid_instruction; |
| 13211 | 13252 | |
| 13212 | 13253 | return cast2; |
| ... | ... | @@ -13309,11 +13350,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 13309 | 13350 | source_node, false).id == ConstCastResultIdOk) |
| 13310 | 13351 | { |
| 13311 | 13352 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value); |
| 13312 | | if (type_is_invalid(cast1->value.type)) |
| 13353 | if (type_is_invalid(cast1->value->type)) |
| 13313 | 13354 | return ira->codegen->invalid_instruction; |
| 13314 | 13355 | |
| 13315 | 13356 | IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); |
| 13316 | | if (type_is_invalid(cast2->value.type)) |
| 13357 | if (type_is_invalid(cast2->value->type)) |
| 13317 | 13358 | return ira->codegen->invalid_instruction; |
| 13318 | 13359 | |
| 13319 | 13360 | return cast2; |
| ... | ... | @@ -13529,13 +13570,13 @@ static IrInstruction *ir_implicit_cast2(IrAnalyze *ira, IrInstruction *value_sou |
| 13529 | 13570 | assert(value); |
| 13530 | 13571 | assert(value != ira->codegen->invalid_instruction); |
| 13531 | 13572 | assert(!expected_type || !type_is_invalid(expected_type)); |
| 13532 | | assert(value->value.type); |
| 13533 | | assert(!type_is_invalid(value->value.type)); |
| 13573 | assert(value->value->type); |
| 13574 | assert(!type_is_invalid(value->value->type)); |
| 13534 | 13575 | if (expected_type == nullptr) |
| 13535 | 13576 | return value; // anything will do |
| 13536 | | if (expected_type == value->value.type) |
| 13577 | if (expected_type == value->value->type) |
| 13537 | 13578 | return value; // match |
| 13538 | | if (value->value.type->id == ZigTypeIdUnreachable) |
| 13579 | if (value->value->type->id == ZigTypeIdUnreachable) |
| 13539 | 13580 | return value; |
| 13540 | 13581 | |
| 13541 | 13582 | return ir_analyze_cast(ira, value_source_instr, expected_type, value); |
| ... | ... | @@ -13549,7 +13590,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc |
| 13549 | 13590 | ResultLoc *result_loc) |
| 13550 | 13591 | { |
| 13551 | 13592 | Error err; |
| 13552 | | ZigType *ptr_type = ptr->value.type; |
| 13593 | ZigType *ptr_type = ptr->value->type; |
| 13553 | 13594 | if (type_is_invalid(ptr_type)) |
| 13554 | 13595 | return ira->codegen->invalid_instruction; |
| 13555 | 13596 | |
| ... | ... | @@ -13571,24 +13612,24 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc |
| 13571 | 13612 | break; |
| 13572 | 13613 | } |
| 13573 | 13614 | if (instr_is_comptime(ptr)) { |
| 13574 | | if (ptr->value.special == ConstValSpecialUndef) { |
| 13615 | if (ptr->value->special == ConstValSpecialUndef) { |
| 13575 | 13616 | ir_add_error(ira, ptr, buf_sprintf("attempt to dereference undefined value")); |
| 13576 | 13617 | return ira->codegen->invalid_instruction; |
| 13577 | 13618 | } |
| 13578 | | if (ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 13579 | | ConstExprValue *pointee = const_ptr_pointee_unchecked(ira->codegen, &ptr->value); |
| 13619 | if (ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 13620 | ZigValue *pointee = const_ptr_pointee_unchecked(ira->codegen, ptr->value); |
| 13580 | 13621 | if (child_type == ira->codegen->builtin_types.entry_var) { |
| 13581 | 13622 | child_type = pointee->type; |
| 13582 | 13623 | } |
| 13583 | 13624 | if (pointee->special != ConstValSpecialRuntime) { |
| 13584 | 13625 | IrInstruction *result = ir_const(ira, source_instruction, child_type); |
| 13585 | 13626 | |
| 13586 | | if ((err = ir_read_const_ptr(ira, ira->codegen, source_instruction->source_node, &result->value, |
| 13587 | | &ptr->value))) |
| 13627 | if ((err = ir_read_const_ptr(ira, ira->codegen, source_instruction->source_node, result->value, |
| 13628 | ptr->value))) |
| 13588 | 13629 | { |
| 13589 | 13630 | return ira->codegen->invalid_instruction; |
| 13590 | 13631 | } |
| 13591 | | result->value.type = child_type; |
| 13632 | result->value->type = child_type; |
| 13592 | 13633 | return result; |
| 13593 | 13634 | } |
| 13594 | 13635 | } |
| ... | ... | @@ -13626,7 +13667,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc |
| 13626 | 13667 | if (result_loc == nullptr) result_loc = no_result_loc(); |
| 13627 | 13668 | result_loc_inst = ir_resolve_result(ira, source_instruction, result_loc, child_type, nullptr, |
| 13628 | 13669 | true, false, true); |
| 13629 | | if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) { |
| 13670 | if (type_is_invalid(result_loc_inst->value->type) || instr_is_unreachable(result_loc_inst)) { |
| 13630 | 13671 | return result_loc_inst; |
| 13631 | 13672 | } |
| 13632 | 13673 | } else { |
| ... | ... | @@ -13637,7 +13678,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc |
| 13637 | 13678 | } |
| 13638 | 13679 | |
| 13639 | 13680 | static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, |
| 13640 | | ConstExprValue *const_val, uint32_t *out) |
| 13681 | ZigValue *const_val, uint32_t *out) |
| 13641 | 13682 | { |
| 13642 | 13683 | Error err; |
| 13643 | 13684 | if ((err = ir_resolve_const_val(codegen, exec, source_node, const_val, UndefBad))) |
| ... | ... | @@ -13660,15 +13701,15 @@ static bool ir_resolve_const_align(CodeGen *codegen, IrExecutable *exec, AstNode |
| 13660 | 13701 | } |
| 13661 | 13702 | |
| 13662 | 13703 | static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, ZigType *elem_type, uint32_t *out) { |
| 13663 | | if (type_is_invalid(value->value.type)) |
| 13704 | if (type_is_invalid(value->value->type)) |
| 13664 | 13705 | return false; |
| 13665 | 13706 | |
| 13666 | 13707 | // Look for this pattern: `*align(@alignOf(T)) T`. |
| 13667 | 13708 | // This can be resolved to be `*out = 0` without resolving any alignment. |
| 13668 | | if (elem_type != nullptr && value->value.special == ConstValSpecialLazy && |
| 13669 | | value->value.data.x_lazy->id == LazyValueIdAlignOf) |
| 13709 | if (elem_type != nullptr && value->value->special == ConstValSpecialLazy && |
| 13710 | value->value->data.x_lazy->id == LazyValueIdAlignOf) |
| 13670 | 13711 | { |
| 13671 | | LazyValueAlignOf *lazy_align_of = reinterpret_cast<LazyValueAlignOf *>(value->value.data.x_lazy); |
| 13712 | LazyValueAlignOf *lazy_align_of = reinterpret_cast<LazyValueAlignOf *>(value->value->data.x_lazy); |
| 13672 | 13713 | |
| 13673 | 13714 | ZigType *lazy_elem_type = ir_resolve_type(lazy_align_of->ira, lazy_align_of->target_type); |
| 13674 | 13715 | if (type_is_invalid(lazy_elem_type)) |
| ... | ... | @@ -13681,22 +13722,22 @@ static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, ZigType *elem |
| 13681 | 13722 | } |
| 13682 | 13723 | |
| 13683 | 13724 | IrInstruction *casted_value = ir_implicit_cast(ira, value, get_align_amt_type(ira->codegen)); |
| 13684 | | if (type_is_invalid(casted_value->value.type)) |
| 13725 | if (type_is_invalid(casted_value->value->type)) |
| 13685 | 13726 | return false; |
| 13686 | 13727 | |
| 13687 | 13728 | return ir_resolve_const_align(ira->codegen, ira->new_irb.exec, value->source_node, |
| 13688 | | &casted_value->value, out); |
| 13729 | casted_value->value, out); |
| 13689 | 13730 | } |
| 13690 | 13731 | |
| 13691 | 13732 | static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, ZigType *int_type, uint64_t *out) { |
| 13692 | | if (type_is_invalid(value->value.type)) |
| 13733 | if (type_is_invalid(value->value->type)) |
| 13693 | 13734 | return false; |
| 13694 | 13735 | |
| 13695 | 13736 | IrInstruction *casted_value = ir_implicit_cast(ira, value, int_type); |
| 13696 | | if (type_is_invalid(casted_value->value.type)) |
| 13737 | if (type_is_invalid(casted_value->value->type)) |
| 13697 | 13738 | return false; |
| 13698 | 13739 | |
| 13699 | | ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); |
| 13740 | ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); |
| 13700 | 13741 | if (!const_val) |
| 13701 | 13742 | return false; |
| 13702 | 13743 | |
| ... | ... | @@ -13709,14 +13750,14 @@ static bool ir_resolve_usize(IrAnalyze *ira, IrInstruction *value, uint64_t *out |
| 13709 | 13750 | } |
| 13710 | 13751 | |
| 13711 | 13752 | static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) { |
| 13712 | | if (type_is_invalid(value->value.type)) |
| 13753 | if (type_is_invalid(value->value->type)) |
| 13713 | 13754 | return false; |
| 13714 | 13755 | |
| 13715 | 13756 | IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_bool); |
| 13716 | | if (type_is_invalid(casted_value->value.type)) |
| 13757 | if (type_is_invalid(casted_value->value->type)) |
| 13717 | 13758 | return false; |
| 13718 | 13759 | |
| 13719 | | ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); |
| 13760 | ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); |
| 13720 | 13761 | if (!const_val) |
| 13721 | 13762 | return false; |
| 13722 | 13763 | |
| ... | ... | @@ -13733,18 +13774,18 @@ static bool ir_resolve_comptime(IrAnalyze *ira, IrInstruction *value, bool *out) |
| 13733 | 13774 | } |
| 13734 | 13775 | |
| 13735 | 13776 | static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, AtomicOrder *out) { |
| 13736 | | if (type_is_invalid(value->value.type)) |
| 13777 | if (type_is_invalid(value->value->type)) |
| 13737 | 13778 | return false; |
| 13738 | 13779 | |
| 13739 | | ConstExprValue *atomic_order_val = get_builtin_value(ira->codegen, "AtomicOrder"); |
| 13780 | ZigValue *atomic_order_val = get_builtin_value(ira->codegen, "AtomicOrder"); |
| 13740 | 13781 | assert(atomic_order_val->type->id == ZigTypeIdMetaType); |
| 13741 | 13782 | ZigType *atomic_order_type = atomic_order_val->data.x_type; |
| 13742 | 13783 | |
| 13743 | 13784 | IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_order_type); |
| 13744 | | if (type_is_invalid(casted_value->value.type)) |
| 13785 | if (type_is_invalid(casted_value->value->type)) |
| 13745 | 13786 | return false; |
| 13746 | 13787 | |
| 13747 | | ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); |
| 13788 | ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); |
| 13748 | 13789 | if (!const_val) |
| 13749 | 13790 | return false; |
| 13750 | 13791 | |
| ... | ... | @@ -13753,18 +13794,18 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic |
| 13753 | 13794 | } |
| 13754 | 13795 | |
| 13755 | 13796 | static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, AtomicRmwOp *out) { |
| 13756 | | if (type_is_invalid(value->value.type)) |
| 13797 | if (type_is_invalid(value->value->type)) |
| 13757 | 13798 | return false; |
| 13758 | 13799 | |
| 13759 | | ConstExprValue *atomic_rmw_op_val = get_builtin_value(ira->codegen, "AtomicRmwOp"); |
| 13800 | ZigValue *atomic_rmw_op_val = get_builtin_value(ira->codegen, "AtomicRmwOp"); |
| 13760 | 13801 | assert(atomic_rmw_op_val->type->id == ZigTypeIdMetaType); |
| 13761 | 13802 | ZigType *atomic_rmw_op_type = atomic_rmw_op_val->data.x_type; |
| 13762 | 13803 | |
| 13763 | 13804 | IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_rmw_op_type); |
| 13764 | | if (type_is_invalid(casted_value->value.type)) |
| 13805 | if (type_is_invalid(casted_value->value->type)) |
| 13765 | 13806 | return false; |
| 13766 | 13807 | |
| 13767 | | ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); |
| 13808 | ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); |
| 13768 | 13809 | if (!const_val) |
| 13769 | 13810 | return false; |
| 13770 | 13811 | |
| ... | ... | @@ -13773,18 +13814,18 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi |
| 13773 | 13814 | } |
| 13774 | 13815 | |
| 13775 | 13816 | static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, GlobalLinkageId *out) { |
| 13776 | | if (type_is_invalid(value->value.type)) |
| 13817 | if (type_is_invalid(value->value->type)) |
| 13777 | 13818 | return false; |
| 13778 | 13819 | |
| 13779 | | ConstExprValue *global_linkage_val = get_builtin_value(ira->codegen, "GlobalLinkage"); |
| 13820 | ZigValue *global_linkage_val = get_builtin_value(ira->codegen, "GlobalLinkage"); |
| 13780 | 13821 | assert(global_linkage_val->type->id == ZigTypeIdMetaType); |
| 13781 | 13822 | ZigType *global_linkage_type = global_linkage_val->data.x_type; |
| 13782 | 13823 | |
| 13783 | 13824 | IrInstruction *casted_value = ir_implicit_cast(ira, value, global_linkage_type); |
| 13784 | | if (type_is_invalid(casted_value->value.type)) |
| 13825 | if (type_is_invalid(casted_value->value->type)) |
| 13785 | 13826 | return false; |
| 13786 | 13827 | |
| 13787 | | ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); |
| 13828 | ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); |
| 13788 | 13829 | if (!const_val) |
| 13789 | 13830 | return false; |
| 13790 | 13831 | |
| ... | ... | @@ -13793,18 +13834,18 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob |
| 13793 | 13834 | } |
| 13794 | 13835 | |
| 13795 | 13836 | static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMode *out) { |
| 13796 | | if (type_is_invalid(value->value.type)) |
| 13837 | if (type_is_invalid(value->value->type)) |
| 13797 | 13838 | return false; |
| 13798 | 13839 | |
| 13799 | | ConstExprValue *float_mode_val = get_builtin_value(ira->codegen, "FloatMode"); |
| 13840 | ZigValue *float_mode_val = get_builtin_value(ira->codegen, "FloatMode"); |
| 13800 | 13841 | assert(float_mode_val->type->id == ZigTypeIdMetaType); |
| 13801 | 13842 | ZigType *float_mode_type = float_mode_val->data.x_type; |
| 13802 | 13843 | |
| 13803 | 13844 | IrInstruction *casted_value = ir_implicit_cast(ira, value, float_mode_type); |
| 13804 | | if (type_is_invalid(casted_value->value.type)) |
| 13845 | if (type_is_invalid(casted_value->value->type)) |
| 13805 | 13846 | return false; |
| 13806 | 13847 | |
| 13807 | | ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); |
| 13848 | ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); |
| 13808 | 13849 | if (!const_val) |
| 13809 | 13850 | return false; |
| 13810 | 13851 | |
| ... | ... | @@ -13813,25 +13854,25 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod |
| 13813 | 13854 | } |
| 13814 | 13855 | |
| 13815 | 13856 | static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) { |
| 13816 | | if (type_is_invalid(value->value.type)) |
| 13857 | if (type_is_invalid(value->value->type)) |
| 13817 | 13858 | return nullptr; |
| 13818 | 13859 | |
| 13819 | 13860 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 13820 | 13861 | true, false, PtrLenUnknown, 0, 0, 0, false); |
| 13821 | 13862 | ZigType *str_type = get_slice_type(ira->codegen, ptr_type); |
| 13822 | 13863 | IrInstruction *casted_value = ir_implicit_cast(ira, value, str_type); |
| 13823 | | if (type_is_invalid(casted_value->value.type)) |
| 13864 | if (type_is_invalid(casted_value->value->type)) |
| 13824 | 13865 | return nullptr; |
| 13825 | 13866 | |
| 13826 | | ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); |
| 13867 | ZigValue *const_val = ir_resolve_const(ira, casted_value, UndefBad); |
| 13827 | 13868 | if (!const_val) |
| 13828 | 13869 | return nullptr; |
| 13829 | 13870 | |
| 13830 | | ConstExprValue *ptr_field = const_val->data.x_struct.fields[slice_ptr_index]; |
| 13831 | | ConstExprValue *len_field = const_val->data.x_struct.fields[slice_len_index]; |
| 13871 | ZigValue *ptr_field = const_val->data.x_struct.fields[slice_ptr_index]; |
| 13872 | ZigValue *len_field = const_val->data.x_struct.fields[slice_len_index]; |
| 13832 | 13873 | |
| 13833 | 13874 | assert(ptr_field->data.x_ptr.special == ConstPtrSpecialBaseArray); |
| 13834 | | ConstExprValue *array_val = ptr_field->data.x_ptr.data.base_array.array_val; |
| 13875 | ZigValue *array_val = ptr_field->data.x_ptr.data.base_array.array_val; |
| 13835 | 13876 | expand_undef_array(ira->codegen, array_val); |
| 13836 | 13877 | size_t len = bigint_as_usize(&len_field->data.x_bigint); |
| 13837 | 13878 | if (array_val->data.x_array.special == ConstArraySpecialBuf && len == buf_len(array_val->data.x_array.data.s_buf)) { |
| ... | ... | @@ -13841,7 +13882,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) { |
| 13841 | 13882 | buf_resize(result, len); |
| 13842 | 13883 | for (size_t i = 0; i < len; i += 1) { |
| 13843 | 13884 | size_t new_index = ptr_field->data.x_ptr.data.base_array.elem_index + i; |
| 13844 | | ConstExprValue *char_val = &array_val->data.x_array.data.s_none.elements[new_index]; |
| 13885 | ZigValue *char_val = &array_val->data.x_array.data.s_none.elements[new_index]; |
| 13845 | 13886 | if (char_val->special == ConstValSpecialUndef) { |
| 13846 | 13887 | ir_add_error(ira, casted_value, buf_sprintf("use of undefined value")); |
| 13847 | 13888 | return nullptr; |
| ... | ... | @@ -13858,7 +13899,7 @@ static IrInstruction *ir_analyze_instruction_add_implicit_return_type(IrAnalyze |
| 13858 | 13899 | IrInstructionAddImplicitReturnType *instruction) |
| 13859 | 13900 | { |
| 13860 | 13901 | IrInstruction *value = instruction->value->child; |
| 13861 | | if (type_is_invalid(value->value.type)) |
| 13902 | if (type_is_invalid(value->value->type)) |
| 13862 | 13903 | return ir_unreach_error(ira); |
| 13863 | 13904 | |
| 13864 | 13905 | if (instruction->result_loc_ret == nullptr || !instruction->result_loc_ret->implicit_return_type_done) { |
| ... | ... | @@ -13870,11 +13911,11 @@ static IrInstruction *ir_analyze_instruction_add_implicit_return_type(IrAnalyze |
| 13870 | 13911 | |
| 13871 | 13912 | static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructionReturn *instruction) { |
| 13872 | 13913 | IrInstruction *operand = instruction->operand->child; |
| 13873 | | if (type_is_invalid(operand->value.type)) |
| 13914 | if (type_is_invalid(operand->value->type)) |
| 13874 | 13915 | return ir_unreach_error(ira); |
| 13875 | 13916 | |
| 13876 | 13917 | IrInstruction *casted_operand = ir_implicit_cast(ira, operand, ira->explicit_return_type); |
| 13877 | | if (type_is_invalid(casted_operand->value.type)) { |
| 13918 | if (type_is_invalid(casted_operand->value->type)) { |
| 13878 | 13919 | AstNode *source_node = ira->explicit_return_type_source_node; |
| 13879 | 13920 | if (source_node != nullptr) { |
| 13880 | 13921 | ErrorMsg *msg = ira->codegen->errors.last(); |
| ... | ... | @@ -13890,13 +13931,13 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio |
| 13890 | 13931 | // result location mechanism took care of it. |
| 13891 | 13932 | IrInstruction *result = ir_build_return(&ira->new_irb, instruction->base.scope, |
| 13892 | 13933 | instruction->base.source_node, nullptr); |
| 13893 | | result->value.type = ira->codegen->builtin_types.entry_unreachable; |
| 13934 | result->value->type = ira->codegen->builtin_types.entry_unreachable; |
| 13894 | 13935 | return ir_finish_anal(ira, result); |
| 13895 | 13936 | } |
| 13896 | 13937 | |
| 13897 | | if (casted_operand->value.special == ConstValSpecialRuntime && |
| 13898 | | casted_operand->value.type->id == ZigTypeIdPointer && |
| 13899 | | casted_operand->value.data.rh_ptr == RuntimeHintPtrStack) |
| 13938 | if (casted_operand->value->special == ConstValSpecialRuntime && |
| 13939 | casted_operand->value->type->id == ZigTypeIdPointer && |
| 13940 | casted_operand->value->data.rh_ptr == RuntimeHintPtrStack) |
| 13900 | 13941 | { |
| 13901 | 13942 | ir_add_error(ira, casted_operand, buf_sprintf("function returns address of local variable")); |
| 13902 | 13943 | return ir_unreach_error(ira); |
| ... | ... | @@ -13904,23 +13945,23 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio |
| 13904 | 13945 | |
| 13905 | 13946 | IrInstruction *result = ir_build_return(&ira->new_irb, instruction->base.scope, |
| 13906 | 13947 | instruction->base.source_node, casted_operand); |
| 13907 | | result->value.type = ira->codegen->builtin_types.entry_unreachable; |
| 13948 | result->value->type = ira->codegen->builtin_types.entry_unreachable; |
| 13908 | 13949 | return ir_finish_anal(ira, result); |
| 13909 | 13950 | } |
| 13910 | 13951 | |
| 13911 | 13952 | static IrInstruction *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *instruction) { |
| 13912 | 13953 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 13913 | | copy_const_val(&result->value, &instruction->base.value, true); |
| 13954 | copy_const_val(result->value, instruction->base.value, true); |
| 13914 | 13955 | return result; |
| 13915 | 13956 | } |
| 13916 | 13957 | |
| 13917 | 13958 | static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { |
| 13918 | 13959 | IrInstruction *op1 = bin_op_instruction->op1->child; |
| 13919 | | if (type_is_invalid(op1->value.type)) |
| 13960 | if (type_is_invalid(op1->value->type)) |
| 13920 | 13961 | return ira->codegen->invalid_instruction; |
| 13921 | 13962 | |
| 13922 | 13963 | IrInstruction *op2 = bin_op_instruction->op2->child; |
| 13923 | | if (type_is_invalid(op2->value.type)) |
| 13964 | if (type_is_invalid(op2->value->type)) |
| 13924 | 13965 | return ira->codegen->invalid_instruction; |
| 13925 | 13966 | |
| 13926 | 13967 | ZigType *bool_type = ira->codegen->builtin_types.entry_bool; |
| ... | ... | @@ -13934,16 +13975,16 @@ static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp |
| 13934 | 13975 | return ira->codegen->invalid_instruction; |
| 13935 | 13976 | |
| 13936 | 13977 | if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2)) { |
| 13937 | | ConstExprValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad); |
| 13978 | ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad); |
| 13938 | 13979 | if (op1_val == nullptr) |
| 13939 | 13980 | return ira->codegen->invalid_instruction; |
| 13940 | 13981 | |
| 13941 | | ConstExprValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); |
| 13982 | ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); |
| 13942 | 13983 | if (op2_val == nullptr) |
| 13943 | 13984 | return ira->codegen->invalid_instruction; |
| 13944 | 13985 | |
| 13945 | | assert(casted_op1->value.type->id == ZigTypeIdBool); |
| 13946 | | assert(casted_op2->value.type->id == ZigTypeIdBool); |
| 13986 | assert(casted_op1->value->type->id == ZigTypeIdBool); |
| 13987 | assert(casted_op2->value->type->id == ZigTypeIdBool); |
| 13947 | 13988 | bool result_bool; |
| 13948 | 13989 | if (bin_op_instruction->op_id == IrBinOpBoolOr) { |
| 13949 | 13990 | result_bool = op1_val->data.x_bool || op2_val->data.x_bool; |
| ... | ... | @@ -13958,7 +13999,7 @@ static IrInstruction *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp |
| 13958 | 13999 | IrInstruction *result = ir_build_bin_op(&ira->new_irb, |
| 13959 | 14000 | bin_op_instruction->base.scope, bin_op_instruction->base.source_node, |
| 13960 | 14001 | bin_op_instruction->op_id, casted_op1, casted_op2, bin_op_instruction->safety_check_on); |
| 13961 | | result->value.type = bool_type; |
| 14002 | result->value->type = bool_type; |
| 13962 | 14003 | return result; |
| 13963 | 14004 | } |
| 13964 | 14005 | |
| ... | ... | @@ -13981,7 +14022,7 @@ static bool resolve_cmp_op_id(IrBinOp op_id, Cmp cmp) { |
| 13981 | 14022 | } |
| 13982 | 14023 | } |
| 13983 | 14024 | |
| 13984 | | static bool optional_value_is_null(ConstExprValue *val) { |
| 14025 | static bool optional_value_is_null(ZigValue *val) { |
| 13985 | 14026 | assert(val->special == ConstValSpecialStatic); |
| 13986 | 14027 | if (get_codegen_ptr_type(val->type) != nullptr) { |
| 13987 | 14028 | if (val->data.x_ptr.special == ConstPtrSpecialNull) { |
| ... | ... | @@ -13999,7 +14040,7 @@ static bool optional_value_is_null(ConstExprValue *val) { |
| 13999 | 14040 | } |
| 14000 | 14041 | |
| 14001 | 14042 | static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_type, |
| 14002 | | ConstExprValue *op1_val, ConstExprValue *op2_val, IrInstructionBinOp *bin_op_instruction, IrBinOp op_id, |
| 14043 | ZigValue *op1_val, ZigValue *op2_val, IrInstructionBinOp *bin_op_instruction, IrBinOp op_id, |
| 14003 | 14044 | bool one_possible_value) { |
| 14004 | 14045 | if (op1_val->special == ConstValSpecialUndef || |
| 14005 | 14046 | op2_val->special == ConstValSpecialUndef) |
| ... | ... | @@ -14052,7 +14093,7 @@ static IrInstruction *ir_evaluate_bin_op_cmp(IrAnalyze *ira, ZigType *resolved_t |
| 14052 | 14093 | } |
| 14053 | 14094 | |
| 14054 | 14095 | // Returns ErrorNotLazy when the value cannot be determined |
| 14055 | | static Error lazy_cmp_zero(AstNode *source_node, ConstExprValue *val, Cmp *result) { |
| 14096 | static Error lazy_cmp_zero(AstNode *source_node, ZigValue *val, Cmp *result) { |
| 14056 | 14097 | Error err; |
| 14057 | 14098 | |
| 14058 | 14099 | switch (val->special) { |
| ... | ... | @@ -14079,7 +14120,7 @@ static Error lazy_cmp_zero(AstNode *source_node, ConstExprValue *val, Cmp *resul |
| 14079 | 14120 | LazyValueSizeOf *lazy_size_of = reinterpret_cast<LazyValueSizeOf *>(val->data.x_lazy); |
| 14080 | 14121 | IrAnalyze *ira = lazy_size_of->ira; |
| 14081 | 14122 | bool is_zero_bits; |
| 14082 | | if ((err = type_val_resolve_zero_bits(ira->codegen, &lazy_size_of->target_type->value, |
| 14123 | if ((err = type_val_resolve_zero_bits(ira->codegen, lazy_size_of->target_type->value, |
| 14083 | 14124 | nullptr, nullptr, &is_zero_bits))) |
| 14084 | 14125 | { |
| 14085 | 14126 | return err; |
| ... | ... | @@ -14098,33 +14139,33 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 14098 | 14139 | Error err; |
| 14099 | 14140 | |
| 14100 | 14141 | IrInstruction *op1 = bin_op_instruction->op1->child; |
| 14101 | | if (type_is_invalid(op1->value.type)) |
| 14142 | if (type_is_invalid(op1->value->type)) |
| 14102 | 14143 | return ira->codegen->invalid_instruction; |
| 14103 | 14144 | |
| 14104 | 14145 | IrInstruction *op2 = bin_op_instruction->op2->child; |
| 14105 | | if (type_is_invalid(op2->value.type)) |
| 14146 | if (type_is_invalid(op2->value->type)) |
| 14106 | 14147 | return ira->codegen->invalid_instruction; |
| 14107 | 14148 | |
| 14108 | 14149 | AstNode *source_node = bin_op_instruction->base.source_node; |
| 14109 | 14150 | |
| 14110 | 14151 | IrBinOp op_id = bin_op_instruction->op_id; |
| 14111 | 14152 | bool is_equality_cmp = (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq); |
| 14112 | | if (is_equality_cmp && op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdNull) { |
| 14153 | if (is_equality_cmp && op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdNull) { |
| 14113 | 14154 | return ir_const_bool(ira, &bin_op_instruction->base, (op_id == IrBinOpCmpEq)); |
| 14114 | 14155 | } else if (is_equality_cmp && |
| 14115 | | ((op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdOptional) || |
| 14116 | | (op2->value.type->id == ZigTypeIdNull && op1->value.type->id == ZigTypeIdOptional))) |
| 14156 | ((op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdOptional) || |
| 14157 | (op2->value->type->id == ZigTypeIdNull && op1->value->type->id == ZigTypeIdOptional))) |
| 14117 | 14158 | { |
| 14118 | 14159 | IrInstruction *maybe_op; |
| 14119 | | if (op1->value.type->id == ZigTypeIdNull) { |
| 14160 | if (op1->value->type->id == ZigTypeIdNull) { |
| 14120 | 14161 | maybe_op = op2; |
| 14121 | | } else if (op2->value.type->id == ZigTypeIdNull) { |
| 14162 | } else if (op2->value->type->id == ZigTypeIdNull) { |
| 14122 | 14163 | maybe_op = op1; |
| 14123 | 14164 | } else { |
| 14124 | 14165 | zig_unreachable(); |
| 14125 | 14166 | } |
| 14126 | 14167 | if (instr_is_comptime(maybe_op)) { |
| 14127 | | ConstExprValue *maybe_val = ir_resolve_const(ira, maybe_op, UndefBad); |
| 14168 | ZigValue *maybe_val = ir_resolve_const(ira, maybe_op, UndefBad); |
| 14128 | 14169 | if (!maybe_val) |
| 14129 | 14170 | return ira->codegen->invalid_instruction; |
| 14130 | 14171 | bool is_null = optional_value_is_null(maybe_val); |
| ... | ... | @@ -14134,32 +14175,32 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 14134 | 14175 | |
| 14135 | 14176 | IrInstruction *is_non_null = ir_build_test_nonnull(&ira->new_irb, bin_op_instruction->base.scope, |
| 14136 | 14177 | source_node, maybe_op); |
| 14137 | | is_non_null->value.type = ira->codegen->builtin_types.entry_bool; |
| 14178 | is_non_null->value->type = ira->codegen->builtin_types.entry_bool; |
| 14138 | 14179 | |
| 14139 | 14180 | if (op_id == IrBinOpCmpEq) { |
| 14140 | 14181 | IrInstruction *result = ir_build_bool_not(&ira->new_irb, bin_op_instruction->base.scope, |
| 14141 | 14182 | bin_op_instruction->base.source_node, is_non_null); |
| 14142 | | result->value.type = ira->codegen->builtin_types.entry_bool; |
| 14183 | result->value->type = ira->codegen->builtin_types.entry_bool; |
| 14143 | 14184 | return result; |
| 14144 | 14185 | } else { |
| 14145 | 14186 | return is_non_null; |
| 14146 | 14187 | } |
| 14147 | 14188 | } else if (is_equality_cmp && |
| 14148 | | ((op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdPointer && |
| 14149 | | op2->value.type->data.pointer.ptr_len == PtrLenC) || |
| 14150 | | (op2->value.type->id == ZigTypeIdNull && op1->value.type->id == ZigTypeIdPointer && |
| 14151 | | op1->value.type->data.pointer.ptr_len == PtrLenC))) |
| 14189 | ((op1->value->type->id == ZigTypeIdNull && op2->value->type->id == ZigTypeIdPointer && |
| 14190 | op2->value->type->data.pointer.ptr_len == PtrLenC) || |
| 14191 | (op2->value->type->id == ZigTypeIdNull && op1->value->type->id == ZigTypeIdPointer && |
| 14192 | op1->value->type->data.pointer.ptr_len == PtrLenC))) |
| 14152 | 14193 | { |
| 14153 | 14194 | IrInstruction *c_ptr_op; |
| 14154 | | if (op1->value.type->id == ZigTypeIdNull) { |
| 14195 | if (op1->value->type->id == ZigTypeIdNull) { |
| 14155 | 14196 | c_ptr_op = op2; |
| 14156 | | } else if (op2->value.type->id == ZigTypeIdNull) { |
| 14197 | } else if (op2->value->type->id == ZigTypeIdNull) { |
| 14157 | 14198 | c_ptr_op = op1; |
| 14158 | 14199 | } else { |
| 14159 | 14200 | zig_unreachable(); |
| 14160 | 14201 | } |
| 14161 | 14202 | if (instr_is_comptime(c_ptr_op)) { |
| 14162 | | ConstExprValue *c_ptr_val = ir_resolve_const(ira, c_ptr_op, UndefOk); |
| 14203 | ZigValue *c_ptr_val = ir_resolve_const(ira, c_ptr_op, UndefOk); |
| 14163 | 14204 | if (!c_ptr_val) |
| 14164 | 14205 | return ira->codegen->invalid_instruction; |
| 14165 | 14206 | if (c_ptr_val->special == ConstValSpecialUndef) |
| ... | ... | @@ -14172,46 +14213,46 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 14172 | 14213 | } |
| 14173 | 14214 | IrInstruction *is_non_null = ir_build_test_nonnull(&ira->new_irb, bin_op_instruction->base.scope, |
| 14174 | 14215 | source_node, c_ptr_op); |
| 14175 | | is_non_null->value.type = ira->codegen->builtin_types.entry_bool; |
| 14216 | is_non_null->value->type = ira->codegen->builtin_types.entry_bool; |
| 14176 | 14217 | |
| 14177 | 14218 | if (op_id == IrBinOpCmpEq) { |
| 14178 | 14219 | IrInstruction *result = ir_build_bool_not(&ira->new_irb, bin_op_instruction->base.scope, |
| 14179 | 14220 | bin_op_instruction->base.source_node, is_non_null); |
| 14180 | | result->value.type = ira->codegen->builtin_types.entry_bool; |
| 14221 | result->value->type = ira->codegen->builtin_types.entry_bool; |
| 14181 | 14222 | return result; |
| 14182 | 14223 | } else { |
| 14183 | 14224 | return is_non_null; |
| 14184 | 14225 | } |
| 14185 | | } else if (op1->value.type->id == ZigTypeIdNull || op2->value.type->id == ZigTypeIdNull) { |
| 14186 | | ZigType *non_null_type = (op1->value.type->id == ZigTypeIdNull) ? op2->value.type : op1->value.type; |
| 14226 | } else if (op1->value->type->id == ZigTypeIdNull || op2->value->type->id == ZigTypeIdNull) { |
| 14227 | ZigType *non_null_type = (op1->value->type->id == ZigTypeIdNull) ? op2->value->type : op1->value->type; |
| 14187 | 14228 | ir_add_error_node(ira, source_node, buf_sprintf("comparison of '%s' with null", |
| 14188 | 14229 | buf_ptr(&non_null_type->name))); |
| 14189 | 14230 | return ira->codegen->invalid_instruction; |
| 14190 | 14231 | } else if (is_equality_cmp && ( |
| 14191 | | (op1->value.type->id == ZigTypeIdEnumLiteral && op2->value.type->id == ZigTypeIdUnion) || |
| 14192 | | (op2->value.type->id == ZigTypeIdEnumLiteral && op1->value.type->id == ZigTypeIdUnion))) |
| 14232 | (op1->value->type->id == ZigTypeIdEnumLiteral && op2->value->type->id == ZigTypeIdUnion) || |
| 14233 | (op2->value->type->id == ZigTypeIdEnumLiteral && op1->value->type->id == ZigTypeIdUnion))) |
| 14193 | 14234 | { |
| 14194 | 14235 | // Support equality comparison between a union's tag value and a enum literal |
| 14195 | | IrInstruction *union_val = op1->value.type->id == ZigTypeIdUnion ? op1 : op2; |
| 14196 | | IrInstruction *enum_val = op1->value.type->id == ZigTypeIdUnion ? op2 : op1; |
| 14236 | IrInstruction *union_val = op1->value->type->id == ZigTypeIdUnion ? op1 : op2; |
| 14237 | IrInstruction *enum_val = op1->value->type->id == ZigTypeIdUnion ? op2 : op1; |
| 14197 | 14238 | |
| 14198 | | ZigType *tag_type = union_val->value.type->data.unionation.tag_type; |
| 14239 | ZigType *tag_type = union_val->value->type->data.unionation.tag_type; |
| 14199 | 14240 | assert(tag_type != nullptr); |
| 14200 | 14241 | |
| 14201 | 14242 | IrInstruction *casted_union = ir_implicit_cast(ira, union_val, tag_type); |
| 14202 | | if (type_is_invalid(casted_union->value.type)) |
| 14243 | if (type_is_invalid(casted_union->value->type)) |
| 14203 | 14244 | return ira->codegen->invalid_instruction; |
| 14204 | 14245 | |
| 14205 | 14246 | IrInstruction *casted_val = ir_implicit_cast(ira, enum_val, tag_type); |
| 14206 | | if (type_is_invalid(casted_val->value.type)) |
| 14247 | if (type_is_invalid(casted_val->value->type)) |
| 14207 | 14248 | return ira->codegen->invalid_instruction; |
| 14208 | 14249 | |
| 14209 | 14250 | if (instr_is_comptime(casted_union)) { |
| 14210 | | ConstExprValue *const_union_val = ir_resolve_const(ira, casted_union, UndefBad); |
| 14251 | ZigValue *const_union_val = ir_resolve_const(ira, casted_union, UndefBad); |
| 14211 | 14252 | if (!const_union_val) |
| 14212 | 14253 | return ira->codegen->invalid_instruction; |
| 14213 | 14254 | |
| 14214 | | ConstExprValue *const_enum_val = ir_resolve_const(ira, casted_val, UndefBad); |
| 14255 | ZigValue *const_enum_val = ir_resolve_const(ira, casted_val, UndefBad); |
| 14215 | 14256 | if (!const_enum_val) |
| 14216 | 14257 | return ira->codegen->invalid_instruction; |
| 14217 | 14258 | |
| ... | ... | @@ -14224,17 +14265,17 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 14224 | 14265 | IrInstruction *result = ir_build_bin_op(&ira->new_irb, |
| 14225 | 14266 | bin_op_instruction->base.scope, bin_op_instruction->base.source_node, |
| 14226 | 14267 | op_id, casted_union, casted_val, bin_op_instruction->safety_check_on); |
| 14227 | | result->value.type = ira->codegen->builtin_types.entry_bool; |
| 14268 | result->value->type = ira->codegen->builtin_types.entry_bool; |
| 14228 | 14269 | |
| 14229 | 14270 | return result; |
| 14230 | 14271 | } |
| 14231 | 14272 | |
| 14232 | | if (op1->value.type->id == ZigTypeIdErrorSet && op2->value.type->id == ZigTypeIdErrorSet) { |
| 14273 | if (op1->value->type->id == ZigTypeIdErrorSet && op2->value->type->id == ZigTypeIdErrorSet) { |
| 14233 | 14274 | if (!is_equality_cmp) { |
| 14234 | 14275 | ir_add_error_node(ira, source_node, buf_sprintf("operator not allowed for errors")); |
| 14235 | 14276 | return ira->codegen->invalid_instruction; |
| 14236 | 14277 | } |
| 14237 | | ZigType *intersect_type = get_error_set_intersection(ira, op1->value.type, op2->value.type, source_node); |
| 14278 | ZigType *intersect_type = get_error_set_intersection(ira, op1->value->type, op2->value->type, source_node); |
| 14238 | 14279 | if (type_is_invalid(intersect_type)) { |
| 14239 | 14280 | return ira->codegen->invalid_instruction; |
| 14240 | 14281 | } |
| ... | ... | @@ -14247,7 +14288,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 14247 | 14288 | // (and make it comptime known) |
| 14248 | 14289 | // this is a function which is evaluated at comptime and returns an inferred error set will have an empty |
| 14249 | 14290 | // error set. |
| 14250 | | if (op1->value.type->data.error_set.err_count == 0 || op2->value.type->data.error_set.err_count == 0) { |
| 14291 | if (op1->value->type->data.error_set.err_count == 0 || op2->value->type->data.error_set.err_count == 0) { |
| 14251 | 14292 | bool are_equal = false; |
| 14252 | 14293 | bool answer; |
| 14253 | 14294 | if (op_id == IrBinOpCmpEq) { |
| ... | ... | @@ -14264,10 +14305,10 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 14264 | 14305 | if (intersect_type->data.error_set.err_count == 0) { |
| 14265 | 14306 | ir_add_error_node(ira, source_node, |
| 14266 | 14307 | buf_sprintf("error sets '%s' and '%s' have no common errors", |
| 14267 | | buf_ptr(&op1->value.type->name), buf_ptr(&op2->value.type->name))); |
| 14308 | buf_ptr(&op1->value->type->name), buf_ptr(&op2->value->type->name))); |
| 14268 | 14309 | return ira->codegen->invalid_instruction; |
| 14269 | 14310 | } |
| 14270 | | if (op1->value.type->data.error_set.err_count == 1 && op2->value.type->data.error_set.err_count == 1) { |
| 14311 | if (op1->value->type->data.error_set.err_count == 1 && op2->value->type->data.error_set.err_count == 1) { |
| 14271 | 14312 | bool are_equal = true; |
| 14272 | 14313 | bool answer; |
| 14273 | 14314 | if (op_id == IrBinOpCmpEq) { |
| ... | ... | @@ -14282,10 +14323,10 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 14282 | 14323 | } |
| 14283 | 14324 | |
| 14284 | 14325 | if (instr_is_comptime(op1) && instr_is_comptime(op2)) { |
| 14285 | | ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad); |
| 14326 | ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad); |
| 14286 | 14327 | if (op1_val == nullptr) |
| 14287 | 14328 | return ira->codegen->invalid_instruction; |
| 14288 | | ConstExprValue *op2_val = ir_resolve_const(ira, op2, UndefBad); |
| 14329 | ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad); |
| 14289 | 14330 | if (op2_val == nullptr) |
| 14290 | 14331 | return ira->codegen->invalid_instruction; |
| 14291 | 14332 | |
| ... | ... | @@ -14305,7 +14346,7 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 14305 | 14346 | IrInstruction *result = ir_build_bin_op(&ira->new_irb, |
| 14306 | 14347 | bin_op_instruction->base.scope, bin_op_instruction->base.source_node, |
| 14307 | 14348 | op_id, op1, op2, bin_op_instruction->safety_check_on); |
| 14308 | | result->value.type = ira->codegen->builtin_types.entry_bool; |
| 14349 | result->value->type = ira->codegen->builtin_types.entry_bool; |
| 14309 | 14350 | return result; |
| 14310 | 14351 | } |
| 14311 | 14352 | |
| ... | ... | @@ -14390,12 +14431,12 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 14390 | 14431 | // Before resolving the values, we special case comparisons against zero. These can often be done |
| 14391 | 14432 | // without resolving lazy values, preventing potential dependency loops. |
| 14392 | 14433 | Cmp op1_cmp_zero; |
| 14393 | | if ((err = lazy_cmp_zero(bin_op_instruction->base.source_node, &casted_op1->value, &op1_cmp_zero))) { |
| 14434 | if ((err = lazy_cmp_zero(bin_op_instruction->base.source_node, casted_op1->value, &op1_cmp_zero))) { |
| 14394 | 14435 | if (err == ErrorNotLazy) goto never_mind_just_calculate_it_normally; |
| 14395 | 14436 | return ira->codegen->invalid_instruction; |
| 14396 | 14437 | } |
| 14397 | 14438 | Cmp op2_cmp_zero; |
| 14398 | | if ((err = lazy_cmp_zero(bin_op_instruction->base.source_node, &casted_op2->value, &op2_cmp_zero))) { |
| 14439 | if ((err = lazy_cmp_zero(bin_op_instruction->base.source_node, casted_op2->value, &op2_cmp_zero))) { |
| 14399 | 14440 | if (err == ErrorNotLazy) goto never_mind_just_calculate_it_normally; |
| 14400 | 14441 | return ira->codegen->invalid_instruction; |
| 14401 | 14442 | } |
| ... | ... | @@ -14430,33 +14471,33 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * |
| 14430 | 14471 | } |
| 14431 | 14472 | never_mind_just_calculate_it_normally: |
| 14432 | 14473 | |
| 14433 | | ConstExprValue *op1_val = one_possible_value ? &casted_op1->value : ir_resolve_const(ira, casted_op1, UndefBad); |
| 14474 | ZigValue *op1_val = one_possible_value ? casted_op1->value : ir_resolve_const(ira, casted_op1, UndefBad); |
| 14434 | 14475 | if (op1_val == nullptr) |
| 14435 | 14476 | return ira->codegen->invalid_instruction; |
| 14436 | | ConstExprValue *op2_val = one_possible_value ? &casted_op2->value : ir_resolve_const(ira, casted_op2, UndefBad); |
| 14477 | ZigValue *op2_val = one_possible_value ? casted_op2->value : ir_resolve_const(ira, casted_op2, UndefBad); |
| 14437 | 14478 | if (op2_val == nullptr) |
| 14438 | 14479 | return ira->codegen->invalid_instruction; |
| 14439 | 14480 | if (resolved_type->id != ZigTypeIdVector) |
| 14440 | 14481 | return ir_evaluate_bin_op_cmp(ira, resolved_type, op1_val, op2_val, bin_op_instruction, op_id, one_possible_value); |
| 14441 | 14482 | IrInstruction *result = ir_const(ira, &bin_op_instruction->base, |
| 14442 | 14483 | get_vector_type(ira->codegen, resolved_type->data.vector.len, ira->codegen->builtin_types.entry_bool)); |
| 14443 | | result->value.data.x_array.data.s_none.elements = |
| 14484 | result->value->data.x_array.data.s_none.elements = |
| 14444 | 14485 | create_const_vals(resolved_type->data.vector.len); |
| 14445 | 14486 | |
| 14446 | | expand_undef_array(ira->codegen, &result->value); |
| 14487 | expand_undef_array(ira->codegen, result->value); |
| 14447 | 14488 | for (size_t i = 0;i < resolved_type->data.vector.len;i++) { |
| 14448 | 14489 | IrInstruction *cur_res = ir_evaluate_bin_op_cmp(ira, resolved_type->data.vector.elem_type, |
| 14449 | 14490 | &op1_val->data.x_array.data.s_none.elements[i], |
| 14450 | 14491 | &op2_val->data.x_array.data.s_none.elements[i], |
| 14451 | 14492 | bin_op_instruction, op_id, one_possible_value); |
| 14452 | | copy_const_val(&result->value.data.x_array.data.s_none.elements[i], &cur_res->value, false); |
| 14493 | copy_const_val(&result->value->data.x_array.data.s_none.elements[i], cur_res->value, false); |
| 14453 | 14494 | } |
| 14454 | 14495 | return result; |
| 14455 | 14496 | } |
| 14456 | 14497 | |
| 14457 | 14498 | // some comparisons with unsigned numbers can be evaluated |
| 14458 | 14499 | if (resolved_type->id == ZigTypeIdInt && !resolved_type->data.integral.is_signed) { |
| 14459 | | ConstExprValue *known_left_val; |
| 14500 | ZigValue *known_left_val; |
| 14460 | 14501 | IrBinOp flipped_op_id; |
| 14461 | 14502 | if (instr_is_comptime(casted_op1)) { |
| 14462 | 14503 | known_left_val = ir_resolve_const(ira, casted_op1, UndefBad); |
| ... | ... | @@ -14495,16 +14536,16 @@ never_mind_just_calculate_it_normally: |
| 14495 | 14536 | bin_op_instruction->base.scope, bin_op_instruction->base.source_node, |
| 14496 | 14537 | op_id, casted_op1, casted_op2, bin_op_instruction->safety_check_on); |
| 14497 | 14538 | if (resolved_type->id == ZigTypeIdVector) { |
| 14498 | | result->value.type = get_vector_type(ira->codegen, resolved_type->data.vector.len, |
| 14539 | result->value->type = get_vector_type(ira->codegen, resolved_type->data.vector.len, |
| 14499 | 14540 | ira->codegen->builtin_types.entry_bool); |
| 14500 | 14541 | } else { |
| 14501 | | result->value.type = ira->codegen->builtin_types.entry_bool; |
| 14542 | result->value->type = ira->codegen->builtin_types.entry_bool; |
| 14502 | 14543 | } |
| 14503 | 14544 | return result; |
| 14504 | 14545 | } |
| 14505 | 14546 | |
| 14506 | 14547 | static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInstruction *source_instr, ZigType *type_entry, |
| 14507 | | ConstExprValue *op1_val, IrBinOp op_id, ConstExprValue *op2_val, ConstExprValue *out_val) |
| 14548 | ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val, ZigValue *out_val) |
| 14508 | 14549 | { |
| 14509 | 14550 | bool is_int; |
| 14510 | 14551 | bool is_float; |
| ... | ... | @@ -14646,7 +14687,7 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInstruction *source_in |
| 14646 | 14687 | } |
| 14647 | 14688 | } else { |
| 14648 | 14689 | float_div_trunc(out_val, op1_val, op2_val); |
| 14649 | | ConstExprValue remainder = {}; |
| 14690 | ZigValue remainder = {}; |
| 14650 | 14691 | float_rem(&remainder, op1_val, op2_val); |
| 14651 | 14692 | if (float_cmp_zero(&remainder) != CmpEQ) { |
| 14652 | 14693 | return ir_add_error(ira, source_instr, buf_sprintf("exact division had a remainder")); |
| ... | ... | @@ -14684,10 +14725,10 @@ static ErrorMsg *ir_eval_math_op_scalar(IrAnalyze *ira, IrInstruction *source_in |
| 14684 | 14725 | |
| 14685 | 14726 | // This works on operands that have already been checked to be comptime known. |
| 14686 | 14727 | static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_instr, |
| 14687 | | ZigType *type_entry, ConstExprValue *op1_val, IrBinOp op_id, ConstExprValue *op2_val) |
| 14728 | ZigType *type_entry, ZigValue *op1_val, IrBinOp op_id, ZigValue *op2_val) |
| 14688 | 14729 | { |
| 14689 | 14730 | IrInstruction *result_instruction = ir_const(ira, source_instr, type_entry); |
| 14690 | | ConstExprValue *out_val = &result_instruction->value; |
| 14731 | ZigValue *out_val = result_instruction->value; |
| 14691 | 14732 | if (type_entry->id == ZigTypeIdVector) { |
| 14692 | 14733 | expand_undef_array(ira->codegen, op1_val); |
| 14693 | 14734 | expand_undef_array(ira->codegen, op2_val); |
| ... | ... | @@ -14696,9 +14737,9 @@ static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_i |
| 14696 | 14737 | size_t len = type_entry->data.vector.len; |
| 14697 | 14738 | ZigType *scalar_type = type_entry->data.vector.elem_type; |
| 14698 | 14739 | for (size_t i = 0; i < len; i += 1) { |
| 14699 | | ConstExprValue *scalar_op1_val = &op1_val->data.x_array.data.s_none.elements[i]; |
| 14700 | | ConstExprValue *scalar_op2_val = &op2_val->data.x_array.data.s_none.elements[i]; |
| 14701 | | ConstExprValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i]; |
| 14740 | ZigValue *scalar_op1_val = &op1_val->data.x_array.data.s_none.elements[i]; |
| 14741 | ZigValue *scalar_op2_val = &op2_val->data.x_array.data.s_none.elements[i]; |
| 14742 | ZigValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i]; |
| 14702 | 14743 | assert(scalar_op1_val->type == scalar_type); |
| 14703 | 14744 | assert(scalar_op2_val->type == scalar_type); |
| 14704 | 14745 | assert(scalar_out_val->type == scalar_type); |
| ... | ... | @@ -14722,52 +14763,52 @@ static IrInstruction *ir_analyze_math_op(IrAnalyze *ira, IrInstruction *source_i |
| 14722 | 14763 | |
| 14723 | 14764 | static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { |
| 14724 | 14765 | IrInstruction *op1 = bin_op_instruction->op1->child; |
| 14725 | | if (type_is_invalid(op1->value.type)) |
| 14766 | if (type_is_invalid(op1->value->type)) |
| 14726 | 14767 | return ira->codegen->invalid_instruction; |
| 14727 | 14768 | |
| 14728 | | if (op1->value.type->id != ZigTypeIdInt && op1->value.type->id != ZigTypeIdComptimeInt) { |
| 14769 | if (op1->value->type->id != ZigTypeIdInt && op1->value->type->id != ZigTypeIdComptimeInt) { |
| 14729 | 14770 | ir_add_error(ira, bin_op_instruction->op1, |
| 14730 | 14771 | buf_sprintf("bit shifting operation expected integer type, found '%s'", |
| 14731 | | buf_ptr(&op1->value.type->name))); |
| 14772 | buf_ptr(&op1->value->type->name))); |
| 14732 | 14773 | return ira->codegen->invalid_instruction; |
| 14733 | 14774 | } |
| 14734 | 14775 | |
| 14735 | 14776 | IrInstruction *op2 = bin_op_instruction->op2->child; |
| 14736 | | if (type_is_invalid(op2->value.type)) |
| 14777 | if (type_is_invalid(op2->value->type)) |
| 14737 | 14778 | return ira->codegen->invalid_instruction; |
| 14738 | 14779 | |
| 14739 | | if (op2->value.type->id != ZigTypeIdInt && op2->value.type->id != ZigTypeIdComptimeInt) { |
| 14780 | if (op2->value->type->id != ZigTypeIdInt && op2->value->type->id != ZigTypeIdComptimeInt) { |
| 14740 | 14781 | ir_add_error(ira, bin_op_instruction->op2, |
| 14741 | 14782 | buf_sprintf("shift amount has to be an integer type, but found '%s'", |
| 14742 | | buf_ptr(&op2->value.type->name))); |
| 14783 | buf_ptr(&op2->value->type->name))); |
| 14743 | 14784 | return ira->codegen->invalid_instruction; |
| 14744 | 14785 | } |
| 14745 | 14786 | |
| 14746 | 14787 | IrInstruction *casted_op2; |
| 14747 | 14788 | IrBinOp op_id = bin_op_instruction->op_id; |
| 14748 | | if (op1->value.type->id == ZigTypeIdComptimeInt) { |
| 14789 | if (op1->value->type->id == ZigTypeIdComptimeInt) { |
| 14749 | 14790 | casted_op2 = op2; |
| 14750 | 14791 | |
| 14751 | 14792 | if (op_id == IrBinOpBitShiftLeftLossy) { |
| 14752 | 14793 | op_id = IrBinOpBitShiftLeftExact; |
| 14753 | 14794 | } |
| 14754 | 14795 | |
| 14755 | | if (casted_op2->value.data.x_bigint.is_negative) { |
| 14796 | if (casted_op2->value->data.x_bigint.is_negative) { |
| 14756 | 14797 | Buf *val_buf = buf_alloc(); |
| 14757 | | bigint_append_buf(val_buf, &casted_op2->value.data.x_bigint, 10); |
| 14798 | bigint_append_buf(val_buf, &casted_op2->value->data.x_bigint, 10); |
| 14758 | 14799 | ir_add_error(ira, casted_op2, buf_sprintf("shift by negative value %s", buf_ptr(val_buf))); |
| 14759 | 14800 | return ira->codegen->invalid_instruction; |
| 14760 | 14801 | } |
| 14761 | 14802 | } else { |
| 14762 | 14803 | ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen, |
| 14763 | | op1->value.type->data.integral.bit_count - 1); |
| 14804 | op1->value->type->data.integral.bit_count - 1); |
| 14764 | 14805 | if (bin_op_instruction->op_id == IrBinOpBitShiftLeftLossy && |
| 14765 | | op2->value.type->id == ZigTypeIdComptimeInt) { |
| 14766 | | if (!bigint_fits_in_bits(&op2->value.data.x_bigint, |
| 14806 | op2->value->type->id == ZigTypeIdComptimeInt) { |
| 14807 | if (!bigint_fits_in_bits(&op2->value->data.x_bigint, |
| 14767 | 14808 | shift_amt_type->data.integral.bit_count, |
| 14768 | | op2->value.data.x_bigint.is_negative)) { |
| 14809 | op2->value->data.x_bigint.is_negative)) { |
| 14769 | 14810 | Buf *val_buf = buf_alloc(); |
| 14770 | | bigint_append_buf(val_buf, &op2->value.data.x_bigint, 10); |
| 14811 | bigint_append_buf(val_buf, &op2->value->data.x_bigint, 10); |
| 14771 | 14812 | ErrorMsg* msg = ir_add_error(ira, |
| 14772 | 14813 | &bin_op_instruction->base, |
| 14773 | 14814 | buf_sprintf("RHS of shift is too large for LHS type")); |
| ... | ... | @@ -14788,30 +14829,30 @@ static IrInstruction *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *b |
| 14788 | 14829 | } |
| 14789 | 14830 | |
| 14790 | 14831 | if (instr_is_comptime(op1) && instr_is_comptime(casted_op2)) { |
| 14791 | | ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad); |
| 14832 | ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad); |
| 14792 | 14833 | if (op1_val == nullptr) |
| 14793 | 14834 | return ira->codegen->invalid_instruction; |
| 14794 | 14835 | |
| 14795 | | ConstExprValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); |
| 14836 | ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); |
| 14796 | 14837 | if (op2_val == nullptr) |
| 14797 | 14838 | return ira->codegen->invalid_instruction; |
| 14798 | 14839 | |
| 14799 | | return ir_analyze_math_op(ira, &bin_op_instruction->base, op1->value.type, op1_val, op_id, op2_val); |
| 14800 | | } else if (op1->value.type->id == ZigTypeIdComptimeInt) { |
| 14840 | return ir_analyze_math_op(ira, &bin_op_instruction->base, op1->value->type, op1_val, op_id, op2_val); |
| 14841 | } else if (op1->value->type->id == ZigTypeIdComptimeInt) { |
| 14801 | 14842 | ir_add_error(ira, &bin_op_instruction->base, |
| 14802 | 14843 | buf_sprintf("LHS of shift must be an integer type, or RHS must be compile-time known")); |
| 14803 | 14844 | return ira->codegen->invalid_instruction; |
| 14804 | | } else if (instr_is_comptime(casted_op2) && bigint_cmp_zero(&casted_op2->value.data.x_bigint) == CmpEQ) { |
| 14845 | } else if (instr_is_comptime(casted_op2) && bigint_cmp_zero(&casted_op2->value->data.x_bigint) == CmpEQ) { |
| 14805 | 14846 | IrInstruction *result = ir_build_cast(&ira->new_irb, bin_op_instruction->base.scope, |
| 14806 | | bin_op_instruction->base.source_node, op1->value.type, op1, CastOpNoop); |
| 14807 | | result->value.type = op1->value.type; |
| 14847 | bin_op_instruction->base.source_node, op1->value->type, op1, CastOpNoop); |
| 14848 | result->value->type = op1->value->type; |
| 14808 | 14849 | return result; |
| 14809 | 14850 | } |
| 14810 | 14851 | |
| 14811 | 14852 | IrInstruction *result = ir_build_bin_op(&ira->new_irb, bin_op_instruction->base.scope, |
| 14812 | 14853 | bin_op_instruction->base.source_node, op_id, |
| 14813 | 14854 | op1, casted_op2, bin_op_instruction->safety_check_on); |
| 14814 | | result->value.type = op1->value.type; |
| 14855 | result->value->type = op1->value->type; |
| 14815 | 14856 | return result; |
| 14816 | 14857 | } |
| 14817 | 14858 | |
| ... | ... | @@ -14880,42 +14921,42 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 14880 | 14921 | Error err; |
| 14881 | 14922 | |
| 14882 | 14923 | IrInstruction *op1 = instruction->op1->child; |
| 14883 | | if (type_is_invalid(op1->value.type)) |
| 14924 | if (type_is_invalid(op1->value->type)) |
| 14884 | 14925 | return ira->codegen->invalid_instruction; |
| 14885 | 14926 | |
| 14886 | 14927 | IrInstruction *op2 = instruction->op2->child; |
| 14887 | | if (type_is_invalid(op2->value.type)) |
| 14928 | if (type_is_invalid(op2->value->type)) |
| 14888 | 14929 | return ira->codegen->invalid_instruction; |
| 14889 | 14930 | |
| 14890 | 14931 | IrBinOp op_id = instruction->op_id; |
| 14891 | 14932 | |
| 14892 | 14933 | // look for pointer math |
| 14893 | | if (is_pointer_arithmetic_allowed(op1->value.type, op_id)) { |
| 14934 | if (is_pointer_arithmetic_allowed(op1->value->type, op_id)) { |
| 14894 | 14935 | IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, ira->codegen->builtin_types.entry_usize); |
| 14895 | | if (type_is_invalid(casted_op2->value.type)) |
| 14936 | if (type_is_invalid(casted_op2->value->type)) |
| 14896 | 14937 | return ira->codegen->invalid_instruction; |
| 14897 | 14938 | |
| 14898 | 14939 | // If either operand is undef, result is undef. |
| 14899 | | ConstExprValue *op1_val = nullptr; |
| 14900 | | ConstExprValue *op2_val = nullptr; |
| 14940 | ZigValue *op1_val = nullptr; |
| 14941 | ZigValue *op2_val = nullptr; |
| 14901 | 14942 | if (instr_is_comptime(op1)) { |
| 14902 | 14943 | op1_val = ir_resolve_const(ira, op1, UndefOk); |
| 14903 | 14944 | if (op1_val == nullptr) |
| 14904 | 14945 | return ira->codegen->invalid_instruction; |
| 14905 | 14946 | if (op1_val->special == ConstValSpecialUndef) |
| 14906 | | return ir_const_undef(ira, &instruction->base, op1->value.type); |
| 14947 | return ir_const_undef(ira, &instruction->base, op1->value->type); |
| 14907 | 14948 | } |
| 14908 | 14949 | if (instr_is_comptime(casted_op2)) { |
| 14909 | 14950 | op2_val = ir_resolve_const(ira, casted_op2, UndefOk); |
| 14910 | 14951 | if (op2_val == nullptr) |
| 14911 | 14952 | return ira->codegen->invalid_instruction; |
| 14912 | 14953 | if (op2_val->special == ConstValSpecialUndef) |
| 14913 | | return ir_const_undef(ira, &instruction->base, op1->value.type); |
| 14954 | return ir_const_undef(ira, &instruction->base, op1->value->type); |
| 14914 | 14955 | } |
| 14915 | 14956 | |
| 14916 | 14957 | if (op2_val != nullptr && op1_val != nullptr && |
| 14917 | | (op1->value.data.x_ptr.special == ConstPtrSpecialHardCodedAddr || |
| 14918 | | op1->value.data.x_ptr.special == ConstPtrSpecialNull)) |
| 14958 | (op1->value->data.x_ptr.special == ConstPtrSpecialHardCodedAddr || |
| 14959 | op1->value->data.x_ptr.special == ConstPtrSpecialNull)) |
| 14919 | 14960 | { |
| 14920 | 14961 | uint64_t start_addr = (op1_val->data.x_ptr.special == ConstPtrSpecialNull) ? |
| 14921 | 14962 | 0 : op1_val->data.x_ptr.data.hard_coded_addr.addr; |
| ... | ... | @@ -14935,15 +14976,15 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 14935 | 14976 | zig_unreachable(); |
| 14936 | 14977 | } |
| 14937 | 14978 | IrInstruction *result = ir_const(ira, &instruction->base, op1_val->type); |
| 14938 | | result->value.data.x_ptr.special = ConstPtrSpecialHardCodedAddr; |
| 14939 | | result->value.data.x_ptr.mut = ConstPtrMutRuntimeVar; |
| 14940 | | result->value.data.x_ptr.data.hard_coded_addr.addr = new_addr; |
| 14979 | result->value->data.x_ptr.special = ConstPtrSpecialHardCodedAddr; |
| 14980 | result->value->data.x_ptr.mut = ConstPtrMutRuntimeVar; |
| 14981 | result->value->data.x_ptr.data.hard_coded_addr.addr = new_addr; |
| 14941 | 14982 | return result; |
| 14942 | 14983 | } |
| 14943 | 14984 | |
| 14944 | 14985 | IrInstruction *result = ir_build_bin_op(&ira->new_irb, instruction->base.scope, |
| 14945 | 14986 | instruction->base.source_node, op_id, op1, casted_op2, true); |
| 14946 | | result->value.type = op1->value.type; |
| 14987 | result->value->type = op1->value->type; |
| 14947 | 14988 | return result; |
| 14948 | 14989 | } |
| 14949 | 14990 | |
| ... | ... | @@ -14958,21 +14999,21 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 14958 | 14999 | (resolved_type->id == ZigTypeIdInt && resolved_type->data.integral.is_signed) || |
| 14959 | 15000 | resolved_type->id == ZigTypeIdFloat || |
| 14960 | 15001 | (resolved_type->id == ZigTypeIdComptimeFloat && |
| 14961 | | ((bigfloat_cmp_zero(&op1->value.data.x_bigfloat) != CmpGT) != |
| 14962 | | (bigfloat_cmp_zero(&op2->value.data.x_bigfloat) != CmpGT))) || |
| 15002 | ((bigfloat_cmp_zero(&op1->value->data.x_bigfloat) != CmpGT) != |
| 15003 | (bigfloat_cmp_zero(&op2->value->data.x_bigfloat) != CmpGT))) || |
| 14963 | 15004 | (resolved_type->id == ZigTypeIdComptimeInt && |
| 14964 | | ((bigint_cmp_zero(&op1->value.data.x_bigint) != CmpGT) != |
| 14965 | | (bigint_cmp_zero(&op2->value.data.x_bigint) != CmpGT))) |
| 15005 | ((bigint_cmp_zero(&op1->value->data.x_bigint) != CmpGT) != |
| 15006 | (bigint_cmp_zero(&op2->value->data.x_bigint) != CmpGT))) |
| 14966 | 15007 | ); |
| 14967 | 15008 | if (op_id == IrBinOpDivUnspecified && is_int) { |
| 14968 | 15009 | if (is_signed_div) { |
| 14969 | 15010 | bool ok = false; |
| 14970 | 15011 | if (instr_is_comptime(op1) && instr_is_comptime(op2)) { |
| 14971 | | ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad); |
| 15012 | ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad); |
| 14972 | 15013 | if (op1_val == nullptr) |
| 14973 | 15014 | return ira->codegen->invalid_instruction; |
| 14974 | 15015 | |
| 14975 | | ConstExprValue *op2_val = ir_resolve_const(ira, op2, UndefBad); |
| 15016 | ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad); |
| 14976 | 15017 | if (op2_val == nullptr) |
| 14977 | 15018 | return ira->codegen->invalid_instruction; |
| 14978 | 15019 | |
| ... | ... | @@ -14995,8 +15036,8 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 14995 | 15036 | if (!ok) { |
| 14996 | 15037 | ir_add_error(ira, &instruction->base, |
| 14997 | 15038 | buf_sprintf("division with '%s' and '%s': signed integers must use @divTrunc, @divFloor, or @divExact", |
| 14998 | | buf_ptr(&op1->value.type->name), |
| 14999 | | buf_ptr(&op2->value.type->name))); |
| 15039 | buf_ptr(&op1->value->type->name), |
| 15040 | buf_ptr(&op2->value->type->name))); |
| 15000 | 15041 | return ira->codegen->invalid_instruction; |
| 15001 | 15042 | } |
| 15002 | 15043 | } else { |
| ... | ... | @@ -15006,16 +15047,16 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 15006 | 15047 | if (is_signed_div && (is_int || is_float)) { |
| 15007 | 15048 | bool ok = false; |
| 15008 | 15049 | if (instr_is_comptime(op1) && instr_is_comptime(op2)) { |
| 15009 | | ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad); |
| 15050 | ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad); |
| 15010 | 15051 | if (op1_val == nullptr) |
| 15011 | 15052 | return ira->codegen->invalid_instruction; |
| 15012 | 15053 | |
| 15013 | 15054 | if (is_int) { |
| 15014 | | ConstExprValue *op2_val = ir_resolve_const(ira, op2, UndefBad); |
| 15055 | ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad); |
| 15015 | 15056 | if (op2_val == nullptr) |
| 15016 | 15057 | return ira->codegen->invalid_instruction; |
| 15017 | 15058 | |
| 15018 | | if (bigint_cmp_zero(&op2->value.data.x_bigint) == CmpEQ) { |
| 15059 | if (bigint_cmp_zero(&op2->value->data.x_bigint) == CmpEQ) { |
| 15019 | 15060 | // the division by zero error will be caught later, but we don't |
| 15020 | 15061 | // have a remainder function ambiguity problem |
| 15021 | 15062 | ok = true; |
| ... | ... | @@ -15031,17 +15072,17 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 15031 | 15072 | if (casted_op2 == ira->codegen->invalid_instruction) |
| 15032 | 15073 | return ira->codegen->invalid_instruction; |
| 15033 | 15074 | |
| 15034 | | ConstExprValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); |
| 15075 | ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); |
| 15035 | 15076 | if (op2_val == nullptr) |
| 15036 | 15077 | return ira->codegen->invalid_instruction; |
| 15037 | 15078 | |
| 15038 | | if (float_cmp_zero(&casted_op2->value) == CmpEQ) { |
| 15079 | if (float_cmp_zero(casted_op2->value) == CmpEQ) { |
| 15039 | 15080 | // the division by zero error will be caught later, but we don't |
| 15040 | 15081 | // have a remainder function ambiguity problem |
| 15041 | 15082 | ok = true; |
| 15042 | 15083 | } else { |
| 15043 | | ConstExprValue rem_result = {}; |
| 15044 | | ConstExprValue mod_result = {}; |
| 15084 | ZigValue rem_result = {}; |
| 15085 | ZigValue mod_result = {}; |
| 15045 | 15086 | float_rem(&rem_result, op1_val, op2_val); |
| 15046 | 15087 | float_mod(&mod_result, op1_val, op2_val); |
| 15047 | 15088 | ok = float_cmp(&rem_result, &mod_result) == CmpEQ; |
| ... | ... | @@ -15051,8 +15092,8 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 15051 | 15092 | if (!ok) { |
| 15052 | 15093 | ir_add_error(ira, &instruction->base, |
| 15053 | 15094 | buf_sprintf("remainder division with '%s' and '%s': signed integers and floats must use @rem or @mod", |
| 15054 | | buf_ptr(&op1->value.type->name), |
| 15055 | | buf_ptr(&op2->value.type->name))); |
| 15095 | buf_ptr(&op1->value->type->name), |
| 15096 | buf_ptr(&op2->value->type->name))); |
| 15056 | 15097 | return ira->codegen->invalid_instruction; |
| 15057 | 15098 | } |
| 15058 | 15099 | } |
| ... | ... | @@ -15076,8 +15117,8 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 15076 | 15117 | AstNode *source_node = instruction->base.source_node; |
| 15077 | 15118 | ir_add_error_node(ira, source_node, |
| 15078 | 15119 | buf_sprintf("invalid operands to binary expression: '%s' and '%s'", |
| 15079 | | buf_ptr(&op1->value.type->name), |
| 15080 | | buf_ptr(&op2->value.type->name))); |
| 15120 | buf_ptr(&op1->value->type->name), |
| 15121 | buf_ptr(&op2->value->type->name))); |
| 15081 | 15122 | return ira->codegen->invalid_instruction; |
| 15082 | 15123 | } |
| 15083 | 15124 | |
| ... | ... | @@ -15100,10 +15141,10 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 15100 | 15141 | return ira->codegen->invalid_instruction; |
| 15101 | 15142 | |
| 15102 | 15143 | if (instr_is_comptime(casted_op1) && instr_is_comptime(casted_op2)) { |
| 15103 | | ConstExprValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad); |
| 15144 | ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad); |
| 15104 | 15145 | if (op1_val == nullptr) |
| 15105 | 15146 | return ira->codegen->invalid_instruction; |
| 15106 | | ConstExprValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); |
| 15147 | ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); |
| 15107 | 15148 | if (op2_val == nullptr) |
| 15108 | 15149 | return ira->codegen->invalid_instruction; |
| 15109 | 15150 | |
| ... | ... | @@ -15112,31 +15153,31 @@ static IrInstruction *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp |
| 15112 | 15153 | |
| 15113 | 15154 | IrInstruction *result = ir_build_bin_op(&ira->new_irb, instruction->base.scope, |
| 15114 | 15155 | instruction->base.source_node, op_id, casted_op1, casted_op2, instruction->safety_check_on); |
| 15115 | | result->value.type = resolved_type; |
| 15156 | result->value->type = resolved_type; |
| 15116 | 15157 | return result; |
| 15117 | 15158 | } |
| 15118 | 15159 | |
| 15119 | 15160 | static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruction) { |
| 15120 | 15161 | IrInstruction *op1 = instruction->op1->child; |
| 15121 | | ZigType *op1_type = op1->value.type; |
| 15162 | ZigType *op1_type = op1->value->type; |
| 15122 | 15163 | if (type_is_invalid(op1_type)) |
| 15123 | 15164 | return ira->codegen->invalid_instruction; |
| 15124 | 15165 | |
| 15125 | 15166 | IrInstruction *op2 = instruction->op2->child; |
| 15126 | | ZigType *op2_type = op2->value.type; |
| 15167 | ZigType *op2_type = op2->value->type; |
| 15127 | 15168 | if (type_is_invalid(op2_type)) |
| 15128 | 15169 | return ira->codegen->invalid_instruction; |
| 15129 | 15170 | |
| 15130 | | ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad); |
| 15171 | ZigValue *op1_val = ir_resolve_const(ira, op1, UndefBad); |
| 15131 | 15172 | if (!op1_val) |
| 15132 | 15173 | return ira->codegen->invalid_instruction; |
| 15133 | 15174 | |
| 15134 | | ConstExprValue *op2_val = ir_resolve_const(ira, op2, UndefBad); |
| 15175 | ZigValue *op2_val = ir_resolve_const(ira, op2, UndefBad); |
| 15135 | 15176 | if (!op2_val) |
| 15136 | 15177 | return ira->codegen->invalid_instruction; |
| 15137 | 15178 | |
| 15138 | | ConstExprValue *sentinel1 = nullptr; |
| 15139 | | ConstExprValue *op1_array_val; |
| 15179 | ZigValue *sentinel1 = nullptr; |
| 15180 | ZigValue *op1_array_val; |
| 15140 | 15181 | size_t op1_array_index; |
| 15141 | 15182 | size_t op1_array_end; |
| 15142 | 15183 | ZigType *child_type; |
| ... | ... | @@ -15159,11 +15200,11 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i |
| 15159 | 15200 | } else if (is_slice(op1_type)) { |
| 15160 | 15201 | ZigType *ptr_type = op1_type->data.structure.fields[slice_ptr_index]->type_entry; |
| 15161 | 15202 | child_type = ptr_type->data.pointer.child_type; |
| 15162 | | ConstExprValue *ptr_val = op1_val->data.x_struct.fields[slice_ptr_index]; |
| 15203 | ZigValue *ptr_val = op1_val->data.x_struct.fields[slice_ptr_index]; |
| 15163 | 15204 | assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray); |
| 15164 | 15205 | op1_array_val = ptr_val->data.x_ptr.data.base_array.array_val; |
| 15165 | 15206 | op1_array_index = ptr_val->data.x_ptr.data.base_array.elem_index; |
| 15166 | | ConstExprValue *len_val = op1_val->data.x_struct.fields[slice_len_index]; |
| 15207 | ZigValue *len_val = op1_val->data.x_struct.fields[slice_len_index]; |
| 15167 | 15208 | op1_array_end = op1_array_index + bigint_as_usize(&len_val->data.x_bigint); |
| 15168 | 15209 | sentinel1 = ptr_type->data.pointer.sentinel; |
| 15169 | 15210 | } else if (op1_type->id == ZigTypeIdPointer && op1_type->data.pointer.ptr_len == PtrLenSingle && |
| ... | ... | @@ -15178,13 +15219,12 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i |
| 15178 | 15219 | op1_array_end = array_type->data.array.len; |
| 15179 | 15220 | sentinel1 = array_type->data.array.sentinel; |
| 15180 | 15221 | } else { |
| 15181 | | ir_add_error(ira, op1, |
| 15182 | | buf_sprintf("expected array, found '%s'", buf_ptr(&op1->value.type->name))); |
| 15222 | ir_add_error(ira, op1, buf_sprintf("expected array, found '%s'", buf_ptr(&op1->value->type->name))); |
| 15183 | 15223 | return ira->codegen->invalid_instruction; |
| 15184 | 15224 | } |
| 15185 | 15225 | |
| 15186 | | ConstExprValue *sentinel2 = nullptr; |
| 15187 | | ConstExprValue *op2_array_val; |
| 15226 | ZigValue *sentinel2 = nullptr; |
| 15227 | ZigValue *op2_array_val; |
| 15188 | 15228 | size_t op2_array_index; |
| 15189 | 15229 | size_t op2_array_end; |
| 15190 | 15230 | bool op2_type_valid; |
| ... | ... | @@ -15207,11 +15247,11 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i |
| 15207 | 15247 | } else if (is_slice(op2_type)) { |
| 15208 | 15248 | ZigType *ptr_type = op2_type->data.structure.fields[slice_ptr_index]->type_entry; |
| 15209 | 15249 | op2_type_valid = ptr_type->data.pointer.child_type == child_type; |
| 15210 | | ConstExprValue *ptr_val = op2_val->data.x_struct.fields[slice_ptr_index]; |
| 15250 | ZigValue *ptr_val = op2_val->data.x_struct.fields[slice_ptr_index]; |
| 15211 | 15251 | assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray); |
| 15212 | 15252 | op2_array_val = ptr_val->data.x_ptr.data.base_array.array_val; |
| 15213 | 15253 | op2_array_index = ptr_val->data.x_ptr.data.base_array.elem_index; |
| 15214 | | ConstExprValue *len_val = op2_val->data.x_struct.fields[slice_len_index]; |
| 15254 | ZigValue *len_val = op2_val->data.x_struct.fields[slice_len_index]; |
| 15215 | 15255 | op2_array_end = op2_array_index + bigint_as_usize(&len_val->data.x_bigint); |
| 15216 | 15256 | |
| 15217 | 15257 | sentinel2 = ptr_type->data.pointer.sentinel; |
| ... | ... | @@ -15229,17 +15269,17 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i |
| 15229 | 15269 | sentinel2 = array_type->data.array.sentinel; |
| 15230 | 15270 | } else { |
| 15231 | 15271 | ir_add_error(ira, op2, |
| 15232 | | buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op2->value.type->name))); |
| 15272 | buf_sprintf("expected array or C string literal, found '%s'", buf_ptr(&op2->value->type->name))); |
| 15233 | 15273 | return ira->codegen->invalid_instruction; |
| 15234 | 15274 | } |
| 15235 | 15275 | if (!op2_type_valid) { |
| 15236 | 15276 | ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'", |
| 15237 | 15277 | buf_ptr(&child_type->name), |
| 15238 | | buf_ptr(&op2->value.type->name))); |
| 15278 | buf_ptr(&op2->value->type->name))); |
| 15239 | 15279 | return ira->codegen->invalid_instruction; |
| 15240 | 15280 | } |
| 15241 | 15281 | |
| 15242 | | ConstExprValue *sentinel; |
| 15282 | ZigValue *sentinel; |
| 15243 | 15283 | if (sentinel1 != nullptr && sentinel2 != nullptr) { |
| 15244 | 15284 | // When there is a sentinel mismatch, no sentinel on the result. The type system |
| 15245 | 15285 | // will catch this if it is a problem. |
| ... | ... | @@ -15254,13 +15294,12 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i |
| 15254 | 15294 | |
| 15255 | 15295 | // The type of result is populated in the following if blocks |
| 15256 | 15296 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 15257 | | ConstExprValue *out_val = &result->value; |
| 15297 | ZigValue *out_val = result->value; |
| 15258 | 15298 | |
| 15259 | | ConstExprValue *out_array_val; |
| 15299 | ZigValue *out_array_val; |
| 15260 | 15300 | size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index); |
| 15261 | 15301 | if (op1_type->id == ZigTypeIdArray || op2_type->id == ZigTypeIdArray) { |
| 15262 | | result->value.type = get_array_type(ira->codegen, child_type, new_len, sentinel); |
| 15263 | | |
| 15302 | result->value->type = get_array_type(ira->codegen, child_type, new_len, sentinel); |
| 15264 | 15303 | out_array_val = out_val; |
| 15265 | 15304 | } else if (op1_type->id == ZigTypeIdPointer || op2_type->id == ZigTypeIdPointer) { |
| 15266 | 15305 | out_array_val = create_const_vals(1); |
| ... | ... | @@ -15274,7 +15313,7 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i |
| 15274 | 15313 | ZigType *ptr_type = get_pointer_to_type_extra2(ira->codegen, child_type, |
| 15275 | 15314 | true, false, PtrLenUnknown, 0, 0, 0, false, |
| 15276 | 15315 | VECTOR_INDEX_NONE, nullptr, sentinel); |
| 15277 | | result->value.type = get_slice_type(ira->codegen, ptr_type); |
| 15316 | result->value->type = get_slice_type(ira->codegen, ptr_type); |
| 15278 | 15317 | out_array_val = create_const_vals(1); |
| 15279 | 15318 | out_array_val->special = ConstValSpecialStatic; |
| 15280 | 15319 | out_array_val->type = get_array_type(ira->codegen, child_type, new_len, sentinel); |
| ... | ... | @@ -15291,9 +15330,8 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i |
| 15291 | 15330 | out_val->data.x_struct.fields[slice_len_index]->special = ConstValSpecialStatic; |
| 15292 | 15331 | bigint_init_unsigned(&out_val->data.x_struct.fields[slice_len_index]->data.x_bigint, new_len); |
| 15293 | 15332 | } else { |
| 15294 | | result->value.type = get_pointer_to_type_extra2(ira->codegen, child_type, true, false, PtrLenUnknown, |
| 15333 | result->value->type = get_pointer_to_type_extra2(ira->codegen, child_type, true, false, PtrLenUnknown, |
| 15295 | 15334 | 0, 0, 0, false, VECTOR_INDEX_NONE, nullptr, sentinel); |
| 15296 | | |
| 15297 | 15335 | out_array_val = create_const_vals(1); |
| 15298 | 15336 | out_array_val->special = ConstValSpecialStatic; |
| 15299 | 15337 | out_array_val->type = get_array_type(ira->codegen, child_type, new_len, sentinel); |
| ... | ... | @@ -15317,21 +15355,21 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i |
| 15317 | 15355 | |
| 15318 | 15356 | size_t next_index = 0; |
| 15319 | 15357 | for (size_t i = op1_array_index; i < op1_array_end; i += 1, next_index += 1) { |
| 15320 | | ConstExprValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index]; |
| 15358 | ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index]; |
| 15321 | 15359 | copy_const_val(elem_dest_val, &op1_array_val->data.x_array.data.s_none.elements[i], false); |
| 15322 | 15360 | elem_dest_val->parent.id = ConstParentIdArray; |
| 15323 | 15361 | elem_dest_val->parent.data.p_array.array_val = out_array_val; |
| 15324 | 15362 | elem_dest_val->parent.data.p_array.elem_index = next_index; |
| 15325 | 15363 | } |
| 15326 | 15364 | for (size_t i = op2_array_index; i < op2_array_end; i += 1, next_index += 1) { |
| 15327 | | ConstExprValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index]; |
| 15365 | ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index]; |
| 15328 | 15366 | copy_const_val(elem_dest_val, &op2_array_val->data.x_array.data.s_none.elements[i], false); |
| 15329 | 15367 | elem_dest_val->parent.id = ConstParentIdArray; |
| 15330 | 15368 | elem_dest_val->parent.data.p_array.array_val = out_array_val; |
| 15331 | 15369 | elem_dest_val->parent.data.p_array.elem_index = next_index; |
| 15332 | 15370 | } |
| 15333 | 15371 | if (next_index < full_len) { |
| 15334 | | ConstExprValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index]; |
| 15372 | ZigValue *elem_dest_val = &out_array_val->data.x_array.data.s_none.elements[next_index]; |
| 15335 | 15373 | copy_const_val(elem_dest_val, sentinel, false); |
| 15336 | 15374 | elem_dest_val->parent.id = ConstParentIdArray; |
| 15337 | 15375 | elem_dest_val->parent.data.p_array.array_val = out_array_val; |
| ... | ... | @@ -15345,34 +15383,34 @@ static IrInstruction *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *i |
| 15345 | 15383 | |
| 15346 | 15384 | static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instruction) { |
| 15347 | 15385 | IrInstruction *op1 = instruction->op1->child; |
| 15348 | | if (type_is_invalid(op1->value.type)) |
| 15386 | if (type_is_invalid(op1->value->type)) |
| 15349 | 15387 | return ira->codegen->invalid_instruction; |
| 15350 | 15388 | |
| 15351 | 15389 | IrInstruction *op2 = instruction->op2->child; |
| 15352 | | if (type_is_invalid(op2->value.type)) |
| 15390 | if (type_is_invalid(op2->value->type)) |
| 15353 | 15391 | return ira->codegen->invalid_instruction; |
| 15354 | 15392 | |
| 15355 | 15393 | bool want_ptr_to_array = false; |
| 15356 | 15394 | ZigType *array_type; |
| 15357 | | ConstExprValue *array_val; |
| 15358 | | if (op1->value.type->id == ZigTypeIdArray) { |
| 15359 | | array_type = op1->value.type; |
| 15395 | ZigValue *array_val; |
| 15396 | if (op1->value->type->id == ZigTypeIdArray) { |
| 15397 | array_type = op1->value->type; |
| 15360 | 15398 | array_val = ir_resolve_const(ira, op1, UndefOk); |
| 15361 | 15399 | if (array_val == nullptr) |
| 15362 | 15400 | return ira->codegen->invalid_instruction; |
| 15363 | | } else if (op1->value.type->id == ZigTypeIdPointer && op1->value.type->data.pointer.ptr_len == PtrLenSingle && |
| 15364 | | op1->value.type->data.pointer.child_type->id == ZigTypeIdArray) |
| 15401 | } else if (op1->value->type->id == ZigTypeIdPointer && op1->value->type->data.pointer.ptr_len == PtrLenSingle && |
| 15402 | op1->value->type->data.pointer.child_type->id == ZigTypeIdArray) |
| 15365 | 15403 | { |
| 15366 | | array_type = op1->value.type->data.pointer.child_type; |
| 15404 | array_type = op1->value->type->data.pointer.child_type; |
| 15367 | 15405 | IrInstruction *array_inst = ir_get_deref(ira, op1, op1, nullptr); |
| 15368 | | if (type_is_invalid(array_inst->value.type)) |
| 15406 | if (type_is_invalid(array_inst->value->type)) |
| 15369 | 15407 | return ira->codegen->invalid_instruction; |
| 15370 | 15408 | array_val = ir_resolve_const(ira, array_inst, UndefOk); |
| 15371 | 15409 | if (array_val == nullptr) |
| 15372 | 15410 | return ira->codegen->invalid_instruction; |
| 15373 | 15411 | want_ptr_to_array = true; |
| 15374 | 15412 | } else { |
| 15375 | | ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value.type->name))); |
| 15413 | ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value->type->name))); |
| 15376 | 15414 | return ira->codegen->invalid_instruction; |
| 15377 | 15415 | } |
| 15378 | 15416 | |
| ... | ... | @@ -15397,7 +15435,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp * |
| 15397 | 15435 | array_result = ir_const_undef(ira, &instruction->base, result_array_type); |
| 15398 | 15436 | } else { |
| 15399 | 15437 | array_result = ir_const(ira, &instruction->base, result_array_type); |
| 15400 | | ConstExprValue *out_val = &array_result->value; |
| 15438 | ZigValue *out_val = array_result->value; |
| 15401 | 15439 | |
| 15402 | 15440 | switch (type_has_one_possible_value(ira->codegen, result_array_type)) { |
| 15403 | 15441 | case OnePossibleValueInvalid: |
| ... | ... | @@ -15416,7 +15454,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp * |
| 15416 | 15454 | uint64_t i = 0; |
| 15417 | 15455 | for (uint64_t x = 0; x < mult_amt; x += 1) { |
| 15418 | 15456 | for (uint64_t y = 0; y < old_array_len; y += 1) { |
| 15419 | | ConstExprValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i]; |
| 15457 | ZigValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i]; |
| 15420 | 15458 | copy_const_val(elem_dest_val, &array_val->data.x_array.data.s_none.elements[y], false); |
| 15421 | 15459 | elem_dest_val->parent.id = ConstParentIdArray; |
| 15422 | 15460 | elem_dest_val->parent.data.p_array.array_val = out_val; |
| ... | ... | @@ -15427,7 +15465,7 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp * |
| 15427 | 15465 | assert(i == new_array_len); |
| 15428 | 15466 | |
| 15429 | 15467 | if (array_type->data.array.sentinel != nullptr) { |
| 15430 | | ConstExprValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i]; |
| 15468 | ZigValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i]; |
| 15431 | 15469 | copy_const_val(elem_dest_val, array_type->data.array.sentinel, false); |
| 15432 | 15470 | elem_dest_val->parent.id = ConstParentIdArray; |
| 15433 | 15471 | elem_dest_val->parent.data.p_array.array_val = out_val; |
| ... | ... | @@ -15554,25 +15592,25 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, |
| 15554 | 15592 | IrInstruction *var_ptr = decl_var_instruction->ptr->child; |
| 15555 | 15593 | // if this is null, a compiler error happened and did not initialize the variable. |
| 15556 | 15594 | // if there are no compile errors there may be a missing ir_expr_wrap in pass1 IR generation. |
| 15557 | | if (var_ptr == nullptr || type_is_invalid(var_ptr->value.type)) { |
| 15595 | if (var_ptr == nullptr || type_is_invalid(var_ptr->value->type)) { |
| 15558 | 15596 | ir_assert(var_ptr != nullptr || ira->codegen->errors.length != 0, &decl_var_instruction->base); |
| 15559 | 15597 | var->var_type = ira->codegen->builtin_types.entry_invalid; |
| 15560 | 15598 | return ira->codegen->invalid_instruction; |
| 15561 | 15599 | } |
| 15562 | 15600 | |
| 15563 | 15601 | // The ir_build_var_decl_src call is supposed to pass a pointer to the allocation, not an initialization value. |
| 15564 | | ir_assert(var_ptr->value.type->id == ZigTypeIdPointer, &decl_var_instruction->base); |
| 15602 | ir_assert(var_ptr->value->type->id == ZigTypeIdPointer, &decl_var_instruction->base); |
| 15565 | 15603 | |
| 15566 | | ZigType *result_type = var_ptr->value.type->data.pointer.child_type; |
| 15604 | ZigType *result_type = var_ptr->value->type->data.pointer.child_type; |
| 15567 | 15605 | if (type_is_invalid(result_type)) { |
| 15568 | 15606 | result_type = ira->codegen->builtin_types.entry_invalid; |
| 15569 | 15607 | } else if (result_type->id == ZigTypeIdUnreachable || result_type->id == ZigTypeIdOpaque) { |
| 15570 | 15608 | zig_unreachable(); |
| 15571 | 15609 | } |
| 15572 | 15610 | |
| 15573 | | ConstExprValue *init_val = nullptr; |
| 15574 | | if (instr_is_comptime(var_ptr) && var_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 15575 | | init_val = const_ptr_pointee(ira, ira->codegen, &var_ptr->value, decl_var_instruction->base.source_node); |
| 15611 | ZigValue *init_val = nullptr; |
| 15612 | if (instr_is_comptime(var_ptr) && var_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 15613 | init_val = const_ptr_pointee(ira, ira->codegen, var_ptr->value, decl_var_instruction->base.source_node); |
| 15576 | 15614 | if (is_comptime_var) { |
| 15577 | 15615 | if (var->gen_is_const) { |
| 15578 | 15616 | var->const_value = init_val; |
| ... | ... | @@ -15631,7 +15669,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, |
| 15631 | 15669 | new_var->owner_exec = var->owner_exec; |
| 15632 | 15670 | new_var->align_bytes = var->align_bytes; |
| 15633 | 15671 | if (var->mem_slot_index != SIZE_MAX) { |
| 15634 | | ConstExprValue *vals = create_const_vals(1); |
| 15672 | ZigValue *vals = create_const_vals(1); |
| 15635 | 15673 | new_var->mem_slot_index = ira->exec_context.mem_slot_list.length; |
| 15636 | 15674 | ira->exec_context.mem_slot_list.append(vals); |
| 15637 | 15675 | } |
| ... | ... | @@ -15665,29 +15703,29 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, |
| 15665 | 15703 | if (init_val != nullptr && value_is_comptime(init_val)) { |
| 15666 | 15704 | // Resolve ConstPtrMutInfer |
| 15667 | 15705 | if (var->gen_is_const) { |
| 15668 | | var_ptr->value.data.x_ptr.mut = ConstPtrMutComptimeConst; |
| 15706 | var_ptr->value->data.x_ptr.mut = ConstPtrMutComptimeConst; |
| 15669 | 15707 | } else if (is_comptime_var) { |
| 15670 | | var_ptr->value.data.x_ptr.mut = ConstPtrMutComptimeVar; |
| 15708 | var_ptr->value->data.x_ptr.mut = ConstPtrMutComptimeVar; |
| 15671 | 15709 | } else { |
| 15672 | 15710 | // we need a runtime ptr but we have a comptime val. |
| 15673 | 15711 | // since it's a comptime val there are no instructions for it. |
| 15674 | 15712 | // we memcpy the init value here |
| 15675 | 15713 | IrInstruction *deref = ir_get_deref(ira, var_ptr, var_ptr, nullptr); |
| 15676 | | if (type_is_invalid(deref->value.type)) { |
| 15714 | if (type_is_invalid(deref->value->type)) { |
| 15677 | 15715 | var->var_type = ira->codegen->builtin_types.entry_invalid; |
| 15678 | 15716 | return ira->codegen->invalid_instruction; |
| 15679 | 15717 | } |
| 15680 | 15718 | // If this assertion trips, something is wrong with the IR instructions, because |
| 15681 | 15719 | // we expected the above deref to return a constant value, but it created a runtime |
| 15682 | 15720 | // instruction. |
| 15683 | | assert(deref->value.special != ConstValSpecialRuntime); |
| 15684 | | var_ptr->value.special = ConstValSpecialRuntime; |
| 15721 | assert(deref->value->special != ConstValSpecialRuntime); |
| 15722 | var_ptr->value->special = ConstValSpecialRuntime; |
| 15685 | 15723 | ir_analyze_store_ptr(ira, var_ptr, var_ptr, deref, false); |
| 15686 | 15724 | } |
| 15687 | 15725 | |
| 15688 | 15726 | if (instr_is_comptime(var_ptr) && var->mem_slot_index != SIZE_MAX) { |
| 15689 | 15727 | assert(var->mem_slot_index < ira->exec_context.mem_slot_list.length); |
| 15690 | | ConstExprValue *mem_slot = ira->exec_context.mem_slot_list.at(var->mem_slot_index); |
| 15728 | ZigValue *mem_slot = ira->exec_context.mem_slot_list.at(var->mem_slot_index); |
| 15691 | 15729 | copy_const_val(mem_slot, init_val, !is_comptime_var || var->gen_is_const); |
| 15692 | 15730 | |
| 15693 | 15731 | if (is_comptime_var || (var_class_requires_const && var->gen_is_const)) { |
| ... | ... | @@ -15718,7 +15756,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio |
| 15718 | 15756 | } |
| 15719 | 15757 | |
| 15720 | 15758 | IrInstruction *target = instruction->target->child; |
| 15721 | | if (type_is_invalid(target->value.type)) { |
| 15759 | if (type_is_invalid(target->value->type)) { |
| 15722 | 15760 | return ira->codegen->invalid_instruction; |
| 15723 | 15761 | } |
| 15724 | 15762 | |
| ... | ... | @@ -15748,13 +15786,13 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio |
| 15748 | 15786 | } |
| 15749 | 15787 | |
| 15750 | 15788 | bool want_var_export = false; |
| 15751 | | switch (target->value.type->id) { |
| 15789 | switch (target->value->type->id) { |
| 15752 | 15790 | case ZigTypeIdInvalid: |
| 15753 | 15791 | case ZigTypeIdUnreachable: |
| 15754 | 15792 | zig_unreachable(); |
| 15755 | 15793 | case ZigTypeIdFn: { |
| 15756 | | assert(target->value.data.x_ptr.special == ConstPtrSpecialFunction); |
| 15757 | | ZigFn *fn_entry = target->value.data.x_ptr.data.fn.fn_entry; |
| 15794 | assert(target->value->data.x_ptr.special == ConstPtrSpecialFunction); |
| 15795 | ZigFn *fn_entry = target->value->data.x_ptr.data.fn.fn_entry; |
| 15758 | 15796 | tld_fn->fn_entry = fn_entry; |
| 15759 | 15797 | CallingConvention cc = fn_entry->type_entry->data.fn.fn_type_id.cc; |
| 15760 | 15798 | switch (cc) { |
| ... | ... | @@ -15778,51 +15816,51 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio |
| 15778 | 15816 | } |
| 15779 | 15817 | } break; |
| 15780 | 15818 | case ZigTypeIdStruct: |
| 15781 | | if (is_slice(target->value.type)) { |
| 15819 | if (is_slice(target->value->type)) { |
| 15782 | 15820 | ir_add_error(ira, target, |
| 15783 | | buf_sprintf("unable to export value of type '%s'", buf_ptr(&target->value.type->name))); |
| 15784 | | } else if (target->value.type->data.structure.layout != ContainerLayoutExtern) { |
| 15821 | buf_sprintf("unable to export value of type '%s'", buf_ptr(&target->value->type->name))); |
| 15822 | } else if (target->value->type->data.structure.layout != ContainerLayoutExtern) { |
| 15785 | 15823 | ErrorMsg *msg = ir_add_error(ira, target, |
| 15786 | 15824 | buf_sprintf("exported struct value must be declared extern")); |
| 15787 | | add_error_note(ira->codegen, msg, target->value.type->data.structure.decl_node, buf_sprintf("declared here")); |
| 15825 | add_error_note(ira->codegen, msg, target->value->type->data.structure.decl_node, buf_sprintf("declared here")); |
| 15788 | 15826 | } else { |
| 15789 | 15827 | want_var_export = true; |
| 15790 | 15828 | } |
| 15791 | 15829 | break; |
| 15792 | 15830 | case ZigTypeIdUnion: |
| 15793 | | if (target->value.type->data.unionation.layout != ContainerLayoutExtern) { |
| 15831 | if (target->value->type->data.unionation.layout != ContainerLayoutExtern) { |
| 15794 | 15832 | ErrorMsg *msg = ir_add_error(ira, target, |
| 15795 | 15833 | buf_sprintf("exported union value must be declared extern")); |
| 15796 | | add_error_note(ira->codegen, msg, target->value.type->data.unionation.decl_node, buf_sprintf("declared here")); |
| 15834 | add_error_note(ira->codegen, msg, target->value->type->data.unionation.decl_node, buf_sprintf("declared here")); |
| 15797 | 15835 | } else { |
| 15798 | 15836 | want_var_export = true; |
| 15799 | 15837 | } |
| 15800 | 15838 | break; |
| 15801 | 15839 | case ZigTypeIdEnum: |
| 15802 | | if (target->value.type->data.enumeration.layout != ContainerLayoutExtern) { |
| 15840 | if (target->value->type->data.enumeration.layout != ContainerLayoutExtern) { |
| 15803 | 15841 | ErrorMsg *msg = ir_add_error(ira, target, |
| 15804 | 15842 | buf_sprintf("exported enum value must be declared extern")); |
| 15805 | | add_error_note(ira->codegen, msg, target->value.type->data.enumeration.decl_node, buf_sprintf("declared here")); |
| 15843 | add_error_note(ira->codegen, msg, target->value->type->data.enumeration.decl_node, buf_sprintf("declared here")); |
| 15806 | 15844 | } else { |
| 15807 | 15845 | want_var_export = true; |
| 15808 | 15846 | } |
| 15809 | 15847 | break; |
| 15810 | 15848 | case ZigTypeIdArray: { |
| 15811 | 15849 | bool ok_type; |
| 15812 | | if ((err = type_allowed_in_extern(ira->codegen, target->value.type->data.array.child_type, &ok_type))) |
| 15850 | if ((err = type_allowed_in_extern(ira->codegen, target->value->type->data.array.child_type, &ok_type))) |
| 15813 | 15851 | return ira->codegen->invalid_instruction; |
| 15814 | 15852 | |
| 15815 | 15853 | if (!ok_type) { |
| 15816 | 15854 | ir_add_error(ira, target, |
| 15817 | 15855 | buf_sprintf("array element type '%s' not extern-compatible", |
| 15818 | | buf_ptr(&target->value.type->data.array.child_type->name))); |
| 15856 | buf_ptr(&target->value->type->data.array.child_type->name))); |
| 15819 | 15857 | } else { |
| 15820 | 15858 | want_var_export = true; |
| 15821 | 15859 | } |
| 15822 | 15860 | break; |
| 15823 | 15861 | } |
| 15824 | 15862 | case ZigTypeIdMetaType: { |
| 15825 | | ZigType *type_value = target->value.data.x_type; |
| 15863 | ZigType *type_value = target->value->data.x_type; |
| 15826 | 15864 | switch (type_value->id) { |
| 15827 | 15865 | case ZigTypeIdInvalid: |
| 15828 | 15866 | zig_unreachable(); |
| ... | ... | @@ -15898,7 +15936,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio |
| 15898 | 15936 | case ZigTypeIdErrorUnion: |
| 15899 | 15937 | case ZigTypeIdErrorSet: |
| 15900 | 15938 | case ZigTypeIdVector: |
| 15901 | | zig_panic("TODO export const value of type %s", buf_ptr(&target->value.type->name)); |
| 15939 | zig_panic("TODO export const value of type %s", buf_ptr(&target->value->type->name)); |
| 15902 | 15940 | case ZigTypeIdBoundFn: |
| 15903 | 15941 | case ZigTypeIdArgTuple: |
| 15904 | 15942 | case ZigTypeIdOpaque: |
| ... | ... | @@ -15906,7 +15944,7 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio |
| 15906 | 15944 | case ZigTypeIdFnFrame: |
| 15907 | 15945 | case ZigTypeIdAnyFrame: |
| 15908 | 15946 | ir_add_error(ira, target, |
| 15909 | | buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value.type->name))); |
| 15947 | buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value->type->name))); |
| 15910 | 15948 | break; |
| 15911 | 15949 | } |
| 15912 | 15950 | |
| ... | ... | @@ -15936,7 +15974,7 @@ static IrInstruction *ir_analyze_instruction_error_return_trace(IrAnalyze *ira, |
| 15936 | 15974 | ZigType *optional_type = get_optional_type(ira->codegen, ptr_to_stack_trace_type); |
| 15937 | 15975 | if (!exec_has_err_ret_trace(ira->codegen, ira->new_irb.exec)) { |
| 15938 | 15976 | IrInstruction *result = ir_const(ira, &instruction->base, optional_type); |
| 15939 | | ConstExprValue *out_val = &result->value; |
| 15977 | ZigValue *out_val = result->value; |
| 15940 | 15978 | assert(get_codegen_ptr_type(optional_type) != nullptr); |
| 15941 | 15979 | out_val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr; |
| 15942 | 15980 | out_val->data.x_ptr.data.hard_coded_addr.addr = 0; |
| ... | ... | @@ -15944,13 +15982,13 @@ static IrInstruction *ir_analyze_instruction_error_return_trace(IrAnalyze *ira, |
| 15944 | 15982 | } |
| 15945 | 15983 | IrInstruction *new_instruction = ir_build_error_return_trace(&ira->new_irb, instruction->base.scope, |
| 15946 | 15984 | instruction->base.source_node, instruction->optional); |
| 15947 | | new_instruction->value.type = optional_type; |
| 15985 | new_instruction->value->type = optional_type; |
| 15948 | 15986 | return new_instruction; |
| 15949 | 15987 | } else { |
| 15950 | 15988 | assert(ira->codegen->have_err_ret_tracing); |
| 15951 | 15989 | IrInstruction *new_instruction = ir_build_error_return_trace(&ira->new_irb, instruction->base.scope, |
| 15952 | 15990 | instruction->base.source_node, instruction->optional); |
| 15953 | | new_instruction->value.type = ptr_to_stack_trace_type; |
| 15991 | new_instruction->value->type = ptr_to_stack_trace_type; |
| 15954 | 15992 | return new_instruction; |
| 15955 | 15993 | } |
| 15956 | 15994 | } |
| ... | ... | @@ -15959,11 +15997,11 @@ static IrInstruction *ir_analyze_instruction_error_union(IrAnalyze *ira, |
| 15959 | 15997 | IrInstructionErrorUnion *instruction) |
| 15960 | 15998 | { |
| 15961 | 15999 | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type); |
| 15962 | | result->value.special = ConstValSpecialLazy; |
| 16000 | result->value->special = ConstValSpecialLazy; |
| 15963 | 16001 | |
| 15964 | 16002 | LazyValueErrUnionType *lazy_err_union_type = allocate<LazyValueErrUnionType>(1); |
| 15965 | 16003 | lazy_err_union_type->ira = ira; |
| 15966 | | result->value.data.x_lazy = &lazy_err_union_type->base; |
| 16004 | result->value->data.x_lazy = &lazy_err_union_type->base; |
| 15967 | 16005 | lazy_err_union_type->base.id = LazyValueIdErrUnionType; |
| 15968 | 16006 | |
| 15969 | 16007 | lazy_err_union_type->err_set_type = instruction->err_set->child; |
| ... | ... | @@ -15982,14 +16020,14 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in |
| 15982 | 16020 | { |
| 15983 | 16021 | Error err; |
| 15984 | 16022 | |
| 15985 | | ConstExprValue *pointee = create_const_vals(1); |
| 16023 | ZigValue *pointee = create_const_vals(1); |
| 15986 | 16024 | pointee->special = ConstValSpecialUndef; |
| 15987 | 16025 | |
| 15988 | 16026 | IrInstructionAllocaGen *result = ir_build_alloca_gen(ira, source_inst, align, name_hint); |
| 15989 | | result->base.value.special = ConstValSpecialStatic; |
| 15990 | | result->base.value.data.x_ptr.special = ConstPtrSpecialRef; |
| 15991 | | result->base.value.data.x_ptr.mut = force_comptime ? ConstPtrMutComptimeVar : ConstPtrMutInfer; |
| 15992 | | result->base.value.data.x_ptr.data.ref.pointee = pointee; |
| 16027 | result->base.value->special = ConstValSpecialStatic; |
| 16028 | result->base.value->data.x_ptr.special = ConstPtrSpecialRef; |
| 16029 | result->base.value->data.x_ptr.mut = force_comptime ? ConstPtrMutComptimeVar : ConstPtrMutInfer; |
| 16030 | result->base.value->data.x_ptr.data.ref.pointee = pointee; |
| 15993 | 16031 | |
| 15994 | 16032 | bool var_type_has_bits; |
| 15995 | 16033 | if ((err = type_has_bits2(ira->codegen, var_type, &var_type_has_bits))) |
| ... | ... | @@ -16004,10 +16042,10 @@ static IrInstruction *ir_analyze_alloca(IrAnalyze *ira, IrInstruction *source_in |
| 16004 | 16042 | return ira->codegen->invalid_instruction; |
| 16005 | 16043 | } |
| 16006 | 16044 | } |
| 16007 | | assert(result->base.value.data.x_ptr.special != ConstPtrSpecialInvalid); |
| 16045 | assert(result->base.value->data.x_ptr.special != ConstPtrSpecialInvalid); |
| 16008 | 16046 | |
| 16009 | 16047 | pointee->type = var_type; |
| 16010 | | result->base.value.type = get_pointer_to_type_extra(ira->codegen, var_type, false, false, |
| 16048 | result->base.value->type = get_pointer_to_type_extra(ira->codegen, var_type, false, false, |
| 16011 | 16049 | PtrLenSingle, align, 0, 0, false); |
| 16012 | 16050 | |
| 16013 | 16051 | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| ... | ... | @@ -16031,7 +16069,7 @@ static ZigType *ir_result_loc_expected_type(IrAnalyze *ira, IrInstruction *suspe |
| 16031 | 16069 | case ResultLocIdCast: |
| 16032 | 16070 | return nullptr; |
| 16033 | 16071 | case ResultLocIdInstruction: |
| 16034 | | return result_loc->source_instruction->child->value.type; |
| 16072 | return result_loc->source_instruction->child->value->type; |
| 16035 | 16073 | case ResultLocIdReturn: |
| 16036 | 16074 | return ira->explicit_return_type; |
| 16037 | 16075 | case ResultLocIdPeer: |
| ... | ... | @@ -16063,13 +16101,13 @@ static bool type_can_bit_cast(ZigType *t) { |
| 16063 | 16101 | } |
| 16064 | 16102 | |
| 16065 | 16103 | static void set_up_result_loc_for_inferred_comptime(IrInstruction *ptr) { |
| 16066 | | ConstExprValue *undef_child = create_const_vals(1); |
| 16067 | | undef_child->type = ptr->value.type->data.pointer.child_type; |
| 16104 | ZigValue *undef_child = create_const_vals(1); |
| 16105 | undef_child->type = ptr->value->type->data.pointer.child_type; |
| 16068 | 16106 | undef_child->special = ConstValSpecialUndef; |
| 16069 | | ptr->value.special = ConstValSpecialStatic; |
| 16070 | | ptr->value.data.x_ptr.mut = ConstPtrMutInfer; |
| 16071 | | ptr->value.data.x_ptr.special = ConstPtrSpecialRef; |
| 16072 | | ptr->value.data.x_ptr.data.ref.pointee = undef_child; |
| 16107 | ptr->value->special = ConstValSpecialStatic; |
| 16108 | ptr->value->data.x_ptr.mut = ConstPtrMutInfer; |
| 16109 | ptr->value->data.x_ptr.special = ConstPtrSpecialRef; |
| 16110 | ptr->value->data.x_ptr.data.ref.pointee = undef_child; |
| 16073 | 16111 | } |
| 16074 | 16112 | |
| 16075 | 16113 | static Error ir_result_has_type(IrAnalyze *ira, ResultLoc *result_loc, bool *out) { |
| ... | ... | @@ -16105,7 +16143,7 @@ static IrInstruction *ir_resolve_no_result_loc(IrAnalyze *ira, IrInstruction *su |
| 16105 | 16143 | ResultLoc *result_loc, ZigType *value_type, bool force_runtime, bool non_null_comptime) |
| 16106 | 16144 | { |
| 16107 | 16145 | IrInstructionAllocaGen *alloca_gen = ir_build_alloca_gen(ira, suspend_source_instr, 0, ""); |
| 16108 | | alloca_gen->base.value.type = get_pointer_to_type_extra(ira->codegen, value_type, false, false, |
| 16146 | alloca_gen->base.value->type = get_pointer_to_type_extra(ira->codegen, value_type, false, false, |
| 16109 | 16147 | PtrLenSingle, 0, 0, 0, false); |
| 16110 | 16148 | set_up_result_loc_for_inferred_comptime(&alloca_gen->base); |
| 16111 | 16149 | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| ... | ... | @@ -16158,7 +16196,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 16158 | 16196 | if (!ir_resolve_comptime(ira, alloca_src->is_comptime->child, &force_comptime)) |
| 16159 | 16197 | return ira->codegen->invalid_instruction; |
| 16160 | 16198 | bool is_comptime = force_comptime || (value != nullptr && |
| 16161 | | value->value.special != ConstValSpecialRuntime && result_loc_var->var->gen_is_const); |
| 16199 | value->value->special != ConstValSpecialRuntime && result_loc_var->var->gen_is_const); |
| 16162 | 16200 | |
| 16163 | 16201 | if (alloca_src->base.child == nullptr || is_comptime) { |
| 16164 | 16202 | uint32_t align = 0; |
| ... | ... | @@ -16167,8 +16205,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 16167 | 16205 | } |
| 16168 | 16206 | IrInstruction *alloca_gen; |
| 16169 | 16207 | if (is_comptime && value != nullptr) { |
| 16170 | | if (align > value->value.global_refs->align) { |
| 16171 | | value->value.global_refs->align = align; |
| 16208 | if (align > value->value->global_refs->align) { |
| 16209 | value->value->global_refs->align = align; |
| 16172 | 16210 | } |
| 16173 | 16211 | alloca_gen = ir_get_ref(ira, result_loc->source_instruction, value, true, false); |
| 16174 | 16212 | } else { |
| ... | ... | @@ -16191,7 +16229,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 16191 | 16229 | } |
| 16192 | 16230 | case ResultLocIdReturn: { |
| 16193 | 16231 | if (!non_null_comptime) { |
| 16194 | | bool is_comptime = value != nullptr && value->value.special != ConstValSpecialRuntime; |
| 16232 | bool is_comptime = value != nullptr && value->value->special != ConstValSpecialRuntime; |
| 16195 | 16233 | if (is_comptime) |
| 16196 | 16234 | return nullptr; |
| 16197 | 16235 | } |
| ... | ... | @@ -16222,8 +16260,8 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 16222 | 16260 | value_type, value, force_runtime, non_null_comptime, true); |
| 16223 | 16261 | result_peer->suspend_pos.basic_block_index = SIZE_MAX; |
| 16224 | 16262 | result_peer->suspend_pos.instruction_index = SIZE_MAX; |
| 16225 | | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) || |
| 16226 | | parent_result_loc->value.type->id == ZigTypeIdUnreachable) |
| 16263 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || |
| 16264 | parent_result_loc->value->type->id == ZigTypeIdUnreachable) |
| 16227 | 16265 | { |
| 16228 | 16266 | return parent_result_loc; |
| 16229 | 16267 | } |
| ... | ... | @@ -16270,19 +16308,19 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 16270 | 16308 | |
| 16271 | 16309 | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, peer_parent->parent, |
| 16272 | 16310 | peer_parent->resolved_type, nullptr, force_runtime, non_null_comptime, true); |
| 16273 | | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) || |
| 16274 | | parent_result_loc->value.type->id == ZigTypeIdUnreachable) |
| 16311 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || |
| 16312 | parent_result_loc->value->type->id == ZigTypeIdUnreachable) |
| 16275 | 16313 | { |
| 16276 | 16314 | return parent_result_loc; |
| 16277 | 16315 | } |
| 16278 | 16316 | // because is_comptime is false, we mark this a runtime pointer |
| 16279 | | parent_result_loc->value.special = ConstValSpecialRuntime; |
| 16317 | parent_result_loc->value->special = ConstValSpecialRuntime; |
| 16280 | 16318 | result_loc->written = true; |
| 16281 | 16319 | result_loc->resolved_loc = parent_result_loc; |
| 16282 | 16320 | return result_loc->resolved_loc; |
| 16283 | 16321 | } |
| 16284 | 16322 | case ResultLocIdCast: { |
| 16285 | | if (value != nullptr && value->value.special != ConstValSpecialRuntime) |
| 16323 | if (value != nullptr && value->value->special != ConstValSpecialRuntime) |
| 16286 | 16324 | return nullptr; |
| 16287 | 16325 | ResultLocCast *result_cast = reinterpret_cast<ResultLocCast *>(result_loc); |
| 16288 | 16326 | ZigType *dest_type = ir_resolve_type(ira, result_cast->base.source_instruction->child); |
| ... | ... | @@ -16313,19 +16351,19 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 16313 | 16351 | casted_value = nullptr; |
| 16314 | 16352 | } |
| 16315 | 16353 | |
| 16316 | | if (casted_value != nullptr && type_is_invalid(casted_value->value.type)) { |
| 16354 | if (casted_value != nullptr && type_is_invalid(casted_value->value->type)) { |
| 16317 | 16355 | return casted_value; |
| 16318 | 16356 | } |
| 16319 | 16357 | |
| 16320 | 16358 | bool old_parent_result_loc_written = result_cast->parent->written; |
| 16321 | 16359 | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_cast->parent, |
| 16322 | 16360 | dest_type, casted_value, force_runtime, non_null_comptime, true); |
| 16323 | | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) || |
| 16324 | | parent_result_loc->value.type->id == ZigTypeIdUnreachable) |
| 16361 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || |
| 16362 | parent_result_loc->value->type->id == ZigTypeIdUnreachable) |
| 16325 | 16363 | { |
| 16326 | 16364 | return parent_result_loc; |
| 16327 | 16365 | } |
| 16328 | | ZigType *parent_ptr_type = parent_result_loc->value.type; |
| 16366 | ZigType *parent_ptr_type = parent_result_loc->value->type; |
| 16329 | 16367 | assert(parent_ptr_type->id == ZigTypeIdPointer); |
| 16330 | 16368 | if ((err = type_resolve(ira->codegen, parent_ptr_type->data.pointer.child_type, |
| 16331 | 16369 | ResolveStatusAlignmentKnown))) |
| ... | ... | @@ -16358,7 +16396,7 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 16358 | 16396 | { |
| 16359 | 16397 | // we also need to check that this cast is OK. |
| 16360 | 16398 | ConstCastOnly const_cast_result = types_match_const_cast_only(ira, |
| 16361 | | parent_result_loc->value.type, ptr_type, |
| 16399 | parent_result_loc->value->type, ptr_type, |
| 16362 | 16400 | result_cast->base.source_instruction->source_node, false); |
| 16363 | 16401 | if (const_cast_result.id == ConstCastResultIdInvalid) |
| 16364 | 16402 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -16413,18 +16451,18 @@ static IrInstruction *ir_resolve_result_raw(IrAnalyze *ira, IrInstruction *suspe |
| 16413 | 16451 | bitcasted_value = nullptr; |
| 16414 | 16452 | } |
| 16415 | 16453 | |
| 16416 | | if (bitcasted_value == nullptr || type_is_invalid(bitcasted_value->value.type)) { |
| 16454 | if (bitcasted_value == nullptr || type_is_invalid(bitcasted_value->value->type)) { |
| 16417 | 16455 | return bitcasted_value; |
| 16418 | 16456 | } |
| 16419 | 16457 | |
| 16420 | 16458 | IrInstruction *parent_result_loc = ir_resolve_result(ira, suspend_source_instr, result_bit_cast->parent, |
| 16421 | 16459 | dest_type, bitcasted_value, force_runtime, non_null_comptime, true); |
| 16422 | | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value.type) || |
| 16423 | | parent_result_loc->value.type->id == ZigTypeIdUnreachable) |
| 16460 | if (parent_result_loc == nullptr || type_is_invalid(parent_result_loc->value->type) || |
| 16461 | parent_result_loc->value->type->id == ZigTypeIdUnreachable) |
| 16424 | 16462 | { |
| 16425 | 16463 | return parent_result_loc; |
| 16426 | 16464 | } |
| 16427 | | ZigType *parent_ptr_type = parent_result_loc->value.type; |
| 16465 | ZigType *parent_ptr_type = parent_result_loc->value->type; |
| 16428 | 16466 | assert(parent_ptr_type->id == ZigTypeIdPointer); |
| 16429 | 16467 | if ((err = type_resolve(ira->codegen, parent_ptr_type->data.pointer.child_type, |
| 16430 | 16468 | ResolveStatusAlignmentKnown))) |
| ... | ... | @@ -16454,24 +16492,24 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s |
| 16454 | 16492 | { |
| 16455 | 16493 | if (!allow_discard && result_loc_pass1->id == ResultLocIdInstruction && |
| 16456 | 16494 | instr_is_comptime(result_loc_pass1->source_instruction) && |
| 16457 | | result_loc_pass1->source_instruction->value.type->id == ZigTypeIdPointer && |
| 16458 | | result_loc_pass1->source_instruction->value.data.x_ptr.special == ConstPtrSpecialDiscard) |
| 16495 | result_loc_pass1->source_instruction->value->type->id == ZigTypeIdPointer && |
| 16496 | result_loc_pass1->source_instruction->value->data.x_ptr.special == ConstPtrSpecialDiscard) |
| 16459 | 16497 | { |
| 16460 | 16498 | result_loc_pass1 = no_result_loc(); |
| 16461 | 16499 | } |
| 16462 | 16500 | IrInstruction *result_loc = ir_resolve_result_raw(ira, suspend_source_instr, result_loc_pass1, value_type, |
| 16463 | 16501 | value, force_runtime, non_null_comptime); |
| 16464 | | if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value.type))) |
| 16502 | if (result_loc == nullptr || (instr_is_unreachable(result_loc) || type_is_invalid(result_loc->value->type))) |
| 16465 | 16503 | return result_loc; |
| 16466 | 16504 | |
| 16467 | 16505 | if ((force_runtime || (value != nullptr && !instr_is_comptime(value))) && |
| 16468 | | result_loc_pass1->written && result_loc->value.data.x_ptr.mut == ConstPtrMutInfer) |
| 16506 | result_loc_pass1->written && result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) |
| 16469 | 16507 | { |
| 16470 | | result_loc->value.special = ConstValSpecialRuntime; |
| 16508 | result_loc->value->special = ConstValSpecialRuntime; |
| 16471 | 16509 | } |
| 16472 | 16510 | |
| 16473 | | ir_assert(result_loc->value.type->id == ZigTypeIdPointer, suspend_source_instr); |
| 16474 | | ZigType *actual_elem_type = result_loc->value.type->data.pointer.child_type; |
| 16511 | ir_assert(result_loc->value->type->id == ZigTypeIdPointer, suspend_source_instr); |
| 16512 | ZigType *actual_elem_type = result_loc->value->type->data.pointer.child_type; |
| 16475 | 16513 | if (actual_elem_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional && |
| 16476 | 16514 | value_type->id != ZigTypeIdNull) |
| 16477 | 16515 | { |
| ... | ... | @@ -16544,18 +16582,18 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira, |
| 16544 | 16582 | result_loc = ir_resolve_result(ira, &instruction->base, no_result_loc(), |
| 16545 | 16583 | implicit_elem_type, nullptr, false, true, true); |
| 16546 | 16584 | if (result_loc != nullptr && |
| 16547 | | (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc))) |
| 16585 | (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) |
| 16548 | 16586 | { |
| 16549 | 16587 | return result_loc; |
| 16550 | 16588 | } |
| 16551 | | result_loc->value.special = ConstValSpecialRuntime; |
| 16589 | result_loc->value->special = ConstValSpecialRuntime; |
| 16552 | 16590 | return result_loc; |
| 16553 | 16591 | } |
| 16554 | 16592 | |
| 16555 | 16593 | IrInstruction *result = ir_const(ira, &instruction->base, implicit_elem_type); |
| 16556 | | result->value.special = ConstValSpecialUndef; |
| 16594 | result->value->special = ConstValSpecialUndef; |
| 16557 | 16595 | IrInstruction *ptr = ir_get_ref(ira, &instruction->base, result, false, false); |
| 16558 | | ptr->value.data.x_ptr.mut = ConstPtrMutComptimeVar; |
| 16596 | ptr->value->data.x_ptr.mut = ConstPtrMutComptimeVar; |
| 16559 | 16597 | return ptr; |
| 16560 | 16598 | } |
| 16561 | 16599 | |
| ... | ... | @@ -16605,9 +16643,9 @@ static IrInstruction *get_async_call_result_loc(IrAnalyze *ira, IrInstructionCal |
| 16605 | 16643 | { |
| 16606 | 16644 | ir_assert(call_instruction->is_async_call_builtin, &call_instruction->base); |
| 16607 | 16645 | IrInstruction *ret_ptr_uncasted = call_instruction->args[call_instruction->arg_count]->child; |
| 16608 | | if (type_is_invalid(ret_ptr_uncasted->value.type)) |
| 16646 | if (type_is_invalid(ret_ptr_uncasted->value->type)) |
| 16609 | 16647 | return ira->codegen->invalid_instruction; |
| 16610 | | if (ret_ptr_uncasted->value.type->id == ZigTypeIdVoid) { |
| 16648 | if (ret_ptr_uncasted->value->type->id == ZigTypeIdVoid) { |
| 16611 | 16649 | // Result location will be inside the async frame. |
| 16612 | 16650 | return nullptr; |
| 16613 | 16651 | } |
| ... | ... | @@ -16632,7 +16670,7 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc |
| 16632 | 16670 | if (casted_new_stack != nullptr) { |
| 16633 | 16671 | ZigType *fn_ret_type = fn_type->data.fn.fn_type_id.return_type; |
| 16634 | 16672 | IrInstruction *ret_ptr = get_async_call_result_loc(ira, call_instruction, fn_ret_type); |
| 16635 | | if (ret_ptr != nullptr && type_is_invalid(ret_ptr->value.type)) |
| 16673 | if (ret_ptr != nullptr && type_is_invalid(ret_ptr->value->type)) |
| 16636 | 16674 | return ira->codegen->invalid_instruction; |
| 16637 | 16675 | |
| 16638 | 16676 | ZigType *anyframe_type = get_any_frame_type(ira->codegen, fn_ret_type); |
| ... | ... | @@ -16645,11 +16683,11 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCallSrc |
| 16645 | 16683 | ZigType *frame_type = get_fn_frame_type(ira->codegen, fn_entry); |
| 16646 | 16684 | IrInstruction *result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc, |
| 16647 | 16685 | frame_type, nullptr, true, true, false); |
| 16648 | | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { |
| 16686 | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 16649 | 16687 | return result_loc; |
| 16650 | 16688 | } |
| 16651 | 16689 | result_loc = ir_implicit_cast(ira, result_loc, get_pointer_to_type(ira->codegen, frame_type, false)); |
| 16652 | | if (type_is_invalid(result_loc->value.type)) |
| 16690 | if (type_is_invalid(result_loc->value->type)) |
| 16653 | 16691 | return ira->codegen->invalid_instruction; |
| 16654 | 16692 | return &ir_build_call_gen(ira, &call_instruction->base, fn_entry, fn_ref, arg_count, |
| 16655 | 16693 | casted_args, FnInlineAuto, CallModifierAsync, casted_new_stack, |
| ... | ... | @@ -16670,13 +16708,13 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node |
| 16670 | 16708 | return false; |
| 16671 | 16709 | |
| 16672 | 16710 | casted_arg = ir_implicit_cast(ira, arg, param_type); |
| 16673 | | if (type_is_invalid(casted_arg->value.type)) |
| 16711 | if (type_is_invalid(casted_arg->value->type)) |
| 16674 | 16712 | return false; |
| 16675 | 16713 | } else { |
| 16676 | 16714 | casted_arg = arg; |
| 16677 | 16715 | } |
| 16678 | 16716 | |
| 16679 | | ConstExprValue *arg_val = ir_resolve_const(ira, casted_arg, UndefOk); |
| 16717 | ZigValue *arg_val = ir_resolve_const(ira, casted_arg, UndefOk); |
| 16680 | 16718 | if (!arg_val) |
| 16681 | 16719 | return false; |
| 16682 | 16720 | |
| ... | ... | @@ -16710,7 +16748,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 16710 | 16748 | return false; |
| 16711 | 16749 | |
| 16712 | 16750 | casted_arg = ir_implicit_cast(ira, arg, param_type); |
| 16713 | | if (type_is_invalid(casted_arg->value.type)) |
| 16751 | if (type_is_invalid(casted_arg->value->type)) |
| 16714 | 16752 | return false; |
| 16715 | 16753 | } else { |
| 16716 | 16754 | arg_part_of_generic_id = true; |
| ... | ... | @@ -16719,9 +16757,9 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 16719 | 16757 | } |
| 16720 | 16758 | |
| 16721 | 16759 | bool comptime_arg = param_decl_node->data.param_decl.is_comptime || |
| 16722 | | casted_arg->value.type->id == ZigTypeIdComptimeInt || casted_arg->value.type->id == ZigTypeIdComptimeFloat; |
| 16760 | casted_arg->value->type->id == ZigTypeIdComptimeInt || casted_arg->value->type->id == ZigTypeIdComptimeFloat; |
| 16723 | 16761 | |
| 16724 | | ConstExprValue *arg_val; |
| 16762 | ZigValue *arg_val; |
| 16725 | 16763 | |
| 16726 | 16764 | if (comptime_arg) { |
| 16727 | 16765 | arg_part_of_generic_id = true; |
| ... | ... | @@ -16729,7 +16767,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 16729 | 16767 | if (!arg_val) |
| 16730 | 16768 | return false; |
| 16731 | 16769 | } else { |
| 16732 | | arg_val = create_const_runtime(casted_arg->value.type); |
| 16770 | arg_val = create_const_runtime(casted_arg->value->type); |
| 16733 | 16771 | } |
| 16734 | 16772 | if (arg_part_of_generic_id) { |
| 16735 | 16773 | copy_const_val(&generic_id->params[generic_id->param_count], arg_val, true); |
| ... | ... | @@ -16745,8 +16783,8 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 16745 | 16783 | var->shadowable = !comptime_arg; |
| 16746 | 16784 | |
| 16747 | 16785 | *next_proto_i += 1; |
| 16748 | | } else if (casted_arg->value.type->id == ZigTypeIdComptimeInt || |
| 16749 | | casted_arg->value.type->id == ZigTypeIdComptimeFloat) |
| 16786 | } else if (casted_arg->value->type->id == ZigTypeIdComptimeInt || |
| 16787 | casted_arg->value->type->id == ZigTypeIdComptimeFloat) |
| 16750 | 16788 | { |
| 16751 | 16789 | ir_add_error(ira, casted_arg, |
| 16752 | 16790 | buf_sprintf("compiler bug: integer and float literals in var args function must be casted. https://github.com/ziglang/zig/issues/557")); |
| ... | ... | @@ -16754,10 +16792,10 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 16754 | 16792 | } |
| 16755 | 16793 | |
| 16756 | 16794 | if (!comptime_arg) { |
| 16757 | | switch (type_requires_comptime(ira->codegen, casted_arg->value.type)) { |
| 16795 | switch (type_requires_comptime(ira->codegen, casted_arg->value->type)) { |
| 16758 | 16796 | case ReqCompTimeYes: |
| 16759 | 16797 | ir_add_error(ira, casted_arg, |
| 16760 | | buf_sprintf("parameter of type '%s' requires comptime", buf_ptr(&casted_arg->value.type->name))); |
| 16798 | buf_sprintf("parameter of type '%s' requires comptime", buf_ptr(&casted_arg->value->type->name))); |
| 16761 | 16799 | return false; |
| 16762 | 16800 | case ReqCompTimeInvalid: |
| 16763 | 16801 | return false; |
| ... | ... | @@ -16767,7 +16805,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod |
| 16767 | 16805 | |
| 16768 | 16806 | casted_args[fn_type_id->param_count] = casted_arg; |
| 16769 | 16807 | FnTypeParamInfo *param_info = &fn_type_id->param_info[fn_type_id->param_count]; |
| 16770 | | param_info->type = casted_arg->value.type; |
| 16808 | param_info->type = casted_arg->value->type; |
| 16771 | 16809 | param_info->is_noalias = param_decl_node->data.param_decl.is_noalias; |
| 16772 | 16810 | impl_fn->param_source_nodes[fn_type_id->param_count] = param_decl_node; |
| 16773 | 16811 | fn_type_id->param_count += 1; |
| ... | ... | @@ -16805,7 +16843,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 16805 | 16843 | if (var->var_type == nullptr || type_is_invalid(var->var_type)) |
| 16806 | 16844 | return ira->codegen->invalid_instruction; |
| 16807 | 16845 | |
| 16808 | | ConstExprValue *mem_slot = nullptr; |
| 16846 | ZigValue *mem_slot = nullptr; |
| 16809 | 16847 | |
| 16810 | 16848 | bool comptime_var_mem = ir_get_var_is_comptime(var); |
| 16811 | 16849 | bool linkage_makes_it_runtime = var->decl_node->data.variable_declaration.is_extern; |
| ... | ... | @@ -16813,7 +16851,7 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 16813 | 16851 | |
| 16814 | 16852 | IrInstruction *result = ir_build_var_ptr(&ira->new_irb, |
| 16815 | 16853 | instruction->scope, instruction->source_node, var); |
| 16816 | | result->value.type = get_pointer_to_type_extra(ira->codegen, var->var_type, |
| 16854 | result->value->type = get_pointer_to_type_extra(ira->codegen, var->var_type, |
| 16817 | 16855 | var->src_is_const, is_volatile, PtrLenSingle, var->align_bytes, 0, 0, false); |
| 16818 | 16856 | |
| 16819 | 16857 | if (linkage_makes_it_runtime) |
| ... | ... | @@ -16846,10 +16884,10 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 16846 | 16884 | assert(!comptime_var_mem); |
| 16847 | 16885 | ptr_mut = ConstPtrMutRuntimeVar; |
| 16848 | 16886 | } |
| 16849 | | result->value.special = ConstValSpecialStatic; |
| 16850 | | result->value.data.x_ptr.mut = ptr_mut; |
| 16851 | | result->value.data.x_ptr.special = ConstPtrSpecialRef; |
| 16852 | | result->value.data.x_ptr.data.ref.pointee = mem_slot; |
| 16887 | result->value->special = ConstValSpecialStatic; |
| 16888 | result->value->data.x_ptr.mut = ptr_mut; |
| 16889 | result->value->data.x_ptr.special = ConstPtrSpecialRef; |
| 16890 | result->value->data.x_ptr.data.ref.pointee = mem_slot; |
| 16853 | 16891 | return result; |
| 16854 | 16892 | } |
| 16855 | 16893 | } |
| ... | ... | @@ -16859,13 +16897,13 @@ static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, |
| 16859 | 16897 | no_mem_slot: |
| 16860 | 16898 | |
| 16861 | 16899 | bool in_fn_scope = (scope_fn_entry(var->parent_scope) != nullptr); |
| 16862 | | result->value.data.rh_ptr = in_fn_scope ? RuntimeHintPtrStack : RuntimeHintPtrNonStack; |
| 16900 | result->value->data.rh_ptr = in_fn_scope ? RuntimeHintPtrStack : RuntimeHintPtrNonStack; |
| 16863 | 16901 | |
| 16864 | 16902 | return result; |
| 16865 | 16903 | } |
| 16866 | 16904 | |
| 16867 | 16905 | // This function is called when a comptime value becomes accessible at runtime. |
| 16868 | | static void mark_comptime_value_escape(IrAnalyze *ira, IrInstruction *source_instr, ConstExprValue *val) { |
| 16906 | static void mark_comptime_value_escape(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *val) { |
| 16869 | 16907 | ir_assert(value_is_comptime(val), source_instr); |
| 16870 | 16908 | if (val->special == ConstValSpecialUndef) |
| 16871 | 16909 | return; |
| ... | ... | @@ -16881,11 +16919,11 @@ static void mark_comptime_value_escape(IrAnalyze *ira, IrInstruction *source_ins |
| 16881 | 16919 | static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source_instr, |
| 16882 | 16920 | IrInstruction *ptr, IrInstruction *uncasted_value, bool allow_write_through_const) |
| 16883 | 16921 | { |
| 16884 | | assert(ptr->value.type->id == ZigTypeIdPointer); |
| 16922 | assert(ptr->value->type->id == ZigTypeIdPointer); |
| 16885 | 16923 | |
| 16886 | | if (ptr->value.data.x_ptr.special == ConstPtrSpecialDiscard) { |
| 16887 | | if (uncasted_value->value.type->id == ZigTypeIdErrorUnion || |
| 16888 | | uncasted_value->value.type->id == ZigTypeIdErrorSet) |
| 16924 | if (ptr->value->data.x_ptr.special == ConstPtrSpecialDiscard) { |
| 16925 | if (uncasted_value->value->type->id == ZigTypeIdErrorUnion || |
| 16926 | uncasted_value->value->type->id == ZigTypeIdErrorSet) |
| 16889 | 16927 | { |
| 16890 | 16928 | ir_add_error(ira, source_instr, buf_sprintf("error is discarded")); |
| 16891 | 16929 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -16893,7 +16931,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 16893 | 16931 | return ir_const_void(ira, source_instr); |
| 16894 | 16932 | } |
| 16895 | 16933 | |
| 16896 | | InferredStructField *isf = ptr->value.type->data.pointer.inferred_struct_field; |
| 16934 | InferredStructField *isf = ptr->value->type->data.pointer.inferred_struct_field; |
| 16897 | 16935 | if (allow_write_through_const && isf != nullptr) { |
| 16898 | 16936 | // Now it's time to add the field to the struct type. |
| 16899 | 16937 | uint32_t old_field_count = isf->inferred_struct_type->data.structure.src_field_count; |
| ... | ... | @@ -16904,7 +16942,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 16904 | 16942 | |
| 16905 | 16943 | TypeStructField *field = isf->inferred_struct_type->data.structure.fields[old_field_count]; |
| 16906 | 16944 | field->name = isf->field_name; |
| 16907 | | field->type_entry = uncasted_value->value.type; |
| 16945 | field->type_entry = uncasted_value->value->type; |
| 16908 | 16946 | field->type_val = create_const_type(ira->codegen, field->type_entry); |
| 16909 | 16947 | field->src_index = old_field_count; |
| 16910 | 16948 | field->decl_node = uncasted_value->source_node; |
| ... | ... | @@ -16913,25 +16951,25 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 16913 | 16951 | IrInstruction *casted_ptr; |
| 16914 | 16952 | if (instr_is_comptime(ptr)) { |
| 16915 | 16953 | casted_ptr = ir_const(ira, source_instr, struct_ptr_type); |
| 16916 | | copy_const_val(&casted_ptr->value, &ptr->value, false); |
| 16917 | | casted_ptr->value.type = struct_ptr_type; |
| 16954 | copy_const_val(casted_ptr->value, ptr->value, false); |
| 16955 | casted_ptr->value->type = struct_ptr_type; |
| 16918 | 16956 | } else { |
| 16919 | 16957 | casted_ptr = ir_build_cast(&ira->new_irb, source_instr->scope, |
| 16920 | 16958 | source_instr->source_node, struct_ptr_type, ptr, CastOpNoop); |
| 16921 | | casted_ptr->value.type = struct_ptr_type; |
| 16959 | casted_ptr->value->type = struct_ptr_type; |
| 16922 | 16960 | } |
| 16923 | 16961 | if (instr_is_comptime(casted_ptr)) { |
| 16924 | | ConstExprValue *ptr_val = ir_resolve_const(ira, casted_ptr, UndefBad); |
| 16962 | ZigValue *ptr_val = ir_resolve_const(ira, casted_ptr, UndefBad); |
| 16925 | 16963 | if (!ptr_val) |
| 16926 | 16964 | return ira->codegen->invalid_instruction; |
| 16927 | 16965 | if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { |
| 16928 | | ConstExprValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, |
| 16966 | ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, |
| 16929 | 16967 | source_instr->source_node); |
| 16930 | 16968 | struct_val->special = ConstValSpecialStatic; |
| 16931 | 16969 | struct_val->data.x_struct.fields = realloc_const_vals_ptrs(struct_val->data.x_struct.fields, |
| 16932 | 16970 | old_field_count, new_field_count); |
| 16933 | 16971 | |
| 16934 | | ConstExprValue *field_val = struct_val->data.x_struct.fields[old_field_count]; |
| 16972 | ZigValue *field_val = struct_val->data.x_struct.fields[old_field_count]; |
| 16935 | 16973 | field_val->special = ConstValSpecialUndef; |
| 16936 | 16974 | field_val->type = field->type_entry; |
| 16937 | 16975 | field_val->parent.id = ConstParentIdStruct; |
| ... | ... | @@ -16944,12 +16982,12 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 16944 | 16982 | isf->inferred_struct_type, true); |
| 16945 | 16983 | } |
| 16946 | 16984 | |
| 16947 | | if (ptr->value.type->data.pointer.is_const && !allow_write_through_const) { |
| 16985 | if (ptr->value->type->data.pointer.is_const && !allow_write_through_const) { |
| 16948 | 16986 | ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant")); |
| 16949 | 16987 | return ira->codegen->invalid_instruction; |
| 16950 | 16988 | } |
| 16951 | 16989 | |
| 16952 | | ZigType *child_type = ptr->value.type->data.pointer.child_type; |
| 16990 | ZigType *child_type = ptr->value->type->data.pointer.child_type; |
| 16953 | 16991 | IrInstruction *value = ir_implicit_cast(ira, uncasted_value, child_type); |
| 16954 | 16992 | if (value == ira->codegen->invalid_instruction) |
| 16955 | 16993 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -16963,16 +17001,16 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 16963 | 17001 | break; |
| 16964 | 17002 | } |
| 16965 | 17003 | |
| 16966 | | if (instr_is_comptime(ptr) && ptr->value.data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { |
| 16967 | | if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst) { |
| 17004 | if (instr_is_comptime(ptr) && ptr->value->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { |
| 17005 | if (ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst) { |
| 16968 | 17006 | ir_add_error(ira, source_instr, buf_sprintf("cannot assign to constant")); |
| 16969 | 17007 | return ira->codegen->invalid_instruction; |
| 16970 | 17008 | } |
| 16971 | | if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar || |
| 16972 | | ptr->value.data.x_ptr.mut == ConstPtrMutInfer) |
| 17009 | if (ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar || |
| 17010 | ptr->value->data.x_ptr.mut == ConstPtrMutInfer) |
| 16973 | 17011 | { |
| 16974 | 17012 | if (instr_is_comptime(value)) { |
| 16975 | | ConstExprValue *dest_val = const_ptr_pointee(ira, ira->codegen, &ptr->value, source_instr->source_node); |
| 17013 | ZigValue *dest_val = const_ptr_pointee(ira, ira->codegen, ptr->value, source_instr->source_node); |
| 16976 | 17014 | if (dest_val == nullptr) |
| 16977 | 17015 | return ira->codegen->invalid_instruction; |
| 16978 | 17016 | if (dest_val->special != ConstValSpecialRuntime) { |
| ... | ... | @@ -16982,9 +17020,9 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 16982 | 17020 | // * "string literal used as comptime slice is memoized" |
| 16983 | 17021 | // * "comptime modification of const struct field" - except modified to avoid |
| 16984 | 17022 | // ConstPtrMutComptimeVar, thus defeating the logic below. |
| 16985 | | bool same_global_refs = ptr->value.data.x_ptr.mut != ConstPtrMutComptimeVar; |
| 16986 | | copy_const_val(dest_val, &value->value, same_global_refs); |
| 16987 | | if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar && |
| 17023 | bool same_global_refs = ptr->value->data.x_ptr.mut != ConstPtrMutComptimeVar; |
| 17024 | copy_const_val(dest_val, value->value, same_global_refs); |
| 17025 | if (ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar && |
| 16988 | 17026 | !ira->new_irb.current_basic_block->must_be_comptime_source_instr) |
| 16989 | 17027 | { |
| 16990 | 17028 | ira->new_irb.current_basic_block->must_be_comptime_source_instr = source_instr; |
| ... | ... | @@ -16992,12 +17030,12 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 16992 | 17030 | return ir_const_void(ira, source_instr); |
| 16993 | 17031 | } |
| 16994 | 17032 | } |
| 16995 | | if (ptr->value.data.x_ptr.mut == ConstPtrMutInfer) { |
| 16996 | | ptr->value.special = ConstValSpecialRuntime; |
| 17033 | if (ptr->value->data.x_ptr.mut == ConstPtrMutInfer) { |
| 17034 | ptr->value->special = ConstValSpecialRuntime; |
| 16997 | 17035 | } else { |
| 16998 | 17036 | ir_add_error(ira, source_instr, |
| 16999 | 17037 | buf_sprintf("cannot store runtime value in compile time variable")); |
| 17000 | | ConstExprValue *dest_val = const_ptr_pointee_unchecked(ira->codegen, &ptr->value); |
| 17038 | ZigValue *dest_val = const_ptr_pointee_unchecked(ira->codegen, ptr->value); |
| 17001 | 17039 | dest_val->type = ira->codegen->builtin_types.entry_invalid; |
| 17002 | 17040 | |
| 17003 | 17041 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -17009,7 +17047,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 17009 | 17047 | case ReqCompTimeInvalid: |
| 17010 | 17048 | return ira->codegen->invalid_instruction; |
| 17011 | 17049 | case ReqCompTimeYes: |
| 17012 | | switch (type_has_one_possible_value(ira->codegen, ptr->value.type)) { |
| 17050 | switch (type_has_one_possible_value(ira->codegen, ptr->value->type)) { |
| 17013 | 17051 | case OnePossibleValueInvalid: |
| 17014 | 17052 | return ira->codegen->invalid_instruction; |
| 17015 | 17053 | case OnePossibleValueNo: |
| ... | ... | @@ -17025,7 +17063,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 17025 | 17063 | } |
| 17026 | 17064 | |
| 17027 | 17065 | if (instr_is_comptime(value)) { |
| 17028 | | mark_comptime_value_escape(ira, source_instr, &value->value); |
| 17066 | mark_comptime_value_escape(ira, source_instr, value->value); |
| 17029 | 17067 | } |
| 17030 | 17068 | |
| 17031 | 17069 | // If this is a store to a pointer with a runtime-known vector index, |
| ... | ... | @@ -17034,7 +17072,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 17034 | 17072 | // explaining why it is impossible for this store to work. Which is that |
| 17035 | 17073 | // the pointer address is of the vector; without the element index being known |
| 17036 | 17074 | // we cannot properly perform the insertion. |
| 17037 | | if (ptr->value.type->data.pointer.vector_index == VECTOR_INDEX_RUNTIME) { |
| 17075 | if (ptr->value->type->data.pointer.vector_index == VECTOR_INDEX_RUNTIME) { |
| 17038 | 17076 | if (ptr->id == IrInstructionIdElemPtr) { |
| 17039 | 17077 | IrInstructionElemPtr *elem_ptr = (IrInstructionElemPtr *)ptr; |
| 17040 | 17078 | return ir_build_vector_store_elem(ira, source_instr, elem_ptr->array_ptr, |
| ... | ... | @@ -17042,7 +17080,7 @@ static IrInstruction *ir_analyze_store_ptr(IrAnalyze *ira, IrInstruction *source |
| 17042 | 17080 | } |
| 17043 | 17081 | ir_add_error(ira, ptr, |
| 17044 | 17082 | buf_sprintf("unable to determine vector element index of type '%s'", |
| 17045 | | buf_ptr(&ptr->value.type->name))); |
| 17083 | buf_ptr(&ptr->value->type->name))); |
| 17046 | 17084 | return ira->codegen->invalid_instruction; |
| 17047 | 17085 | } |
| 17048 | 17086 | |
| ... | ... | @@ -17058,12 +17096,12 @@ static IrInstruction *analyze_casted_new_stack(IrAnalyze *ira, IrInstructionCall |
| 17058 | 17096 | return nullptr; |
| 17059 | 17097 | |
| 17060 | 17098 | IrInstruction *new_stack = call_instruction->new_stack->child; |
| 17061 | | if (type_is_invalid(new_stack->value.type)) |
| 17099 | if (type_is_invalid(new_stack->value->type)) |
| 17062 | 17100 | return ira->codegen->invalid_instruction; |
| 17063 | 17101 | |
| 17064 | 17102 | if (call_instruction->is_async_call_builtin && |
| 17065 | | fn_entry != nullptr && new_stack->value.type->id == ZigTypeIdPointer && |
| 17066 | | new_stack->value.type->data.pointer.child_type->id == ZigTypeIdFnFrame) |
| 17103 | fn_entry != nullptr && new_stack->value->type->id == ZigTypeIdPointer && |
| 17104 | new_stack->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame) |
| 17067 | 17105 | { |
| 17068 | 17106 | ZigType *needed_frame_type = get_pointer_to_type(ira->codegen, |
| 17069 | 17107 | get_fn_frame_type(ira->codegen, fn_entry), false); |
| ... | ... | @@ -17097,7 +17135,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17097 | 17135 | |
| 17098 | 17136 | size_t call_param_count = call_instruction->arg_count + first_arg_1_or_0; |
| 17099 | 17137 | for (size_t i = 0; i < call_instruction->arg_count; i += 1) { |
| 17100 | | ConstExprValue *arg_tuple_value = &call_instruction->args[i]->child->value; |
| 17138 | ZigValue *arg_tuple_value = call_instruction->args[i]->child->value; |
| 17101 | 17139 | if (arg_tuple_value->type->id == ZigTypeIdArgTuple) { |
| 17102 | 17140 | call_param_count -= 1; |
| 17103 | 17141 | call_param_count += arg_tuple_value->data.x_arg_tuple.end_index - |
| ... | ... | @@ -17152,7 +17190,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17152 | 17190 | |
| 17153 | 17191 | size_t next_proto_i = 0; |
| 17154 | 17192 | if (first_arg_ptr) { |
| 17155 | | assert(first_arg_ptr->value.type->id == ZigTypeIdPointer); |
| 17193 | assert(first_arg_ptr->value->type->id == ZigTypeIdPointer); |
| 17156 | 17194 | |
| 17157 | 17195 | bool first_arg_known_bare = false; |
| 17158 | 17196 | if (fn_type_id->next_param_index >= 1) { |
| ... | ... | @@ -17163,11 +17201,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17163 | 17201 | } |
| 17164 | 17202 | |
| 17165 | 17203 | IrInstruction *first_arg; |
| 17166 | | if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type)) { |
| 17204 | if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type)) { |
| 17167 | 17205 | first_arg = first_arg_ptr; |
| 17168 | 17206 | } else { |
| 17169 | 17207 | first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr, nullptr); |
| 17170 | | if (type_is_invalid(first_arg->value.type)) |
| 17208 | if (type_is_invalid(first_arg->value->type)) |
| 17171 | 17209 | return ira->codegen->invalid_instruction; |
| 17172 | 17210 | } |
| 17173 | 17211 | |
| ... | ... | @@ -17184,7 +17222,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17184 | 17222 | |
| 17185 | 17223 | for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) { |
| 17186 | 17224 | IrInstruction *old_arg = call_instruction->args[call_i]->child; |
| 17187 | | if (type_is_invalid(old_arg->value.type)) |
| 17225 | if (type_is_invalid(old_arg->value->type)) |
| 17188 | 17226 | return ira->codegen->invalid_instruction; |
| 17189 | 17227 | |
| 17190 | 17228 | if (!ir_analyze_fn_call_inline_arg(ira, fn_proto_node, old_arg, &exec_scope, &next_proto_i)) |
| ... | ... | @@ -17207,7 +17245,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17207 | 17245 | } |
| 17208 | 17246 | |
| 17209 | 17247 | bool cacheable = fn_eval_cacheable(exec_scope, return_type); |
| 17210 | | ConstExprValue *result = nullptr; |
| 17248 | ZigValue *result = nullptr; |
| 17211 | 17249 | if (cacheable) { |
| 17212 | 17250 | auto entry = ira->codegen->memoized_fn_eval_table.maybe_get(exec_scope); |
| 17213 | 17251 | if (entry) |
| ... | ... | @@ -17250,8 +17288,8 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17250 | 17288 | } |
| 17251 | 17289 | |
| 17252 | 17290 | IrInstruction *new_instruction = ir_const(ira, &call_instruction->base, result->type); |
| 17253 | | copy_const_val(&new_instruction->value, result, true); |
| 17254 | | new_instruction->value.type = return_type; |
| 17291 | copy_const_val(new_instruction->value, result, true); |
| 17292 | new_instruction->value->type = return_type; |
| 17255 | 17293 | return ir_finish_anal(ira, new_instruction); |
| 17256 | 17294 | } |
| 17257 | 17295 | |
| ... | ... | @@ -17266,11 +17304,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17266 | 17304 | size_t new_fn_arg_count = first_arg_1_or_0; |
| 17267 | 17305 | for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) { |
| 17268 | 17306 | IrInstruction *arg = call_instruction->args[call_i]->child; |
| 17269 | | if (type_is_invalid(arg->value.type)) |
| 17307 | if (type_is_invalid(arg->value->type)) |
| 17270 | 17308 | return ira->codegen->invalid_instruction; |
| 17271 | 17309 | |
| 17272 | | if (arg->value.type->id == ZigTypeIdArgTuple) { |
| 17273 | | new_fn_arg_count += arg->value.data.x_arg_tuple.end_index - arg->value.data.x_arg_tuple.start_index; |
| 17310 | if (arg->value->type->id == ZigTypeIdArgTuple) { |
| 17311 | new_fn_arg_count += arg->value->data.x_arg_tuple.end_index - arg->value->data.x_arg_tuple.start_index; |
| 17274 | 17312 | } else { |
| 17275 | 17313 | new_fn_arg_count += 1; |
| 17276 | 17314 | } |
| ... | ... | @@ -17299,7 +17337,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17299 | 17337 | size_t next_proto_i = 0; |
| 17300 | 17338 | |
| 17301 | 17339 | if (first_arg_ptr) { |
| 17302 | | assert(first_arg_ptr->value.type->id == ZigTypeIdPointer); |
| 17340 | assert(first_arg_ptr->value->type->id == ZigTypeIdPointer); |
| 17303 | 17341 | |
| 17304 | 17342 | bool first_arg_known_bare = false; |
| 17305 | 17343 | if (fn_type_id->next_param_index >= 1) { |
| ... | ... | @@ -17310,11 +17348,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17310 | 17348 | } |
| 17311 | 17349 | |
| 17312 | 17350 | IrInstruction *first_arg; |
| 17313 | | if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type)) { |
| 17351 | if (!first_arg_known_bare && handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type)) { |
| 17314 | 17352 | first_arg = first_arg_ptr; |
| 17315 | 17353 | } else { |
| 17316 | 17354 | first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr, nullptr); |
| 17317 | | if (type_is_invalid(first_arg->value.type)) |
| 17355 | if (type_is_invalid(first_arg->value->type)) |
| 17318 | 17356 | return ira->codegen->invalid_instruction; |
| 17319 | 17357 | } |
| 17320 | 17358 | |
| ... | ... | @@ -17332,12 +17370,12 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17332 | 17370 | assert(parent_fn_entry); |
| 17333 | 17371 | for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) { |
| 17334 | 17372 | IrInstruction *arg = call_instruction->args[call_i]->child; |
| 17335 | | if (type_is_invalid(arg->value.type)) |
| 17373 | if (type_is_invalid(arg->value->type)) |
| 17336 | 17374 | return ira->codegen->invalid_instruction; |
| 17337 | 17375 | |
| 17338 | | if (arg->value.type->id == ZigTypeIdArgTuple) { |
| 17339 | | for (size_t arg_tuple_i = arg->value.data.x_arg_tuple.start_index; |
| 17340 | | arg_tuple_i < arg->value.data.x_arg_tuple.end_index; arg_tuple_i += 1) |
| 17376 | if (arg->value->type->id == ZigTypeIdArgTuple) { |
| 17377 | for (size_t arg_tuple_i = arg->value->data.x_arg_tuple.start_index; |
| 17378 | arg_tuple_i < arg->value->data.x_arg_tuple.end_index; arg_tuple_i += 1) |
| 17341 | 17379 | { |
| 17342 | 17380 | AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(next_proto_i); |
| 17343 | 17381 | assert(param_decl_node->type == NodeTypeParamDecl); |
| ... | ... | @@ -17354,11 +17392,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17354 | 17392 | return ira->codegen->invalid_instruction; |
| 17355 | 17393 | } |
| 17356 | 17394 | IrInstruction *arg_var_ptr_inst = ir_get_var_ptr(ira, arg, arg_var); |
| 17357 | | if (type_is_invalid(arg_var_ptr_inst->value.type)) |
| 17395 | if (type_is_invalid(arg_var_ptr_inst->value->type)) |
| 17358 | 17396 | return ira->codegen->invalid_instruction; |
| 17359 | 17397 | |
| 17360 | 17398 | IrInstruction *arg_tuple_arg = ir_get_deref(ira, arg, arg_var_ptr_inst, nullptr); |
| 17361 | | if (type_is_invalid(arg_tuple_arg->value.type)) |
| 17399 | if (type_is_invalid(arg_tuple_arg->value->type)) |
| 17362 | 17400 | return ira->codegen->invalid_instruction; |
| 17363 | 17401 | |
| 17364 | 17402 | if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, arg_tuple_arg, &impl_fn->child_scope, |
| ... | ... | @@ -17392,7 +17430,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17392 | 17430 | first_var_arg = inst_fn_type_id.param_count; |
| 17393 | 17431 | } |
| 17394 | 17432 | |
| 17395 | | ConstExprValue *var_args_val = create_const_arg_tuple(ira->codegen, |
| 17433 | ZigValue *var_args_val = create_const_arg_tuple(ira->codegen, |
| 17396 | 17434 | first_var_arg, inst_fn_type_id.param_count); |
| 17397 | 17435 | ZigVar *var = add_variable(ira->codegen, param_decl_node, |
| 17398 | 17436 | impl_fn->child_scope, param_name, true, var_args_val, nullptr, var_args_val->type); |
| ... | ... | @@ -17400,14 +17438,14 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17400 | 17438 | } |
| 17401 | 17439 | |
| 17402 | 17440 | if (fn_proto_node->data.fn_proto.align_expr != nullptr) { |
| 17403 | | ConstExprValue *align_result = ir_eval_const_value(ira->codegen, impl_fn->child_scope, |
| 17441 | ZigValue *align_result = ir_eval_const_value(ira->codegen, impl_fn->child_scope, |
| 17404 | 17442 | fn_proto_node->data.fn_proto.align_expr, get_align_amt_type(ira->codegen), |
| 17405 | 17443 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, |
| 17406 | 17444 | nullptr, nullptr, fn_proto_node->data.fn_proto.align_expr, nullptr, ira->new_irb.exec, |
| 17407 | 17445 | nullptr, UndefBad); |
| 17408 | 17446 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, |
| 17409 | 17447 | impl_fn->child_scope, fn_proto_node->data.fn_proto.align_expr); |
| 17410 | | copy_const_val(&const_instruction->base.value, align_result, true); |
| 17448 | copy_const_val(const_instruction->base.value, align_result, true); |
| 17411 | 17449 | |
| 17412 | 17450 | uint32_t align_bytes = 0; |
| 17413 | 17451 | ir_resolve_align(ira, &const_instruction->base, nullptr, &align_bytes); |
| ... | ... | @@ -17468,7 +17506,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17468 | 17506 | } |
| 17469 | 17507 | |
| 17470 | 17508 | IrInstruction *casted_new_stack = analyze_casted_new_stack(ira, call_instruction, impl_fn); |
| 17471 | | if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value.type)) |
| 17509 | if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type)) |
| 17472 | 17510 | return ira->codegen->invalid_instruction; |
| 17473 | 17511 | |
| 17474 | 17512 | size_t impl_param_count = impl_fn_type_id->param_count; |
| ... | ... | @@ -17483,17 +17521,17 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17483 | 17521 | result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc, |
| 17484 | 17522 | impl_fn_type_id->return_type, nullptr, true, true, false); |
| 17485 | 17523 | if (result_loc != nullptr) { |
| 17486 | | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { |
| 17524 | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 17487 | 17525 | return result_loc; |
| 17488 | 17526 | } |
| 17489 | | if (!handle_is_ptr(result_loc->value.type->data.pointer.child_type)) { |
| 17527 | if (!handle_is_ptr(result_loc->value->type->data.pointer.child_type)) { |
| 17490 | 17528 | ir_reset_result(call_instruction->result_loc); |
| 17491 | 17529 | result_loc = nullptr; |
| 17492 | 17530 | } |
| 17493 | 17531 | } |
| 17494 | 17532 | } else if (call_instruction->is_async_call_builtin) { |
| 17495 | 17533 | result_loc = get_async_call_result_loc(ira, call_instruction, impl_fn_type_id->return_type); |
| 17496 | | if (result_loc != nullptr && type_is_invalid(result_loc->value.type)) |
| 17534 | if (result_loc != nullptr && type_is_invalid(result_loc->value->type)) |
| 17497 | 17535 | return ira->codegen->invalid_instruction; |
| 17498 | 17536 | } else { |
| 17499 | 17537 | result_loc = nullptr; |
| ... | ... | @@ -17530,7 +17568,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17530 | 17568 | IrInstruction **casted_args = allocate<IrInstruction *>(call_param_count); |
| 17531 | 17569 | size_t next_arg_index = 0; |
| 17532 | 17570 | if (first_arg_ptr) { |
| 17533 | | assert(first_arg_ptr->value.type->id == ZigTypeIdPointer); |
| 17571 | assert(first_arg_ptr->value->type->id == ZigTypeIdPointer); |
| 17534 | 17572 | |
| 17535 | 17573 | ZigType *param_type = fn_type_id->param_info[next_arg_index].type; |
| 17536 | 17574 | if (type_is_invalid(param_type)) |
| ... | ... | @@ -17538,17 +17576,17 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17538 | 17576 | |
| 17539 | 17577 | IrInstruction *first_arg; |
| 17540 | 17578 | if (param_type->id == ZigTypeIdPointer && |
| 17541 | | handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type)) |
| 17579 | handle_is_ptr(first_arg_ptr->value->type->data.pointer.child_type)) |
| 17542 | 17580 | { |
| 17543 | 17581 | first_arg = first_arg_ptr; |
| 17544 | 17582 | } else { |
| 17545 | 17583 | first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr, nullptr); |
| 17546 | | if (type_is_invalid(first_arg->value.type)) |
| 17584 | if (type_is_invalid(first_arg->value->type)) |
| 17547 | 17585 | return ira->codegen->invalid_instruction; |
| 17548 | 17586 | } |
| 17549 | 17587 | |
| 17550 | 17588 | IrInstruction *casted_arg = ir_implicit_cast(ira, first_arg, param_type); |
| 17551 | | if (type_is_invalid(casted_arg->value.type)) |
| 17589 | if (type_is_invalid(casted_arg->value->type)) |
| 17552 | 17590 | return ira->codegen->invalid_instruction; |
| 17553 | 17591 | |
| 17554 | 17592 | casted_args[next_arg_index] = casted_arg; |
| ... | ... | @@ -17556,12 +17594,12 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17556 | 17594 | } |
| 17557 | 17595 | for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) { |
| 17558 | 17596 | IrInstruction *old_arg = call_instruction->args[call_i]->child; |
| 17559 | | if (type_is_invalid(old_arg->value.type)) |
| 17597 | if (type_is_invalid(old_arg->value->type)) |
| 17560 | 17598 | return ira->codegen->invalid_instruction; |
| 17561 | 17599 | |
| 17562 | | if (old_arg->value.type->id == ZigTypeIdArgTuple) { |
| 17563 | | for (size_t arg_tuple_i = old_arg->value.data.x_arg_tuple.start_index; |
| 17564 | | arg_tuple_i < old_arg->value.data.x_arg_tuple.end_index; arg_tuple_i += 1) |
| 17600 | if (old_arg->value->type->id == ZigTypeIdArgTuple) { |
| 17601 | for (size_t arg_tuple_i = old_arg->value->data.x_arg_tuple.start_index; |
| 17602 | arg_tuple_i < old_arg->value->data.x_arg_tuple.end_index; arg_tuple_i += 1) |
| 17565 | 17603 | { |
| 17566 | 17604 | ZigVar *arg_var = get_fn_var_by_index(parent_fn_entry, arg_tuple_i); |
| 17567 | 17605 | if (arg_var == nullptr) { |
| ... | ... | @@ -17570,11 +17608,11 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17570 | 17608 | return ira->codegen->invalid_instruction; |
| 17571 | 17609 | } |
| 17572 | 17610 | IrInstruction *arg_var_ptr_inst = ir_get_var_ptr(ira, old_arg, arg_var); |
| 17573 | | if (type_is_invalid(arg_var_ptr_inst->value.type)) |
| 17611 | if (type_is_invalid(arg_var_ptr_inst->value->type)) |
| 17574 | 17612 | return ira->codegen->invalid_instruction; |
| 17575 | 17613 | |
| 17576 | 17614 | IrInstruction *arg_tuple_arg = ir_get_deref(ira, old_arg, arg_var_ptr_inst, nullptr); |
| 17577 | | if (type_is_invalid(arg_tuple_arg->value.type)) |
| 17615 | if (type_is_invalid(arg_tuple_arg->value->type)) |
| 17578 | 17616 | return ira->codegen->invalid_instruction; |
| 17579 | 17617 | |
| 17580 | 17618 | IrInstruction *casted_arg; |
| ... | ... | @@ -17583,7 +17621,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17583 | 17621 | if (type_is_invalid(param_type)) |
| 17584 | 17622 | return ira->codegen->invalid_instruction; |
| 17585 | 17623 | casted_arg = ir_implicit_cast(ira, arg_tuple_arg, param_type); |
| 17586 | | if (type_is_invalid(casted_arg->value.type)) |
| 17624 | if (type_is_invalid(casted_arg->value->type)) |
| 17587 | 17625 | return ira->codegen->invalid_instruction; |
| 17588 | 17626 | } else { |
| 17589 | 17627 | casted_arg = arg_tuple_arg; |
| ... | ... | @@ -17599,7 +17637,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17599 | 17637 | if (type_is_invalid(param_type)) |
| 17600 | 17638 | return ira->codegen->invalid_instruction; |
| 17601 | 17639 | casted_arg = ir_implicit_cast(ira, old_arg, param_type); |
| 17602 | | if (type_is_invalid(casted_arg->value.type)) |
| 17640 | if (type_is_invalid(casted_arg->value->type)) |
| 17603 | 17641 | return ira->codegen->invalid_instruction; |
| 17604 | 17642 | } else { |
| 17605 | 17643 | casted_arg = old_arg; |
| ... | ... | @@ -17623,7 +17661,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17623 | 17661 | } |
| 17624 | 17662 | |
| 17625 | 17663 | IrInstruction *casted_new_stack = analyze_casted_new_stack(ira, call_instruction, fn_entry); |
| 17626 | | if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value.type)) |
| 17664 | if (casted_new_stack != nullptr && type_is_invalid(casted_new_stack->value->type)) |
| 17627 | 17665 | return ira->codegen->invalid_instruction; |
| 17628 | 17666 | |
| 17629 | 17667 | if (call_instruction->modifier == CallModifierAsync) { |
| ... | ... | @@ -17645,17 +17683,17 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17645 | 17683 | result_loc = ir_resolve_result(ira, &call_instruction->base, call_instruction->result_loc, |
| 17646 | 17684 | return_type, nullptr, true, true, false); |
| 17647 | 17685 | if (result_loc != nullptr) { |
| 17648 | | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { |
| 17686 | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 17649 | 17687 | return result_loc; |
| 17650 | 17688 | } |
| 17651 | | if (!handle_is_ptr(result_loc->value.type->data.pointer.child_type)) { |
| 17689 | if (!handle_is_ptr(result_loc->value->type->data.pointer.child_type)) { |
| 17652 | 17690 | ir_reset_result(call_instruction->result_loc); |
| 17653 | 17691 | result_loc = nullptr; |
| 17654 | 17692 | } |
| 17655 | 17693 | } |
| 17656 | 17694 | } else if (call_instruction->is_async_call_builtin) { |
| 17657 | 17695 | result_loc = get_async_call_result_loc(ira, call_instruction, return_type); |
| 17658 | | if (result_loc != nullptr && type_is_invalid(result_loc->value.type)) |
| 17696 | if (result_loc != nullptr && type_is_invalid(result_loc->value->type)) |
| 17659 | 17697 | return ira->codegen->invalid_instruction; |
| 17660 | 17698 | } else { |
| 17661 | 17699 | result_loc = nullptr; |
| ... | ... | @@ -17672,14 +17710,14 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c |
| 17672 | 17710 | |
| 17673 | 17711 | static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCallSrc *call_instruction) { |
| 17674 | 17712 | IrInstruction *fn_ref = call_instruction->fn_ref->child; |
| 17675 | | if (type_is_invalid(fn_ref->value.type)) |
| 17713 | if (type_is_invalid(fn_ref->value->type)) |
| 17676 | 17714 | return ira->codegen->invalid_instruction; |
| 17677 | 17715 | |
| 17678 | 17716 | bool is_comptime = call_instruction->is_comptime || |
| 17679 | 17717 | ir_should_inline(ira->new_irb.exec, call_instruction->base.scope); |
| 17680 | 17718 | |
| 17681 | 17719 | if (is_comptime || instr_is_comptime(fn_ref)) { |
| 17682 | | if (fn_ref->value.type->id == ZigTypeIdMetaType) { |
| 17720 | if (fn_ref->value->type->id == ZigTypeIdMetaType) { |
| 17683 | 17721 | ZigType *ty = ir_resolve_type(ira, fn_ref); |
| 17684 | 17722 | if (ty == nullptr) |
| 17685 | 17723 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -17688,30 +17726,30 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC |
| 17688 | 17726 | add_error_note(ira->codegen, msg, call_instruction->base.source_node, |
| 17689 | 17727 | buf_sprintf("use @as builtin for type coercion")); |
| 17690 | 17728 | return ira->codegen->invalid_instruction; |
| 17691 | | } else if (fn_ref->value.type->id == ZigTypeIdFn) { |
| 17729 | } else if (fn_ref->value->type->id == ZigTypeIdFn) { |
| 17692 | 17730 | ZigFn *fn_table_entry = ir_resolve_fn(ira, fn_ref); |
| 17693 | | ZigType *fn_type = fn_table_entry ? fn_table_entry->type_entry : fn_ref->value.type; |
| 17731 | ZigType *fn_type = fn_table_entry ? fn_table_entry->type_entry : fn_ref->value->type; |
| 17694 | 17732 | return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_type, |
| 17695 | 17733 | fn_ref, nullptr, is_comptime, call_instruction->fn_inline); |
| 17696 | | } else if (fn_ref->value.type->id == ZigTypeIdBoundFn) { |
| 17697 | | assert(fn_ref->value.special == ConstValSpecialStatic); |
| 17698 | | ZigFn *fn_table_entry = fn_ref->value.data.x_bound_fn.fn; |
| 17699 | | IrInstruction *first_arg_ptr = fn_ref->value.data.x_bound_fn.first_arg; |
| 17734 | } else if (fn_ref->value->type->id == ZigTypeIdBoundFn) { |
| 17735 | assert(fn_ref->value->special == ConstValSpecialStatic); |
| 17736 | ZigFn *fn_table_entry = fn_ref->value->data.x_bound_fn.fn; |
| 17737 | IrInstruction *first_arg_ptr = fn_ref->value->data.x_bound_fn.first_arg; |
| 17700 | 17738 | return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry, |
| 17701 | 17739 | fn_ref, first_arg_ptr, is_comptime, call_instruction->fn_inline); |
| 17702 | 17740 | } else { |
| 17703 | 17741 | ir_add_error_node(ira, fn_ref->source_node, |
| 17704 | | buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value.type->name))); |
| 17742 | buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name))); |
| 17705 | 17743 | return ira->codegen->invalid_instruction; |
| 17706 | 17744 | } |
| 17707 | 17745 | } |
| 17708 | 17746 | |
| 17709 | | if (fn_ref->value.type->id == ZigTypeIdFn) { |
| 17710 | | return ir_analyze_fn_call(ira, call_instruction, nullptr, fn_ref->value.type, |
| 17747 | if (fn_ref->value->type->id == ZigTypeIdFn) { |
| 17748 | return ir_analyze_fn_call(ira, call_instruction, nullptr, fn_ref->value->type, |
| 17711 | 17749 | fn_ref, nullptr, false, call_instruction->fn_inline); |
| 17712 | 17750 | } else { |
| 17713 | 17751 | ir_add_error_node(ira, fn_ref->source_node, |
| 17714 | | buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value.type->name))); |
| 17752 | buf_sprintf("type '%s' not a function", buf_ptr(&fn_ref->value->type->name))); |
| 17715 | 17753 | return ira->codegen->invalid_instruction; |
| 17716 | 17754 | } |
| 17717 | 17755 | } |
| ... | ... | @@ -17719,12 +17757,12 @@ static IrInstruction *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionC |
| 17719 | 17757 | // out_val->type must be the type to read the pointer as |
| 17720 | 17758 | // if the type is different than the actual type then it does a comptime byte reinterpretation |
| 17721 | 17759 | static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, |
| 17722 | | ConstExprValue *out_val, ConstExprValue *ptr_val) |
| 17760 | ZigValue *out_val, ZigValue *ptr_val) |
| 17723 | 17761 | { |
| 17724 | 17762 | Error err; |
| 17725 | 17763 | assert(out_val->type != nullptr); |
| 17726 | 17764 | |
| 17727 | | ConstExprValue *pointee = const_ptr_pointee_unchecked(codegen, ptr_val); |
| 17765 | ZigValue *pointee = const_ptr_pointee_unchecked(codegen, ptr_val); |
| 17728 | 17766 | src_assert(pointee->type != nullptr, source_node); |
| 17729 | 17767 | |
| 17730 | 17768 | if ((err = type_resolve(codegen, pointee->type, ResolveStatusSizeKnown))) |
| ... | ... | @@ -17765,7 +17803,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source |
| 17765 | 17803 | return ErrorSemanticAnalyzeFail; |
| 17766 | 17804 | } |
| 17767 | 17805 | case ConstPtrSpecialBaseArray: { |
| 17768 | | ConstExprValue *array_val = ptr_val->data.x_ptr.data.base_array.array_val; |
| 17806 | ZigValue *array_val = ptr_val->data.x_ptr.data.base_array.array_val; |
| 17769 | 17807 | assert(array_val->type->id == ZigTypeIdArray); |
| 17770 | 17808 | if (array_val->data.x_array.special != ConstArraySpecialNone) |
| 17771 | 17809 | zig_panic("TODO"); |
| ... | ... | @@ -17782,7 +17820,7 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source |
| 17782 | 17820 | Buf buf = BUF_INIT; |
| 17783 | 17821 | buf_resize(&buf, elem_count * elem_size); |
| 17784 | 17822 | for (size_t i = 0; i < elem_count; i += 1) { |
| 17785 | | ConstExprValue *elem_val = &array_val->data.x_array.data.s_none.elements[elem_index + i]; |
| 17823 | ZigValue *elem_val = &array_val->data.x_array.data.s_none.elements[elem_index + i]; |
| 17786 | 17824 | buf_write_value_bytes(codegen, (uint8_t*)buf_ptr(&buf) + (i * elem_size), elem_val); |
| 17787 | 17825 | } |
| 17788 | 17826 | if ((err = buf_read_value_bytes(ira, codegen, source_node, (uint8_t*)buf_ptr(&buf), out_val))) |
| ... | ... | @@ -17803,11 +17841,11 @@ static Error ir_read_const_ptr(IrAnalyze *ira, CodeGen *codegen, AstNode *source |
| 17803 | 17841 | |
| 17804 | 17842 | static IrInstruction *ir_analyze_optional_type(IrAnalyze *ira, IrInstructionUnOp *instruction) { |
| 17805 | 17843 | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type); |
| 17806 | | result->value.special = ConstValSpecialLazy; |
| 17844 | result->value->special = ConstValSpecialLazy; |
| 17807 | 17845 | |
| 17808 | 17846 | LazyValueOptType *lazy_opt_type = allocate<LazyValueOptType>(1); |
| 17809 | 17847 | lazy_opt_type->ira = ira; |
| 17810 | | result->value.data.x_lazy = &lazy_opt_type->base; |
| 17848 | result->value->data.x_lazy = &lazy_opt_type->base; |
| 17811 | 17849 | lazy_opt_type->base.id = LazyValueIdOptType; |
| 17812 | 17850 | |
| 17813 | 17851 | lazy_opt_type->payload_type = instruction->value->child; |
| ... | ... | @@ -17818,7 +17856,7 @@ static IrInstruction *ir_analyze_optional_type(IrAnalyze *ira, IrInstructionUnOp |
| 17818 | 17856 | } |
| 17819 | 17857 | |
| 17820 | 17858 | static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInstruction *source_instr, ZigType *scalar_type, |
| 17821 | | ConstExprValue *operand_val, ConstExprValue *scalar_out_val, bool is_wrap_op) |
| 17859 | ZigValue *operand_val, ZigValue *scalar_out_val, bool is_wrap_op) |
| 17822 | 17860 | { |
| 17823 | 17861 | bool is_float = (scalar_type->id == ZigTypeIdFloat || scalar_type->id == ZigTypeIdComptimeFloat); |
| 17824 | 17862 | |
| ... | ... | @@ -17854,7 +17892,7 @@ static ErrorMsg *ir_eval_negation_scalar(IrAnalyze *ira, IrInstruction *source_i |
| 17854 | 17892 | |
| 17855 | 17893 | static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *instruction) { |
| 17856 | 17894 | IrInstruction *value = instruction->value->child; |
| 17857 | | ZigType *expr_type = value->value.type; |
| 17895 | ZigType *expr_type = value->value->type; |
| 17858 | 17896 | if (type_is_invalid(expr_type)) |
| 17859 | 17897 | return ira->codegen->invalid_instruction; |
| 17860 | 17898 | |
| ... | ... | @@ -17872,20 +17910,20 @@ static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *ins |
| 17872 | 17910 | ZigType *scalar_type = (expr_type->id == ZigTypeIdVector) ? expr_type->data.vector.elem_type : expr_type; |
| 17873 | 17911 | |
| 17874 | 17912 | if (instr_is_comptime(value)) { |
| 17875 | | ConstExprValue *operand_val = ir_resolve_const(ira, value, UndefBad); |
| 17913 | ZigValue *operand_val = ir_resolve_const(ira, value, UndefBad); |
| 17876 | 17914 | if (!operand_val) |
| 17877 | 17915 | return ira->codegen->invalid_instruction; |
| 17878 | 17916 | |
| 17879 | 17917 | IrInstruction *result_instruction = ir_const(ira, &instruction->base, expr_type); |
| 17880 | | ConstExprValue *out_val = &result_instruction->value; |
| 17918 | ZigValue *out_val = result_instruction->value; |
| 17881 | 17919 | if (expr_type->id == ZigTypeIdVector) { |
| 17882 | 17920 | expand_undef_array(ira->codegen, operand_val); |
| 17883 | 17921 | out_val->special = ConstValSpecialUndef; |
| 17884 | 17922 | expand_undef_array(ira->codegen, out_val); |
| 17885 | 17923 | size_t len = expr_type->data.vector.len; |
| 17886 | 17924 | for (size_t i = 0; i < len; i += 1) { |
| 17887 | | ConstExprValue *scalar_operand_val = &operand_val->data.x_array.data.s_none.elements[i]; |
| 17888 | | ConstExprValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i]; |
| 17925 | ZigValue *scalar_operand_val = &operand_val->data.x_array.data.s_none.elements[i]; |
| 17926 | ZigValue *scalar_out_val = &out_val->data.x_array.data.s_none.elements[i]; |
| 17889 | 17927 | assert(scalar_operand_val->type == scalar_type); |
| 17890 | 17928 | assert(scalar_out_val->type == scalar_type); |
| 17891 | 17929 | ErrorMsg *msg = ir_eval_negation_scalar(ira, &instruction->base, scalar_type, |
| ... | ... | @@ -17911,31 +17949,31 @@ static IrInstruction *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *ins |
| 17911 | 17949 | IrInstruction *result = ir_build_un_op(&ira->new_irb, |
| 17912 | 17950 | instruction->base.scope, instruction->base.source_node, |
| 17913 | 17951 | instruction->op_id, value); |
| 17914 | | result->value.type = expr_type; |
| 17952 | result->value->type = expr_type; |
| 17915 | 17953 | return result; |
| 17916 | 17954 | } |
| 17917 | 17955 | |
| 17918 | 17956 | static IrInstruction *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *instruction) { |
| 17919 | 17957 | IrInstruction *value = instruction->value->child; |
| 17920 | | ZigType *expr_type = value->value.type; |
| 17958 | ZigType *expr_type = value->value->type; |
| 17921 | 17959 | if (type_is_invalid(expr_type)) |
| 17922 | 17960 | return ira->codegen->invalid_instruction; |
| 17923 | 17961 | |
| 17924 | 17962 | if (expr_type->id == ZigTypeIdInt) { |
| 17925 | 17963 | if (instr_is_comptime(value)) { |
| 17926 | | ConstExprValue *target_const_val = ir_resolve_const(ira, value, UndefBad); |
| 17964 | ZigValue *target_const_val = ir_resolve_const(ira, value, UndefBad); |
| 17927 | 17965 | if (target_const_val == nullptr) |
| 17928 | 17966 | return ira->codegen->invalid_instruction; |
| 17929 | 17967 | |
| 17930 | 17968 | IrInstruction *result = ir_const(ira, &instruction->base, expr_type); |
| 17931 | | bigint_not(&result->value.data.x_bigint, &target_const_val->data.x_bigint, |
| 17969 | bigint_not(&result->value->data.x_bigint, &target_const_val->data.x_bigint, |
| 17932 | 17970 | expr_type->data.integral.bit_count, expr_type->data.integral.is_signed); |
| 17933 | 17971 | return result; |
| 17934 | 17972 | } |
| 17935 | 17973 | |
| 17936 | 17974 | IrInstruction *result = ir_build_un_op(&ira->new_irb, instruction->base.scope, |
| 17937 | 17975 | instruction->base.source_node, IrUnOpBinNot, value); |
| 17938 | | result->value.type = expr_type; |
| 17976 | result->value->type = expr_type; |
| 17939 | 17977 | return result; |
| 17940 | 17978 | } |
| 17941 | 17979 | |
| ... | ... | @@ -17956,9 +17994,9 @@ static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstruction |
| 17956 | 17994 | return ir_analyze_negation(ira, instruction); |
| 17957 | 17995 | case IrUnOpDereference: { |
| 17958 | 17996 | IrInstruction *ptr = instruction->value->child; |
| 17959 | | if (type_is_invalid(ptr->value.type)) |
| 17997 | if (type_is_invalid(ptr->value->type)) |
| 17960 | 17998 | return ira->codegen->invalid_instruction; |
| 17961 | | ZigType *ptr_type = ptr->value.type; |
| 17999 | ZigType *ptr_type = ptr->value->type; |
| 17962 | 18000 | if (ptr_type->id == ZigTypeIdPointer && ptr_type->data.pointer.ptr_len == PtrLenUnknown) { |
| 17963 | 18001 | ir_add_error_node(ira, instruction->base.source_node, |
| 17964 | 18002 | buf_sprintf("index syntax required for unknown-length pointer type '%s'", |
| ... | ... | @@ -17971,9 +18009,9 @@ static IrInstruction *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstruction |
| 17971 | 18009 | return ira->codegen->invalid_instruction; |
| 17972 | 18010 | |
| 17973 | 18011 | // If the result needs to be an lvalue, type check it |
| 17974 | | if (instruction->lval == LValPtr && result->value.type->id != ZigTypeIdPointer) { |
| 18012 | if (instruction->lval == LValPtr && result->value->type->id != ZigTypeIdPointer) { |
| 17975 | 18013 | ir_add_error(ira, &instruction->base, |
| 17976 | | buf_sprintf("attempt to dereference non-pointer type '%s'", buf_ptr(&result->value.type->name))); |
| 18014 | buf_sprintf("attempt to dereference non-pointer type '%s'", buf_ptr(&result->value->type->name))); |
| 17977 | 18015 | return ira->codegen->invalid_instruction; |
| 17978 | 18016 | } |
| 17979 | 18017 | |
| ... | ... | @@ -18016,13 +18054,13 @@ static IrInstruction *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr |
| 18016 | 18054 | |
| 18017 | 18055 | IrInstruction *result = ir_build_br(&ira->new_irb, |
| 18018 | 18056 | br_instruction->base.scope, br_instruction->base.source_node, new_bb, nullptr); |
| 18019 | | result->value.type = ira->codegen->builtin_types.entry_unreachable; |
| 18057 | result->value->type = ira->codegen->builtin_types.entry_unreachable; |
| 18020 | 18058 | return ir_finish_anal(ira, result); |
| 18021 | 18059 | } |
| 18022 | 18060 | |
| 18023 | 18061 | static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructionCondBr *cond_br_instruction) { |
| 18024 | 18062 | IrInstruction *condition = cond_br_instruction->condition->child; |
| 18025 | | if (type_is_invalid(condition->value.type)) |
| 18063 | if (type_is_invalid(condition->value->type)) |
| 18026 | 18064 | return ir_unreach_error(ira); |
| 18027 | 18065 | |
| 18028 | 18066 | bool is_comptime; |
| ... | ... | @@ -18031,7 +18069,7 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi |
| 18031 | 18069 | |
| 18032 | 18070 | ZigType *bool_type = ira->codegen->builtin_types.entry_bool; |
| 18033 | 18071 | IrInstruction *casted_condition = ir_implicit_cast(ira, condition, bool_type); |
| 18034 | | if (type_is_invalid(casted_condition->value.type)) |
| 18072 | if (type_is_invalid(casted_condition->value->type)) |
| 18035 | 18073 | return ir_unreach_error(ira); |
| 18036 | 18074 | |
| 18037 | 18075 | if (is_comptime || instr_is_comptime(casted_condition)) { |
| ... | ... | @@ -18053,7 +18091,7 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi |
| 18053 | 18091 | |
| 18054 | 18092 | IrInstruction *result = ir_build_br(&ira->new_irb, |
| 18055 | 18093 | cond_br_instruction->base.scope, cond_br_instruction->base.source_node, new_dest_block, nullptr); |
| 18056 | | result->value.type = ira->codegen->builtin_types.entry_unreachable; |
| 18094 | result->value->type = ira->codegen->builtin_types.entry_unreachable; |
| 18057 | 18095 | return ir_finish_anal(ira, result); |
| 18058 | 18096 | } |
| 18059 | 18097 | |
| ... | ... | @@ -18072,7 +18110,7 @@ static IrInstruction *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructi |
| 18072 | 18110 | IrInstruction *result = ir_build_cond_br(&ira->new_irb, |
| 18073 | 18111 | cond_br_instruction->base.scope, cond_br_instruction->base.source_node, |
| 18074 | 18112 | casted_condition, new_then_block, new_else_block, nullptr); |
| 18075 | | result->value.type = ira->codegen->builtin_types.entry_unreachable; |
| 18113 | result->value->type = ira->codegen->builtin_types.entry_unreachable; |
| 18076 | 18114 | return ir_finish_anal(ira, result); |
| 18077 | 18115 | } |
| 18078 | 18116 | |
| ... | ... | @@ -18081,7 +18119,7 @@ static IrInstruction *ir_analyze_instruction_unreachable(IrAnalyze *ira, |
| 18081 | 18119 | { |
| 18082 | 18120 | IrInstruction *result = ir_build_unreachable(&ira->new_irb, |
| 18083 | 18121 | unreachable_instruction->base.scope, unreachable_instruction->base.source_node); |
| 18084 | | result->value.type = ira->codegen->builtin_types.entry_unreachable; |
| 18122 | result->value->type = ira->codegen->builtin_types.entry_unreachable; |
| 18085 | 18123 | return ir_finish_anal(ira, result); |
| 18086 | 18124 | } |
| 18087 | 18125 | |
| ... | ... | @@ -18094,13 +18132,13 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 18094 | 18132 | if (predecessor != ira->const_predecessor_bb) |
| 18095 | 18133 | continue; |
| 18096 | 18134 | IrInstruction *value = phi_instruction->incoming_values[i]->child; |
| 18097 | | assert(value->value.type); |
| 18098 | | if (type_is_invalid(value->value.type)) |
| 18135 | assert(value->value->type); |
| 18136 | if (type_is_invalid(value->value->type)) |
| 18099 | 18137 | return ira->codegen->invalid_instruction; |
| 18100 | 18138 | |
| 18101 | | if (value->value.special != ConstValSpecialRuntime) { |
| 18139 | if (value->value->special != ConstValSpecialRuntime) { |
| 18102 | 18140 | IrInstruction *result = ir_const(ira, &phi_instruction->base, nullptr); |
| 18103 | | copy_const_val(&result->value, &value->value, true); |
| 18141 | copy_const_val(result->value, value->value, true); |
| 18104 | 18142 | return result; |
| 18105 | 18143 | } else { |
| 18106 | 18144 | return value; |
| ... | ... | @@ -18126,7 +18164,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 18126 | 18164 | } else { |
| 18127 | 18165 | instructions[i] = ir_const(ira, this_peer->base.source_instruction, |
| 18128 | 18166 | this_peer->base.implicit_elem_type); |
| 18129 | | instructions[i]->value.special = ConstValSpecialRuntime; |
| 18167 | instructions[i]->value->special = ConstValSpecialRuntime; |
| 18130 | 18168 | } |
| 18131 | 18169 | } else { |
| 18132 | 18170 | instructions[i] = gen_instruction; |
| ... | ... | @@ -18147,7 +18185,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 18147 | 18185 | IrInstruction *parent_result_loc = ir_resolve_result(ira, &phi_instruction->base, peer_parent->parent, |
| 18148 | 18186 | peer_parent->resolved_type, nullptr, false, false, true); |
| 18149 | 18187 | if (parent_result_loc != nullptr && |
| 18150 | | (type_is_invalid(parent_result_loc->value.type) || instr_is_unreachable(parent_result_loc))) |
| 18188 | (type_is_invalid(parent_result_loc->value->type) || instr_is_unreachable(parent_result_loc))) |
| 18151 | 18189 | { |
| 18152 | 18190 | return parent_result_loc; |
| 18153 | 18191 | } |
| ... | ... | @@ -18160,7 +18198,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 18160 | 18198 | if (instrs_to_move.length != 0) { |
| 18161 | 18199 | IrBasicBlock *predecessor = peer_parent->base.source_instruction->child->owner_bb; |
| 18162 | 18200 | IrInstruction *branch_instruction = predecessor->instruction_list.pop(); |
| 18163 | | ir_assert(branch_instruction->value.type->id == ZigTypeIdUnreachable, &phi_instruction->base); |
| 18201 | ir_assert(branch_instruction->value->type->id == ZigTypeIdUnreachable, &phi_instruction->base); |
| 18164 | 18202 | while (instrs_to_move.length != 0) { |
| 18165 | 18203 | predecessor->instruction_list.append(instrs_to_move.pop()); |
| 18166 | 18204 | } |
| ... | ... | @@ -18197,10 +18235,10 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 18197 | 18235 | IrInstruction *old_value = phi_instruction->incoming_values[i]; |
| 18198 | 18236 | assert(old_value); |
| 18199 | 18237 | IrInstruction *new_value = old_value->child; |
| 18200 | | if (!new_value || new_value->value.type->id == ZigTypeIdUnreachable || predecessor->other == nullptr) |
| 18238 | if (!new_value || new_value->value->type->id == ZigTypeIdUnreachable || predecessor->other == nullptr) |
| 18201 | 18239 | continue; |
| 18202 | 18240 | |
| 18203 | | if (type_is_invalid(new_value->value.type)) |
| 18241 | if (type_is_invalid(new_value->value->type)) |
| 18204 | 18242 | return ira->codegen->invalid_instruction; |
| 18205 | 18243 | |
| 18206 | 18244 | |
| ... | ... | @@ -18212,7 +18250,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 18212 | 18250 | if (new_incoming_blocks.length == 0) { |
| 18213 | 18251 | IrInstruction *result = ir_build_unreachable(&ira->new_irb, |
| 18214 | 18252 | phi_instruction->base.scope, phi_instruction->base.source_node); |
| 18215 | | result->value.type = ira->codegen->builtin_types.entry_unreachable; |
| 18253 | result->value->type = ira->codegen->builtin_types.entry_unreachable; |
| 18216 | 18254 | return ir_finish_anal(ira, result); |
| 18217 | 18255 | } |
| 18218 | 18256 | |
| ... | ... | @@ -18233,7 +18271,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh |
| 18233 | 18271 | if (type_is_invalid(resolved_type)) |
| 18234 | 18272 | return ira->codegen->invalid_instruction; |
| 18235 | 18273 | } else { |
| 18236 | | ZigType *resolved_loc_ptr_type = peer_parent->parent->resolved_loc->value.type; |
| 18274 | ZigType *resolved_loc_ptr_type = peer_parent->parent->resolved_loc->value->type; |
| 18237 | 18275 | ir_assert(resolved_loc_ptr_type->id == ZigTypeIdPointer, &phi_instruction->base); |
| 18238 | 18276 | resolved_type = resolved_loc_ptr_type->data.pointer.child_type; |
| 18239 | 18277 | } |
| ... | ... | @@ -18281,14 +18319,14 @@ skip_resolve_peer_types: |
| 18281 | 18319 | IrInstruction *branch_instruction = predecessor->instruction_list.pop(); |
| 18282 | 18320 | ir_set_cursor_at_end(&ira->new_irb, predecessor); |
| 18283 | 18321 | IrInstruction *casted_value = ir_implicit_cast(ira, new_value, resolved_type); |
| 18284 | | if (type_is_invalid(casted_value->value.type)) { |
| 18322 | if (type_is_invalid(casted_value->value->type)) { |
| 18285 | 18323 | return ira->codegen->invalid_instruction; |
| 18286 | 18324 | } |
| 18287 | 18325 | new_incoming_values.items[i] = casted_value; |
| 18288 | 18326 | predecessor->instruction_list.append(branch_instruction); |
| 18289 | 18327 | |
| 18290 | | if (all_stack_ptrs && (casted_value->value.special != ConstValSpecialRuntime || |
| 18291 | | casted_value->value.data.rh_ptr != RuntimeHintPtrStack)) |
| 18328 | if (all_stack_ptrs && (casted_value->value->special != ConstValSpecialRuntime || |
| 18329 | casted_value->value->data.rh_ptr != RuntimeHintPtrStack)) |
| 18292 | 18330 | { |
| 18293 | 18331 | all_stack_ptrs = false; |
| 18294 | 18332 | } |
| ... | ... | @@ -18298,11 +18336,11 @@ skip_resolve_peer_types: |
| 18298 | 18336 | IrInstruction *result = ir_build_phi(&ira->new_irb, |
| 18299 | 18337 | phi_instruction->base.scope, phi_instruction->base.source_node, |
| 18300 | 18338 | new_incoming_blocks.length, new_incoming_blocks.items, new_incoming_values.items, nullptr); |
| 18301 | | result->value.type = resolved_type; |
| 18339 | result->value->type = resolved_type; |
| 18302 | 18340 | |
| 18303 | 18341 | if (all_stack_ptrs) { |
| 18304 | | assert(result->value.special == ConstValSpecialRuntime); |
| 18305 | | result->value.data.rh_ptr = RuntimeHintPtrStack; |
| 18342 | assert(result->value->special == ConstValSpecialRuntime); |
| 18343 | result->value->data.rh_ptr = RuntimeHintPtrStack; |
| 18306 | 18344 | } |
| 18307 | 18345 | |
| 18308 | 18346 | return result; |
| ... | ... | @@ -18358,13 +18396,13 @@ static ZigType *adjust_ptr_len(CodeGen *g, ZigType *ptr_type, PtrLen ptr_len) { |
| 18358 | 18396 | static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) { |
| 18359 | 18397 | Error err; |
| 18360 | 18398 | IrInstruction *array_ptr = elem_ptr_instruction->array_ptr->child; |
| 18361 | | if (type_is_invalid(array_ptr->value.type)) |
| 18399 | if (type_is_invalid(array_ptr->value->type)) |
| 18362 | 18400 | return ira->codegen->invalid_instruction; |
| 18363 | 18401 | |
| 18364 | | ConstExprValue *orig_array_ptr_val = &array_ptr->value; |
| 18402 | ZigValue *orig_array_ptr_val = array_ptr->value; |
| 18365 | 18403 | |
| 18366 | 18404 | IrInstruction *elem_index = elem_ptr_instruction->elem_index->child; |
| 18367 | | if (type_is_invalid(elem_index->value.type)) |
| 18405 | if (type_is_invalid(elem_index->value->type)) |
| 18368 | 18406 | return ira->codegen->invalid_instruction; |
| 18369 | 18407 | |
| 18370 | 18408 | ZigType *ptr_type = orig_array_ptr_val->type; |
| ... | ... | @@ -18428,10 +18466,10 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 18428 | 18466 | return_type = adjust_ptr_len(ira->codegen, array_type->data.structure.fields[slice_ptr_index]->type_entry, |
| 18429 | 18467 | elem_ptr_instruction->ptr_len); |
| 18430 | 18468 | } else if (array_type->id == ZigTypeIdArgTuple) { |
| 18431 | | ConstExprValue *ptr_val = ir_resolve_const(ira, array_ptr, UndefBad); |
| 18469 | ZigValue *ptr_val = ir_resolve_const(ira, array_ptr, UndefBad); |
| 18432 | 18470 | if (!ptr_val) |
| 18433 | 18471 | return ira->codegen->invalid_instruction; |
| 18434 | | ConstExprValue *args_val = const_ptr_pointee(ira, ira->codegen, ptr_val, elem_ptr_instruction->base.source_node); |
| 18472 | ZigValue *args_val = const_ptr_pointee(ira, ira->codegen, ptr_val, elem_ptr_instruction->base.source_node); |
| 18435 | 18473 | if (args_val == nullptr) |
| 18436 | 18474 | return ira->codegen->invalid_instruction; |
| 18437 | 18475 | size_t start = args_val->data.x_arg_tuple.start_index; |
| ... | ... | @@ -18471,7 +18509,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 18471 | 18509 | return ira->codegen->invalid_instruction; |
| 18472 | 18510 | ir_assert(instr_is_comptime(casted_elem_index), &elem_ptr_instruction->base); |
| 18473 | 18511 | Buf *field_name = buf_alloc(); |
| 18474 | | bigint_append_buf(field_name, &casted_elem_index->value.data.x_bigint, 10); |
| 18512 | bigint_append_buf(field_name, &casted_elem_index->value->data.x_bigint, 10); |
| 18475 | 18513 | return ir_analyze_inferred_field_ptr(ira, field_name, &elem_ptr_instruction->base, |
| 18476 | 18514 | array_ptr, array_type); |
| 18477 | 18515 | } else { |
| ... | ... | @@ -18487,13 +18525,13 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 18487 | 18525 | |
| 18488 | 18526 | bool safety_check_on = elem_ptr_instruction->safety_check_on; |
| 18489 | 18527 | if (instr_is_comptime(casted_elem_index)) { |
| 18490 | | uint64_t index = bigint_as_u64(&casted_elem_index->value.data.x_bigint); |
| 18528 | uint64_t index = bigint_as_u64(&casted_elem_index->value->data.x_bigint); |
| 18491 | 18529 | if (array_type->id == ZigTypeIdArray) { |
| 18492 | 18530 | uint64_t array_len = array_type->data.array.len; |
| 18493 | 18531 | if (index == array_len && array_type->data.array.sentinel != nullptr) { |
| 18494 | 18532 | ZigType *elem_type = array_type->data.array.child_type; |
| 18495 | 18533 | IrInstruction *sentinel_elem = ir_const(ira, &elem_ptr_instruction->base, elem_type); |
| 18496 | | copy_const_val(&sentinel_elem->value, array_type->data.array.sentinel, false); |
| 18534 | copy_const_val(sentinel_elem->value, array_type->data.array.sentinel, false); |
| 18497 | 18535 | return ir_get_ref(ira, &elem_ptr_instruction->base, sentinel_elem, true, false); |
| 18498 | 18536 | } |
| 18499 | 18537 | if (index >= array_len) { |
| ... | ... | @@ -18544,7 +18582,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 18544 | 18582 | (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar || |
| 18545 | 18583 | array_type->id == ZigTypeIdArray)) |
| 18546 | 18584 | { |
| 18547 | | ConstExprValue *array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val, |
| 18585 | ZigValue *array_ptr_val = const_ptr_pointee(ira, ira->codegen, orig_array_ptr_val, |
| 18548 | 18586 | elem_ptr_instruction->base.source_node); |
| 18549 | 18587 | if (array_ptr_val == nullptr) |
| 18550 | 18588 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -18557,7 +18595,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 18557 | 18595 | array_ptr_val->data.x_array.data.s_none.elements = create_const_vals(array_type->data.array.len); |
| 18558 | 18596 | array_ptr_val->special = ConstValSpecialStatic; |
| 18559 | 18597 | for (size_t i = 0; i < array_type->data.array.len; i += 1) { |
| 18560 | | ConstExprValue *elem_val = &array_ptr_val->data.x_array.data.s_none.elements[i]; |
| 18598 | ZigValue *elem_val = &array_ptr_val->data.x_array.data.s_none.elements[i]; |
| 18561 | 18599 | elem_val->special = ConstValSpecialUndef; |
| 18562 | 18600 | elem_val->type = array_type->data.array.child_type; |
| 18563 | 18601 | elem_val->parent.id = ConstParentIdArray; |
| ... | ... | @@ -18565,8 +18603,8 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 18565 | 18603 | elem_val->parent.data.p_array.elem_index = i; |
| 18566 | 18604 | } |
| 18567 | 18605 | } else if (is_slice(array_type)) { |
| 18568 | | ir_assert(array_ptr->value.type->id == ZigTypeIdPointer, &elem_ptr_instruction->base); |
| 18569 | | ZigType *actual_array_type = array_ptr->value.type->data.pointer.child_type; |
| 18606 | ir_assert(array_ptr->value->type->id == ZigTypeIdPointer, &elem_ptr_instruction->base); |
| 18607 | ZigType *actual_array_type = array_ptr->value->type->data.pointer.child_type; |
| 18570 | 18608 | |
| 18571 | 18609 | if (type_is_invalid(actual_array_type)) |
| 18572 | 18610 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -18576,14 +18614,14 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 18576 | 18614 | return ira->codegen->invalid_instruction; |
| 18577 | 18615 | } |
| 18578 | 18616 | |
| 18579 | | ConstExprValue *array_init_val = create_const_vals(1); |
| 18617 | ZigValue *array_init_val = create_const_vals(1); |
| 18580 | 18618 | array_init_val->special = ConstValSpecialStatic; |
| 18581 | 18619 | array_init_val->type = actual_array_type; |
| 18582 | 18620 | array_init_val->data.x_array.special = ConstArraySpecialNone; |
| 18583 | 18621 | array_init_val->data.x_array.data.s_none.elements = create_const_vals(actual_array_type->data.array.len); |
| 18584 | 18622 | array_init_val->special = ConstValSpecialStatic; |
| 18585 | 18623 | for (size_t i = 0; i < actual_array_type->data.array.len; i += 1) { |
| 18586 | | ConstExprValue *elem_val = &array_init_val->data.x_array.data.s_none.elements[i]; |
| 18624 | ZigValue *elem_val = &array_init_val->data.x_array.data.s_none.elements[i]; |
| 18587 | 18625 | elem_val->special = ConstValSpecialUndef; |
| 18588 | 18626 | elem_val->type = actual_array_type->data.array.child_type; |
| 18589 | 18627 | elem_val->parent.id = ConstParentIdArray; |
| ... | ... | @@ -18608,7 +18646,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 18608 | 18646 | { |
| 18609 | 18647 | if (array_type->id == ZigTypeIdPointer) { |
| 18610 | 18648 | IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type); |
| 18611 | | ConstExprValue *out_val = &result->value; |
| 18649 | ZigValue *out_val = result->value; |
| 18612 | 18650 | out_val->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut; |
| 18613 | 18651 | size_t new_index; |
| 18614 | 18652 | size_t mem_size; |
| ... | ... | @@ -18619,7 +18657,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 18619 | 18657 | zig_unreachable(); |
| 18620 | 18658 | case ConstPtrSpecialRef: |
| 18621 | 18659 | if (array_ptr_val->data.x_ptr.data.ref.pointee->type->id == ZigTypeIdArray) { |
| 18622 | | ConstExprValue *array_val = array_ptr_val->data.x_ptr.data.ref.pointee; |
| 18660 | ZigValue *array_val = array_ptr_val->data.x_ptr.data.ref.pointee; |
| 18623 | 18661 | new_index = index; |
| 18624 | 18662 | ZigType *array_type = array_val->type; |
| 18625 | 18663 | mem_size = array_type->data.array.len; |
| ... | ... | @@ -18682,18 +18720,18 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 18682 | 18720 | } |
| 18683 | 18721 | return result; |
| 18684 | 18722 | } else if (is_slice(array_type)) { |
| 18685 | | ConstExprValue *ptr_field = array_ptr_val->data.x_struct.fields[slice_ptr_index]; |
| 18723 | ZigValue *ptr_field = array_ptr_val->data.x_struct.fields[slice_ptr_index]; |
| 18686 | 18724 | ir_assert(ptr_field != nullptr, &elem_ptr_instruction->base); |
| 18687 | 18725 | if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) { |
| 18688 | 18726 | IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, |
| 18689 | 18727 | elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, false, |
| 18690 | 18728 | elem_ptr_instruction->ptr_len, nullptr); |
| 18691 | | result->value.type = return_type; |
| 18729 | result->value->type = return_type; |
| 18692 | 18730 | return result; |
| 18693 | 18731 | } |
| 18694 | | ConstExprValue *len_field = array_ptr_val->data.x_struct.fields[slice_len_index]; |
| 18732 | ZigValue *len_field = array_ptr_val->data.x_struct.fields[slice_len_index]; |
| 18695 | 18733 | IrInstruction *result = ir_const(ira, &elem_ptr_instruction->base, return_type); |
| 18696 | | ConstExprValue *out_val = &result->value; |
| 18734 | ZigValue *out_val = result->value; |
| 18697 | 18735 | ZigType *slice_ptr_type = array_type->data.structure.fields[slice_ptr_index]->type_entry; |
| 18698 | 18736 | uint64_t slice_len = bigint_as_u64(&len_field->data.x_bigint); |
| 18699 | 18737 | uint64_t full_slice_len = slice_len + |
| ... | ... | @@ -18752,12 +18790,12 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 18752 | 18790 | result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, |
| 18753 | 18791 | elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, |
| 18754 | 18792 | false, elem_ptr_instruction->ptr_len, nullptr); |
| 18755 | | result->value.type = return_type; |
| 18756 | | result->value.special = ConstValSpecialStatic; |
| 18793 | result->value->type = return_type; |
| 18794 | result->value->special = ConstValSpecialStatic; |
| 18757 | 18795 | } else { |
| 18758 | 18796 | result = ir_const(ira, &elem_ptr_instruction->base, return_type); |
| 18759 | 18797 | } |
| 18760 | | ConstExprValue *out_val = &result->value; |
| 18798 | ZigValue *out_val = result->value; |
| 18761 | 18799 | out_val->data.x_ptr.special = ConstPtrSpecialBaseArray; |
| 18762 | 18800 | out_val->data.x_ptr.mut = orig_array_ptr_val->data.x_ptr.mut; |
| 18763 | 18801 | out_val->data.x_ptr.data.base_array.array_val = array_ptr_val; |
| ... | ... | @@ -18814,7 +18852,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct |
| 18814 | 18852 | IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope, |
| 18815 | 18853 | elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, safety_check_on, |
| 18816 | 18854 | elem_ptr_instruction->ptr_len, nullptr); |
| 18817 | | result->value.type = return_type; |
| 18855 | result->value->type = return_type; |
| 18818 | 18856 | return result; |
| 18819 | 18857 | } |
| 18820 | 18858 | |
| ... | ... | @@ -18892,8 +18930,8 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction |
| 18892 | 18930 | case OnePossibleValueNo: |
| 18893 | 18931 | break; |
| 18894 | 18932 | } |
| 18895 | | bool is_const = struct_ptr->value.type->data.pointer.is_const; |
| 18896 | | bool is_volatile = struct_ptr->value.type->data.pointer.is_volatile; |
| 18933 | bool is_const = struct_ptr->value->type->data.pointer.is_const; |
| 18934 | bool is_volatile = struct_ptr->value->type->data.pointer.is_volatile; |
| 18897 | 18935 | ZigType *ptr_type; |
| 18898 | 18936 | if (struct_type->data.structure.is_inferred) { |
| 18899 | 18937 | ptr_type = get_pointer_to_type_extra(ira->codegen, field_type, |
| ... | ... | @@ -18904,9 +18942,9 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction |
| 18904 | 18942 | ResolveStatusZeroBitsKnown : ResolveStatusSizeKnown; |
| 18905 | 18943 | if ((err = type_resolve(ira->codegen, struct_type, needed_resolve_status))) |
| 18906 | 18944 | return ira->codegen->invalid_instruction; |
| 18907 | | assert(struct_ptr->value.type->id == ZigTypeIdPointer); |
| 18908 | | uint32_t ptr_bit_offset = struct_ptr->value.type->data.pointer.bit_offset_in_host; |
| 18909 | | uint32_t ptr_host_int_bytes = struct_ptr->value.type->data.pointer.host_int_bytes; |
| 18945 | assert(struct_ptr->value->type->id == ZigTypeIdPointer); |
| 18946 | uint32_t ptr_bit_offset = struct_ptr->value->type->data.pointer.bit_offset_in_host; |
| 18947 | uint32_t ptr_host_int_bytes = struct_ptr->value->type->data.pointer.host_int_bytes; |
| 18910 | 18948 | uint32_t host_int_bytes_for_result_type = (ptr_host_int_bytes == 0) ? |
| 18911 | 18949 | get_host_int_bytes(ira->codegen, struct_type, field) : ptr_host_int_bytes; |
| 18912 | 18950 | ptr_type = get_pointer_to_type_extra(ira->codegen, field_type, |
| ... | ... | @@ -18915,12 +18953,12 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction |
| 18915 | 18953 | (uint32_t)host_int_bytes_for_result_type, false); |
| 18916 | 18954 | } |
| 18917 | 18955 | if (instr_is_comptime(struct_ptr)) { |
| 18918 | | ConstExprValue *ptr_val = ir_resolve_const(ira, struct_ptr, UndefBad); |
| 18956 | ZigValue *ptr_val = ir_resolve_const(ira, struct_ptr, UndefBad); |
| 18919 | 18957 | if (!ptr_val) |
| 18920 | 18958 | return ira->codegen->invalid_instruction; |
| 18921 | 18959 | |
| 18922 | 18960 | if (ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { |
| 18923 | | ConstExprValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); |
| 18961 | ZigValue *struct_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); |
| 18924 | 18962 | if (struct_val == nullptr) |
| 18925 | 18963 | return ira->codegen->invalid_instruction; |
| 18926 | 18964 | if (type_is_invalid(struct_val->type)) |
| ... | ... | @@ -18929,7 +18967,7 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction |
| 18929 | 18967 | struct_val->data.x_struct.fields = alloc_const_vals_ptrs(struct_type->data.structure.src_field_count); |
| 18930 | 18968 | struct_val->special = ConstValSpecialStatic; |
| 18931 | 18969 | for (size_t i = 0; i < struct_type->data.structure.src_field_count; i += 1) { |
| 18932 | | ConstExprValue *field_val = struct_val->data.x_struct.fields[i]; |
| 18970 | ZigValue *field_val = struct_val->data.x_struct.fields[i]; |
| 18933 | 18971 | field_val->special = ConstValSpecialUndef; |
| 18934 | 18972 | field_val->type = resolve_struct_field_type(ira->codegen, |
| 18935 | 18973 | struct_type->data.structure.fields[i]); |
| ... | ... | @@ -18942,12 +18980,12 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction |
| 18942 | 18980 | if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { |
| 18943 | 18981 | result = ir_build_struct_field_ptr(&ira->new_irb, source_instr->scope, |
| 18944 | 18982 | source_instr->source_node, struct_ptr, field); |
| 18945 | | result->value.type = ptr_type; |
| 18946 | | result->value.special = ConstValSpecialStatic; |
| 18983 | result->value->type = ptr_type; |
| 18984 | result->value->special = ConstValSpecialStatic; |
| 18947 | 18985 | } else { |
| 18948 | 18986 | result = ir_const(ira, source_instr, ptr_type); |
| 18949 | 18987 | } |
| 18950 | | ConstExprValue *const_val = &result->value; |
| 18988 | ZigValue *const_val = result->value; |
| 18951 | 18989 | const_val->data.x_ptr.special = ConstPtrSpecialBaseStruct; |
| 18952 | 18990 | const_val->data.x_ptr.mut = ptr_val->data.x_ptr.mut; |
| 18953 | 18991 | const_val->data.x_ptr.data.base_struct.struct_val = struct_val; |
| ... | ... | @@ -18957,7 +18995,7 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction |
| 18957 | 18995 | } |
| 18958 | 18996 | IrInstruction *result = ir_build_struct_field_ptr(&ira->new_irb, source_instr->scope, source_instr->source_node, |
| 18959 | 18997 | struct_ptr, field); |
| 18960 | | result->value.type = ptr_type; |
| 18998 | result->value->type = ptr_type; |
| 18961 | 18999 | return result; |
| 18962 | 19000 | } |
| 18963 | 19001 | |
| ... | ... | @@ -18970,7 +19008,7 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n |
| 18970 | 19008 | // the field type will then be available, and the field will be added to the inferred |
| 18971 | 19009 | // struct. |
| 18972 | 19010 | |
| 18973 | | ZigType *container_ptr_type = container_ptr->value.type; |
| 19011 | ZigType *container_ptr_type = container_ptr->value->type; |
| 18974 | 19012 | ir_assert(container_ptr_type->id == ZigTypeIdPointer, source_instr); |
| 18975 | 19013 | |
| 18976 | 19014 | InferredStructField *inferred_struct_field = allocate<InferredStructField>(1, "InferredStructField"); |
| ... | ... | @@ -18984,14 +19022,14 @@ static IrInstruction *ir_analyze_inferred_field_ptr(IrAnalyze *ira, Buf *field_n |
| 18984 | 19022 | |
| 18985 | 19023 | if (instr_is_comptime(container_ptr)) { |
| 18986 | 19024 | IrInstruction *result = ir_const(ira, source_instr, field_ptr_type); |
| 18987 | | copy_const_val(&result->value, &container_ptr->value, false); |
| 18988 | | result->value.type = field_ptr_type; |
| 19025 | copy_const_val(result->value, container_ptr->value, false); |
| 19026 | result->value->type = field_ptr_type; |
| 18989 | 19027 | return result; |
| 18990 | 19028 | } |
| 18991 | 19029 | |
| 18992 | 19030 | IrInstruction *result = ir_build_cast(&ira->new_irb, source_instr->scope, |
| 18993 | 19031 | source_instr->source_node, field_ptr_type, container_ptr, CastOpNoop); |
| 18994 | | result->value.type = field_ptr_type; |
| 19032 | result->value->type = field_ptr_type; |
| 18995 | 19033 | return result; |
| 18996 | 19034 | } |
| 18997 | 19035 | |
| ... | ... | @@ -19011,7 +19049,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 19011 | 19049 | if ((err = type_resolve(ira->codegen, bare_type, ResolveStatusZeroBitsKnown))) |
| 19012 | 19050 | return ira->codegen->invalid_instruction; |
| 19013 | 19051 | |
| 19014 | | assert(container_ptr->value.type->id == ZigTypeIdPointer); |
| 19052 | assert(container_ptr->value->type->id == ZigTypeIdPointer); |
| 19015 | 19053 | if (bare_type->id == ZigTypeIdStruct) { |
| 19016 | 19054 | TypeStructField *field = find_struct_type_field(bare_type, field_name); |
| 19017 | 19055 | if (field != nullptr) { |
| ... | ... | @@ -19028,8 +19066,8 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 19028 | 19066 | } |
| 19029 | 19067 | |
| 19030 | 19068 | if (bare_type->id == ZigTypeIdUnion) { |
| 19031 | | bool is_const = container_ptr->value.type->data.pointer.is_const; |
| 19032 | | bool is_volatile = container_ptr->value.type->data.pointer.is_volatile; |
| 19069 | bool is_const = container_ptr->value->type->data.pointer.is_const; |
| 19070 | bool is_volatile = container_ptr->value->type->data.pointer.is_volatile; |
| 19033 | 19071 | |
| 19034 | 19072 | TypeUnionField *field = find_union_type_field(bare_type, field_name); |
| 19035 | 19073 | if (field == nullptr) { |
| ... | ... | @@ -19044,20 +19082,20 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 19044 | 19082 | ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type, |
| 19045 | 19083 | is_const, is_volatile, PtrLenSingle, 0, 0, 0, false); |
| 19046 | 19084 | if (instr_is_comptime(container_ptr)) { |
| 19047 | | ConstExprValue *ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); |
| 19085 | ZigValue *ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); |
| 19048 | 19086 | if (!ptr_val) |
| 19049 | 19087 | return ira->codegen->invalid_instruction; |
| 19050 | 19088 | |
| 19051 | 19089 | if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar && |
| 19052 | 19090 | ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { |
| 19053 | | ConstExprValue *union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); |
| 19091 | ZigValue *union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); |
| 19054 | 19092 | if (union_val == nullptr) |
| 19055 | 19093 | return ira->codegen->invalid_instruction; |
| 19056 | 19094 | if (type_is_invalid(union_val->type)) |
| 19057 | 19095 | return ira->codegen->invalid_instruction; |
| 19058 | 19096 | |
| 19059 | 19097 | if (initializing) { |
| 19060 | | ConstExprValue *payload_val = create_const_vals(1); |
| 19098 | ZigValue *payload_val = create_const_vals(1); |
| 19061 | 19099 | payload_val->special = ConstValSpecialUndef; |
| 19062 | 19100 | payload_val->type = field_type; |
| 19063 | 19101 | payload_val->parent.id = ConstParentIdUnion; |
| ... | ... | @@ -19079,20 +19117,20 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 19079 | 19117 | } |
| 19080 | 19118 | } |
| 19081 | 19119 | |
| 19082 | | ConstExprValue *payload_val = union_val->data.x_union.payload; |
| 19120 | ZigValue *payload_val = union_val->data.x_union.payload; |
| 19083 | 19121 | |
| 19084 | 19122 | IrInstruction *result; |
| 19085 | 19123 | if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { |
| 19086 | 19124 | result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope, |
| 19087 | 19125 | source_instr->source_node, container_ptr, field, true, initializing); |
| 19088 | | result->value.type = ptr_type; |
| 19089 | | result->value.special = ConstValSpecialStatic; |
| 19126 | result->value->type = ptr_type; |
| 19127 | result->value->special = ConstValSpecialStatic; |
| 19090 | 19128 | } else { |
| 19091 | 19129 | result = ir_const(ira, source_instr, ptr_type); |
| 19092 | 19130 | } |
| 19093 | | ConstExprValue *const_val = &result->value; |
| 19131 | ZigValue *const_val = result->value; |
| 19094 | 19132 | const_val->data.x_ptr.special = ConstPtrSpecialRef; |
| 19095 | | const_val->data.x_ptr.mut = container_ptr->value.data.x_ptr.mut; |
| 19133 | const_val->data.x_ptr.mut = container_ptr->value->data.x_ptr.mut; |
| 19096 | 19134 | const_val->data.x_ptr.data.ref.pointee = payload_val; |
| 19097 | 19135 | return result; |
| 19098 | 19136 | } |
| ... | ... | @@ -19100,7 +19138,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ |
| 19100 | 19138 | |
| 19101 | 19139 | IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb, source_instr->scope, |
| 19102 | 19140 | source_instr->source_node, container_ptr, field, true, initializing); |
| 19103 | | result->value.type = ptr_type; |
| 19141 | result->value->type = ptr_type; |
| 19104 | 19142 | return result; |
| 19105 | 19143 | } |
| 19106 | 19144 | |
| ... | ... | @@ -19205,10 +19243,10 @@ static ErrorTableEntry *find_err_table_entry(ZigType *err_set_type, Buf *field_n |
| 19205 | 19243 | static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFieldPtr *field_ptr_instruction) { |
| 19206 | 19244 | Error err; |
| 19207 | 19245 | IrInstruction *container_ptr = field_ptr_instruction->container_ptr->child; |
| 19208 | | if (type_is_invalid(container_ptr->value.type)) |
| 19246 | if (type_is_invalid(container_ptr->value->type)) |
| 19209 | 19247 | return ira->codegen->invalid_instruction; |
| 19210 | 19248 | |
| 19211 | | ZigType *container_type = container_ptr->value.type->data.pointer.child_type; |
| 19249 | ZigType *container_type = container_ptr->value->type->data.pointer.child_type; |
| 19212 | 19250 | |
| 19213 | 19251 | Buf *field_name = field_ptr_instruction->field_name_buffer; |
| 19214 | 19252 | if (!field_name) { |
| ... | ... | @@ -19224,7 +19262,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc |
| 19224 | 19262 | if (type_is_invalid(container_type)) { |
| 19225 | 19263 | return ira->codegen->invalid_instruction; |
| 19226 | 19264 | } else if (is_slice(container_type) || is_container_ref(container_type)) { |
| 19227 | | assert(container_ptr->value.type->id == ZigTypeIdPointer); |
| 19265 | assert(container_ptr->value->type->id == ZigTypeIdPointer); |
| 19228 | 19266 | if (container_type->id == ZigTypeIdPointer) { |
| 19229 | 19267 | ZigType *bare_type = container_ref_type(container_type); |
| 19230 | 19268 | IrInstruction *container_child = ir_get_deref(ira, &field_ptr_instruction->base, container_ptr, nullptr); |
| ... | ... | @@ -19236,7 +19274,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc |
| 19236 | 19274 | } |
| 19237 | 19275 | } else if (is_array_ref(container_type) && !field_ptr_instruction->initializing) { |
| 19238 | 19276 | if (buf_eql_str(field_name, "len")) { |
| 19239 | | ConstExprValue *len_val = create_const_vals(1); |
| 19277 | ZigValue *len_val = create_const_vals(1); |
| 19240 | 19278 | if (container_type->id == ZigTypeIdPointer) { |
| 19241 | 19279 | init_const_usize(ira->codegen, len_val, container_type->data.pointer.child_type->data.array.len); |
| 19242 | 19280 | } else { |
| ... | ... | @@ -19255,17 +19293,17 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc |
| 19255 | 19293 | return ira->codegen->invalid_instruction; |
| 19256 | 19294 | } |
| 19257 | 19295 | } else if (container_type->id == ZigTypeIdArgTuple) { |
| 19258 | | ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); |
| 19296 | ZigValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); |
| 19259 | 19297 | if (!container_ptr_val) |
| 19260 | 19298 | return ira->codegen->invalid_instruction; |
| 19261 | 19299 | |
| 19262 | | assert(container_ptr->value.type->id == ZigTypeIdPointer); |
| 19263 | | ConstExprValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node); |
| 19300 | assert(container_ptr->value->type->id == ZigTypeIdPointer); |
| 19301 | ZigValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node); |
| 19264 | 19302 | if (child_val == nullptr) |
| 19265 | 19303 | return ira->codegen->invalid_instruction; |
| 19266 | 19304 | |
| 19267 | 19305 | if (buf_eql_str(field_name, "len")) { |
| 19268 | | ConstExprValue *len_val = create_const_vals(1); |
| 19306 | ZigValue *len_val = create_const_vals(1); |
| 19269 | 19307 | size_t len = child_val->data.x_arg_tuple.end_index - child_val->data.x_arg_tuple.start_index; |
| 19270 | 19308 | init_const_usize(ira->codegen, len_val, len); |
| 19271 | 19309 | |
| ... | ... | @@ -19281,12 +19319,12 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc |
| 19281 | 19319 | return ira->codegen->invalid_instruction; |
| 19282 | 19320 | } |
| 19283 | 19321 | } else if (container_type->id == ZigTypeIdMetaType) { |
| 19284 | | ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); |
| 19322 | ZigValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); |
| 19285 | 19323 | if (!container_ptr_val) |
| 19286 | 19324 | return ira->codegen->invalid_instruction; |
| 19287 | 19325 | |
| 19288 | | assert(container_ptr->value.type->id == ZigTypeIdPointer); |
| 19289 | | ConstExprValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node); |
| 19326 | assert(container_ptr->value->type->id == ZigTypeIdPointer); |
| 19327 | ZigValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node); |
| 19290 | 19328 | if (child_val == nullptr) |
| 19291 | 19329 | return ira->codegen->invalid_instruction; |
| 19292 | 19330 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, |
| ... | ... | @@ -19382,7 +19420,7 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc |
| 19382 | 19420 | } |
| 19383 | 19421 | err_set_type = child_type; |
| 19384 | 19422 | } |
| 19385 | | ConstExprValue *const_val = create_const_vals(1); |
| 19423 | ZigValue *const_val = create_const_vals(1); |
| 19386 | 19424 | const_val->special = ConstValSpecialStatic; |
| 19387 | 19425 | const_val->type = err_set_type; |
| 19388 | 19426 | const_val->data.x_err_set = err_entry; |
| ... | ... | @@ -19567,11 +19605,11 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc |
| 19567 | 19605 | |
| 19568 | 19606 | static IrInstruction *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstructionStorePtr *instruction) { |
| 19569 | 19607 | IrInstruction *ptr = instruction->ptr->child; |
| 19570 | | if (type_is_invalid(ptr->value.type)) |
| 19608 | if (type_is_invalid(ptr->value->type)) |
| 19571 | 19609 | return ira->codegen->invalid_instruction; |
| 19572 | 19610 | |
| 19573 | 19611 | IrInstruction *value = instruction->value->child; |
| 19574 | | if (type_is_invalid(value->value.type)) |
| 19612 | if (type_is_invalid(value->value->type)) |
| 19575 | 19613 | return ira->codegen->invalid_instruction; |
| 19576 | 19614 | |
| 19577 | 19615 | return ir_analyze_store_ptr(ira, &instruction->base, ptr, value, instruction->allow_write_through_const); |
| ... | ... | @@ -19579,14 +19617,14 @@ static IrInstruction *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstruc |
| 19579 | 19617 | |
| 19580 | 19618 | static IrInstruction *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstructionLoadPtr *instruction) { |
| 19581 | 19619 | IrInstruction *ptr = instruction->ptr->child; |
| 19582 | | if (type_is_invalid(ptr->value.type)) |
| 19620 | if (type_is_invalid(ptr->value->type)) |
| 19583 | 19621 | return ira->codegen->invalid_instruction; |
| 19584 | 19622 | return ir_get_deref(ira, &instruction->base, ptr, nullptr); |
| 19585 | 19623 | } |
| 19586 | 19624 | |
| 19587 | 19625 | static IrInstruction *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeOf *typeof_instruction) { |
| 19588 | 19626 | IrInstruction *expr_value = typeof_instruction->value->child; |
| 19589 | | ZigType *type_entry = expr_value->value.type; |
| 19627 | ZigType *type_entry = expr_value->value->type; |
| 19590 | 19628 | if (type_is_invalid(type_entry)) |
| 19591 | 19629 | return ira->codegen->invalid_instruction; |
| 19592 | 19630 | return ir_const_type(ira, &typeof_instruction->base, type_entry); |
| ... | ... | @@ -19749,11 +19787,11 @@ static IrInstruction *ir_analyze_instruction_slice_type(IrAnalyze *ira, |
| 19749 | 19787 | IrInstructionSliceType *slice_type_instruction) |
| 19750 | 19788 | { |
| 19751 | 19789 | IrInstruction *result = ir_const(ira, &slice_type_instruction->base, ira->codegen->builtin_types.entry_type); |
| 19752 | | result->value.special = ConstValSpecialLazy; |
| 19790 | result->value->special = ConstValSpecialLazy; |
| 19753 | 19791 | |
| 19754 | 19792 | LazyValueSliceType *lazy_slice_type = allocate<LazyValueSliceType>(1); |
| 19755 | 19793 | lazy_slice_type->ira = ira; |
| 19756 | | result->value.data.x_lazy = &lazy_slice_type->base; |
| 19794 | result->value->data.x_lazy = &lazy_slice_type->base; |
| 19757 | 19795 | lazy_slice_type->base.id = LazyValueIdSliceType; |
| 19758 | 19796 | |
| 19759 | 19797 | if (slice_type_instruction->align_value != nullptr) { |
| ... | ... | @@ -19812,14 +19850,14 @@ static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAs |
| 19812 | 19850 | |
| 19813 | 19851 | for (size_t i = 0; i < asm_expr->input_list.length; i += 1) { |
| 19814 | 19852 | IrInstruction *const input_value = asm_instruction->input_list[i]->child; |
| 19815 | | if (type_is_invalid(input_value->value.type)) |
| 19853 | if (type_is_invalid(input_value->value->type)) |
| 19816 | 19854 | return ira->codegen->invalid_instruction; |
| 19817 | 19855 | |
| 19818 | 19856 | if (instr_is_comptime(input_value) && |
| 19819 | | (input_value->value.type->id == ZigTypeIdComptimeInt || |
| 19820 | | input_value->value.type->id == ZigTypeIdComptimeFloat)) { |
| 19857 | (input_value->value->type->id == ZigTypeIdComptimeInt || |
| 19858 | input_value->value->type->id == ZigTypeIdComptimeFloat)) { |
| 19821 | 19859 | ir_add_error_node(ira, input_value->source_node, |
| 19822 | | buf_sprintf("expected sized integer or sized float, found %s", buf_ptr(&input_value->value.type->name))); |
| 19860 | buf_sprintf("expected sized integer or sized float, found %s", buf_ptr(&input_value->value->type->name))); |
| 19823 | 19861 | return ira->codegen->invalid_instruction; |
| 19824 | 19862 | } |
| 19825 | 19863 | |
| ... | ... | @@ -19831,7 +19869,7 @@ static IrInstruction *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAs |
| 19831 | 19869 | asm_instruction->asm_template, asm_instruction->token_list, asm_instruction->token_list_len, |
| 19832 | 19870 | input_list, output_types, asm_instruction->output_vars, asm_instruction->return_count, |
| 19833 | 19871 | asm_instruction->has_side_effects); |
| 19834 | | result->value.type = return_type; |
| 19872 | result->value->type = return_type; |
| 19835 | 19873 | return result; |
| 19836 | 19874 | } |
| 19837 | 19875 | |
| ... | ... | @@ -19850,13 +19888,13 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira, |
| 19850 | 19888 | if (type_is_invalid(child_type)) |
| 19851 | 19889 | return ira->codegen->invalid_instruction; |
| 19852 | 19890 | |
| 19853 | | ConstExprValue *sentinel_val; |
| 19891 | ZigValue *sentinel_val; |
| 19854 | 19892 | if (array_type_instruction->sentinel != nullptr) { |
| 19855 | 19893 | IrInstruction *uncasted_sentinel = array_type_instruction->sentinel->child; |
| 19856 | | if (type_is_invalid(uncasted_sentinel->value.type)) |
| 19894 | if (type_is_invalid(uncasted_sentinel->value->type)) |
| 19857 | 19895 | return ira->codegen->invalid_instruction; |
| 19858 | 19896 | IrInstruction *sentinel = ir_implicit_cast(ira, uncasted_sentinel, child_type); |
| 19859 | | if (type_is_invalid(sentinel->value.type)) |
| 19897 | if (type_is_invalid(sentinel->value->type)) |
| 19860 | 19898 | return ira->codegen->invalid_instruction; |
| 19861 | 19899 | sentinel_val = ir_resolve_const(ira, sentinel, UndefBad); |
| 19862 | 19900 | if (sentinel_val == nullptr) |
| ... | ... | @@ -19909,11 +19947,11 @@ static IrInstruction *ir_analyze_instruction_array_type(IrAnalyze *ira, |
| 19909 | 19947 | |
| 19910 | 19948 | static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstructionSizeOf *instruction) { |
| 19911 | 19949 | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int); |
| 19912 | | result->value.special = ConstValSpecialLazy; |
| 19950 | result->value->special = ConstValSpecialLazy; |
| 19913 | 19951 | |
| 19914 | 19952 | LazyValueSizeOf *lazy_size_of = allocate<LazyValueSizeOf>(1); |
| 19915 | 19953 | lazy_size_of->ira = ira; |
| 19916 | | result->value.data.x_lazy = &lazy_size_of->base; |
| 19954 | result->value->data.x_lazy = &lazy_size_of->base; |
| 19917 | 19955 | lazy_size_of->base.id = LazyValueIdSizeOf; |
| 19918 | 19956 | |
| 19919 | 19957 | lazy_size_of->target_type = instruction->type_value->child; |
| ... | ... | @@ -19924,11 +19962,11 @@ static IrInstruction *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstructi |
| 19924 | 19962 | } |
| 19925 | 19963 | |
| 19926 | 19964 | static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *source_inst, IrInstruction *value) { |
| 19927 | | ZigType *type_entry = value->value.type; |
| 19965 | ZigType *type_entry = value->value->type; |
| 19928 | 19966 | |
| 19929 | 19967 | if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.allow_zero) { |
| 19930 | 19968 | if (instr_is_comptime(value)) { |
| 19931 | | ConstExprValue *c_ptr_val = ir_resolve_const(ira, value, UndefOk); |
| 19969 | ZigValue *c_ptr_val = ir_resolve_const(ira, value, UndefOk); |
| 19932 | 19970 | if (c_ptr_val == nullptr) |
| 19933 | 19971 | return ira->codegen->invalid_instruction; |
| 19934 | 19972 | if (c_ptr_val->special == ConstValSpecialUndef) |
| ... | ... | @@ -19941,11 +19979,11 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so |
| 19941 | 19979 | |
| 19942 | 19980 | IrInstruction *result = ir_build_test_nonnull(&ira->new_irb, |
| 19943 | 19981 | source_inst->scope, source_inst->source_node, value); |
| 19944 | | result->value.type = ira->codegen->builtin_types.entry_bool; |
| 19982 | result->value->type = ira->codegen->builtin_types.entry_bool; |
| 19945 | 19983 | return result; |
| 19946 | 19984 | } else if (type_entry->id == ZigTypeIdOptional) { |
| 19947 | 19985 | if (instr_is_comptime(value)) { |
| 19948 | | ConstExprValue *maybe_val = ir_resolve_const(ira, value, UndefOk); |
| 19986 | ZigValue *maybe_val = ir_resolve_const(ira, value, UndefOk); |
| 19949 | 19987 | if (maybe_val == nullptr) |
| 19950 | 19988 | return ira->codegen->invalid_instruction; |
| 19951 | 19989 | if (maybe_val->special == ConstValSpecialUndef) |
| ... | ... | @@ -19956,7 +19994,7 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so |
| 19956 | 19994 | |
| 19957 | 19995 | IrInstruction *result = ir_build_test_nonnull(&ira->new_irb, |
| 19958 | 19996 | source_inst->scope, source_inst->source_node, value); |
| 19959 | | result->value.type = ira->codegen->builtin_types.entry_bool; |
| 19997 | result->value->type = ira->codegen->builtin_types.entry_bool; |
| 19960 | 19998 | return result; |
| 19961 | 19999 | } else if (type_entry->id == ZigTypeIdNull) { |
| 19962 | 20000 | return ir_const_bool(ira, source_inst, false); |
| ... | ... | @@ -19967,23 +20005,23 @@ static IrInstruction *ir_analyze_test_non_null(IrAnalyze *ira, IrInstruction *so |
| 19967 | 20005 | |
| 19968 | 20006 | static IrInstruction *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructionTestNonNull *instruction) { |
| 19969 | 20007 | IrInstruction *value = instruction->value->child; |
| 19970 | | if (type_is_invalid(value->value.type)) |
| 20008 | if (type_is_invalid(value->value->type)) |
| 19971 | 20009 | return ira->codegen->invalid_instruction; |
| 19972 | 20010 | |
| 19973 | 20011 | return ir_analyze_test_non_null(ira, &instruction->base, value); |
| 19974 | 20012 | } |
| 19975 | 20013 | |
| 19976 | 20014 | static ZigType *get_ptr_elem_type(CodeGen *g, IrInstruction *ptr) { |
| 19977 | | ir_assert(ptr->value.type->id == ZigTypeIdPointer, ptr); |
| 19978 | | ZigType *elem_type = ptr->value.type->data.pointer.child_type; |
| 20015 | ir_assert(ptr->value->type->id == ZigTypeIdPointer, ptr); |
| 20016 | ZigType *elem_type = ptr->value->type->data.pointer.child_type; |
| 19979 | 20017 | if (elem_type != g->builtin_types.entry_var) |
| 19980 | 20018 | return elem_type; |
| 19981 | 20019 | |
| 19982 | | if (ir_resolve_lazy(g, ptr->source_node, &ptr->value)) |
| 20020 | if (ir_resolve_lazy(g, ptr->source_node, ptr->value)) |
| 19983 | 20021 | return g->builtin_types.entry_invalid; |
| 19984 | 20022 | |
| 19985 | | assert(value_is_comptime(&ptr->value)); |
| 19986 | | ConstExprValue *pointee = const_ptr_pointee_unchecked(g, &ptr->value); |
| 20023 | assert(value_is_comptime(ptr->value)); |
| 20024 | ZigValue *pointee = const_ptr_pointee_unchecked(g, ptr->value); |
| 19987 | 20025 | return pointee->type; |
| 19988 | 20026 | } |
| 19989 | 20027 | |
| ... | ... | @@ -19996,11 +20034,11 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr |
| 19996 | 20034 | |
| 19997 | 20035 | if (type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.ptr_len == PtrLenC) { |
| 19998 | 20036 | if (instr_is_comptime(base_ptr)) { |
| 19999 | | ConstExprValue *val = ir_resolve_const(ira, base_ptr, UndefBad); |
| 20037 | ZigValue *val = ir_resolve_const(ira, base_ptr, UndefBad); |
| 20000 | 20038 | if (!val) |
| 20001 | 20039 | return ira->codegen->invalid_instruction; |
| 20002 | 20040 | if (val->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 20003 | | ConstExprValue *c_ptr_val = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node); |
| 20041 | ZigValue *c_ptr_val = const_ptr_pointee(ira, ira->codegen, val, source_instr->source_node); |
| 20004 | 20042 | if (c_ptr_val == nullptr) |
| 20005 | 20043 | return ira->codegen->invalid_instruction; |
| 20006 | 20044 | bool is_null = c_ptr_val->data.x_ptr.special == ConstPtrSpecialNull || |
| ... | ... | @@ -20028,17 +20066,17 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr |
| 20028 | 20066 | |
| 20029 | 20067 | ZigType *child_type = type_entry->data.maybe.child_type; |
| 20030 | 20068 | ZigType *result_type = get_pointer_to_type_extra(ira->codegen, child_type, |
| 20031 | | base_ptr->value.type->data.pointer.is_const, base_ptr->value.type->data.pointer.is_volatile, |
| 20069 | base_ptr->value->type->data.pointer.is_const, base_ptr->value->type->data.pointer.is_volatile, |
| 20032 | 20070 | PtrLenSingle, 0, 0, 0, false); |
| 20033 | 20071 | |
| 20034 | 20072 | bool same_comptime_repr = types_have_same_zig_comptime_repr(ira->codegen, child_type, type_entry); |
| 20035 | 20073 | |
| 20036 | 20074 | if (instr_is_comptime(base_ptr)) { |
| 20037 | | ConstExprValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad); |
| 20075 | ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad); |
| 20038 | 20076 | if (!ptr_val) |
| 20039 | 20077 | return ira->codegen->invalid_instruction; |
| 20040 | 20078 | if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 20041 | | ConstExprValue *optional_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); |
| 20079 | ZigValue *optional_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); |
| 20042 | 20080 | if (optional_val == nullptr) |
| 20043 | 20081 | return ira->codegen->invalid_instruction; |
| 20044 | 20082 | |
| ... | ... | @@ -20048,7 +20086,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr |
| 20048 | 20086 | return ira->codegen->invalid_instruction; |
| 20049 | 20087 | case OnePossibleValueNo: |
| 20050 | 20088 | if (!same_comptime_repr) { |
| 20051 | | ConstExprValue *payload_val = create_const_vals(1); |
| 20089 | ZigValue *payload_val = create_const_vals(1); |
| 20052 | 20090 | payload_val->type = child_type; |
| 20053 | 20091 | payload_val->special = ConstValSpecialUndef; |
| 20054 | 20092 | payload_val->parent.id = ConstParentIdOptionalPayload; |
| ... | ... | @@ -20059,7 +20097,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr |
| 20059 | 20097 | } |
| 20060 | 20098 | break; |
| 20061 | 20099 | case OnePossibleValueYes: { |
| 20062 | | ConstExprValue *pointee = create_const_vals(1); |
| 20100 | ZigValue *pointee = create_const_vals(1); |
| 20063 | 20101 | pointee->special = ConstValSpecialStatic; |
| 20064 | 20102 | pointee->type = child_type; |
| 20065 | 20103 | pointee->parent.id = ConstParentIdOptionalPayload; |
| ... | ... | @@ -20079,12 +20117,12 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr |
| 20079 | 20117 | if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { |
| 20080 | 20118 | result = ir_build_optional_unwrap_ptr(&ira->new_irb, source_instr->scope, |
| 20081 | 20119 | source_instr->source_node, base_ptr, false, initializing); |
| 20082 | | result->value.type = result_type; |
| 20083 | | result->value.special = ConstValSpecialStatic; |
| 20120 | result->value->type = result_type; |
| 20121 | result->value->special = ConstValSpecialStatic; |
| 20084 | 20122 | } else { |
| 20085 | 20123 | result = ir_const(ira, source_instr, result_type); |
| 20086 | 20124 | } |
| 20087 | | ConstExprValue *result_val = &result->value; |
| 20125 | ZigValue *result_val = result->value; |
| 20088 | 20126 | result_val->data.x_ptr.special = ConstPtrSpecialRef; |
| 20089 | 20127 | result_val->data.x_ptr.mut = ptr_val->data.x_ptr.mut; |
| 20090 | 20128 | switch (type_has_one_possible_value(ira->codegen, child_type)) { |
| ... | ... | @@ -20109,7 +20147,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr |
| 20109 | 20147 | |
| 20110 | 20148 | IrInstruction *result = ir_build_optional_unwrap_ptr(&ira->new_irb, source_instr->scope, |
| 20111 | 20149 | source_instr->source_node, base_ptr, safety_check_on, initializing); |
| 20112 | | result->value.type = result_type; |
| 20150 | result->value->type = result_type; |
| 20113 | 20151 | return result; |
| 20114 | 20152 | } |
| 20115 | 20153 | |
| ... | ... | @@ -20117,7 +20155,7 @@ static IrInstruction *ir_analyze_instruction_optional_unwrap_ptr(IrAnalyze *ira, |
| 20117 | 20155 | IrInstructionOptionalUnwrapPtr *instruction) |
| 20118 | 20156 | { |
| 20119 | 20157 | IrInstruction *base_ptr = instruction->base_ptr->child; |
| 20120 | | if (type_is_invalid(base_ptr->value.type)) |
| 20158 | if (type_is_invalid(base_ptr->value->type)) |
| 20121 | 20159 | return ira->codegen->invalid_instruction; |
| 20122 | 20160 | |
| 20123 | 20161 | return ir_analyze_unwrap_optional_payload(ira, &instruction->base, base_ptr, |
| ... | ... | @@ -20130,26 +20168,26 @@ static IrInstruction *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCt |
| 20130 | 20168 | return ira->codegen->invalid_instruction; |
| 20131 | 20169 | |
| 20132 | 20170 | IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type); |
| 20133 | | if (type_is_invalid(op->value.type)) |
| 20171 | if (type_is_invalid(op->value->type)) |
| 20134 | 20172 | return ira->codegen->invalid_instruction; |
| 20135 | 20173 | |
| 20136 | 20174 | if (int_type->data.integral.bit_count == 0) |
| 20137 | 20175 | return ir_const_unsigned(ira, &instruction->base, 0); |
| 20138 | 20176 | |
| 20139 | 20177 | if (instr_is_comptime(op)) { |
| 20140 | | ConstExprValue *val = ir_resolve_const(ira, op, UndefOk); |
| 20178 | ZigValue *val = ir_resolve_const(ira, op, UndefOk); |
| 20141 | 20179 | if (val == nullptr) |
| 20142 | 20180 | return ira->codegen->invalid_instruction; |
| 20143 | 20181 | if (val->special == ConstValSpecialUndef) |
| 20144 | 20182 | return ir_const_undef(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int); |
| 20145 | | size_t result_usize = bigint_ctz(&op->value.data.x_bigint, int_type->data.integral.bit_count); |
| 20183 | size_t result_usize = bigint_ctz(&op->value->data.x_bigint, int_type->data.integral.bit_count); |
| 20146 | 20184 | return ir_const_unsigned(ira, &instruction->base, result_usize); |
| 20147 | 20185 | } |
| 20148 | 20186 | |
| 20149 | 20187 | ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count); |
| 20150 | 20188 | IrInstruction *result = ir_build_ctz(&ira->new_irb, instruction->base.scope, |
| 20151 | 20189 | instruction->base.source_node, nullptr, op); |
| 20152 | | result->value.type = return_type; |
| 20190 | result->value->type = return_type; |
| 20153 | 20191 | return result; |
| 20154 | 20192 | } |
| 20155 | 20193 | |
| ... | ... | @@ -20159,26 +20197,26 @@ static IrInstruction *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionCl |
| 20159 | 20197 | return ira->codegen->invalid_instruction; |
| 20160 | 20198 | |
| 20161 | 20199 | IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type); |
| 20162 | | if (type_is_invalid(op->value.type)) |
| 20200 | if (type_is_invalid(op->value->type)) |
| 20163 | 20201 | return ira->codegen->invalid_instruction; |
| 20164 | 20202 | |
| 20165 | 20203 | if (int_type->data.integral.bit_count == 0) |
| 20166 | 20204 | return ir_const_unsigned(ira, &instruction->base, 0); |
| 20167 | 20205 | |
| 20168 | 20206 | if (instr_is_comptime(op)) { |
| 20169 | | ConstExprValue *val = ir_resolve_const(ira, op, UndefOk); |
| 20207 | ZigValue *val = ir_resolve_const(ira, op, UndefOk); |
| 20170 | 20208 | if (val == nullptr) |
| 20171 | 20209 | return ira->codegen->invalid_instruction; |
| 20172 | 20210 | if (val->special == ConstValSpecialUndef) |
| 20173 | 20211 | return ir_const_undef(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int); |
| 20174 | | size_t result_usize = bigint_clz(&op->value.data.x_bigint, int_type->data.integral.bit_count); |
| 20212 | size_t result_usize = bigint_clz(&op->value->data.x_bigint, int_type->data.integral.bit_count); |
| 20175 | 20213 | return ir_const_unsigned(ira, &instruction->base, result_usize); |
| 20176 | 20214 | } |
| 20177 | 20215 | |
| 20178 | 20216 | ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count); |
| 20179 | 20217 | IrInstruction *result = ir_build_clz(&ira->new_irb, instruction->base.scope, |
| 20180 | 20218 | instruction->base.source_node, nullptr, op); |
| 20181 | | result->value.type = return_type; |
| 20219 | result->value->type = return_type; |
| 20182 | 20220 | return result; |
| 20183 | 20221 | } |
| 20184 | 20222 | |
| ... | ... | @@ -20188,14 +20226,14 @@ static IrInstruction *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstruc |
| 20188 | 20226 | return ira->codegen->invalid_instruction; |
| 20189 | 20227 | |
| 20190 | 20228 | IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type); |
| 20191 | | if (type_is_invalid(op->value.type)) |
| 20229 | if (type_is_invalid(op->value->type)) |
| 20192 | 20230 | return ira->codegen->invalid_instruction; |
| 20193 | 20231 | |
| 20194 | 20232 | if (int_type->data.integral.bit_count == 0) |
| 20195 | 20233 | return ir_const_unsigned(ira, &instruction->base, 0); |
| 20196 | 20234 | |
| 20197 | 20235 | if (instr_is_comptime(op)) { |
| 20198 | | ConstExprValue *val = ir_resolve_const(ira, op, UndefOk); |
| 20236 | ZigValue *val = ir_resolve_const(ira, op, UndefOk); |
| 20199 | 20237 | if (val == nullptr) |
| 20200 | 20238 | return ira->codegen->invalid_instruction; |
| 20201 | 20239 | if (val->special == ConstValSpecialUndef) |
| ... | ... | @@ -20212,50 +20250,50 @@ static IrInstruction *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstruc |
| 20212 | 20250 | ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, int_type->data.integral.bit_count); |
| 20213 | 20251 | IrInstruction *result = ir_build_pop_count(&ira->new_irb, instruction->base.scope, |
| 20214 | 20252 | instruction->base.source_node, nullptr, op); |
| 20215 | | result->value.type = return_type; |
| 20253 | result->value->type = return_type; |
| 20216 | 20254 | return result; |
| 20217 | 20255 | } |
| 20218 | 20256 | |
| 20219 | 20257 | static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value) { |
| 20220 | | if (type_is_invalid(value->value.type)) |
| 20258 | if (type_is_invalid(value->value->type)) |
| 20221 | 20259 | return ira->codegen->invalid_instruction; |
| 20222 | 20260 | |
| 20223 | | if (value->value.type->id == ZigTypeIdEnum) { |
| 20261 | if (value->value->type->id == ZigTypeIdEnum) { |
| 20224 | 20262 | return value; |
| 20225 | 20263 | } |
| 20226 | 20264 | |
| 20227 | | if (value->value.type->id != ZigTypeIdUnion) { |
| 20265 | if (value->value->type->id != ZigTypeIdUnion) { |
| 20228 | 20266 | ir_add_error(ira, value, |
| 20229 | | buf_sprintf("expected enum or union type, found '%s'", buf_ptr(&value->value.type->name))); |
| 20267 | buf_sprintf("expected enum or union type, found '%s'", buf_ptr(&value->value->type->name))); |
| 20230 | 20268 | return ira->codegen->invalid_instruction; |
| 20231 | 20269 | } |
| 20232 | | if (!value->value.type->data.unionation.have_explicit_tag_type && !source_instr->is_gen) { |
| 20270 | if (!value->value->type->data.unionation.have_explicit_tag_type && !source_instr->is_gen) { |
| 20233 | 20271 | ErrorMsg *msg = ir_add_error(ira, source_instr, buf_sprintf("union has no associated enum")); |
| 20234 | | if (value->value.type->data.unionation.decl_node != nullptr) { |
| 20235 | | add_error_note(ira->codegen, msg, value->value.type->data.unionation.decl_node, |
| 20272 | if (value->value->type->data.unionation.decl_node != nullptr) { |
| 20273 | add_error_note(ira->codegen, msg, value->value->type->data.unionation.decl_node, |
| 20236 | 20274 | buf_sprintf("declared here")); |
| 20237 | 20275 | } |
| 20238 | 20276 | return ira->codegen->invalid_instruction; |
| 20239 | 20277 | } |
| 20240 | 20278 | |
| 20241 | | ZigType *tag_type = value->value.type->data.unionation.tag_type; |
| 20279 | ZigType *tag_type = value->value->type->data.unionation.tag_type; |
| 20242 | 20280 | assert(tag_type->id == ZigTypeIdEnum); |
| 20243 | 20281 | |
| 20244 | 20282 | if (instr_is_comptime(value)) { |
| 20245 | | ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); |
| 20283 | ZigValue *val = ir_resolve_const(ira, value, UndefBad); |
| 20246 | 20284 | if (!val) |
| 20247 | 20285 | return ira->codegen->invalid_instruction; |
| 20248 | 20286 | |
| 20249 | 20287 | IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb, |
| 20250 | 20288 | source_instr->scope, source_instr->source_node); |
| 20251 | | const_instruction->base.value.type = tag_type; |
| 20252 | | const_instruction->base.value.special = ConstValSpecialStatic; |
| 20253 | | bigint_init_bigint(&const_instruction->base.value.data.x_enum_tag, &val->data.x_union.tag); |
| 20289 | const_instruction->base.value->type = tag_type; |
| 20290 | const_instruction->base.value->special = ConstValSpecialStatic; |
| 20291 | bigint_init_bigint(&const_instruction->base.value->data.x_enum_tag, &val->data.x_union.tag); |
| 20254 | 20292 | return &const_instruction->base; |
| 20255 | 20293 | } |
| 20256 | 20294 | |
| 20257 | 20295 | IrInstruction *result = ir_build_union_tag(&ira->new_irb, source_instr->scope, source_instr->source_node, value); |
| 20258 | | result->value.type = tag_type; |
| 20296 | result->value->type = tag_type; |
| 20259 | 20297 | return result; |
| 20260 | 20298 | } |
| 20261 | 20299 | |
| ... | ... | @@ -20263,11 +20301,11 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 20263 | 20301 | IrInstructionSwitchBr *switch_br_instruction) |
| 20264 | 20302 | { |
| 20265 | 20303 | IrInstruction *target_value = switch_br_instruction->target_value->child; |
| 20266 | | if (type_is_invalid(target_value->value.type)) |
| 20304 | if (type_is_invalid(target_value->value->type)) |
| 20267 | 20305 | return ir_unreach_error(ira); |
| 20268 | 20306 | |
| 20269 | 20307 | if (switch_br_instruction->switch_prongs_void != nullptr) { |
| 20270 | | if (type_is_invalid(switch_br_instruction->switch_prongs_void->child->value.type)) { |
| 20308 | if (type_is_invalid(switch_br_instruction->switch_prongs_void->child->value->type)) { |
| 20271 | 20309 | return ir_unreach_error(ira); |
| 20272 | 20310 | } |
| 20273 | 20311 | } |
| ... | ... | @@ -20280,7 +20318,7 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 20280 | 20318 | return ira->codegen->invalid_instruction; |
| 20281 | 20319 | |
| 20282 | 20320 | if (is_comptime || instr_is_comptime(target_value)) { |
| 20283 | | ConstExprValue *target_val = ir_resolve_const(ira, target_value, UndefBad); |
| 20321 | ZigValue *target_val = ir_resolve_const(ira, target_value, UndefBad); |
| 20284 | 20322 | if (!target_val) |
| 20285 | 20323 | return ir_unreach_error(ira); |
| 20286 | 20324 | |
| ... | ... | @@ -20288,20 +20326,20 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 20288 | 20326 | for (size_t i = 0; i < case_count; i += 1) { |
| 20289 | 20327 | IrInstructionSwitchBrCase *old_case = &switch_br_instruction->cases[i]; |
| 20290 | 20328 | IrInstruction *case_value = old_case->value->child; |
| 20291 | | if (type_is_invalid(case_value->value.type)) |
| 20329 | if (type_is_invalid(case_value->value->type)) |
| 20292 | 20330 | return ir_unreach_error(ira); |
| 20293 | 20331 | |
| 20294 | | if (case_value->value.type->id == ZigTypeIdEnum) { |
| 20332 | if (case_value->value->type->id == ZigTypeIdEnum) { |
| 20295 | 20333 | case_value = ir_analyze_union_tag(ira, &switch_br_instruction->base, case_value); |
| 20296 | | if (type_is_invalid(case_value->value.type)) |
| 20334 | if (type_is_invalid(case_value->value->type)) |
| 20297 | 20335 | return ir_unreach_error(ira); |
| 20298 | 20336 | } |
| 20299 | 20337 | |
| 20300 | | IrInstruction *casted_case_value = ir_implicit_cast(ira, case_value, target_value->value.type); |
| 20301 | | if (type_is_invalid(casted_case_value->value.type)) |
| 20338 | IrInstruction *casted_case_value = ir_implicit_cast(ira, case_value, target_value->value->type); |
| 20339 | if (type_is_invalid(casted_case_value->value->type)) |
| 20302 | 20340 | return ir_unreach_error(ira); |
| 20303 | 20341 | |
| 20304 | | ConstExprValue *case_val = ir_resolve_const(ira, casted_case_value, UndefBad); |
| 20342 | ZigValue *case_val = ir_resolve_const(ira, casted_case_value, UndefBad); |
| 20305 | 20343 | if (!case_val) |
| 20306 | 20344 | return ir_unreach_error(ira); |
| 20307 | 20345 | |
| ... | ... | @@ -20318,7 +20356,7 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 20318 | 20356 | IrInstruction *result = ir_build_br(&ira->new_irb, |
| 20319 | 20357 | switch_br_instruction->base.scope, switch_br_instruction->base.source_node, |
| 20320 | 20358 | new_dest_block, nullptr); |
| 20321 | | result->value.type = ira->codegen->builtin_types.entry_unreachable; |
| 20359 | result->value->type = ira->codegen->builtin_types.entry_unreachable; |
| 20322 | 20360 | return ir_finish_anal(ira, result); |
| 20323 | 20361 | } |
| 20324 | 20362 | } |
| ... | ... | @@ -20338,17 +20376,17 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 20338 | 20376 | |
| 20339 | 20377 | IrInstruction *old_value = old_case->value; |
| 20340 | 20378 | IrInstruction *new_value = old_value->child; |
| 20341 | | if (type_is_invalid(new_value->value.type)) |
| 20379 | if (type_is_invalid(new_value->value->type)) |
| 20342 | 20380 | continue; |
| 20343 | 20381 | |
| 20344 | | if (new_value->value.type->id == ZigTypeIdEnum) { |
| 20382 | if (new_value->value->type->id == ZigTypeIdEnum) { |
| 20345 | 20383 | new_value = ir_analyze_union_tag(ira, &switch_br_instruction->base, new_value); |
| 20346 | | if (type_is_invalid(new_value->value.type)) |
| 20384 | if (type_is_invalid(new_value->value->type)) |
| 20347 | 20385 | continue; |
| 20348 | 20386 | } |
| 20349 | 20387 | |
| 20350 | | IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, target_value->value.type); |
| 20351 | | if (type_is_invalid(casted_new_value->value.type)) |
| 20388 | IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, target_value->value->type); |
| 20389 | if (type_is_invalid(casted_new_value->value->type)) |
| 20352 | 20390 | continue; |
| 20353 | 20391 | |
| 20354 | 20392 | if (!ir_resolve_const(ira, casted_new_value, UndefBad)) |
| ... | ... | @@ -20368,7 +20406,7 @@ static IrInstruction *ir_analyze_instruction_switch_br(IrAnalyze *ira, |
| 20368 | 20406 | IrInstructionSwitchBr *switch_br = ir_build_switch_br(&ira->new_irb, |
| 20369 | 20407 | switch_br_instruction->base.scope, switch_br_instruction->base.source_node, |
| 20370 | 20408 | target_value, new_else_block, case_count, cases, nullptr, nullptr); |
| 20371 | | switch_br->base.value.type = ira->codegen->builtin_types.entry_unreachable; |
| 20409 | switch_br->base.value->type = ira->codegen->builtin_types.entry_unreachable; |
| 20372 | 20410 | return ir_finish_anal(ira, &switch_br->base); |
| 20373 | 20411 | } |
| 20374 | 20412 | |
| ... | ... | @@ -20377,20 +20415,20 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 20377 | 20415 | { |
| 20378 | 20416 | Error err; |
| 20379 | 20417 | IrInstruction *target_value_ptr = switch_target_instruction->target_value_ptr->child; |
| 20380 | | if (type_is_invalid(target_value_ptr->value.type)) |
| 20418 | if (type_is_invalid(target_value_ptr->value->type)) |
| 20381 | 20419 | return ira->codegen->invalid_instruction; |
| 20382 | 20420 | |
| 20383 | | if (target_value_ptr->value.type->id == ZigTypeIdMetaType) { |
| 20421 | if (target_value_ptr->value->type->id == ZigTypeIdMetaType) { |
| 20384 | 20422 | assert(instr_is_comptime(target_value_ptr)); |
| 20385 | | ZigType *ptr_type = target_value_ptr->value.data.x_type; |
| 20423 | ZigType *ptr_type = target_value_ptr->value->data.x_type; |
| 20386 | 20424 | assert(ptr_type->id == ZigTypeIdPointer); |
| 20387 | 20425 | return ir_const_type(ira, &switch_target_instruction->base, ptr_type->data.pointer.child_type); |
| 20388 | 20426 | } |
| 20389 | 20427 | |
| 20390 | | ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type; |
| 20391 | | ConstExprValue *pointee_val = nullptr; |
| 20392 | | if (instr_is_comptime(target_value_ptr) && target_value_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 20393 | | pointee_val = const_ptr_pointee(ira, ira->codegen, &target_value_ptr->value, target_value_ptr->source_node); |
| 20428 | ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type; |
| 20429 | ZigValue *pointee_val = nullptr; |
| 20430 | if (instr_is_comptime(target_value_ptr) && target_value_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 20431 | pointee_val = const_ptr_pointee(ira, ira->codegen, target_value_ptr->value, target_value_ptr->source_node); |
| 20394 | 20432 | if (pointee_val == nullptr) |
| 20395 | 20433 | return ira->codegen->invalid_instruction; |
| 20396 | 20434 | |
| ... | ... | @@ -20416,13 +20454,13 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 20416 | 20454 | case ZigTypeIdErrorSet: { |
| 20417 | 20455 | if (pointee_val) { |
| 20418 | 20456 | IrInstruction *result = ir_const(ira, &switch_target_instruction->base, nullptr); |
| 20419 | | copy_const_val(&result->value, pointee_val, true); |
| 20420 | | result->value.type = target_type; |
| 20457 | copy_const_val(result->value, pointee_val, true); |
| 20458 | result->value->type = target_type; |
| 20421 | 20459 | return result; |
| 20422 | 20460 | } |
| 20423 | 20461 | |
| 20424 | 20462 | IrInstruction *result = ir_get_deref(ira, &switch_target_instruction->base, target_value_ptr, nullptr); |
| 20425 | | result->value.type = target_type; |
| 20463 | result->value->type = target_type; |
| 20426 | 20464 | return result; |
| 20427 | 20465 | } |
| 20428 | 20466 | case ZigTypeIdUnion: { |
| ... | ... | @@ -20441,22 +20479,22 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 20441 | 20479 | assert(tag_type->id == ZigTypeIdEnum); |
| 20442 | 20480 | if (pointee_val) { |
| 20443 | 20481 | IrInstruction *result = ir_const(ira, &switch_target_instruction->base, tag_type); |
| 20444 | | bigint_init_bigint(&result->value.data.x_enum_tag, &pointee_val->data.x_union.tag); |
| 20482 | bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_union.tag); |
| 20445 | 20483 | return result; |
| 20446 | 20484 | } |
| 20447 | 20485 | if (tag_type->data.enumeration.src_field_count == 1) { |
| 20448 | 20486 | IrInstruction *result = ir_const(ira, &switch_target_instruction->base, tag_type); |
| 20449 | 20487 | TypeEnumField *only_field = &tag_type->data.enumeration.fields[0]; |
| 20450 | | bigint_init_bigint(&result->value.data.x_enum_tag, &only_field->value); |
| 20488 | bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value); |
| 20451 | 20489 | return result; |
| 20452 | 20490 | } |
| 20453 | 20491 | |
| 20454 | 20492 | IrInstruction *union_value = ir_get_deref(ira, &switch_target_instruction->base, target_value_ptr, nullptr); |
| 20455 | | union_value->value.type = target_type; |
| 20493 | union_value->value->type = target_type; |
| 20456 | 20494 | |
| 20457 | 20495 | IrInstruction *union_tag_inst = ir_build_union_tag(&ira->new_irb, switch_target_instruction->base.scope, |
| 20458 | 20496 | switch_target_instruction->base.source_node, union_value); |
| 20459 | | union_tag_inst->value.type = tag_type; |
| 20497 | union_tag_inst->value->type = tag_type; |
| 20460 | 20498 | return union_tag_inst; |
| 20461 | 20499 | } |
| 20462 | 20500 | case ZigTypeIdEnum: { |
| ... | ... | @@ -20465,18 +20503,18 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 20465 | 20503 | if (target_type->data.enumeration.src_field_count < 2) { |
| 20466 | 20504 | TypeEnumField *only_field = &target_type->data.enumeration.fields[0]; |
| 20467 | 20505 | IrInstruction *result = ir_const(ira, &switch_target_instruction->base, target_type); |
| 20468 | | bigint_init_bigint(&result->value.data.x_enum_tag, &only_field->value); |
| 20506 | bigint_init_bigint(&result->value->data.x_enum_tag, &only_field->value); |
| 20469 | 20507 | return result; |
| 20470 | 20508 | } |
| 20471 | 20509 | |
| 20472 | 20510 | if (pointee_val) { |
| 20473 | 20511 | IrInstruction *result = ir_const(ira, &switch_target_instruction->base, target_type); |
| 20474 | | bigint_init_bigint(&result->value.data.x_enum_tag, &pointee_val->data.x_enum_tag); |
| 20512 | bigint_init_bigint(&result->value->data.x_enum_tag, &pointee_val->data.x_enum_tag); |
| 20475 | 20513 | return result; |
| 20476 | 20514 | } |
| 20477 | 20515 | |
| 20478 | 20516 | IrInstruction *enum_value = ir_get_deref(ira, &switch_target_instruction->base, target_value_ptr, nullptr); |
| 20479 | | enum_value->value.type = target_type; |
| 20517 | enum_value->value->type = target_type; |
| 20480 | 20518 | return enum_value; |
| 20481 | 20519 | } |
| 20482 | 20520 | case ZigTypeIdErrorUnion: |
| ... | ... | @@ -20501,12 +20539,12 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira, |
| 20501 | 20539 | |
| 20502 | 20540 | static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstructionSwitchVar *instruction) { |
| 20503 | 20541 | IrInstruction *target_value_ptr = instruction->target_value_ptr->child; |
| 20504 | | if (type_is_invalid(target_value_ptr->value.type)) |
| 20542 | if (type_is_invalid(target_value_ptr->value->type)) |
| 20505 | 20543 | return ira->codegen->invalid_instruction; |
| 20506 | 20544 | |
| 20507 | | ZigType *ref_type = target_value_ptr->value.type; |
| 20545 | ZigType *ref_type = target_value_ptr->value->type; |
| 20508 | 20546 | assert(ref_type->id == ZigTypeIdPointer); |
| 20509 | | ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type; |
| 20547 | ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type; |
| 20510 | 20548 | if (target_type->id == ZigTypeIdUnion) { |
| 20511 | 20549 | ZigType *enum_type = target_type->data.unionation.tag_type; |
| 20512 | 20550 | assert(enum_type != nullptr); |
| ... | ... | @@ -20514,14 +20552,14 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru |
| 20514 | 20552 | assert(instruction->prongs_len > 0); |
| 20515 | 20553 | |
| 20516 | 20554 | IrInstruction *first_prong_value = instruction->prongs_ptr[0]->child; |
| 20517 | | if (type_is_invalid(first_prong_value->value.type)) |
| 20555 | if (type_is_invalid(first_prong_value->value->type)) |
| 20518 | 20556 | return ira->codegen->invalid_instruction; |
| 20519 | 20557 | |
| 20520 | 20558 | IrInstruction *first_casted_prong_value = ir_implicit_cast(ira, first_prong_value, enum_type); |
| 20521 | | if (type_is_invalid(first_casted_prong_value->value.type)) |
| 20559 | if (type_is_invalid(first_casted_prong_value->value->type)) |
| 20522 | 20560 | return ira->codegen->invalid_instruction; |
| 20523 | 20561 | |
| 20524 | | ConstExprValue *first_prong_val = ir_resolve_const(ira, first_casted_prong_value, UndefBad); |
| 20562 | ZigValue *first_prong_val = ir_resolve_const(ira, first_casted_prong_value, UndefBad); |
| 20525 | 20563 | if (first_prong_val == nullptr) |
| 20526 | 20564 | return ira->codegen->invalid_instruction; |
| 20527 | 20565 | |
| ... | ... | @@ -20530,14 +20568,14 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru |
| 20530 | 20568 | ErrorMsg *invalid_payload_msg = nullptr; |
| 20531 | 20569 | for (size_t prong_i = 1; prong_i < instruction->prongs_len; prong_i += 1) { |
| 20532 | 20570 | IrInstruction *this_prong_inst = instruction->prongs_ptr[prong_i]->child; |
| 20533 | | if (type_is_invalid(this_prong_inst->value.type)) |
| 20571 | if (type_is_invalid(this_prong_inst->value->type)) |
| 20534 | 20572 | return ira->codegen->invalid_instruction; |
| 20535 | 20573 | |
| 20536 | 20574 | IrInstruction *this_casted_prong_value = ir_implicit_cast(ira, this_prong_inst, enum_type); |
| 20537 | | if (type_is_invalid(this_casted_prong_value->value.type)) |
| 20575 | if (type_is_invalid(this_casted_prong_value->value->type)) |
| 20538 | 20576 | return ira->codegen->invalid_instruction; |
| 20539 | 20577 | |
| 20540 | | ConstExprValue *this_prong = ir_resolve_const(ira, this_casted_prong_value, UndefBad); |
| 20578 | ZigValue *this_prong = ir_resolve_const(ira, this_casted_prong_value, UndefBad); |
| 20541 | 20579 | if (this_prong == nullptr) |
| 20542 | 20580 | return ira->codegen->invalid_instruction; |
| 20543 | 20581 | |
| ... | ... | @@ -20560,18 +20598,18 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru |
| 20560 | 20598 | } |
| 20561 | 20599 | |
| 20562 | 20600 | if (instr_is_comptime(target_value_ptr)) { |
| 20563 | | ConstExprValue *target_val_ptr = ir_resolve_const(ira, target_value_ptr, UndefBad); |
| 20601 | ZigValue *target_val_ptr = ir_resolve_const(ira, target_value_ptr, UndefBad); |
| 20564 | 20602 | if (!target_value_ptr) |
| 20565 | 20603 | return ira->codegen->invalid_instruction; |
| 20566 | 20604 | |
| 20567 | | ConstExprValue *pointee_val = const_ptr_pointee(ira, ira->codegen, target_val_ptr, instruction->base.source_node); |
| 20605 | ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, target_val_ptr, instruction->base.source_node); |
| 20568 | 20606 | if (pointee_val == nullptr) |
| 20569 | 20607 | return ira->codegen->invalid_instruction; |
| 20570 | 20608 | |
| 20571 | 20609 | IrInstruction *result = ir_const(ira, &instruction->base, |
| 20572 | 20610 | get_pointer_to_type(ira->codegen, first_field->type_entry, |
| 20573 | 20611 | target_val_ptr->type->data.pointer.is_const)); |
| 20574 | | ConstExprValue *out_val = &result->value; |
| 20612 | ZigValue *out_val = result->value; |
| 20575 | 20613 | out_val->data.x_ptr.special = ConstPtrSpecialRef; |
| 20576 | 20614 | out_val->data.x_ptr.mut = target_val_ptr->data.x_ptr.mut; |
| 20577 | 20615 | out_val->data.x_ptr.data.ref.pointee = pointee_val->data.x_union.payload; |
| ... | ... | @@ -20580,8 +20618,8 @@ static IrInstruction *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstru |
| 20580 | 20618 | |
| 20581 | 20619 | IrInstruction *result = ir_build_union_field_ptr(&ira->new_irb, |
| 20582 | 20620 | instruction->base.scope, instruction->base.source_node, target_value_ptr, first_field, false, false); |
| 20583 | | result->value.type = get_pointer_to_type(ira->codegen, first_field->type_entry, |
| 20584 | | target_value_ptr->value.type->data.pointer.is_const); |
| 20621 | result->value->type = get_pointer_to_type(ira->codegen, first_field->type_entry, |
| 20622 | target_value_ptr->value->type->data.pointer.is_const); |
| 20585 | 20623 | return result; |
| 20586 | 20624 | } else if (target_type->id == ZigTypeIdErrorSet) { |
| 20587 | 20625 | // construct an error set from the prong values |
| ... | ... | @@ -20624,12 +20662,12 @@ static IrInstruction *ir_analyze_instruction_switch_else_var(IrAnalyze *ira, |
| 20624 | 20662 | IrInstructionSwitchElseVar *instruction) |
| 20625 | 20663 | { |
| 20626 | 20664 | IrInstruction *target_value_ptr = instruction->target_value_ptr->child; |
| 20627 | | if (type_is_invalid(target_value_ptr->value.type)) |
| 20665 | if (type_is_invalid(target_value_ptr->value->type)) |
| 20628 | 20666 | return ira->codegen->invalid_instruction; |
| 20629 | 20667 | |
| 20630 | | ZigType *ref_type = target_value_ptr->value.type; |
| 20668 | ZigType *ref_type = target_value_ptr->value->type; |
| 20631 | 20669 | assert(ref_type->id == ZigTypeIdPointer); |
| 20632 | | ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type; |
| 20670 | ZigType *target_type = target_value_ptr->value->type->data.pointer.child_type; |
| 20633 | 20671 | if (target_type->id == ZigTypeIdErrorSet) { |
| 20634 | 20672 | // make a new set that has the other cases removed |
| 20635 | 20673 | if (!resolve_inferred_error_set(ira->codegen, target_type, instruction->base.source_node)) { |
| ... | ... | @@ -20645,12 +20683,12 @@ static IrInstruction *ir_analyze_instruction_switch_else_var(IrAnalyze *ira, |
| 20645 | 20683 | for (size_t case_i = 0; case_i < instruction->switch_br->case_count; case_i += 1) { |
| 20646 | 20684 | IrInstructionSwitchBrCase *br_case = &instruction->switch_br->cases[case_i]; |
| 20647 | 20685 | IrInstruction *case_expr = br_case->value->child; |
| 20648 | | if (case_expr->value.type->id == ZigTypeIdErrorSet) { |
| 20686 | if (case_expr->value->type->id == ZigTypeIdErrorSet) { |
| 20649 | 20687 | ErrorTableEntry *err = ir_resolve_error(ira, case_expr); |
| 20650 | 20688 | if (err == nullptr) |
| 20651 | 20689 | return ira->codegen->invalid_instruction; |
| 20652 | 20690 | errors[err->value] = err; |
| 20653 | | } else if (case_expr->value.type->id == ZigTypeIdMetaType) { |
| 20691 | } else if (case_expr->value->type->id == ZigTypeIdMetaType) { |
| 20654 | 20692 | ZigType *err_set_type = ir_resolve_type(ira, case_expr); |
| 20655 | 20693 | if (type_is_invalid(err_set_type)) |
| 20656 | 20694 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -20742,7 +20780,7 @@ static IrInstruction *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructio |
| 20742 | 20780 | |
| 20743 | 20781 | static IrInstruction *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstructionRef *ref_instruction) { |
| 20744 | 20782 | IrInstruction *value = ref_instruction->value->child; |
| 20745 | | if (type_is_invalid(value->value.type)) |
| 20783 | if (type_is_invalid(value->value->type)) |
| 20746 | 20784 | return ira->codegen->invalid_instruction; |
| 20747 | 20785 | return ir_get_ref(ira, &ref_instruction->base, value, ref_instruction->is_const, ref_instruction->is_volatile); |
| 20748 | 20786 | } |
| ... | ... | @@ -20768,13 +20806,13 @@ static IrInstruction *ir_analyze_union_init(IrAnalyze *ira, IrInstruction *sourc |
| 20768 | 20806 | if (type_is_invalid(type_field->type_entry)) |
| 20769 | 20807 | return ira->codegen->invalid_instruction; |
| 20770 | 20808 | |
| 20771 | | if (result_loc->value.data.x_ptr.mut == ConstPtrMutInfer) { |
| 20809 | if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) { |
| 20772 | 20810 | if (instr_is_comptime(field_result_loc) && |
| 20773 | | field_result_loc->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) |
| 20811 | field_result_loc->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) |
| 20774 | 20812 | { |
| 20775 | 20813 | // nothing |
| 20776 | 20814 | } else { |
| 20777 | | result_loc->value.special = ConstValSpecialRuntime; |
| 20815 | result_loc->value->special = ConstValSpecialRuntime; |
| 20778 | 20816 | } |
| 20779 | 20817 | } |
| 20780 | 20818 | |
| ... | ... | @@ -20803,7 +20841,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc |
| 20803 | 20841 | } |
| 20804 | 20842 | IrInstructionContainerInitFieldsField *field = &fields[0]; |
| 20805 | 20843 | IrInstruction *field_result_loc = field->result_loc->child; |
| 20806 | | if (type_is_invalid(field_result_loc->value.type)) |
| 20844 | if (type_is_invalid(field_result_loc->value->type)) |
| 20807 | 20845 | return ira->codegen->invalid_instruction; |
| 20808 | 20846 | |
| 20809 | 20847 | return ir_analyze_union_init(ira, instruction, field->source_node, container_type, field->name, |
| ... | ... | @@ -20850,7 +20888,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc |
| 20850 | 20888 | IrInstructionContainerInitFieldsField *field = &fields[i]; |
| 20851 | 20889 | |
| 20852 | 20890 | IrInstruction *field_result_loc = field->result_loc->child; |
| 20853 | | if (type_is_invalid(field_result_loc->value.type)) |
| 20891 | if (type_is_invalid(field_result_loc->value->type)) |
| 20854 | 20892 | return ira->codegen->invalid_instruction; |
| 20855 | 20893 | |
| 20856 | 20894 | TypeStructField *type_field = find_struct_type_field(container_type, field->name); |
| ... | ... | @@ -20874,7 +20912,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc |
| 20874 | 20912 | field_assign_nodes[field_index] = field->source_node; |
| 20875 | 20913 | |
| 20876 | 20914 | if (instr_is_comptime(field_result_loc) && |
| 20877 | | field_result_loc->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) |
| 20915 | field_result_loc->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) |
| 20878 | 20916 | { |
| 20879 | 20917 | const_ptrs.append(field_result_loc); |
| 20880 | 20918 | } else { |
| ... | ... | @@ -20912,12 +20950,12 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc |
| 20912 | 20950 | return ira->codegen->invalid_instruction; |
| 20913 | 20951 | |
| 20914 | 20952 | IrInstruction *runtime_inst = ir_const(ira, instruction, field->init_val->type); |
| 20915 | | copy_const_val(&runtime_inst->value, field->init_val, true); |
| 20953 | copy_const_val(runtime_inst->value, field->init_val, true); |
| 20916 | 20954 | |
| 20917 | 20955 | IrInstruction *field_ptr = ir_analyze_struct_field_ptr(ira, instruction, field, result_loc, |
| 20918 | 20956 | container_type, true); |
| 20919 | 20957 | ir_analyze_store_ptr(ira, instruction, field_ptr, runtime_inst, false); |
| 20920 | | if (instr_is_comptime(field_ptr) && field_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 20958 | if (instr_is_comptime(field_ptr) && field_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 20921 | 20959 | const_ptrs.append(field_ptr); |
| 20922 | 20960 | } else { |
| 20923 | 20961 | first_non_const_instruction = result_loc; |
| ... | ... | @@ -20926,13 +20964,13 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc |
| 20926 | 20964 | if (any_missing) |
| 20927 | 20965 | return ira->codegen->invalid_instruction; |
| 20928 | 20966 | |
| 20929 | | if (result_loc->value.data.x_ptr.mut == ConstPtrMutInfer) { |
| 20967 | if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) { |
| 20930 | 20968 | if (const_ptrs.length != actual_field_count) { |
| 20931 | | result_loc->value.special = ConstValSpecialRuntime; |
| 20969 | result_loc->value->special = ConstValSpecialRuntime; |
| 20932 | 20970 | for (size_t i = 0; i < const_ptrs.length; i += 1) { |
| 20933 | 20971 | IrInstruction *field_result_loc = const_ptrs.at(i); |
| 20934 | 20972 | IrInstruction *deref = ir_get_deref(ira, field_result_loc, field_result_loc, nullptr); |
| 20935 | | field_result_loc->value.special = ConstValSpecialRuntime; |
| 20973 | field_result_loc->value->special = ConstValSpecialRuntime; |
| 20936 | 20974 | ir_analyze_store_ptr(ira, field_result_loc, field_result_loc, deref, false); |
| 20937 | 20975 | } |
| 20938 | 20976 | } |
| ... | ... | @@ -20954,11 +20992,11 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 20954 | 20992 | { |
| 20955 | 20993 | ir_assert(instruction->result_loc != nullptr, &instruction->base); |
| 20956 | 20994 | IrInstruction *result_loc = instruction->result_loc->child; |
| 20957 | | if (type_is_invalid(result_loc->value.type)) |
| 20995 | if (type_is_invalid(result_loc->value->type)) |
| 20958 | 20996 | return result_loc; |
| 20959 | | ir_assert(result_loc->value.type->id == ZigTypeIdPointer, &instruction->base); |
| 20997 | ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base); |
| 20960 | 20998 | |
| 20961 | | ZigType *container_type = result_loc->value.type->data.pointer.child_type; |
| 20999 | ZigType *container_type = result_loc->value->type->data.pointer.child_type; |
| 20962 | 21000 | |
| 20963 | 21001 | size_t elem_count = instruction->item_count; |
| 20964 | 21002 | |
| ... | ... | @@ -20980,7 +21018,7 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 20980 | 21018 | if (container_type->id == ZigTypeIdStruct && elem_count == 0) { |
| 20981 | 21019 | ir_assert(instruction->result_loc != nullptr, &instruction->base); |
| 20982 | 21020 | IrInstruction *result_loc = instruction->result_loc->child; |
| 20983 | | if (type_is_invalid(result_loc->value.type)) |
| 21021 | if (type_is_invalid(result_loc->value->type)) |
| 20984 | 21022 | return result_loc; |
| 20985 | 21023 | return ir_analyze_container_init_fields(ira, &instruction->base, container_type, 0, nullptr, result_loc); |
| 20986 | 21024 | } |
| ... | ... | @@ -21041,13 +21079,13 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 21041 | 21079 | |
| 21042 | 21080 | for (size_t i = 0; i < elem_count; i += 1) { |
| 21043 | 21081 | IrInstruction *elem_result_loc = instruction->elem_result_loc_list[i]->child; |
| 21044 | | if (type_is_invalid(elem_result_loc->value.type)) |
| 21082 | if (type_is_invalid(elem_result_loc->value->type)) |
| 21045 | 21083 | return ira->codegen->invalid_instruction; |
| 21046 | 21084 | |
| 21047 | | assert(elem_result_loc->value.type->id == ZigTypeIdPointer); |
| 21085 | assert(elem_result_loc->value->type->id == ZigTypeIdPointer); |
| 21048 | 21086 | |
| 21049 | 21087 | if (instr_is_comptime(elem_result_loc) && |
| 21050 | | elem_result_loc->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) |
| 21088 | elem_result_loc->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) |
| 21051 | 21089 | { |
| 21052 | 21090 | const_ptrs.append(elem_result_loc); |
| 21053 | 21091 | } else { |
| ... | ... | @@ -21055,14 +21093,14 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 21055 | 21093 | } |
| 21056 | 21094 | } |
| 21057 | 21095 | |
| 21058 | | if (result_loc->value.data.x_ptr.mut == ConstPtrMutInfer) { |
| 21096 | if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer) { |
| 21059 | 21097 | if (const_ptrs.length != elem_count) { |
| 21060 | | result_loc->value.special = ConstValSpecialRuntime; |
| 21098 | result_loc->value->special = ConstValSpecialRuntime; |
| 21061 | 21099 | for (size_t i = 0; i < const_ptrs.length; i += 1) { |
| 21062 | 21100 | IrInstruction *elem_result_loc = const_ptrs.at(i); |
| 21063 | | assert(elem_result_loc->value.special == ConstValSpecialStatic); |
| 21101 | assert(elem_result_loc->value->special == ConstValSpecialStatic); |
| 21064 | 21102 | IrInstruction *deref = ir_get_deref(ira, elem_result_loc, elem_result_loc, nullptr); |
| 21065 | | elem_result_loc->value.special = ConstValSpecialRuntime; |
| 21103 | elem_result_loc->value->special = ConstValSpecialRuntime; |
| 21066 | 21104 | ir_analyze_store_ptr(ira, elem_result_loc, elem_result_loc, deref, false); |
| 21067 | 21105 | } |
| 21068 | 21106 | } |
| ... | ... | @@ -21078,7 +21116,7 @@ static IrInstruction *ir_analyze_instruction_container_init_list(IrAnalyze *ira, |
| 21078 | 21116 | return ira->codegen->invalid_instruction; |
| 21079 | 21117 | } |
| 21080 | 21118 | |
| 21081 | | ZigType *result_elem_type = result_loc->value.type->data.pointer.child_type; |
| 21119 | ZigType *result_elem_type = result_loc->value->type->data.pointer.child_type; |
| 21082 | 21120 | if (is_slice(result_elem_type)) { |
| 21083 | 21121 | ErrorMsg *msg = ir_add_error(ira, &instruction->base, |
| 21084 | 21122 | buf_sprintf("runtime-initialized array cannot be casted to slice type '%s'", |
| ... | ... | @@ -21095,11 +21133,11 @@ static IrInstruction *ir_analyze_instruction_container_init_fields(IrAnalyze *ir |
| 21095 | 21133 | { |
| 21096 | 21134 | ir_assert(instruction->result_loc != nullptr, &instruction->base); |
| 21097 | 21135 | IrInstruction *result_loc = instruction->result_loc->child; |
| 21098 | | if (type_is_invalid(result_loc->value.type)) |
| 21136 | if (type_is_invalid(result_loc->value->type)) |
| 21099 | 21137 | return result_loc; |
| 21100 | 21138 | |
| 21101 | | ir_assert(result_loc->value.type->id == ZigTypeIdPointer, &instruction->base); |
| 21102 | | ZigType *container_type = result_loc->value.type->data.pointer.child_type; |
| 21139 | ir_assert(result_loc->value->type->id == ZigTypeIdPointer, &instruction->base); |
| 21140 | ZigType *container_type = result_loc->value->type->data.pointer.child_type; |
| 21103 | 21141 | |
| 21104 | 21142 | return ir_analyze_container_init_fields(ira, &instruction->base, container_type, |
| 21105 | 21143 | instruction->field_count, instruction->fields, result_loc); |
| ... | ... | @@ -21123,15 +21161,15 @@ static IrInstruction *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstr |
| 21123 | 21161 | fprintf(stderr, "| "); |
| 21124 | 21162 | for (size_t i = 0; i < instruction->msg_count; i += 1) { |
| 21125 | 21163 | IrInstruction *msg = instruction->msg_list[i]->child; |
| 21126 | | if (type_is_invalid(msg->value.type)) |
| 21164 | if (type_is_invalid(msg->value->type)) |
| 21127 | 21165 | return ira->codegen->invalid_instruction; |
| 21128 | 21166 | buf_resize(&buf, 0); |
| 21129 | | if (msg->value.special == ConstValSpecialLazy) { |
| 21167 | if (msg->value->special == ConstValSpecialLazy) { |
| 21130 | 21168 | // Resolve any lazy value that's passed, we need its value |
| 21131 | | if (ir_resolve_lazy(ira->codegen, msg->source_node, &msg->value)) |
| 21169 | if (ir_resolve_lazy(ira->codegen, msg->source_node, msg->value)) |
| 21132 | 21170 | return ira->codegen->invalid_instruction; |
| 21133 | 21171 | } |
| 21134 | | render_const_value(ira->codegen, &buf, &msg->value); |
| 21172 | render_const_value(ira->codegen, &buf, msg->value); |
| 21135 | 21173 | const char *comma_str = (i != 0) ? ", " : ""; |
| 21136 | 21174 | fprintf(stderr, "%s%s", comma_str, buf_ptr(&buf)); |
| 21137 | 21175 | } |
| ... | ... | @@ -21150,28 +21188,28 @@ static IrInstruction *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstr |
| 21150 | 21188 | |
| 21151 | 21189 | static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstructionErrName *instruction) { |
| 21152 | 21190 | IrInstruction *value = instruction->value->child; |
| 21153 | | if (type_is_invalid(value->value.type)) |
| 21191 | if (type_is_invalid(value->value->type)) |
| 21154 | 21192 | return ira->codegen->invalid_instruction; |
| 21155 | 21193 | |
| 21156 | 21194 | IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_global_error_set); |
| 21157 | | if (type_is_invalid(casted_value->value.type)) |
| 21195 | if (type_is_invalid(casted_value->value->type)) |
| 21158 | 21196 | return ira->codegen->invalid_instruction; |
| 21159 | 21197 | |
| 21160 | 21198 | ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 21161 | 21199 | true, false, PtrLenUnknown, 0, 0, 0, false); |
| 21162 | 21200 | ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type); |
| 21163 | 21201 | if (instr_is_comptime(casted_value)) { |
| 21164 | | ConstExprValue *val = ir_resolve_const(ira, casted_value, UndefBad); |
| 21202 | ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad); |
| 21165 | 21203 | if (val == nullptr) |
| 21166 | 21204 | return ira->codegen->invalid_instruction; |
| 21167 | | ErrorTableEntry *err = casted_value->value.data.x_err_set; |
| 21205 | ErrorTableEntry *err = casted_value->value->data.x_err_set; |
| 21168 | 21206 | if (!err->cached_error_name_val) { |
| 21169 | | ConstExprValue *array_val = create_const_str_lit(ira->codegen, &err->name)->data.x_ptr.data.ref.pointee; |
| 21207 | ZigValue *array_val = create_const_str_lit(ira->codegen, &err->name)->data.x_ptr.data.ref.pointee; |
| 21170 | 21208 | err->cached_error_name_val = create_const_slice(ira->codegen, array_val, 0, buf_len(&err->name), true); |
| 21171 | 21209 | } |
| 21172 | 21210 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 21173 | | copy_const_val(&result->value, err->cached_error_name_val, true); |
| 21174 | | result->value.type = str_type; |
| 21211 | copy_const_val(result->value, err->cached_error_name_val, true); |
| 21212 | result->value->type = str_type; |
| 21175 | 21213 | return result; |
| 21176 | 21214 | } |
| 21177 | 21215 | |
| ... | ... | @@ -21179,25 +21217,25 @@ static IrInstruction *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruct |
| 21179 | 21217 | |
| 21180 | 21218 | IrInstruction *result = ir_build_err_name(&ira->new_irb, |
| 21181 | 21219 | instruction->base.scope, instruction->base.source_node, value); |
| 21182 | | result->value.type = str_type; |
| 21220 | result->value->type = str_type; |
| 21183 | 21221 | return result; |
| 21184 | 21222 | } |
| 21185 | 21223 | |
| 21186 | 21224 | static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstructionTagName *instruction) { |
| 21187 | 21225 | Error err; |
| 21188 | 21226 | IrInstruction *target = instruction->target->child; |
| 21189 | | if (type_is_invalid(target->value.type)) |
| 21227 | if (type_is_invalid(target->value->type)) |
| 21190 | 21228 | return ira->codegen->invalid_instruction; |
| 21191 | 21229 | |
| 21192 | | assert(target->value.type->id == ZigTypeIdEnum); |
| 21230 | assert(target->value->type->id == ZigTypeIdEnum); |
| 21193 | 21231 | |
| 21194 | 21232 | if (instr_is_comptime(target)) { |
| 21195 | | if ((err = type_resolve(ira->codegen, target->value.type, ResolveStatusZeroBitsKnown))) |
| 21233 | if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusZeroBitsKnown))) |
| 21196 | 21234 | return ira->codegen->invalid_instruction; |
| 21197 | | TypeEnumField *field = find_enum_field_by_tag(target->value.type, &target->value.data.x_bigint); |
| 21198 | | ConstExprValue *array_val = create_const_str_lit(ira->codegen, field->name)->data.x_ptr.data.ref.pointee; |
| 21235 | TypeEnumField *field = find_enum_field_by_tag(target->value->type, &target->value->data.x_bigint); |
| 21236 | ZigValue *array_val = create_const_str_lit(ira->codegen, field->name)->data.x_ptr.data.ref.pointee; |
| 21199 | 21237 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 21200 | | init_const_slice(ira->codegen, &result->value, array_val, 0, buf_len(field->name), true); |
| 21238 | init_const_slice(ira->codegen, result->value, array_val, 0, buf_len(field->name), true); |
| 21201 | 21239 | return result; |
| 21202 | 21240 | } |
| 21203 | 21241 | |
| ... | ... | @@ -21207,7 +21245,7 @@ static IrInstruction *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIns |
| 21207 | 21245 | ira->codegen, ira->codegen->builtin_types.entry_u8, |
| 21208 | 21246 | true, false, PtrLenUnknown, |
| 21209 | 21247 | 0, 0, 0, false); |
| 21210 | | result->value.type = get_slice_type(ira->codegen, u8_ptr_type); |
| 21248 | result->value->type = get_slice_type(ira->codegen, u8_ptr_type); |
| 21211 | 21249 | return result; |
| 21212 | 21250 | } |
| 21213 | 21251 | |
| ... | ... | @@ -21226,7 +21264,7 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 21226 | 21264 | return ira->codegen->invalid_instruction; |
| 21227 | 21265 | |
| 21228 | 21266 | IrInstruction *field_ptr = instruction->field_ptr->child; |
| 21229 | | if (type_is_invalid(field_ptr->value.type)) |
| 21267 | if (type_is_invalid(field_ptr->value->type)) |
| 21230 | 21268 | return ira->codegen->invalid_instruction; |
| 21231 | 21269 | |
| 21232 | 21270 | if (container_type->id != ZigTypeIdStruct) { |
| ... | ... | @@ -21246,9 +21284,9 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 21246 | 21284 | return ira->codegen->invalid_instruction; |
| 21247 | 21285 | } |
| 21248 | 21286 | |
| 21249 | | if (field_ptr->value.type->id != ZigTypeIdPointer) { |
| 21287 | if (field_ptr->value->type->id != ZigTypeIdPointer) { |
| 21250 | 21288 | ir_add_error(ira, field_ptr, |
| 21251 | | buf_sprintf("expected pointer, found '%s'", buf_ptr(&field_ptr->value.type->name))); |
| 21289 | buf_sprintf("expected pointer, found '%s'", buf_ptr(&field_ptr->value->type->name))); |
| 21252 | 21290 | return ira->codegen->invalid_instruction; |
| 21253 | 21291 | } |
| 21254 | 21292 | |
| ... | ... | @@ -21257,22 +21295,22 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 21257 | 21295 | uint32_t parent_ptr_align = is_packed ? 1 : get_abi_alignment(ira->codegen, container_type); |
| 21258 | 21296 | |
| 21259 | 21297 | ZigType *field_ptr_type = get_pointer_to_type_extra(ira->codegen, field->type_entry, |
| 21260 | | field_ptr->value.type->data.pointer.is_const, |
| 21261 | | field_ptr->value.type->data.pointer.is_volatile, |
| 21298 | field_ptr->value->type->data.pointer.is_const, |
| 21299 | field_ptr->value->type->data.pointer.is_volatile, |
| 21262 | 21300 | PtrLenSingle, |
| 21263 | 21301 | field_ptr_align, 0, 0, false); |
| 21264 | 21302 | IrInstruction *casted_field_ptr = ir_implicit_cast(ira, field_ptr, field_ptr_type); |
| 21265 | | if (type_is_invalid(casted_field_ptr->value.type)) |
| 21303 | if (type_is_invalid(casted_field_ptr->value->type)) |
| 21266 | 21304 | return ira->codegen->invalid_instruction; |
| 21267 | 21305 | |
| 21268 | 21306 | ZigType *result_type = get_pointer_to_type_extra(ira->codegen, container_type, |
| 21269 | | casted_field_ptr->value.type->data.pointer.is_const, |
| 21270 | | casted_field_ptr->value.type->data.pointer.is_volatile, |
| 21307 | casted_field_ptr->value->type->data.pointer.is_const, |
| 21308 | casted_field_ptr->value->type->data.pointer.is_volatile, |
| 21271 | 21309 | PtrLenSingle, |
| 21272 | 21310 | parent_ptr_align, 0, 0, false); |
| 21273 | 21311 | |
| 21274 | 21312 | if (instr_is_comptime(casted_field_ptr)) { |
| 21275 | | ConstExprValue *field_ptr_val = ir_resolve_const(ira, casted_field_ptr, UndefBad); |
| 21313 | ZigValue *field_ptr_val = ir_resolve_const(ira, casted_field_ptr, UndefBad); |
| 21276 | 21314 | if (!field_ptr_val) |
| 21277 | 21315 | return ira->codegen->invalid_instruction; |
| 21278 | 21316 | |
| ... | ... | @@ -21291,7 +21329,7 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 21291 | 21329 | } |
| 21292 | 21330 | |
| 21293 | 21331 | IrInstruction *result = ir_const(ira, &instruction->base, result_type); |
| 21294 | | ConstExprValue *out_val = &result->value; |
| 21332 | ZigValue *out_val = result->value; |
| 21295 | 21333 | out_val->data.x_ptr.special = ConstPtrSpecialRef; |
| 21296 | 21334 | out_val->data.x_ptr.data.ref.pointee = field_ptr_val->data.x_ptr.data.base_struct.struct_val; |
| 21297 | 21335 | out_val->data.x_ptr.mut = field_ptr_val->data.x_ptr.mut; |
| ... | ... | @@ -21300,7 +21338,7 @@ static IrInstruction *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, |
| 21300 | 21338 | |
| 21301 | 21339 | IrInstruction *result = ir_build_field_parent_ptr(&ira->new_irb, instruction->base.scope, |
| 21302 | 21340 | instruction->base.source_node, type_value, field_name_value, casted_field_ptr, field); |
| 21303 | | result->value.type = result_type; |
| 21341 | result->value->type = result_type; |
| 21304 | 21342 | return result; |
| 21305 | 21343 | } |
| 21306 | 21344 | |
| ... | ... | @@ -21350,7 +21388,7 @@ static IrInstruction *ir_analyze_instruction_byte_offset_of(IrAnalyze *ira, |
| 21350 | 21388 | IrInstructionByteOffsetOf *instruction) |
| 21351 | 21389 | { |
| 21352 | 21390 | IrInstruction *type_value = instruction->type_value->child; |
| 21353 | | if (type_is_invalid(type_value->value.type)) |
| 21391 | if (type_is_invalid(type_value->value->type)) |
| 21354 | 21392 | return ira->codegen->invalid_instruction; |
| 21355 | 21393 | |
| 21356 | 21394 | IrInstruction *field_name_value = instruction->field_name->child; |
| ... | ... | @@ -21366,7 +21404,7 @@ static IrInstruction *ir_analyze_instruction_bit_offset_of(IrAnalyze *ira, |
| 21366 | 21404 | IrInstructionBitOffsetOf *instruction) |
| 21367 | 21405 | { |
| 21368 | 21406 | IrInstruction *type_value = instruction->type_value->child; |
| 21369 | | if (type_is_invalid(type_value->value.type)) |
| 21407 | if (type_is_invalid(type_value->value->type)) |
| 21370 | 21408 | return ira->codegen->invalid_instruction; |
| 21371 | 21409 | IrInstruction *field_name_value = instruction->field_name->child; |
| 21372 | 21410 | size_t byte_offset = 0; |
| ... | ... | @@ -21390,7 +21428,7 @@ static void ensure_field_index(ZigType *type, const char *field_name, size_t ind |
| 21390 | 21428 | |
| 21391 | 21429 | static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, ZigType *root) { |
| 21392 | 21430 | Error err; |
| 21393 | | ConstExprValue *type_info_var = get_builtin_value(ira->codegen, "TypeInfo"); |
| 21431 | ZigValue *type_info_var = get_builtin_value(ira->codegen, "TypeInfo"); |
| 21394 | 21432 | assert(type_info_var->type->id == ZigTypeIdMetaType); |
| 21395 | 21433 | ZigType *type_info_type = type_info_var->data.x_type; |
| 21396 | 21434 | assert(type_info_type->id == ZigTypeIdUnion); |
| ... | ... | @@ -21423,7 +21461,7 @@ static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, Zig |
| 21423 | 21461 | return ir_resolve_const_type(ira->codegen, ira->new_irb.exec, nullptr, var->const_value); |
| 21424 | 21462 | } |
| 21425 | 21463 | |
| 21426 | | static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr, ConstExprValue *out_val, |
| 21464 | static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *out_val, |
| 21427 | 21465 | ScopeDecls *decls_scope) |
| 21428 | 21466 | { |
| 21429 | 21467 | Error err; |
| ... | ... | @@ -21473,7 +21511,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr |
| 21473 | 21511 | } |
| 21474 | 21512 | } |
| 21475 | 21513 | |
| 21476 | | ConstExprValue *declaration_array = create_const_vals(1); |
| 21514 | ZigValue *declaration_array = create_const_vals(1); |
| 21477 | 21515 | declaration_array->special = ConstValSpecialStatic; |
| 21478 | 21516 | declaration_array->type = get_array_type(ira->codegen, type_info_declaration_type, declaration_count, nullptr); |
| 21479 | 21517 | declaration_array->data.x_array.special = ConstArraySpecialNone; |
| ... | ... | @@ -21494,13 +21532,13 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr |
| 21494 | 21532 | continue; |
| 21495 | 21533 | } |
| 21496 | 21534 | |
| 21497 | | ConstExprValue *declaration_val = &declaration_array->data.x_array.data.s_none.elements[declaration_index]; |
| 21535 | ZigValue *declaration_val = &declaration_array->data.x_array.data.s_none.elements[declaration_index]; |
| 21498 | 21536 | |
| 21499 | 21537 | declaration_val->special = ConstValSpecialStatic; |
| 21500 | 21538 | declaration_val->type = type_info_declaration_type; |
| 21501 | 21539 | |
| 21502 | | ConstExprValue **inner_fields = alloc_const_vals_ptrs(3); |
| 21503 | | ConstExprValue *name = create_const_str_lit(ira->codegen, curr_entry->key)->data.x_ptr.data.ref.pointee; |
| 21540 | ZigValue **inner_fields = alloc_const_vals_ptrs(3); |
| 21541 | ZigValue *name = create_const_str_lit(ira->codegen, curr_entry->key)->data.x_ptr.data.ref.pointee; |
| 21504 | 21542 | init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(curr_entry->key), true); |
| 21505 | 21543 | inner_fields[1]->special = ConstValSpecialStatic; |
| 21506 | 21544 | inner_fields[1]->type = ira->codegen->builtin_types.entry_bool; |
| ... | ... | @@ -21528,7 +21566,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr |
| 21528 | 21566 | // 1: Data.Var: type |
| 21529 | 21567 | bigint_init_unsigned(&inner_fields[2]->data.x_union.tag, 1); |
| 21530 | 21568 | |
| 21531 | | ConstExprValue *payload = create_const_vals(1); |
| 21569 | ZigValue *payload = create_const_vals(1); |
| 21532 | 21570 | payload->special = ConstValSpecialStatic; |
| 21533 | 21571 | payload->type = ira->codegen->builtin_types.entry_type; |
| 21534 | 21572 | payload->data.x_type = var->const_value->type; |
| ... | ... | @@ -21553,13 +21591,13 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr |
| 21553 | 21591 | |
| 21554 | 21592 | AstNodeFnProto *fn_node = &fn_entry->proto_node->data.fn_proto; |
| 21555 | 21593 | |
| 21556 | | ConstExprValue *fn_decl_val = create_const_vals(1); |
| 21594 | ZigValue *fn_decl_val = create_const_vals(1); |
| 21557 | 21595 | fn_decl_val->special = ConstValSpecialStatic; |
| 21558 | 21596 | fn_decl_val->type = type_info_fn_decl_type; |
| 21559 | 21597 | fn_decl_val->parent.id = ConstParentIdUnion; |
| 21560 | 21598 | fn_decl_val->parent.data.p_union.union_val = inner_fields[2]; |
| 21561 | 21599 | |
| 21562 | | ConstExprValue **fn_decl_fields = alloc_const_vals_ptrs(9); |
| 21600 | ZigValue **fn_decl_fields = alloc_const_vals_ptrs(9); |
| 21563 | 21601 | fn_decl_val->data.x_struct.fields = fn_decl_fields; |
| 21564 | 21602 | |
| 21565 | 21603 | // fn_type: type |
| ... | ... | @@ -21603,7 +21641,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr |
| 21603 | 21641 | fn_decl_fields[6]->type = get_optional_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr)); |
| 21604 | 21642 | if (fn_node->is_extern && fn_node->lib_name != nullptr && buf_len(fn_node->lib_name) > 0) { |
| 21605 | 21643 | fn_decl_fields[6]->data.x_optional = create_const_vals(1); |
| 21606 | | ConstExprValue *lib_name = create_const_str_lit(ira->codegen, fn_node->lib_name)->data.x_ptr.data.ref.pointee; |
| 21644 | ZigValue *lib_name = create_const_str_lit(ira->codegen, fn_node->lib_name)->data.x_ptr.data.ref.pointee; |
| 21607 | 21645 | init_const_slice(ira->codegen, fn_decl_fields[6]->data.x_optional, lib_name, 0, |
| 21608 | 21646 | buf_len(fn_node->lib_name), true); |
| 21609 | 21647 | } else { |
| ... | ... | @@ -21617,7 +21655,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr |
| 21617 | 21655 | // arg_names: [][] const u8 |
| 21618 | 21656 | ensure_field_index(fn_decl_val->type, "arg_names", 8); |
| 21619 | 21657 | size_t fn_arg_count = fn_entry->variable_list.length; |
| 21620 | | ConstExprValue *fn_arg_name_array = create_const_vals(1); |
| 21658 | ZigValue *fn_arg_name_array = create_const_vals(1); |
| 21621 | 21659 | fn_arg_name_array->special = ConstValSpecialStatic; |
| 21622 | 21660 | fn_arg_name_array->type = get_array_type(ira->codegen, |
| 21623 | 21661 | get_slice_type(ira->codegen, u8_ptr), fn_arg_count, nullptr); |
| ... | ... | @@ -21628,8 +21666,8 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr |
| 21628 | 21666 | |
| 21629 | 21667 | for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) { |
| 21630 | 21668 | ZigVar *arg_var = fn_entry->variable_list.at(fn_arg_index); |
| 21631 | | ConstExprValue *fn_arg_name_val = &fn_arg_name_array->data.x_array.data.s_none.elements[fn_arg_index]; |
| 21632 | | ConstExprValue *arg_name = create_const_str_lit(ira->codegen, |
| 21669 | ZigValue *fn_arg_name_val = &fn_arg_name_array->data.x_array.data.s_none.elements[fn_arg_index]; |
| 21670 | ZigValue *arg_name = create_const_str_lit(ira->codegen, |
| 21633 | 21671 | buf_create_from_str(arg_var->name))->data.x_ptr.data.ref.pointee; |
| 21634 | 21672 | init_const_slice(ira->codegen, fn_arg_name_val, arg_name, 0, strlen(arg_var->name), true); |
| 21635 | 21673 | fn_arg_name_val->parent.id = ConstParentIdArray; |
| ... | ... | @@ -21649,7 +21687,7 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, IrInstruction *source_instr |
| 21649 | 21687 | // This is a type. |
| 21650 | 21688 | bigint_init_unsigned(&inner_fields[2]->data.x_union.tag, 0); |
| 21651 | 21689 | |
| 21652 | | ConstExprValue *payload = create_const_vals(1); |
| 21690 | ZigValue *payload = create_const_vals(1); |
| 21653 | 21691 | payload->special = ConstValSpecialStatic; |
| 21654 | 21692 | payload->type = ira->codegen->builtin_types.entry_type; |
| 21655 | 21693 | payload->data.x_type = type_entry; |
| ... | ... | @@ -21695,7 +21733,7 @@ static PtrLen size_enum_index_to_ptr_len(BuiltinPtrSize size_enum_index) { |
| 21695 | 21733 | zig_unreachable(); |
| 21696 | 21734 | } |
| 21697 | 21735 | |
| 21698 | | static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_type_entry) { |
| 21736 | static ZigValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_type_entry) { |
| 21699 | 21737 | Error err; |
| 21700 | 21738 | ZigType *attrs_type; |
| 21701 | 21739 | BuiltinPtrSize size_enum_index; |
| ... | ... | @@ -21715,11 +21753,11 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty |
| 21715 | 21753 | ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr); |
| 21716 | 21754 | assertNoError(type_resolve(ira->codegen, type_info_pointer_type, ResolveStatusSizeKnown)); |
| 21717 | 21755 | |
| 21718 | | ConstExprValue *result = create_const_vals(1); |
| 21756 | ZigValue *result = create_const_vals(1); |
| 21719 | 21757 | result->special = ConstValSpecialStatic; |
| 21720 | 21758 | result->type = type_info_pointer_type; |
| 21721 | 21759 | |
| 21722 | | ConstExprValue **fields = alloc_const_vals_ptrs(7); |
| 21760 | ZigValue **fields = alloc_const_vals_ptrs(7); |
| 21723 | 21761 | result->data.x_struct.fields = fields; |
| 21724 | 21762 | |
| 21725 | 21763 | // size: Size |
| ... | ... | @@ -21769,17 +21807,17 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty |
| 21769 | 21807 | return result; |
| 21770 | 21808 | }; |
| 21771 | 21809 | |
| 21772 | | static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val, TypeEnumField *enum_field, |
| 21810 | static void make_enum_field_val(IrAnalyze *ira, ZigValue *enum_field_val, TypeEnumField *enum_field, |
| 21773 | 21811 | ZigType *type_info_enum_field_type) |
| 21774 | 21812 | { |
| 21775 | 21813 | enum_field_val->special = ConstValSpecialStatic; |
| 21776 | 21814 | enum_field_val->type = type_info_enum_field_type; |
| 21777 | 21815 | |
| 21778 | | ConstExprValue **inner_fields = alloc_const_vals_ptrs(2); |
| 21816 | ZigValue **inner_fields = alloc_const_vals_ptrs(2); |
| 21779 | 21817 | inner_fields[1]->special = ConstValSpecialStatic; |
| 21780 | 21818 | inner_fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int; |
| 21781 | 21819 | |
| 21782 | | ConstExprValue *name = create_const_str_lit(ira->codegen, enum_field->name)->data.x_ptr.data.ref.pointee; |
| 21820 | ZigValue *name = create_const_str_lit(ira->codegen, enum_field->name)->data.x_ptr.data.ref.pointee; |
| 21783 | 21821 | init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(enum_field->name), true); |
| 21784 | 21822 | |
| 21785 | 21823 | bigint_init_bigint(&inner_fields[1]->data.x_bigint, &enum_field->value); |
| ... | ... | @@ -21788,7 +21826,7 @@ static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val, |
| 21788 | 21826 | } |
| 21789 | 21827 | |
| 21790 | 21828 | static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr, ZigType *type_entry, |
| 21791 | | ConstExprValue **out) |
| 21829 | ZigValue **out) |
| 21792 | 21830 | { |
| 21793 | 21831 | Error err; |
| 21794 | 21832 | assert(type_entry != nullptr); |
| ... | ... | @@ -21803,7 +21841,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 21803 | 21841 | return ErrorNone; |
| 21804 | 21842 | } |
| 21805 | 21843 | |
| 21806 | | ConstExprValue *result = nullptr; |
| 21844 | ZigValue *result = nullptr; |
| 21807 | 21845 | switch (type_entry->id) { |
| 21808 | 21846 | case ZigTypeIdInvalid: |
| 21809 | 21847 | zig_unreachable(); |
| ... | ... | @@ -21826,7 +21864,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 21826 | 21864 | result->special = ConstValSpecialStatic; |
| 21827 | 21865 | result->type = ir_type_info_get_type(ira, "Int", nullptr); |
| 21828 | 21866 | |
| 21829 | | ConstExprValue **fields = alloc_const_vals_ptrs(2); |
| 21867 | ZigValue **fields = alloc_const_vals_ptrs(2); |
| 21830 | 21868 | result->data.x_struct.fields = fields; |
| 21831 | 21869 | |
| 21832 | 21870 | // is_signed: bool |
| ... | ... | @@ -21848,7 +21886,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 21848 | 21886 | result->special = ConstValSpecialStatic; |
| 21849 | 21887 | result->type = ir_type_info_get_type(ira, "Float", nullptr); |
| 21850 | 21888 | |
| 21851 | | ConstExprValue **fields = alloc_const_vals_ptrs(1); |
| 21889 | ZigValue **fields = alloc_const_vals_ptrs(1); |
| 21852 | 21890 | result->data.x_struct.fields = fields; |
| 21853 | 21891 | |
| 21854 | 21892 | // bits: u8 |
| ... | ... | @@ -21872,7 +21910,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 21872 | 21910 | result->special = ConstValSpecialStatic; |
| 21873 | 21911 | result->type = ir_type_info_get_type(ira, "Array", nullptr); |
| 21874 | 21912 | |
| 21875 | | ConstExprValue **fields = alloc_const_vals_ptrs(3); |
| 21913 | ZigValue **fields = alloc_const_vals_ptrs(3); |
| 21876 | 21914 | result->data.x_struct.fields = fields; |
| 21877 | 21915 | |
| 21878 | 21916 | // len: usize |
| ... | ... | @@ -21896,7 +21934,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 21896 | 21934 | result->special = ConstValSpecialStatic; |
| 21897 | 21935 | result->type = ir_type_info_get_type(ira, "Vector", nullptr); |
| 21898 | 21936 | |
| 21899 | | ConstExprValue **fields = alloc_const_vals_ptrs(2); |
| 21937 | ZigValue **fields = alloc_const_vals_ptrs(2); |
| 21900 | 21938 | result->data.x_struct.fields = fields; |
| 21901 | 21939 | |
| 21902 | 21940 | // len: usize |
| ... | ... | @@ -21918,7 +21956,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 21918 | 21956 | result->special = ConstValSpecialStatic; |
| 21919 | 21957 | result->type = ir_type_info_get_type(ira, "Optional", nullptr); |
| 21920 | 21958 | |
| 21921 | | ConstExprValue **fields = alloc_const_vals_ptrs(1); |
| 21959 | ZigValue **fields = alloc_const_vals_ptrs(1); |
| 21922 | 21960 | result->data.x_struct.fields = fields; |
| 21923 | 21961 | |
| 21924 | 21962 | // child: type |
| ... | ... | @@ -21934,7 +21972,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 21934 | 21972 | result->special = ConstValSpecialStatic; |
| 21935 | 21973 | result->type = ir_type_info_get_type(ira, "AnyFrame", nullptr); |
| 21936 | 21974 | |
| 21937 | | ConstExprValue **fields = alloc_const_vals_ptrs(1); |
| 21975 | ZigValue **fields = alloc_const_vals_ptrs(1); |
| 21938 | 21976 | result->data.x_struct.fields = fields; |
| 21939 | 21977 | |
| 21940 | 21978 | // child: ?type |
| ... | ... | @@ -21951,7 +21989,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 21951 | 21989 | result->special = ConstValSpecialStatic; |
| 21952 | 21990 | result->type = ir_type_info_get_type(ira, "Enum", nullptr); |
| 21953 | 21991 | |
| 21954 | | ConstExprValue **fields = alloc_const_vals_ptrs(4); |
| 21992 | ZigValue **fields = alloc_const_vals_ptrs(4); |
| 21955 | 21993 | result->data.x_struct.fields = fields; |
| 21956 | 21994 | |
| 21957 | 21995 | // layout: ContainerLayout |
| ... | ... | @@ -21973,7 +22011,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 21973 | 22011 | } |
| 21974 | 22012 | uint32_t enum_field_count = type_entry->data.enumeration.src_field_count; |
| 21975 | 22013 | |
| 21976 | | ConstExprValue *enum_field_array = create_const_vals(1); |
| 22014 | ZigValue *enum_field_array = create_const_vals(1); |
| 21977 | 22015 | enum_field_array->special = ConstValSpecialStatic; |
| 21978 | 22016 | enum_field_array->type = get_array_type(ira->codegen, type_info_enum_field_type, enum_field_count, nullptr); |
| 21979 | 22017 | enum_field_array->data.x_array.special = ConstArraySpecialNone; |
| ... | ... | @@ -21984,7 +22022,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 21984 | 22022 | for (uint32_t enum_field_index = 0; enum_field_index < enum_field_count; enum_field_index++) |
| 21985 | 22023 | { |
| 21986 | 22024 | TypeEnumField *enum_field = &type_entry->data.enumeration.fields[enum_field_index]; |
| 21987 | | ConstExprValue *enum_field_val = &enum_field_array->data.x_array.data.s_none.elements[enum_field_index]; |
| 22025 | ZigValue *enum_field_val = &enum_field_array->data.x_array.data.s_none.elements[enum_field_index]; |
| 21988 | 22026 | make_enum_field_val(ira, enum_field_val, enum_field, type_info_enum_field_type); |
| 21989 | 22027 | enum_field_val->parent.id = ConstParentIdArray; |
| 21990 | 22028 | enum_field_val->parent.data.p_array.array_val = enum_field_array; |
| ... | ... | @@ -22017,11 +22055,11 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 22017 | 22055 | if ((err = type_resolve(ira->codegen, type_info_error_type, ResolveStatusSizeKnown))) { |
| 22018 | 22056 | zig_unreachable(); |
| 22019 | 22057 | } |
| 22020 | | ConstExprValue *slice_val = create_const_vals(1); |
| 22058 | ZigValue *slice_val = create_const_vals(1); |
| 22021 | 22059 | result->data.x_optional = slice_val; |
| 22022 | 22060 | |
| 22023 | 22061 | uint32_t error_count = type_entry->data.error_set.err_count; |
| 22024 | | ConstExprValue *error_array = create_const_vals(1); |
| 22062 | ZigValue *error_array = create_const_vals(1); |
| 22025 | 22063 | error_array->special = ConstValSpecialStatic; |
| 22026 | 22064 | error_array->type = get_array_type(ira->codegen, type_info_error_type, error_count, nullptr); |
| 22027 | 22065 | error_array->data.x_array.special = ConstArraySpecialNone; |
| ... | ... | @@ -22030,16 +22068,16 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 22030 | 22068 | init_const_slice(ira->codegen, slice_val, error_array, 0, error_count, false); |
| 22031 | 22069 | for (uint32_t error_index = 0; error_index < error_count; error_index++) { |
| 22032 | 22070 | ErrorTableEntry *error = type_entry->data.error_set.errors[error_index]; |
| 22033 | | ConstExprValue *error_val = &error_array->data.x_array.data.s_none.elements[error_index]; |
| 22071 | ZigValue *error_val = &error_array->data.x_array.data.s_none.elements[error_index]; |
| 22034 | 22072 | |
| 22035 | 22073 | error_val->special = ConstValSpecialStatic; |
| 22036 | 22074 | error_val->type = type_info_error_type; |
| 22037 | 22075 | |
| 22038 | | ConstExprValue **inner_fields = alloc_const_vals_ptrs(2); |
| 22076 | ZigValue **inner_fields = alloc_const_vals_ptrs(2); |
| 22039 | 22077 | inner_fields[1]->special = ConstValSpecialStatic; |
| 22040 | 22078 | inner_fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int; |
| 22041 | 22079 | |
| 22042 | | ConstExprValue *name = nullptr; |
| 22080 | ZigValue *name = nullptr; |
| 22043 | 22081 | if (error->cached_error_name_val != nullptr) |
| 22044 | 22082 | name = error->cached_error_name_val; |
| 22045 | 22083 | if (name == nullptr) |
| ... | ... | @@ -22061,7 +22099,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 22061 | 22099 | result->special = ConstValSpecialStatic; |
| 22062 | 22100 | result->type = ir_type_info_get_type(ira, "ErrorUnion", nullptr); |
| 22063 | 22101 | |
| 22064 | | ConstExprValue **fields = alloc_const_vals_ptrs(2); |
| 22102 | ZigValue **fields = alloc_const_vals_ptrs(2); |
| 22065 | 22103 | result->data.x_struct.fields = fields; |
| 22066 | 22104 | |
| 22067 | 22105 | // error_set: type |
| ... | ... | @@ -22084,7 +22122,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 22084 | 22122 | result->special = ConstValSpecialStatic; |
| 22085 | 22123 | result->type = ir_type_info_get_type(ira, "Union", nullptr); |
| 22086 | 22124 | |
| 22087 | | ConstExprValue **fields = alloc_const_vals_ptrs(4); |
| 22125 | ZigValue **fields = alloc_const_vals_ptrs(4); |
| 22088 | 22126 | result->data.x_struct.fields = fields; |
| 22089 | 22127 | |
| 22090 | 22128 | // layout: ContainerLayout |
| ... | ... | @@ -22101,7 +22139,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 22101 | 22139 | if (union_decl_node->data.container_decl.auto_enum || |
| 22102 | 22140 | union_decl_node->data.container_decl.init_arg_expr != nullptr) |
| 22103 | 22141 | { |
| 22104 | | ConstExprValue *tag_type = create_const_vals(1); |
| 22142 | ZigValue *tag_type = create_const_vals(1); |
| 22105 | 22143 | tag_type->special = ConstValSpecialStatic; |
| 22106 | 22144 | tag_type->type = ira->codegen->builtin_types.entry_type; |
| 22107 | 22145 | tag_type->data.x_type = type_entry->data.unionation.tag_type; |
| ... | ... | @@ -22117,7 +22155,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 22117 | 22155 | zig_unreachable(); |
| 22118 | 22156 | uint32_t union_field_count = type_entry->data.unionation.src_field_count; |
| 22119 | 22157 | |
| 22120 | | ConstExprValue *union_field_array = create_const_vals(1); |
| 22158 | ZigValue *union_field_array = create_const_vals(1); |
| 22121 | 22159 | union_field_array->special = ConstValSpecialStatic; |
| 22122 | 22160 | union_field_array->type = get_array_type(ira->codegen, type_info_union_field_type, union_field_count, nullptr); |
| 22123 | 22161 | union_field_array->data.x_array.special = ConstArraySpecialNone; |
| ... | ... | @@ -22129,12 +22167,12 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 22129 | 22167 | |
| 22130 | 22168 | for (uint32_t union_field_index = 0; union_field_index < union_field_count; union_field_index++) { |
| 22131 | 22169 | TypeUnionField *union_field = &type_entry->data.unionation.fields[union_field_index]; |
| 22132 | | ConstExprValue *union_field_val = &union_field_array->data.x_array.data.s_none.elements[union_field_index]; |
| 22170 | ZigValue *union_field_val = &union_field_array->data.x_array.data.s_none.elements[union_field_index]; |
| 22133 | 22171 | |
| 22134 | 22172 | union_field_val->special = ConstValSpecialStatic; |
| 22135 | 22173 | union_field_val->type = type_info_union_field_type; |
| 22136 | 22174 | |
| 22137 | | ConstExprValue **inner_fields = alloc_const_vals_ptrs(3); |
| 22175 | ZigValue **inner_fields = alloc_const_vals_ptrs(3); |
| 22138 | 22176 | inner_fields[1]->special = ConstValSpecialStatic; |
| 22139 | 22177 | inner_fields[1]->type = get_optional_type(ira->codegen, type_info_enum_field_type); |
| 22140 | 22178 | |
| ... | ... | @@ -22149,7 +22187,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 22149 | 22187 | inner_fields[2]->type = ira->codegen->builtin_types.entry_type; |
| 22150 | 22188 | inner_fields[2]->data.x_type = union_field->type_entry; |
| 22151 | 22189 | |
| 22152 | | ConstExprValue *name = create_const_str_lit(ira->codegen, union_field->name)->data.x_ptr.data.ref.pointee; |
| 22190 | ZigValue *name = create_const_str_lit(ira->codegen, union_field->name)->data.x_ptr.data.ref.pointee; |
| 22153 | 22191 | init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(union_field->name), true); |
| 22154 | 22192 | |
| 22155 | 22193 | union_field_val->data.x_struct.fields = inner_fields; |
| ... | ... | @@ -22180,7 +22218,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 22180 | 22218 | result->special = ConstValSpecialStatic; |
| 22181 | 22219 | result->type = ir_type_info_get_type(ira, "Struct", nullptr); |
| 22182 | 22220 | |
| 22183 | | ConstExprValue **fields = alloc_const_vals_ptrs(3); |
| 22221 | ZigValue **fields = alloc_const_vals_ptrs(3); |
| 22184 | 22222 | result->data.x_struct.fields = fields; |
| 22185 | 22223 | |
| 22186 | 22224 | // layout: ContainerLayout |
| ... | ... | @@ -22197,7 +22235,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 22197 | 22235 | } |
| 22198 | 22236 | uint32_t struct_field_count = type_entry->data.structure.src_field_count; |
| 22199 | 22237 | |
| 22200 | | ConstExprValue *struct_field_array = create_const_vals(1); |
| 22238 | ZigValue *struct_field_array = create_const_vals(1); |
| 22201 | 22239 | struct_field_array->special = ConstValSpecialStatic; |
| 22202 | 22240 | struct_field_array->type = get_array_type(ira->codegen, type_info_struct_field_type, struct_field_count, nullptr); |
| 22203 | 22241 | struct_field_array->data.x_array.special = ConstArraySpecialNone; |
| ... | ... | @@ -22207,12 +22245,12 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 22207 | 22245 | |
| 22208 | 22246 | for (uint32_t struct_field_index = 0; struct_field_index < struct_field_count; struct_field_index++) { |
| 22209 | 22247 | TypeStructField *struct_field = type_entry->data.structure.fields[struct_field_index]; |
| 22210 | | ConstExprValue *struct_field_val = &struct_field_array->data.x_array.data.s_none.elements[struct_field_index]; |
| 22248 | ZigValue *struct_field_val = &struct_field_array->data.x_array.data.s_none.elements[struct_field_index]; |
| 22211 | 22249 | |
| 22212 | 22250 | struct_field_val->special = ConstValSpecialStatic; |
| 22213 | 22251 | struct_field_val->type = type_info_struct_field_type; |
| 22214 | 22252 | |
| 22215 | | ConstExprValue **inner_fields = alloc_const_vals_ptrs(3); |
| 22253 | ZigValue **inner_fields = alloc_const_vals_ptrs(3); |
| 22216 | 22254 | inner_fields[1]->special = ConstValSpecialStatic; |
| 22217 | 22255 | inner_fields[1]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_num_lit_int); |
| 22218 | 22256 | |
| ... | ... | @@ -22235,7 +22273,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 22235 | 22273 | inner_fields[2]->type = ira->codegen->builtin_types.entry_type; |
| 22236 | 22274 | inner_fields[2]->data.x_type = struct_field->type_entry; |
| 22237 | 22275 | |
| 22238 | | ConstExprValue *name = create_const_str_lit(ira->codegen, struct_field->name)->data.x_ptr.data.ref.pointee; |
| 22276 | ZigValue *name = create_const_str_lit(ira->codegen, struct_field->name)->data.x_ptr.data.ref.pointee; |
| 22239 | 22277 | init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(struct_field->name), true); |
| 22240 | 22278 | |
| 22241 | 22279 | struct_field_val->data.x_struct.fields = inner_fields; |
| ... | ... | @@ -22259,7 +22297,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 22259 | 22297 | result->special = ConstValSpecialStatic; |
| 22260 | 22298 | result->type = ir_type_info_get_type(ira, "Fn", nullptr); |
| 22261 | 22299 | |
| 22262 | | ConstExprValue **fields = alloc_const_vals_ptrs(5); |
| 22300 | ZigValue **fields = alloc_const_vals_ptrs(5); |
| 22263 | 22301 | result->data.x_struct.fields = fields; |
| 22264 | 22302 | |
| 22265 | 22303 | // calling_convention: TypeInfo.CallingConvention |
| ... | ... | @@ -22286,7 +22324,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 22286 | 22324 | if (type_entry->data.fn.fn_type_id.return_type == nullptr) |
| 22287 | 22325 | fields[3]->data.x_optional = nullptr; |
| 22288 | 22326 | else { |
| 22289 | | ConstExprValue *return_type = create_const_vals(1); |
| 22327 | ZigValue *return_type = create_const_vals(1); |
| 22290 | 22328 | return_type->special = ConstValSpecialStatic; |
| 22291 | 22329 | return_type->type = ira->codegen->builtin_types.entry_type; |
| 22292 | 22330 | return_type->data.x_type = type_entry->data.fn.fn_type_id.return_type; |
| ... | ... | @@ -22300,7 +22338,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 22300 | 22338 | size_t fn_arg_count = type_entry->data.fn.fn_type_id.param_count - |
| 22301 | 22339 | (is_varargs && type_entry->data.fn.fn_type_id.cc != CallingConventionC); |
| 22302 | 22340 | |
| 22303 | | ConstExprValue *fn_arg_array = create_const_vals(1); |
| 22341 | ZigValue *fn_arg_array = create_const_vals(1); |
| 22304 | 22342 | fn_arg_array->special = ConstValSpecialStatic; |
| 22305 | 22343 | fn_arg_array->type = get_array_type(ira->codegen, type_info_fn_arg_type, fn_arg_count, nullptr); |
| 22306 | 22344 | fn_arg_array->data.x_array.special = ConstArraySpecialNone; |
| ... | ... | @@ -22310,7 +22348,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 22310 | 22348 | |
| 22311 | 22349 | for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) { |
| 22312 | 22350 | FnTypeParamInfo *fn_param_info = &type_entry->data.fn.fn_type_id.param_info[fn_arg_index]; |
| 22313 | | ConstExprValue *fn_arg_val = &fn_arg_array->data.x_array.data.s_none.elements[fn_arg_index]; |
| 22351 | ZigValue *fn_arg_val = &fn_arg_array->data.x_array.data.s_none.elements[fn_arg_index]; |
| 22314 | 22352 | |
| 22315 | 22353 | fn_arg_val->special = ConstValSpecialStatic; |
| 22316 | 22354 | fn_arg_val->type = type_info_fn_arg_type; |
| ... | ... | @@ -22318,7 +22356,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 22318 | 22356 | bool arg_is_generic = fn_param_info->type == nullptr; |
| 22319 | 22357 | if (arg_is_generic) assert(is_generic); |
| 22320 | 22358 | |
| 22321 | | ConstExprValue **inner_fields = alloc_const_vals_ptrs(3); |
| 22359 | ZigValue **inner_fields = alloc_const_vals_ptrs(3); |
| 22322 | 22360 | inner_fields[0]->special = ConstValSpecialStatic; |
| 22323 | 22361 | inner_fields[0]->type = ira->codegen->builtin_types.entry_bool; |
| 22324 | 22362 | inner_fields[0]->data.x_bool = arg_is_generic; |
| ... | ... | @@ -22331,7 +22369,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr |
| 22331 | 22369 | if (arg_is_generic) |
| 22332 | 22370 | inner_fields[2]->data.x_optional = nullptr; |
| 22333 | 22371 | else { |
| 22334 | | ConstExprValue *arg_type = create_const_vals(1); |
| 22372 | ZigValue *arg_type = create_const_vals(1); |
| 22335 | 22373 | arg_type->special = ConstValSpecialStatic; |
| 22336 | 22374 | arg_type->type = ira->codegen->builtin_types.entry_type; |
| 22337 | 22375 | arg_type->data.x_type = fn_param_info->type; |
| ... | ... | @@ -22376,12 +22414,12 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira, |
| 22376 | 22414 | |
| 22377 | 22415 | ZigType *result_type = ir_type_info_get_type(ira, nullptr, nullptr); |
| 22378 | 22416 | |
| 22379 | | ConstExprValue *payload; |
| 22417 | ZigValue *payload; |
| 22380 | 22418 | if ((err = ir_make_type_info_value(ira, &instruction->base, type_entry, &payload))) |
| 22381 | 22419 | return ira->codegen->invalid_instruction; |
| 22382 | 22420 | |
| 22383 | 22421 | IrInstruction *result = ir_const(ira, &instruction->base, result_type); |
| 22384 | | ConstExprValue *out_val = &result->value; |
| 22422 | ZigValue *out_val = result->value; |
| 22385 | 22423 | bigint_init_unsigned(&out_val->data.x_union.tag, type_id_index(type_entry)); |
| 22386 | 22424 | out_val->data.x_union.payload = payload; |
| 22387 | 22425 | |
| ... | ... | @@ -22393,49 +22431,49 @@ static IrInstruction *ir_analyze_instruction_type_info(IrAnalyze *ira, |
| 22393 | 22431 | return result; |
| 22394 | 22432 | } |
| 22395 | 22433 | |
| 22396 | | static ConstExprValue *get_const_field(IrAnalyze *ira, ConstExprValue *struct_value, const char *name, size_t field_index) |
| 22434 | static ZigValue *get_const_field(IrAnalyze *ira, ZigValue *struct_value, const char *name, size_t field_index) |
| 22397 | 22435 | { |
| 22398 | 22436 | ensure_field_index(struct_value->type, name, field_index); |
| 22399 | 22437 | assert(struct_value->data.x_struct.fields[field_index]->special == ConstValSpecialStatic); |
| 22400 | 22438 | return struct_value->data.x_struct.fields[field_index]; |
| 22401 | 22439 | } |
| 22402 | 22440 | |
| 22403 | | static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_instr, ConstExprValue *struct_value, |
| 22404 | | const char *name, size_t field_index, ZigType *elem_type, ConstExprValue **result) |
| 22441 | static Error get_const_field_sentinel(IrAnalyze *ira, IrInstruction *source_instr, ZigValue *struct_value, |
| 22442 | const char *name, size_t field_index, ZigType *elem_type, ZigValue **result) |
| 22405 | 22443 | { |
| 22406 | | ConstExprValue *field_val = get_const_field(ira, struct_value, name, field_index); |
| 22444 | ZigValue *field_val = get_const_field(ira, struct_value, name, field_index); |
| 22407 | 22445 | IrInstruction *field_inst = ir_const(ira, source_instr, field_val->type); |
| 22408 | 22446 | IrInstruction *casted_field_inst = ir_implicit_cast(ira, field_inst, |
| 22409 | 22447 | get_optional_type(ira->codegen, elem_type)); |
| 22410 | | if (type_is_invalid(casted_field_inst->value.type)) |
| 22448 | if (type_is_invalid(casted_field_inst->value->type)) |
| 22411 | 22449 | return ErrorSemanticAnalyzeFail; |
| 22412 | 22450 | |
| 22413 | | *result = casted_field_inst->value.data.x_optional; |
| 22451 | *result = casted_field_inst->value->data.x_optional; |
| 22414 | 22452 | return ErrorNone; |
| 22415 | 22453 | } |
| 22416 | 22454 | |
| 22417 | | static bool get_const_field_bool(IrAnalyze *ira, ConstExprValue *struct_value, const char *name, size_t field_index) |
| 22455 | static bool get_const_field_bool(IrAnalyze *ira, ZigValue *struct_value, const char *name, size_t field_index) |
| 22418 | 22456 | { |
| 22419 | | ConstExprValue *value = get_const_field(ira, struct_value, name, field_index); |
| 22457 | ZigValue *value = get_const_field(ira, struct_value, name, field_index); |
| 22420 | 22458 | assert(value->type == ira->codegen->builtin_types.entry_bool); |
| 22421 | 22459 | return value->data.x_bool; |
| 22422 | 22460 | } |
| 22423 | 22461 | |
| 22424 | | static BigInt *get_const_field_lit_int(IrAnalyze *ira, ConstExprValue *struct_value, const char *name, size_t field_index) |
| 22462 | static BigInt *get_const_field_lit_int(IrAnalyze *ira, ZigValue *struct_value, const char *name, size_t field_index) |
| 22425 | 22463 | { |
| 22426 | | ConstExprValue *value = get_const_field(ira, struct_value, name, field_index); |
| 22464 | ZigValue *value = get_const_field(ira, struct_value, name, field_index); |
| 22427 | 22465 | assert(value->type == ira->codegen->builtin_types.entry_num_lit_int); |
| 22428 | 22466 | return &value->data.x_bigint; |
| 22429 | 22467 | } |
| 22430 | 22468 | |
| 22431 | | static ZigType *get_const_field_meta_type(IrAnalyze *ira, ConstExprValue *struct_value, const char *name, size_t field_index) |
| 22469 | static ZigType *get_const_field_meta_type(IrAnalyze *ira, ZigValue *struct_value, const char *name, size_t field_index) |
| 22432 | 22470 | { |
| 22433 | | ConstExprValue *value = get_const_field(ira, struct_value, name, field_index); |
| 22471 | ZigValue *value = get_const_field(ira, struct_value, name, field_index); |
| 22434 | 22472 | assert(value->type == ira->codegen->builtin_types.entry_type); |
| 22435 | 22473 | return value->data.x_type; |
| 22436 | 22474 | } |
| 22437 | 22475 | |
| 22438 | | static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, ZigTypeId tagTypeId, ConstExprValue *payload) { |
| 22476 | static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, ZigTypeId tagTypeId, ZigValue *payload) { |
| 22439 | 22477 | Error err; |
| 22440 | 22478 | switch (tagTypeId) { |
| 22441 | 22479 | case ZigTypeIdInvalid: |
| ... | ... | @@ -22474,12 +22512,12 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi |
| 22474 | 22512 | ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr); |
| 22475 | 22513 | assert(payload->special == ConstValSpecialStatic); |
| 22476 | 22514 | assert(payload->type == type_info_pointer_type); |
| 22477 | | ConstExprValue *size_value = get_const_field(ira, payload, "size", 0); |
| 22515 | ZigValue *size_value = get_const_field(ira, payload, "size", 0); |
| 22478 | 22516 | assert(size_value->type == ir_type_info_get_type(ira, "Size", type_info_pointer_type)); |
| 22479 | 22517 | BuiltinPtrSize size_enum_index = (BuiltinPtrSize)bigint_as_u32(&size_value->data.x_enum_tag); |
| 22480 | 22518 | PtrLen ptr_len = size_enum_index_to_ptr_len(size_enum_index); |
| 22481 | 22519 | ZigType *elem_type = get_const_field_meta_type(ira, payload, "child", 4); |
| 22482 | | ConstExprValue *sentinel; |
| 22520 | ZigValue *sentinel; |
| 22483 | 22521 | if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 6, |
| 22484 | 22522 | elem_type, &sentinel))) |
| 22485 | 22523 | { |
| ... | ... | @@ -22504,7 +22542,7 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi |
| 22504 | 22542 | assert(payload->special == ConstValSpecialStatic); |
| 22505 | 22543 | assert(payload->type == ir_type_info_get_type(ira, "Array", nullptr)); |
| 22506 | 22544 | ZigType *elem_type = get_const_field_meta_type(ira, payload, "child", 1); |
| 22507 | | ConstExprValue *sentinel; |
| 22545 | ZigValue *sentinel; |
| 22508 | 22546 | if ((err = get_const_field_sentinel(ira, instruction, payload, "sentinel", 2, |
| 22509 | 22547 | elem_type, &sentinel))) |
| 22510 | 22548 | { |
| ... | ... | @@ -22549,14 +22587,14 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi |
| 22549 | 22587 | |
| 22550 | 22588 | static IrInstruction *ir_analyze_instruction_type(IrAnalyze *ira, IrInstructionType *instruction) { |
| 22551 | 22589 | IrInstruction *type_info_ir = instruction->type_info->child; |
| 22552 | | if (type_is_invalid(type_info_ir->value.type)) |
| 22590 | if (type_is_invalid(type_info_ir->value->type)) |
| 22553 | 22591 | return ira->codegen->invalid_instruction; |
| 22554 | 22592 | |
| 22555 | 22593 | IrInstruction *casted_ir = ir_implicit_cast(ira, type_info_ir, ir_type_info_get_type(ira, nullptr, nullptr)); |
| 22556 | | if (type_is_invalid(casted_ir->value.type)) |
| 22594 | if (type_is_invalid(casted_ir->value->type)) |
| 22557 | 22595 | return ira->codegen->invalid_instruction; |
| 22558 | 22596 | |
| 22559 | | ConstExprValue *type_info_value = ir_resolve_const(ira, casted_ir, UndefBad); |
| 22597 | ZigValue *type_info_value = ir_resolve_const(ira, casted_ir, UndefBad); |
| 22560 | 22598 | if (!type_info_value) |
| 22561 | 22599 | return ira->codegen->invalid_instruction; |
| 22562 | 22600 | ZigTypeId typeId = type_id_at_index(bigint_as_usize(&type_info_value->data.x_union.tag)); |
| ... | ... | @@ -22574,12 +22612,12 @@ static IrInstruction *ir_analyze_instruction_type_id(IrAnalyze *ira, |
| 22574 | 22612 | if (type_is_invalid(type_entry)) |
| 22575 | 22613 | return ira->codegen->invalid_instruction; |
| 22576 | 22614 | |
| 22577 | | ConstExprValue *var_value = get_builtin_value(ira->codegen, "TypeId"); |
| 22615 | ZigValue *var_value = get_builtin_value(ira->codegen, "TypeId"); |
| 22578 | 22616 | assert(var_value->type->id == ZigTypeIdMetaType); |
| 22579 | 22617 | ZigType *result_type = var_value->data.x_type; |
| 22580 | 22618 | |
| 22581 | 22619 | IrInstruction *result = ir_const(ira, &instruction->base, result_type); |
| 22582 | | bigint_init_unsigned(&result->value.data.x_enum_tag, type_id_index(type_entry)); |
| 22620 | bigint_init_unsigned(&result->value->data.x_enum_tag, type_id_index(type_entry)); |
| 22583 | 22621 | return result; |
| 22584 | 22622 | } |
| 22585 | 22623 | |
| ... | ... | @@ -22607,7 +22645,7 @@ static IrInstruction *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstruc |
| 22607 | 22645 | type_entry->cached_const_name_val = create_const_str_lit(ira->codegen, type_bare_name(type_entry)); |
| 22608 | 22646 | } |
| 22609 | 22647 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 22610 | | copy_const_val(&result->value, type_entry->cached_const_name_val, true); |
| 22648 | copy_const_val(result->value, type_entry->cached_const_name_val, true); |
| 22611 | 22649 | return result; |
| 22612 | 22650 | } |
| 22613 | 22651 | |
| ... | ... | @@ -22628,7 +22666,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct |
| 22628 | 22666 | |
| 22629 | 22667 | // Execute the C import block like an inline function |
| 22630 | 22668 | ZigType *void_type = ira->codegen->builtin_types.entry_void; |
| 22631 | | ConstExprValue *cimport_result = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, void_type, |
| 22669 | ZigValue *cimport_result = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, void_type, |
| 22632 | 22670 | ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr, |
| 22633 | 22671 | &cimport_scope->buf, block_node, nullptr, nullptr, nullptr, UndefBad); |
| 22634 | 22672 | if (type_is_invalid(cimport_result->type)) |
| ... | ... | @@ -22796,7 +22834,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct |
| 22796 | 22834 | |
| 22797 | 22835 | static IrInstruction *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCInclude *instruction) { |
| 22798 | 22836 | IrInstruction *name_value = instruction->name->child; |
| 22799 | | if (type_is_invalid(name_value->value.type)) |
| 22837 | if (type_is_invalid(name_value->value->type)) |
| 22800 | 22838 | return ira->codegen->invalid_instruction; |
| 22801 | 22839 | |
| 22802 | 22840 | Buf *include_name = ir_resolve_str(ira, name_value); |
| ... | ... | @@ -22814,7 +22852,7 @@ static IrInstruction *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstruc |
| 22814 | 22852 | |
| 22815 | 22853 | static IrInstruction *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstructionCDefine *instruction) { |
| 22816 | 22854 | IrInstruction *name = instruction->name->child; |
| 22817 | | if (type_is_invalid(name->value.type)) |
| 22855 | if (type_is_invalid(name->value->type)) |
| 22818 | 22856 | return ira->codegen->invalid_instruction; |
| 22819 | 22857 | |
| 22820 | 22858 | Buf *define_name = ir_resolve_str(ira, name); |
| ... | ... | @@ -22822,12 +22860,12 @@ static IrInstruction *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstruct |
| 22822 | 22860 | return ira->codegen->invalid_instruction; |
| 22823 | 22861 | |
| 22824 | 22862 | IrInstruction *value = instruction->value->child; |
| 22825 | | if (type_is_invalid(value->value.type)) |
| 22863 | if (type_is_invalid(value->value->type)) |
| 22826 | 22864 | return ira->codegen->invalid_instruction; |
| 22827 | 22865 | |
| 22828 | 22866 | Buf *define_value = nullptr; |
| 22829 | 22867 | // The second parameter is either a string or void (equivalent to "") |
| 22830 | | if (value->value.type->id != ZigTypeIdVoid) { |
| 22868 | if (value->value->type->id != ZigTypeIdVoid) { |
| 22831 | 22869 | define_value = ir_resolve_str(ira, value); |
| 22832 | 22870 | if (!define_value) |
| 22833 | 22871 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -22845,7 +22883,7 @@ static IrInstruction *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstruct |
| 22845 | 22883 | |
| 22846 | 22884 | static IrInstruction *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructionCUndef *instruction) { |
| 22847 | 22885 | IrInstruction *name = instruction->name->child; |
| 22848 | | if (type_is_invalid(name->value.type)) |
| 22886 | if (type_is_invalid(name->value->type)) |
| 22849 | 22887 | return ira->codegen->invalid_instruction; |
| 22850 | 22888 | |
| 22851 | 22889 | Buf *undef_name = ir_resolve_str(ira, name); |
| ... | ... | @@ -22863,7 +22901,7 @@ static IrInstruction *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructi |
| 22863 | 22901 | |
| 22864 | 22902 | static IrInstruction *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstructionEmbedFile *instruction) { |
| 22865 | 22903 | IrInstruction *name = instruction->name->child; |
| 22866 | | if (type_is_invalid(name->value.type)) |
| 22904 | if (type_is_invalid(name->value->type)) |
| 22867 | 22905 | return ira->codegen->invalid_instruction; |
| 22868 | 22906 | |
| 22869 | 22907 | Buf *rel_file_path = ir_resolve_str(ira, name); |
| ... | ... | @@ -22898,7 +22936,7 @@ static IrInstruction *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstru |
| 22898 | 22936 | ZigType *result_type = get_array_type(ira->codegen, |
| 22899 | 22937 | ira->codegen->builtin_types.entry_u8, buf_len(file_contents), nullptr); |
| 22900 | 22938 | IrInstruction *result = ir_const(ira, &instruction->base, result_type); |
| 22901 | | init_const_str_lit(ira->codegen, &result->value, file_contents); |
| 22939 | init_const_str_lit(ira->codegen, result->value, file_contents); |
| 22902 | 22940 | return result; |
| 22903 | 22941 | } |
| 22904 | 22942 | |
| ... | ... | @@ -22908,25 +22946,25 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi |
| 22908 | 22946 | return ira->codegen->invalid_instruction; |
| 22909 | 22947 | |
| 22910 | 22948 | IrInstruction *ptr = instruction->ptr->child; |
| 22911 | | if (type_is_invalid(ptr->value.type)) |
| 22949 | if (type_is_invalid(ptr->value->type)) |
| 22912 | 22950 | return ira->codegen->invalid_instruction; |
| 22913 | 22951 | |
| 22914 | 22952 | // TODO let this be volatile |
| 22915 | 22953 | ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false); |
| 22916 | 22954 | IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr, ptr_type); |
| 22917 | | if (type_is_invalid(casted_ptr->value.type)) |
| 22955 | if (type_is_invalid(casted_ptr->value->type)) |
| 22918 | 22956 | return ira->codegen->invalid_instruction; |
| 22919 | 22957 | |
| 22920 | 22958 | IrInstruction *cmp_value = instruction->cmp_value->child; |
| 22921 | | if (type_is_invalid(cmp_value->value.type)) |
| 22959 | if (type_is_invalid(cmp_value->value->type)) |
| 22922 | 22960 | return ira->codegen->invalid_instruction; |
| 22923 | 22961 | |
| 22924 | 22962 | IrInstruction *new_value = instruction->new_value->child; |
| 22925 | | if (type_is_invalid(new_value->value.type)) |
| 22963 | if (type_is_invalid(new_value->value->type)) |
| 22926 | 22964 | return ira->codegen->invalid_instruction; |
| 22927 | 22965 | |
| 22928 | 22966 | IrInstruction *success_order_value = instruction->success_order_value->child; |
| 22929 | | if (type_is_invalid(success_order_value->value.type)) |
| 22967 | if (type_is_invalid(success_order_value->value->type)) |
| 22930 | 22968 | return ira->codegen->invalid_instruction; |
| 22931 | 22969 | |
| 22932 | 22970 | AtomicOrder success_order; |
| ... | ... | @@ -22934,7 +22972,7 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi |
| 22934 | 22972 | return ira->codegen->invalid_instruction; |
| 22935 | 22973 | |
| 22936 | 22974 | IrInstruction *failure_order_value = instruction->failure_order_value->child; |
| 22937 | | if (type_is_invalid(failure_order_value->value.type)) |
| 22975 | if (type_is_invalid(failure_order_value->value->type)) |
| 22938 | 22976 | return ira->codegen->invalid_instruction; |
| 22939 | 22977 | |
| 22940 | 22978 | AtomicOrder failure_order; |
| ... | ... | @@ -22942,11 +22980,11 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi |
| 22942 | 22980 | return ira->codegen->invalid_instruction; |
| 22943 | 22981 | |
| 22944 | 22982 | IrInstruction *casted_cmp_value = ir_implicit_cast(ira, cmp_value, operand_type); |
| 22945 | | if (type_is_invalid(casted_cmp_value->value.type)) |
| 22983 | if (type_is_invalid(casted_cmp_value->value->type)) |
| 22946 | 22984 | return ira->codegen->invalid_instruction; |
| 22947 | 22985 | |
| 22948 | 22986 | IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, operand_type); |
| 22949 | | if (type_is_invalid(casted_new_value->value.type)) |
| 22987 | if (type_is_invalid(casted_new_value->value->type)) |
| 22950 | 22988 | return ira->codegen->invalid_instruction; |
| 22951 | 22989 | |
| 22952 | 22990 | if (success_order < AtomicOrderMonotonic) { |
| ... | ... | @@ -22970,7 +23008,7 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi |
| 22970 | 23008 | return ira->codegen->invalid_instruction; |
| 22971 | 23009 | } |
| 22972 | 23010 | |
| 22973 | | if (instr_is_comptime(casted_ptr) && casted_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar && |
| 23011 | if (instr_is_comptime(casted_ptr) && casted_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar && |
| 22974 | 23012 | instr_is_comptime(casted_cmp_value) && instr_is_comptime(casted_new_value)) { |
| 22975 | 23013 | zig_panic("TODO compile-time execution of cmpxchg"); |
| 22976 | 23014 | } |
| ... | ... | @@ -22980,7 +23018,7 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi |
| 22980 | 23018 | if (handle_is_ptr(result_type)) { |
| 22981 | 23019 | result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 22982 | 23020 | result_type, nullptr, true, false, true); |
| 22983 | | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { |
| 23021 | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 22984 | 23022 | return result_loc; |
| 22985 | 23023 | } |
| 22986 | 23024 | } else { |
| ... | ... | @@ -22994,7 +23032,7 @@ static IrInstruction *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructi |
| 22994 | 23032 | |
| 22995 | 23033 | static IrInstruction *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructionFence *instruction) { |
| 22996 | 23034 | IrInstruction *order_value = instruction->order_value->child; |
| 22997 | | if (type_is_invalid(order_value->value.type)) |
| 23035 | if (type_is_invalid(order_value->value->type)) |
| 22998 | 23036 | return ira->codegen->invalid_instruction; |
| 22999 | 23037 | |
| 23000 | 23038 | AtomicOrder order; |
| ... | ... | @@ -23009,7 +23047,7 @@ static IrInstruction *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstruction |
| 23009 | 23047 | |
| 23010 | 23048 | IrInstruction *result = ir_build_fence(&ira->new_irb, |
| 23011 | 23049 | instruction->base.scope, instruction->base.source_node, order_value, order); |
| 23012 | | result->value.type = ira->codegen->builtin_types.entry_void; |
| 23050 | result->value->type = ira->codegen->builtin_types.entry_void; |
| 23013 | 23051 | return result; |
| 23014 | 23052 | } |
| 23015 | 23053 | |
| ... | ... | @@ -23027,7 +23065,7 @@ static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruct |
| 23027 | 23065 | } |
| 23028 | 23066 | |
| 23029 | 23067 | IrInstruction *target = instruction->target->child; |
| 23030 | | ZigType *src_type = target->value.type; |
| 23068 | ZigType *src_type = target->value->type; |
| 23031 | 23069 | if (type_is_invalid(src_type)) |
| 23032 | 23070 | return ira->codegen->invalid_instruction; |
| 23033 | 23071 | |
| ... | ... | @@ -23043,19 +23081,19 @@ static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruct |
| 23043 | 23081 | } |
| 23044 | 23082 | |
| 23045 | 23083 | if (instr_is_comptime(target)) { |
| 23046 | | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); |
| 23084 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 23047 | 23085 | if (val == nullptr) |
| 23048 | 23086 | return ira->codegen->invalid_instruction; |
| 23049 | 23087 | |
| 23050 | 23088 | IrInstruction *result = ir_const(ira, &instruction->base, dest_type); |
| 23051 | | bigint_truncate(&result->value.data.x_bigint, &val->data.x_bigint, |
| 23089 | bigint_truncate(&result->value->data.x_bigint, &val->data.x_bigint, |
| 23052 | 23090 | dest_type->data.integral.bit_count, dest_type->data.integral.is_signed); |
| 23053 | 23091 | return result; |
| 23054 | 23092 | } |
| 23055 | 23093 | |
| 23056 | 23094 | if (src_type->data.integral.bit_count == 0 || dest_type->data.integral.bit_count == 0) { |
| 23057 | 23095 | IrInstruction *result = ir_const(ira, &instruction->base, dest_type); |
| 23058 | | bigint_init_unsigned(&result->value.data.x_bigint, 0); |
| 23096 | bigint_init_unsigned(&result->value->data.x_bigint, 0); |
| 23059 | 23097 | return result; |
| 23060 | 23098 | } |
| 23061 | 23099 | |
| ... | ... | @@ -23071,7 +23109,7 @@ static IrInstruction *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruct |
| 23071 | 23109 | |
| 23072 | 23110 | IrInstruction *new_instruction = ir_build_truncate(&ira->new_irb, instruction->base.scope, |
| 23073 | 23111 | instruction->base.source_node, dest_type_value, target); |
| 23074 | | new_instruction->value.type = dest_type; |
| 23112 | new_instruction->value->type = dest_type; |
| 23075 | 23113 | return new_instruction; |
| 23076 | 23114 | } |
| 23077 | 23115 | |
| ... | ... | @@ -23086,12 +23124,12 @@ static IrInstruction *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruct |
| 23086 | 23124 | } |
| 23087 | 23125 | |
| 23088 | 23126 | IrInstruction *target = instruction->target->child; |
| 23089 | | if (type_is_invalid(target->value.type)) |
| 23127 | if (type_is_invalid(target->value->type)) |
| 23090 | 23128 | return ira->codegen->invalid_instruction; |
| 23091 | 23129 | |
| 23092 | | if (target->value.type->id != ZigTypeIdInt && target->value.type->id != ZigTypeIdComptimeInt) { |
| 23130 | if (target->value->type->id != ZigTypeIdInt && target->value->type->id != ZigTypeIdComptimeInt) { |
| 23093 | 23131 | ir_add_error(ira, instruction->target, buf_sprintf("expected integer type, found '%s'", |
| 23094 | | buf_ptr(&target->value.type->name))); |
| 23132 | buf_ptr(&target->value->type->name))); |
| 23095 | 23133 | return ira->codegen->invalid_instruction; |
| 23096 | 23134 | } |
| 23097 | 23135 | |
| ... | ... | @@ -23120,15 +23158,15 @@ static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstru |
| 23120 | 23158 | } |
| 23121 | 23159 | |
| 23122 | 23160 | IrInstruction *target = instruction->target->child; |
| 23123 | | if (type_is_invalid(target->value.type)) |
| 23161 | if (type_is_invalid(target->value->type)) |
| 23124 | 23162 | return ira->codegen->invalid_instruction; |
| 23125 | 23163 | |
| 23126 | | if (target->value.type->id == ZigTypeIdComptimeInt || |
| 23127 | | target->value.type->id == ZigTypeIdComptimeFloat) |
| 23164 | if (target->value->type->id == ZigTypeIdComptimeInt || |
| 23165 | target->value->type->id == ZigTypeIdComptimeFloat) |
| 23128 | 23166 | { |
| 23129 | 23167 | if (ir_num_lit_fits_in_other_type(ira, target, dest_type, true)) { |
| 23130 | 23168 | CastOp op; |
| 23131 | | if (target->value.type->id == ZigTypeIdComptimeInt) { |
| 23169 | if (target->value->type->id == ZigTypeIdComptimeInt) { |
| 23132 | 23170 | op = CastOpIntToFloat; |
| 23133 | 23171 | } else { |
| 23134 | 23172 | op = CastOpNumLitToConcrete; |
| ... | ... | @@ -23139,9 +23177,9 @@ static IrInstruction *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstru |
| 23139 | 23177 | } |
| 23140 | 23178 | } |
| 23141 | 23179 | |
| 23142 | | if (target->value.type->id != ZigTypeIdFloat) { |
| 23180 | if (target->value->type->id != ZigTypeIdFloat) { |
| 23143 | 23181 | ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'", |
| 23144 | | buf_ptr(&target->value.type->name))); |
| 23182 | buf_ptr(&target->value->type->name))); |
| 23145 | 23183 | return ira->codegen->invalid_instruction; |
| 23146 | 23184 | } |
| 23147 | 23185 | |
| ... | ... | @@ -23160,12 +23198,12 @@ static IrInstruction *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInst |
| 23160 | 23198 | } |
| 23161 | 23199 | |
| 23162 | 23200 | IrInstruction *target = instruction->target->child; |
| 23163 | | if (type_is_invalid(target->value.type)) |
| 23201 | if (type_is_invalid(target->value->type)) |
| 23164 | 23202 | return ira->codegen->invalid_instruction; |
| 23165 | 23203 | |
| 23166 | | if (target->value.type->id != ZigTypeIdErrorSet) { |
| 23204 | if (target->value->type->id != ZigTypeIdErrorSet) { |
| 23167 | 23205 | ir_add_error(ira, instruction->target, |
| 23168 | | buf_sprintf("expected error set type, found '%s'", buf_ptr(&target->value.type->name))); |
| 23206 | buf_sprintf("expected error set type, found '%s'", buf_ptr(&target->value->type->name))); |
| 23169 | 23207 | return ira->codegen->invalid_instruction; |
| 23170 | 23208 | } |
| 23171 | 23209 | |
| ... | ... | @@ -23180,20 +23218,20 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru |
| 23180 | 23218 | return ira->codegen->invalid_instruction; |
| 23181 | 23219 | |
| 23182 | 23220 | IrInstruction *target = instruction->target->child; |
| 23183 | | if (type_is_invalid(target->value.type)) |
| 23221 | if (type_is_invalid(target->value->type)) |
| 23184 | 23222 | return ira->codegen->invalid_instruction; |
| 23185 | 23223 | |
| 23186 | 23224 | bool src_ptr_const; |
| 23187 | 23225 | bool src_ptr_volatile; |
| 23188 | 23226 | uint32_t src_ptr_align; |
| 23189 | | if (target->value.type->id == ZigTypeIdPointer) { |
| 23190 | | src_ptr_const = target->value.type->data.pointer.is_const; |
| 23191 | | src_ptr_volatile = target->value.type->data.pointer.is_volatile; |
| 23227 | if (target->value->type->id == ZigTypeIdPointer) { |
| 23228 | src_ptr_const = target->value->type->data.pointer.is_const; |
| 23229 | src_ptr_volatile = target->value->type->data.pointer.is_volatile; |
| 23192 | 23230 | |
| 23193 | | if ((err = resolve_ptr_align(ira, target->value.type, &src_ptr_align))) |
| 23231 | if ((err = resolve_ptr_align(ira, target->value->type, &src_ptr_align))) |
| 23194 | 23232 | return ira->codegen->invalid_instruction; |
| 23195 | | } else if (is_slice(target->value.type)) { |
| 23196 | | ZigType *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index]->type_entry; |
| 23233 | } else if (is_slice(target->value->type)) { |
| 23234 | ZigType *src_ptr_type = target->value->type->data.structure.fields[slice_ptr_index]->type_entry; |
| 23197 | 23235 | src_ptr_const = src_ptr_type->data.pointer.is_const; |
| 23198 | 23236 | src_ptr_volatile = src_ptr_type->data.pointer.is_volatile; |
| 23199 | 23237 | |
| ... | ... | @@ -23203,10 +23241,10 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru |
| 23203 | 23241 | src_ptr_const = true; |
| 23204 | 23242 | src_ptr_volatile = false; |
| 23205 | 23243 | |
| 23206 | | if ((err = type_resolve(ira->codegen, target->value.type, ResolveStatusAlignmentKnown))) |
| 23244 | if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusAlignmentKnown))) |
| 23207 | 23245 | return ira->codegen->invalid_instruction; |
| 23208 | 23246 | |
| 23209 | | src_ptr_align = get_abi_alignment(ira->codegen, target->value.type); |
| 23247 | src_ptr_align = get_abi_alignment(ira->codegen, target->value->type); |
| 23210 | 23248 | } |
| 23211 | 23249 | |
| 23212 | 23250 | if (src_ptr_align != 0) { |
| ... | ... | @@ -23225,18 +23263,18 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru |
| 23225 | 23263 | ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr); |
| 23226 | 23264 | |
| 23227 | 23265 | IrInstruction *casted_value = ir_implicit_cast(ira, target, u8_slice); |
| 23228 | | if (type_is_invalid(casted_value->value.type)) |
| 23266 | if (type_is_invalid(casted_value->value->type)) |
| 23229 | 23267 | return ira->codegen->invalid_instruction; |
| 23230 | 23268 | |
| 23231 | 23269 | bool have_known_len = false; |
| 23232 | 23270 | uint64_t known_len; |
| 23233 | 23271 | |
| 23234 | 23272 | if (instr_is_comptime(casted_value)) { |
| 23235 | | ConstExprValue *val = ir_resolve_const(ira, casted_value, UndefBad); |
| 23273 | ZigValue *val = ir_resolve_const(ira, casted_value, UndefBad); |
| 23236 | 23274 | if (!val) |
| 23237 | 23275 | return ira->codegen->invalid_instruction; |
| 23238 | 23276 | |
| 23239 | | ConstExprValue *len_val = val->data.x_struct.fields[slice_len_index]; |
| 23277 | ZigValue *len_val = val->data.x_struct.fields[slice_len_index]; |
| 23240 | 23278 | if (value_is_comptime(len_val)) { |
| 23241 | 23279 | known_len = bigint_as_u64(&len_val->data.x_bigint); |
| 23242 | 23280 | have_known_len = true; |
| ... | ... | @@ -23245,12 +23283,12 @@ static IrInstruction *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstru |
| 23245 | 23283 | |
| 23246 | 23284 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 23247 | 23285 | dest_slice_type, nullptr, true, false, true); |
| 23248 | | if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc))) { |
| 23286 | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) { |
| 23249 | 23287 | return result_loc; |
| 23250 | 23288 | } |
| 23251 | 23289 | |
| 23252 | | if (casted_value->value.data.rh_slice.id == RuntimeHintSliceIdLen) { |
| 23253 | | known_len = casted_value->value.data.rh_slice.len; |
| 23290 | if (casted_value->value->data.rh_slice.id == RuntimeHintSliceIdLen) { |
| 23291 | known_len = casted_value->value->data.rh_slice.len; |
| 23254 | 23292 | have_known_len = true; |
| 23255 | 23293 | } |
| 23256 | 23294 | |
| ... | ... | @@ -23277,16 +23315,16 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct |
| 23277 | 23315 | Error err; |
| 23278 | 23316 | |
| 23279 | 23317 | IrInstruction *target = instruction->target->child; |
| 23280 | | if (type_is_invalid(target->value.type)) |
| 23318 | if (type_is_invalid(target->value->type)) |
| 23281 | 23319 | return ira->codegen->invalid_instruction; |
| 23282 | 23320 | |
| 23283 | | if (!is_slice(target->value.type)) { |
| 23321 | if (!is_slice(target->value->type)) { |
| 23284 | 23322 | ir_add_error(ira, instruction->target, |
| 23285 | | buf_sprintf("expected slice, found '%s'", buf_ptr(&target->value.type->name))); |
| 23323 | buf_sprintf("expected slice, found '%s'", buf_ptr(&target->value->type->name))); |
| 23286 | 23324 | return ira->codegen->invalid_instruction; |
| 23287 | 23325 | } |
| 23288 | 23326 | |
| 23289 | | ZigType *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index]->type_entry; |
| 23327 | ZigType *src_ptr_type = target->value->type->data.structure.fields[slice_ptr_index]->type_entry; |
| 23290 | 23328 | |
| 23291 | 23329 | uint32_t alignment; |
| 23292 | 23330 | if ((err = resolve_ptr_align(ira, src_ptr_type, &alignment))) |
| ... | ... | @@ -23298,22 +23336,22 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct |
| 23298 | 23336 | ZigType *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type); |
| 23299 | 23337 | |
| 23300 | 23338 | if (instr_is_comptime(target)) { |
| 23301 | | ConstExprValue *target_val = ir_resolve_const(ira, target, UndefBad); |
| 23339 | ZigValue *target_val = ir_resolve_const(ira, target, UndefBad); |
| 23302 | 23340 | if (target_val == nullptr) |
| 23303 | 23341 | return ira->codegen->invalid_instruction; |
| 23304 | 23342 | |
| 23305 | 23343 | IrInstruction *result = ir_const(ira, &instruction->base, dest_slice_type); |
| 23306 | | result->value.data.x_struct.fields = alloc_const_vals_ptrs(2); |
| 23344 | result->value->data.x_struct.fields = alloc_const_vals_ptrs(2); |
| 23307 | 23345 | |
| 23308 | | ConstExprValue *ptr_val = result->value.data.x_struct.fields[slice_ptr_index]; |
| 23309 | | ConstExprValue *target_ptr_val = target_val->data.x_struct.fields[slice_ptr_index]; |
| 23346 | ZigValue *ptr_val = result->value->data.x_struct.fields[slice_ptr_index]; |
| 23347 | ZigValue *target_ptr_val = target_val->data.x_struct.fields[slice_ptr_index]; |
| 23310 | 23348 | copy_const_val(ptr_val, target_ptr_val, false); |
| 23311 | 23349 | ptr_val->type = dest_ptr_type; |
| 23312 | 23350 | |
| 23313 | | ConstExprValue *len_val = result->value.data.x_struct.fields[slice_len_index]; |
| 23351 | ZigValue *len_val = result->value->data.x_struct.fields[slice_len_index]; |
| 23314 | 23352 | len_val->special = ConstValSpecialStatic; |
| 23315 | 23353 | len_val->type = ira->codegen->builtin_types.entry_usize; |
| 23316 | | ConstExprValue *target_len_val = target_val->data.x_struct.fields[slice_len_index]; |
| 23354 | ZigValue *target_len_val = target_val->data.x_struct.fields[slice_len_index]; |
| 23317 | 23355 | ZigType *elem_type = src_ptr_type->data.pointer.child_type; |
| 23318 | 23356 | BigInt elem_size_bigint; |
| 23319 | 23357 | bigint_init_unsigned(&elem_size_bigint, type_size(ira->codegen, elem_type)); |
| ... | ... | @@ -23324,7 +23362,7 @@ static IrInstruction *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruct |
| 23324 | 23362 | |
| 23325 | 23363 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 23326 | 23364 | dest_slice_type, nullptr, true, false, true); |
| 23327 | | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { |
| 23365 | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 23328 | 23366 | return result_loc; |
| 23329 | 23367 | } |
| 23330 | 23368 | |
| ... | ... | @@ -23351,12 +23389,12 @@ static IrInstruction *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInst |
| 23351 | 23389 | return ira->codegen->invalid_instruction; |
| 23352 | 23390 | |
| 23353 | 23391 | IrInstruction *target = instruction->target->child; |
| 23354 | | if (type_is_invalid(target->value.type)) |
| 23392 | if (type_is_invalid(target->value->type)) |
| 23355 | 23393 | return ira->codegen->invalid_instruction; |
| 23356 | 23394 | |
| 23357 | | if (target->value.type->id != ZigTypeIdInt && target->value.type->id != ZigTypeIdComptimeInt) { |
| 23395 | if (target->value->type->id != ZigTypeIdInt && target->value->type->id != ZigTypeIdComptimeInt) { |
| 23358 | 23396 | ir_add_error(ira, instruction->target, buf_sprintf("expected int type, found '%s'", |
| 23359 | | buf_ptr(&target->value.type->name))); |
| 23397 | buf_ptr(&target->value->type->name))); |
| 23360 | 23398 | return ira->codegen->invalid_instruction; |
| 23361 | 23399 | } |
| 23362 | 23400 | |
| ... | ... | @@ -23369,16 +23407,16 @@ static IrInstruction *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInst |
| 23369 | 23407 | return ira->codegen->invalid_instruction; |
| 23370 | 23408 | |
| 23371 | 23409 | IrInstruction *target = instruction->target->child; |
| 23372 | | if (type_is_invalid(target->value.type)) |
| 23410 | if (type_is_invalid(target->value->type)) |
| 23373 | 23411 | return ira->codegen->invalid_instruction; |
| 23374 | 23412 | |
| 23375 | | if (target->value.type->id == ZigTypeIdComptimeInt) { |
| 23413 | if (target->value->type->id == ZigTypeIdComptimeInt) { |
| 23376 | 23414 | return ir_implicit_cast(ira, target, dest_type); |
| 23377 | 23415 | } |
| 23378 | 23416 | |
| 23379 | | if (target->value.type->id != ZigTypeIdFloat && target->value.type->id != ZigTypeIdComptimeFloat) { |
| 23417 | if (target->value->type->id != ZigTypeIdFloat && target->value->type->id != ZigTypeIdComptimeFloat) { |
| 23380 | 23418 | ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'", |
| 23381 | | buf_ptr(&target->value.type->name))); |
| 23419 | buf_ptr(&target->value->type->name))); |
| 23382 | 23420 | return ira->codegen->invalid_instruction; |
| 23383 | 23421 | } |
| 23384 | 23422 | |
| ... | ... | @@ -23387,15 +23425,15 @@ static IrInstruction *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInst |
| 23387 | 23425 | |
| 23388 | 23426 | static IrInstruction *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstructionErrToInt *instruction) { |
| 23389 | 23427 | IrInstruction *target = instruction->target->child; |
| 23390 | | if (type_is_invalid(target->value.type)) |
| 23428 | if (type_is_invalid(target->value->type)) |
| 23391 | 23429 | return ira->codegen->invalid_instruction; |
| 23392 | 23430 | |
| 23393 | 23431 | IrInstruction *casted_target; |
| 23394 | | if (target->value.type->id == ZigTypeIdErrorSet) { |
| 23432 | if (target->value->type->id == ZigTypeIdErrorSet) { |
| 23395 | 23433 | casted_target = target; |
| 23396 | 23434 | } else { |
| 23397 | 23435 | casted_target = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_global_error_set); |
| 23398 | | if (type_is_invalid(casted_target->value.type)) |
| 23436 | if (type_is_invalid(casted_target->value->type)) |
| 23399 | 23437 | return ira->codegen->invalid_instruction; |
| 23400 | 23438 | } |
| 23401 | 23439 | |
| ... | ... | @@ -23404,11 +23442,11 @@ static IrInstruction *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstru |
| 23404 | 23442 | |
| 23405 | 23443 | static IrInstruction *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstructionIntToErr *instruction) { |
| 23406 | 23444 | IrInstruction *target = instruction->target->child; |
| 23407 | | if (type_is_invalid(target->value.type)) |
| 23445 | if (type_is_invalid(target->value->type)) |
| 23408 | 23446 | return ira->codegen->invalid_instruction; |
| 23409 | 23447 | |
| 23410 | 23448 | IrInstruction *casted_target = ir_implicit_cast(ira, target, ira->codegen->err_tag_type); |
| 23411 | | if (type_is_invalid(casted_target->value.type)) |
| 23449 | if (type_is_invalid(casted_target->value->type)) |
| 23412 | 23450 | return ira->codegen->invalid_instruction; |
| 23413 | 23451 | |
| 23414 | 23452 | return ir_analyze_int_to_err(ira, &instruction->base, casted_target, ira->codegen->builtin_types.entry_global_error_set); |
| ... | ... | @@ -23416,12 +23454,12 @@ static IrInstruction *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstru |
| 23416 | 23454 | |
| 23417 | 23455 | static IrInstruction *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstructionBoolToInt *instruction) { |
| 23418 | 23456 | IrInstruction *target = instruction->target->child; |
| 23419 | | if (type_is_invalid(target->value.type)) |
| 23457 | if (type_is_invalid(target->value->type)) |
| 23420 | 23458 | return ira->codegen->invalid_instruction; |
| 23421 | 23459 | |
| 23422 | | if (target->value.type->id != ZigTypeIdBool) { |
| 23460 | if (target->value->type->id != ZigTypeIdBool) { |
| 23423 | 23461 | ir_add_error(ira, instruction->target, buf_sprintf("expected bool, found '%s'", |
| 23424 | | buf_ptr(&target->value.type->name))); |
| 23462 | buf_ptr(&target->value->type->name))); |
| 23425 | 23463 | return ira->codegen->invalid_instruction; |
| 23426 | 23464 | } |
| 23427 | 23465 | |
| ... | ... | @@ -23472,48 +23510,48 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 23472 | 23510 | ir_assert(is_valid_vector_elem_type(scalar_type), source_instr); |
| 23473 | 23511 | |
| 23474 | 23512 | uint32_t len_mask; |
| 23475 | | if (mask->value.type->id == ZigTypeIdVector) { |
| 23476 | | len_mask = mask->value.type->data.vector.len; |
| 23477 | | } else if (mask->value.type->id == ZigTypeIdArray) { |
| 23478 | | len_mask = mask->value.type->data.array.len; |
| 23513 | if (mask->value->type->id == ZigTypeIdVector) { |
| 23514 | len_mask = mask->value->type->data.vector.len; |
| 23515 | } else if (mask->value->type->id == ZigTypeIdArray) { |
| 23516 | len_mask = mask->value->type->data.array.len; |
| 23479 | 23517 | } else { |
| 23480 | 23518 | ir_add_error(ira, mask, |
| 23481 | 23519 | buf_sprintf("expected vector or array, found '%s'", |
| 23482 | | buf_ptr(&mask->value.type->name))); |
| 23520 | buf_ptr(&mask->value->type->name))); |
| 23483 | 23521 | return ira->codegen->invalid_instruction; |
| 23484 | 23522 | } |
| 23485 | 23523 | mask = ir_implicit_cast(ira, mask, get_vector_type(ira->codegen, len_mask, |
| 23486 | 23524 | ira->codegen->builtin_types.entry_i32)); |
| 23487 | | if (type_is_invalid(mask->value.type)) |
| 23525 | if (type_is_invalid(mask->value->type)) |
| 23488 | 23526 | return ira->codegen->invalid_instruction; |
| 23489 | 23527 | |
| 23490 | 23528 | uint32_t len_a; |
| 23491 | | if (a->value.type->id == ZigTypeIdVector) { |
| 23492 | | len_a = a->value.type->data.vector.len; |
| 23493 | | } else if (a->value.type->id == ZigTypeIdArray) { |
| 23494 | | len_a = a->value.type->data.array.len; |
| 23495 | | } else if (a->value.type->id == ZigTypeIdUndefined) { |
| 23529 | if (a->value->type->id == ZigTypeIdVector) { |
| 23530 | len_a = a->value->type->data.vector.len; |
| 23531 | } else if (a->value->type->id == ZigTypeIdArray) { |
| 23532 | len_a = a->value->type->data.array.len; |
| 23533 | } else if (a->value->type->id == ZigTypeIdUndefined) { |
| 23496 | 23534 | len_a = UINT32_MAX; |
| 23497 | 23535 | } else { |
| 23498 | 23536 | ir_add_error(ira, a, |
| 23499 | 23537 | buf_sprintf("expected vector or array with element type '%s', found '%s'", |
| 23500 | 23538 | buf_ptr(&scalar_type->name), |
| 23501 | | buf_ptr(&a->value.type->name))); |
| 23539 | buf_ptr(&a->value->type->name))); |
| 23502 | 23540 | return ira->codegen->invalid_instruction; |
| 23503 | 23541 | } |
| 23504 | 23542 | |
| 23505 | 23543 | uint32_t len_b; |
| 23506 | | if (b->value.type->id == ZigTypeIdVector) { |
| 23507 | | len_b = b->value.type->data.vector.len; |
| 23508 | | } else if (b->value.type->id == ZigTypeIdArray) { |
| 23509 | | len_b = b->value.type->data.array.len; |
| 23510 | | } else if (b->value.type->id == ZigTypeIdUndefined) { |
| 23544 | if (b->value->type->id == ZigTypeIdVector) { |
| 23545 | len_b = b->value->type->data.vector.len; |
| 23546 | } else if (b->value->type->id == ZigTypeIdArray) { |
| 23547 | len_b = b->value->type->data.array.len; |
| 23548 | } else if (b->value->type->id == ZigTypeIdUndefined) { |
| 23511 | 23549 | len_b = UINT32_MAX; |
| 23512 | 23550 | } else { |
| 23513 | 23551 | ir_add_error(ira, b, |
| 23514 | 23552 | buf_sprintf("expected vector or array with element type '%s', found '%s'", |
| 23515 | 23553 | buf_ptr(&scalar_type->name), |
| 23516 | | buf_ptr(&b->value.type->name))); |
| 23554 | buf_ptr(&b->value->type->name))); |
| 23517 | 23555 | return ira->codegen->invalid_instruction; |
| 23518 | 23556 | } |
| 23519 | 23557 | |
| ... | ... | @@ -23526,7 +23564,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 23526 | 23564 | a = ir_const_undef(ira, a, get_vector_type(ira->codegen, len_a, scalar_type)); |
| 23527 | 23565 | } else { |
| 23528 | 23566 | a = ir_implicit_cast(ira, a, get_vector_type(ira->codegen, len_a, scalar_type)); |
| 23529 | | if (type_is_invalid(a->value.type)) |
| 23567 | if (type_is_invalid(a->value->type)) |
| 23530 | 23568 | return ira->codegen->invalid_instruction; |
| 23531 | 23569 | } |
| 23532 | 23570 | |
| ... | ... | @@ -23535,18 +23573,18 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 23535 | 23573 | b = ir_const_undef(ira, b, get_vector_type(ira->codegen, len_b, scalar_type)); |
| 23536 | 23574 | } else { |
| 23537 | 23575 | b = ir_implicit_cast(ira, b, get_vector_type(ira->codegen, len_b, scalar_type)); |
| 23538 | | if (type_is_invalid(b->value.type)) |
| 23576 | if (type_is_invalid(b->value->type)) |
| 23539 | 23577 | return ira->codegen->invalid_instruction; |
| 23540 | 23578 | } |
| 23541 | 23579 | |
| 23542 | | ConstExprValue *mask_val = ir_resolve_const(ira, mask, UndefOk); |
| 23580 | ZigValue *mask_val = ir_resolve_const(ira, mask, UndefOk); |
| 23543 | 23581 | if (mask_val == nullptr) |
| 23544 | 23582 | return ira->codegen->invalid_instruction; |
| 23545 | 23583 | |
| 23546 | 23584 | expand_undef_array(ira->codegen, mask_val); |
| 23547 | 23585 | |
| 23548 | 23586 | for (uint32_t i = 0; i < len_mask; i += 1) { |
| 23549 | | ConstExprValue *mask_elem_val = &mask_val->data.x_array.data.s_none.elements[i]; |
| 23587 | ZigValue *mask_elem_val = &mask_val->data.x_array.data.s_none.elements[i]; |
| 23550 | 23588 | if (mask_elem_val->special == ConstValSpecialUndef) |
| 23551 | 23589 | continue; |
| 23552 | 23590 | int32_t v_i32 = bigint_as_signed(&mask_elem_val->data.x_bigint); |
| ... | ... | @@ -23559,12 +23597,12 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 23559 | 23597 | v = (uint32_t)~v_i32; |
| 23560 | 23598 | chosen_operand = b; |
| 23561 | 23599 | } |
| 23562 | | if (v >= chosen_operand->value.type->data.vector.len) { |
| 23600 | if (v >= chosen_operand->value->type->data.vector.len) { |
| 23563 | 23601 | ErrorMsg *msg = ir_add_error(ira, mask, |
| 23564 | 23602 | buf_sprintf("mask index '%u' has out-of-bounds selection", i)); |
| 23565 | 23603 | add_error_note(ira->codegen, msg, chosen_operand->source_node, |
| 23566 | 23604 | buf_sprintf("selected index '%u' out of bounds of %s", v, |
| 23567 | | buf_ptr(&chosen_operand->value.type->name))); |
| 23605 | buf_ptr(&chosen_operand->value->type->name))); |
| 23568 | 23606 | if (chosen_operand == a && v < len_a + len_b) { |
| 23569 | 23607 | add_error_note(ira->codegen, msg, b->source_node, |
| 23570 | 23608 | buf_create_from_str("selections from the second vector are specified with negative numbers")); |
| ... | ... | @@ -23575,11 +23613,11 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 23575 | 23613 | |
| 23576 | 23614 | ZigType *result_type = get_vector_type(ira->codegen, len_mask, scalar_type); |
| 23577 | 23615 | if (instr_is_comptime(a) && instr_is_comptime(b)) { |
| 23578 | | ConstExprValue *a_val = ir_resolve_const(ira, a, UndefOk); |
| 23616 | ZigValue *a_val = ir_resolve_const(ira, a, UndefOk); |
| 23579 | 23617 | if (a_val == nullptr) |
| 23580 | 23618 | return ira->codegen->invalid_instruction; |
| 23581 | 23619 | |
| 23582 | | ConstExprValue *b_val = ir_resolve_const(ira, b, UndefOk); |
| 23620 | ZigValue *b_val = ir_resolve_const(ira, b, UndefOk); |
| 23583 | 23621 | if (b_val == nullptr) |
| 23584 | 23622 | return ira->codegen->invalid_instruction; |
| 23585 | 23623 | |
| ... | ... | @@ -23587,24 +23625,24 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 23587 | 23625 | expand_undef_array(ira->codegen, b_val); |
| 23588 | 23626 | |
| 23589 | 23627 | IrInstruction *result = ir_const(ira, source_instr, result_type); |
| 23590 | | result->value.data.x_array.data.s_none.elements = create_const_vals(len_mask); |
| 23628 | result->value->data.x_array.data.s_none.elements = create_const_vals(len_mask); |
| 23591 | 23629 | for (uint32_t i = 0; i < mask_val->type->data.vector.len; i += 1) { |
| 23592 | | ConstExprValue *mask_elem_val = &mask_val->data.x_array.data.s_none.elements[i]; |
| 23593 | | ConstExprValue *result_elem_val = &result->value.data.x_array.data.s_none.elements[i]; |
| 23630 | ZigValue *mask_elem_val = &mask_val->data.x_array.data.s_none.elements[i]; |
| 23631 | ZigValue *result_elem_val = &result->value->data.x_array.data.s_none.elements[i]; |
| 23594 | 23632 | if (mask_elem_val->special == ConstValSpecialUndef) { |
| 23595 | 23633 | result_elem_val->special = ConstValSpecialUndef; |
| 23596 | 23634 | continue; |
| 23597 | 23635 | } |
| 23598 | 23636 | int32_t v = bigint_as_signed(&mask_elem_val->data.x_bigint); |
| 23599 | 23637 | // We've already checked for and emitted compile errors for index out of bounds here. |
| 23600 | | ConstExprValue *src_elem_val = (v >= 0) ? |
| 23601 | | &a->value.data.x_array.data.s_none.elements[v] : |
| 23602 | | &b->value.data.x_array.data.s_none.elements[~v]; |
| 23638 | ZigValue *src_elem_val = (v >= 0) ? |
| 23639 | &a->value->data.x_array.data.s_none.elements[v] : |
| 23640 | &b->value->data.x_array.data.s_none.elements[~v]; |
| 23603 | 23641 | copy_const_val(result_elem_val, src_elem_val, false); |
| 23604 | 23642 | |
| 23605 | 23643 | ir_assert(result_elem_val->special == ConstValSpecialStatic, source_instr); |
| 23606 | 23644 | } |
| 23607 | | result->value.special = ConstValSpecialStatic; |
| 23645 | result->value->special = ConstValSpecialStatic; |
| 23608 | 23646 | return result; |
| 23609 | 23647 | } |
| 23610 | 23648 | |
| ... | ... | @@ -23620,12 +23658,12 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 23620 | 23658 | |
| 23621 | 23659 | IrInstruction *expand_mask = ir_const(ira, mask, |
| 23622 | 23660 | get_vector_type(ira->codegen, len_max, ira->codegen->builtin_types.entry_i32)); |
| 23623 | | expand_mask->value.data.x_array.data.s_none.elements = create_const_vals(len_max); |
| 23661 | expand_mask->value->data.x_array.data.s_none.elements = create_const_vals(len_max); |
| 23624 | 23662 | uint32_t i = 0; |
| 23625 | 23663 | for (; i < len_min; i += 1) |
| 23626 | | bigint_init_unsigned(&expand_mask->value.data.x_array.data.s_none.elements[i].data.x_bigint, i); |
| 23664 | bigint_init_unsigned(&expand_mask->value->data.x_array.data.s_none.elements[i].data.x_bigint, i); |
| 23627 | 23665 | for (; i < len_max; i += 1) |
| 23628 | | bigint_init_signed(&expand_mask->value.data.x_array.data.s_none.elements[i].data.x_bigint, -1); |
| 23666 | bigint_init_signed(&expand_mask->value->data.x_array.data.s_none.elements[i].data.x_bigint, -1); |
| 23629 | 23667 | |
| 23630 | 23668 | IrInstruction *undef = ir_const_undef(ira, source_instr, |
| 23631 | 23669 | get_vector_type(ira->codegen, len_min, scalar_type)); |
| ... | ... | @@ -23640,7 +23678,7 @@ static IrInstruction *ir_analyze_shuffle_vector(IrAnalyze *ira, IrInstruction *s |
| 23640 | 23678 | IrInstruction *result = ir_build_shuffle_vector(&ira->new_irb, |
| 23641 | 23679 | source_instr->scope, source_instr->source_node, |
| 23642 | 23680 | nullptr, a, b, mask); |
| 23643 | | result->value.type = result_type; |
| 23681 | result->value->type = result_type; |
| 23644 | 23682 | return result; |
| 23645 | 23683 | } |
| 23646 | 23684 | |
| ... | ... | @@ -23650,15 +23688,15 @@ static IrInstruction *ir_analyze_instruction_shuffle_vector(IrAnalyze *ira, IrIn |
| 23650 | 23688 | return ira->codegen->invalid_instruction; |
| 23651 | 23689 | |
| 23652 | 23690 | IrInstruction *a = instruction->a->child; |
| 23653 | | if (type_is_invalid(a->value.type)) |
| 23691 | if (type_is_invalid(a->value->type)) |
| 23654 | 23692 | return ira->codegen->invalid_instruction; |
| 23655 | 23693 | |
| 23656 | 23694 | IrInstruction *b = instruction->b->child; |
| 23657 | | if (type_is_invalid(b->value.type)) |
| 23695 | if (type_is_invalid(b->value->type)) |
| 23658 | 23696 | return ira->codegen->invalid_instruction; |
| 23659 | 23697 | |
| 23660 | 23698 | IrInstruction *mask = instruction->mask->child; |
| 23661 | | if (type_is_invalid(mask->value.type)) |
| 23699 | if (type_is_invalid(mask->value->type)) |
| 23662 | 23700 | return ira->codegen->invalid_instruction; |
| 23663 | 23701 | |
| 23664 | 23702 | return ir_analyze_shuffle_vector(ira, &instruction->base, scalar_type, a, b, mask); |
| ... | ... | @@ -23668,11 +23706,11 @@ static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstruction |
| 23668 | 23706 | Error err; |
| 23669 | 23707 | |
| 23670 | 23708 | IrInstruction *len = instruction->len->child; |
| 23671 | | if (type_is_invalid(len->value.type)) |
| 23709 | if (type_is_invalid(len->value->type)) |
| 23672 | 23710 | return ira->codegen->invalid_instruction; |
| 23673 | 23711 | |
| 23674 | 23712 | IrInstruction *scalar = instruction->scalar->child; |
| 23675 | | if (type_is_invalid(scalar->value.type)) |
| 23713 | if (type_is_invalid(scalar->value->type)) |
| 23676 | 23714 | return ira->codegen->invalid_instruction; |
| 23677 | 23715 | |
| 23678 | 23716 | uint64_t len_u64; |
| ... | ... | @@ -23680,22 +23718,22 @@ static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstruction |
| 23680 | 23718 | return ira->codegen->invalid_instruction; |
| 23681 | 23719 | uint32_t len_int = len_u64; |
| 23682 | 23720 | |
| 23683 | | if ((err = ir_validate_vector_elem_type(ira, scalar, scalar->value.type))) |
| 23721 | if ((err = ir_validate_vector_elem_type(ira, scalar, scalar->value->type))) |
| 23684 | 23722 | return ira->codegen->invalid_instruction; |
| 23685 | 23723 | |
| 23686 | | ZigType *return_type = get_vector_type(ira->codegen, len_int, scalar->value.type); |
| 23724 | ZigType *return_type = get_vector_type(ira->codegen, len_int, scalar->value->type); |
| 23687 | 23725 | |
| 23688 | 23726 | if (instr_is_comptime(scalar)) { |
| 23689 | | ConstExprValue *scalar_val = ir_resolve_const(ira, scalar, UndefOk); |
| 23727 | ZigValue *scalar_val = ir_resolve_const(ira, scalar, UndefOk); |
| 23690 | 23728 | if (scalar_val == nullptr) |
| 23691 | 23729 | return ira->codegen->invalid_instruction; |
| 23692 | 23730 | if (scalar_val->special == ConstValSpecialUndef) |
| 23693 | 23731 | return ir_const_undef(ira, &instruction->base, return_type); |
| 23694 | 23732 | |
| 23695 | 23733 | IrInstruction *result = ir_const(ira, &instruction->base, return_type); |
| 23696 | | result->value.data.x_array.data.s_none.elements = create_const_vals(len_int); |
| 23734 | result->value->data.x_array.data.s_none.elements = create_const_vals(len_int); |
| 23697 | 23735 | for (uint32_t i = 0; i < len_int; i += 1) { |
| 23698 | | copy_const_val(&result->value.data.x_array.data.s_none.elements[i], scalar_val, false); |
| 23736 | copy_const_val(&result->value->data.x_array.data.s_none.elements[i], scalar_val, false); |
| 23699 | 23737 | } |
| 23700 | 23738 | return result; |
| 23701 | 23739 | } |
| ... | ... | @@ -23705,17 +23743,17 @@ static IrInstruction *ir_analyze_instruction_splat(IrAnalyze *ira, IrInstruction |
| 23705 | 23743 | |
| 23706 | 23744 | static IrInstruction *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstructionBoolNot *instruction) { |
| 23707 | 23745 | IrInstruction *value = instruction->value->child; |
| 23708 | | if (type_is_invalid(value->value.type)) |
| 23746 | if (type_is_invalid(value->value->type)) |
| 23709 | 23747 | return ira->codegen->invalid_instruction; |
| 23710 | 23748 | |
| 23711 | 23749 | ZigType *bool_type = ira->codegen->builtin_types.entry_bool; |
| 23712 | 23750 | |
| 23713 | 23751 | IrInstruction *casted_value = ir_implicit_cast(ira, value, bool_type); |
| 23714 | | if (type_is_invalid(casted_value->value.type)) |
| 23752 | if (type_is_invalid(casted_value->value->type)) |
| 23715 | 23753 | return ira->codegen->invalid_instruction; |
| 23716 | 23754 | |
| 23717 | 23755 | if (instr_is_comptime(casted_value)) { |
| 23718 | | ConstExprValue *value = ir_resolve_const(ira, casted_value, UndefBad); |
| 23756 | ZigValue *value = ir_resolve_const(ira, casted_value, UndefBad); |
| 23719 | 23757 | if (value == nullptr) |
| 23720 | 23758 | return ira->codegen->invalid_instruction; |
| 23721 | 23759 | |
| ... | ... | @@ -23724,7 +23762,7 @@ static IrInstruction *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstruct |
| 23724 | 23762 | |
| 23725 | 23763 | IrInstruction *result = ir_build_bool_not(&ira->new_irb, instruction->base.scope, |
| 23726 | 23764 | instruction->base.source_node, casted_value); |
| 23727 | | result->value.type = bool_type; |
| 23765 | result->value->type = bool_type; |
| 23728 | 23766 | return result; |
| 23729 | 23767 | } |
| 23730 | 23768 | |
| ... | ... | @@ -23732,18 +23770,18 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio |
| 23732 | 23770 | Error err; |
| 23733 | 23771 | |
| 23734 | 23772 | IrInstruction *dest_ptr = instruction->dest_ptr->child; |
| 23735 | | if (type_is_invalid(dest_ptr->value.type)) |
| 23773 | if (type_is_invalid(dest_ptr->value->type)) |
| 23736 | 23774 | return ira->codegen->invalid_instruction; |
| 23737 | 23775 | |
| 23738 | 23776 | IrInstruction *byte_value = instruction->byte->child; |
| 23739 | | if (type_is_invalid(byte_value->value.type)) |
| 23777 | if (type_is_invalid(byte_value->value->type)) |
| 23740 | 23778 | return ira->codegen->invalid_instruction; |
| 23741 | 23779 | |
| 23742 | 23780 | IrInstruction *count_value = instruction->count->child; |
| 23743 | | if (type_is_invalid(count_value->value.type)) |
| 23781 | if (type_is_invalid(count_value->value->type)) |
| 23744 | 23782 | return ira->codegen->invalid_instruction; |
| 23745 | 23783 | |
| 23746 | | ZigType *dest_uncasted_type = dest_ptr->value.type; |
| 23784 | ZigType *dest_uncasted_type = dest_ptr->value->type; |
| 23747 | 23785 | bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) && |
| 23748 | 23786 | dest_uncasted_type->data.pointer.is_volatile; |
| 23749 | 23787 | |
| ... | ... | @@ -23760,15 +23798,15 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio |
| 23760 | 23798 | PtrLenUnknown, dest_align, 0, 0, false); |
| 23761 | 23799 | |
| 23762 | 23800 | IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr); |
| 23763 | | if (type_is_invalid(casted_dest_ptr->value.type)) |
| 23801 | if (type_is_invalid(casted_dest_ptr->value->type)) |
| 23764 | 23802 | return ira->codegen->invalid_instruction; |
| 23765 | 23803 | |
| 23766 | 23804 | IrInstruction *casted_byte = ir_implicit_cast(ira, byte_value, u8); |
| 23767 | | if (type_is_invalid(casted_byte->value.type)) |
| 23805 | if (type_is_invalid(casted_byte->value->type)) |
| 23768 | 23806 | return ira->codegen->invalid_instruction; |
| 23769 | 23807 | |
| 23770 | 23808 | IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize); |
| 23771 | | if (type_is_invalid(casted_count->value.type)) |
| 23809 | if (type_is_invalid(casted_count->value->type)) |
| 23772 | 23810 | return ira->codegen->invalid_instruction; |
| 23773 | 23811 | |
| 23774 | 23812 | // TODO test this at comptime with u8 and non-u8 types |
| ... | ... | @@ -23776,22 +23814,22 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio |
| 23776 | 23814 | instr_is_comptime(casted_byte) && |
| 23777 | 23815 | instr_is_comptime(casted_count)) |
| 23778 | 23816 | { |
| 23779 | | ConstExprValue *dest_ptr_val = ir_resolve_const(ira, casted_dest_ptr, UndefBad); |
| 23817 | ZigValue *dest_ptr_val = ir_resolve_const(ira, casted_dest_ptr, UndefBad); |
| 23780 | 23818 | if (dest_ptr_val == nullptr) |
| 23781 | 23819 | return ira->codegen->invalid_instruction; |
| 23782 | 23820 | |
| 23783 | | ConstExprValue *byte_val = ir_resolve_const(ira, casted_byte, UndefOk); |
| 23821 | ZigValue *byte_val = ir_resolve_const(ira, casted_byte, UndefOk); |
| 23784 | 23822 | if (byte_val == nullptr) |
| 23785 | 23823 | return ira->codegen->invalid_instruction; |
| 23786 | 23824 | |
| 23787 | | ConstExprValue *count_val = ir_resolve_const(ira, casted_count, UndefBad); |
| 23825 | ZigValue *count_val = ir_resolve_const(ira, casted_count, UndefBad); |
| 23788 | 23826 | if (count_val == nullptr) |
| 23789 | 23827 | return ira->codegen->invalid_instruction; |
| 23790 | 23828 | |
| 23791 | | if (casted_dest_ptr->value.data.x_ptr.special != ConstPtrSpecialHardCodedAddr && |
| 23792 | | casted_dest_ptr->value.data.x_ptr.mut != ConstPtrMutRuntimeVar) |
| 23829 | if (casted_dest_ptr->value->data.x_ptr.special != ConstPtrSpecialHardCodedAddr && |
| 23830 | casted_dest_ptr->value->data.x_ptr.mut != ConstPtrMutRuntimeVar) |
| 23793 | 23831 | { |
| 23794 | | ConstExprValue *dest_elements; |
| 23832 | ZigValue *dest_elements; |
| 23795 | 23833 | size_t start; |
| 23796 | 23834 | size_t bound_end; |
| 23797 | 23835 | switch (dest_ptr_val->data.x_ptr.special) { |
| ... | ... | @@ -23805,7 +23843,7 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio |
| 23805 | 23843 | break; |
| 23806 | 23844 | case ConstPtrSpecialBaseArray: |
| 23807 | 23845 | { |
| 23808 | | ConstExprValue *array_val = dest_ptr_val->data.x_ptr.data.base_array.array_val; |
| 23846 | ZigValue *array_val = dest_ptr_val->data.x_ptr.data.base_array.array_val; |
| 23809 | 23847 | expand_undef_array(ira->codegen, array_val); |
| 23810 | 23848 | dest_elements = array_val->data.x_array.data.s_none.elements; |
| 23811 | 23849 | start = dest_ptr_val->data.x_ptr.data.base_array.elem_index; |
| ... | ... | @@ -23845,7 +23883,7 @@ static IrInstruction *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructio |
| 23845 | 23883 | |
| 23846 | 23884 | IrInstruction *result = ir_build_memset(&ira->new_irb, instruction->base.scope, instruction->base.source_node, |
| 23847 | 23885 | casted_dest_ptr, casted_byte, casted_count); |
| 23848 | | result->value.type = ira->codegen->builtin_types.entry_void; |
| 23886 | result->value->type = ira->codegen->builtin_types.entry_void; |
| 23849 | 23887 | return result; |
| 23850 | 23888 | } |
| 23851 | 23889 | |
| ... | ... | @@ -23853,20 +23891,20 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio |
| 23853 | 23891 | Error err; |
| 23854 | 23892 | |
| 23855 | 23893 | IrInstruction *dest_ptr = instruction->dest_ptr->child; |
| 23856 | | if (type_is_invalid(dest_ptr->value.type)) |
| 23894 | if (type_is_invalid(dest_ptr->value->type)) |
| 23857 | 23895 | return ira->codegen->invalid_instruction; |
| 23858 | 23896 | |
| 23859 | 23897 | IrInstruction *src_ptr = instruction->src_ptr->child; |
| 23860 | | if (type_is_invalid(src_ptr->value.type)) |
| 23898 | if (type_is_invalid(src_ptr->value->type)) |
| 23861 | 23899 | return ira->codegen->invalid_instruction; |
| 23862 | 23900 | |
| 23863 | 23901 | IrInstruction *count_value = instruction->count->child; |
| 23864 | | if (type_is_invalid(count_value->value.type)) |
| 23902 | if (type_is_invalid(count_value->value->type)) |
| 23865 | 23903 | return ira->codegen->invalid_instruction; |
| 23866 | 23904 | |
| 23867 | 23905 | ZigType *u8 = ira->codegen->builtin_types.entry_u8; |
| 23868 | | ZigType *dest_uncasted_type = dest_ptr->value.type; |
| 23869 | | ZigType *src_uncasted_type = src_ptr->value.type; |
| 23906 | ZigType *dest_uncasted_type = dest_ptr->value->type; |
| 23907 | ZigType *src_uncasted_type = src_ptr->value->type; |
| 23870 | 23908 | bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) && |
| 23871 | 23909 | dest_uncasted_type->data.pointer.is_volatile; |
| 23872 | 23910 | bool src_is_volatile = (src_uncasted_type->id == ZigTypeIdPointer) && |
| ... | ... | @@ -23895,15 +23933,15 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio |
| 23895 | 23933 | PtrLenUnknown, src_align, 0, 0, false); |
| 23896 | 23934 | |
| 23897 | 23935 | IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr_mut); |
| 23898 | | if (type_is_invalid(casted_dest_ptr->value.type)) |
| 23936 | if (type_is_invalid(casted_dest_ptr->value->type)) |
| 23899 | 23937 | return ira->codegen->invalid_instruction; |
| 23900 | 23938 | |
| 23901 | 23939 | IrInstruction *casted_src_ptr = ir_implicit_cast(ira, src_ptr, u8_ptr_const); |
| 23902 | | if (type_is_invalid(casted_src_ptr->value.type)) |
| 23940 | if (type_is_invalid(casted_src_ptr->value->type)) |
| 23903 | 23941 | return ira->codegen->invalid_instruction; |
| 23904 | 23942 | |
| 23905 | 23943 | IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize); |
| 23906 | | if (type_is_invalid(casted_count->value.type)) |
| 23944 | if (type_is_invalid(casted_count->value->type)) |
| 23907 | 23945 | return ira->codegen->invalid_instruction; |
| 23908 | 23946 | |
| 23909 | 23947 | // TODO test this at comptime with u8 and non-u8 types |
| ... | ... | @@ -23912,22 +23950,22 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio |
| 23912 | 23950 | instr_is_comptime(casted_src_ptr) && |
| 23913 | 23951 | instr_is_comptime(casted_count)) |
| 23914 | 23952 | { |
| 23915 | | ConstExprValue *dest_ptr_val = ir_resolve_const(ira, casted_dest_ptr, UndefBad); |
| 23953 | ZigValue *dest_ptr_val = ir_resolve_const(ira, casted_dest_ptr, UndefBad); |
| 23916 | 23954 | if (dest_ptr_val == nullptr) |
| 23917 | 23955 | return ira->codegen->invalid_instruction; |
| 23918 | 23956 | |
| 23919 | | ConstExprValue *src_ptr_val = ir_resolve_const(ira, casted_src_ptr, UndefBad); |
| 23957 | ZigValue *src_ptr_val = ir_resolve_const(ira, casted_src_ptr, UndefBad); |
| 23920 | 23958 | if (src_ptr_val == nullptr) |
| 23921 | 23959 | return ira->codegen->invalid_instruction; |
| 23922 | 23960 | |
| 23923 | | ConstExprValue *count_val = ir_resolve_const(ira, casted_count, UndefBad); |
| 23961 | ZigValue *count_val = ir_resolve_const(ira, casted_count, UndefBad); |
| 23924 | 23962 | if (count_val == nullptr) |
| 23925 | 23963 | return ira->codegen->invalid_instruction; |
| 23926 | 23964 | |
| 23927 | 23965 | if (dest_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) { |
| 23928 | 23966 | size_t count = bigint_as_usize(&count_val->data.x_bigint); |
| 23929 | 23967 | |
| 23930 | | ConstExprValue *dest_elements; |
| 23968 | ZigValue *dest_elements; |
| 23931 | 23969 | size_t dest_start; |
| 23932 | 23970 | size_t dest_end; |
| 23933 | 23971 | switch (dest_ptr_val->data.x_ptr.special) { |
| ... | ... | @@ -23941,7 +23979,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio |
| 23941 | 23979 | break; |
| 23942 | 23980 | case ConstPtrSpecialBaseArray: |
| 23943 | 23981 | { |
| 23944 | | ConstExprValue *array_val = dest_ptr_val->data.x_ptr.data.base_array.array_val; |
| 23982 | ZigValue *array_val = dest_ptr_val->data.x_ptr.data.base_array.array_val; |
| 23945 | 23983 | expand_undef_array(ira->codegen, array_val); |
| 23946 | 23984 | dest_elements = array_val->data.x_array.data.s_none.elements; |
| 23947 | 23985 | dest_start = dest_ptr_val->data.x_ptr.data.base_array.elem_index; |
| ... | ... | @@ -23969,7 +24007,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio |
| 23969 | 24007 | return ira->codegen->invalid_instruction; |
| 23970 | 24008 | } |
| 23971 | 24009 | |
| 23972 | | ConstExprValue *src_elements; |
| 24010 | ZigValue *src_elements; |
| 23973 | 24011 | size_t src_start; |
| 23974 | 24012 | size_t src_end; |
| 23975 | 24013 | |
| ... | ... | @@ -23984,7 +24022,7 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio |
| 23984 | 24022 | break; |
| 23985 | 24023 | case ConstPtrSpecialBaseArray: |
| 23986 | 24024 | { |
| 23987 | | ConstExprValue *array_val = src_ptr_val->data.x_ptr.data.base_array.array_val; |
| 24025 | ZigValue *array_val = src_ptr_val->data.x_ptr.data.base_array.array_val; |
| 23988 | 24026 | expand_undef_array(ira->codegen, array_val); |
| 23989 | 24027 | src_elements = array_val->data.x_array.data.s_none.elements; |
| 23990 | 24028 | src_start = src_ptr_val->data.x_ptr.data.base_array.elem_index; |
| ... | ... | @@ -24024,35 +24062,35 @@ static IrInstruction *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructio |
| 24024 | 24062 | |
| 24025 | 24063 | IrInstruction *result = ir_build_memcpy(&ira->new_irb, instruction->base.scope, instruction->base.source_node, |
| 24026 | 24064 | casted_dest_ptr, casted_src_ptr, casted_count); |
| 24027 | | result->value.type = ira->codegen->builtin_types.entry_void; |
| 24065 | result->value->type = ira->codegen->builtin_types.entry_void; |
| 24028 | 24066 | return result; |
| 24029 | 24067 | } |
| 24030 | 24068 | |
| 24031 | 24069 | static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSliceSrc *instruction) { |
| 24032 | 24070 | IrInstruction *ptr_ptr = instruction->ptr->child; |
| 24033 | | if (type_is_invalid(ptr_ptr->value.type)) |
| 24071 | if (type_is_invalid(ptr_ptr->value->type)) |
| 24034 | 24072 | return ira->codegen->invalid_instruction; |
| 24035 | 24073 | |
| 24036 | | ZigType *ptr_ptr_type = ptr_ptr->value.type; |
| 24074 | ZigType *ptr_ptr_type = ptr_ptr->value->type; |
| 24037 | 24075 | assert(ptr_ptr_type->id == ZigTypeIdPointer); |
| 24038 | 24076 | ZigType *array_type = ptr_ptr_type->data.pointer.child_type; |
| 24039 | 24077 | |
| 24040 | 24078 | IrInstruction *start = instruction->start->child; |
| 24041 | | if (type_is_invalid(start->value.type)) |
| 24079 | if (type_is_invalid(start->value->type)) |
| 24042 | 24080 | return ira->codegen->invalid_instruction; |
| 24043 | 24081 | |
| 24044 | 24082 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 24045 | 24083 | IrInstruction *casted_start = ir_implicit_cast(ira, start, usize); |
| 24046 | | if (type_is_invalid(casted_start->value.type)) |
| 24084 | if (type_is_invalid(casted_start->value->type)) |
| 24047 | 24085 | return ira->codegen->invalid_instruction; |
| 24048 | 24086 | |
| 24049 | 24087 | IrInstruction *end; |
| 24050 | 24088 | if (instruction->end) { |
| 24051 | 24089 | end = instruction->end->child; |
| 24052 | | if (type_is_invalid(end->value.type)) |
| 24090 | if (type_is_invalid(end->value->type)) |
| 24053 | 24091 | return ira->codegen->invalid_instruction; |
| 24054 | 24092 | end = ir_implicit_cast(ira, end, usize); |
| 24055 | | if (type_is_invalid(end->value.type)) |
| 24093 | if (type_is_invalid(end->value->type)) |
| 24056 | 24094 | return ira->codegen->invalid_instruction; |
| 24057 | 24095 | } else { |
| 24058 | 24096 | end = nullptr; |
| ... | ... | @@ -24061,8 +24099,8 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 24061 | 24099 | ZigType *return_type; |
| 24062 | 24100 | |
| 24063 | 24101 | if (array_type->id == ZigTypeIdArray) { |
| 24064 | | bool is_comptime_const = ptr_ptr->value.special == ConstValSpecialStatic && |
| 24065 | | ptr_ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst; |
| 24102 | bool is_comptime_const = ptr_ptr->value->special == ConstValSpecialStatic && |
| 24103 | ptr_ptr->value->data.x_ptr.mut == ConstPtrMutComptimeConst; |
| 24066 | 24104 | ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.array.child_type, |
| 24067 | 24105 | ptr_ptr_type->data.pointer.is_const || is_comptime_const, |
| 24068 | 24106 | ptr_ptr_type->data.pointer.is_volatile, |
| ... | ... | @@ -24103,11 +24141,11 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 24103 | 24141 | } |
| 24104 | 24142 | |
| 24105 | 24143 | if (instr_is_comptime(ptr_ptr) && |
| 24106 | | value_is_comptime(&casted_start->value) && |
| 24107 | | (!end || value_is_comptime(&end->value))) |
| 24144 | value_is_comptime(casted_start->value) && |
| 24145 | (!end || value_is_comptime(end->value))) |
| 24108 | 24146 | { |
| 24109 | | ConstExprValue *array_val; |
| 24110 | | ConstExprValue *parent_ptr; |
| 24147 | ZigValue *array_val; |
| 24148 | ZigValue *parent_ptr; |
| 24111 | 24149 | size_t abs_offset; |
| 24112 | 24150 | size_t rel_end; |
| 24113 | 24151 | bool ptr_is_undef = false; |
| ... | ... | @@ -24117,7 +24155,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 24117 | 24155 | if (array_type->id == ZigTypeIdPointer) { |
| 24118 | 24156 | ZigType *child_array_type = array_type->data.pointer.child_type; |
| 24119 | 24157 | assert(child_array_type->id == ZigTypeIdArray); |
| 24120 | | parent_ptr = const_ptr_pointee(ira, ira->codegen, &ptr_ptr->value, instruction->base.source_node); |
| 24158 | parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node); |
| 24121 | 24159 | if (parent_ptr == nullptr) |
| 24122 | 24160 | return ira->codegen->invalid_instruction; |
| 24123 | 24161 | |
| ... | ... | @@ -24136,7 +24174,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 24136 | 24174 | abs_offset = 0; |
| 24137 | 24175 | } |
| 24138 | 24176 | } else { |
| 24139 | | array_val = const_ptr_pointee(ira, ira->codegen, &ptr_ptr->value, instruction->base.source_node); |
| 24177 | array_val = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node); |
| 24140 | 24178 | if (array_val == nullptr) |
| 24141 | 24179 | return ira->codegen->invalid_instruction; |
| 24142 | 24180 | rel_end = array_type->data.array.len; |
| ... | ... | @@ -24145,7 +24183,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 24145 | 24183 | } |
| 24146 | 24184 | } else if (array_type->id == ZigTypeIdPointer) { |
| 24147 | 24185 | assert(array_type->data.pointer.ptr_len == PtrLenUnknown); |
| 24148 | | parent_ptr = const_ptr_pointee(ira, ira->codegen, &ptr_ptr->value, instruction->base.source_node); |
| 24186 | parent_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node); |
| 24149 | 24187 | if (parent_ptr == nullptr) |
| 24150 | 24188 | return ira->codegen->invalid_instruction; |
| 24151 | 24189 | |
| ... | ... | @@ -24193,7 +24231,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 24193 | 24231 | zig_panic("TODO slice of null ptr"); |
| 24194 | 24232 | } |
| 24195 | 24233 | } else if (is_slice(array_type)) { |
| 24196 | | ConstExprValue *slice_ptr = const_ptr_pointee(ira, ira->codegen, &ptr_ptr->value, instruction->base.source_node); |
| 24234 | ZigValue *slice_ptr = const_ptr_pointee(ira, ira->codegen, ptr_ptr->value, instruction->base.source_node); |
| 24197 | 24235 | if (slice_ptr == nullptr) |
| 24198 | 24236 | return ira->codegen->invalid_instruction; |
| 24199 | 24237 | |
| ... | ... | @@ -24208,7 +24246,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 24208 | 24246 | return ira->codegen->invalid_instruction; |
| 24209 | 24247 | } |
| 24210 | 24248 | |
| 24211 | | ConstExprValue *len_val = slice_ptr->data.x_struct.fields[slice_len_index]; |
| 24249 | ZigValue *len_val = slice_ptr->data.x_struct.fields[slice_len_index]; |
| 24212 | 24250 | |
| 24213 | 24251 | switch (parent_ptr->data.x_ptr.special) { |
| 24214 | 24252 | case ConstPtrSpecialInvalid: |
| ... | ... | @@ -24246,7 +24284,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 24246 | 24284 | zig_unreachable(); |
| 24247 | 24285 | } |
| 24248 | 24286 | |
| 24249 | | ConstExprValue *start_val = ir_resolve_const(ira, casted_start, UndefBad); |
| 24287 | ZigValue *start_val = ir_resolve_const(ira, casted_start, UndefBad); |
| 24250 | 24288 | if (!start_val) |
| 24251 | 24289 | return ira->codegen->invalid_instruction; |
| 24252 | 24290 | |
| ... | ... | @@ -24258,7 +24296,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 24258 | 24296 | |
| 24259 | 24297 | uint64_t end_scalar = rel_end; |
| 24260 | 24298 | if (end) { |
| 24261 | | ConstExprValue *end_val = ir_resolve_const(ira, end, UndefBad); |
| 24299 | ZigValue *end_val = ir_resolve_const(ira, end, UndefBad); |
| 24262 | 24300 | if (!end_val) |
| 24263 | 24301 | return ira->codegen->invalid_instruction; |
| 24264 | 24302 | end_scalar = bigint_as_u64(&end_val->data.x_bigint); |
| ... | ... | @@ -24279,17 +24317,17 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 24279 | 24317 | } |
| 24280 | 24318 | |
| 24281 | 24319 | IrInstruction *result = ir_const(ira, &instruction->base, return_type); |
| 24282 | | ConstExprValue *out_val = &result->value; |
| 24320 | ZigValue *out_val = result->value; |
| 24283 | 24321 | out_val->data.x_struct.fields = alloc_const_vals_ptrs(2); |
| 24284 | 24322 | |
| 24285 | | ConstExprValue *ptr_val = out_val->data.x_struct.fields[slice_ptr_index]; |
| 24323 | ZigValue *ptr_val = out_val->data.x_struct.fields[slice_ptr_index]; |
| 24286 | 24324 | |
| 24287 | 24325 | if (array_val) { |
| 24288 | 24326 | size_t index = abs_offset + start_scalar; |
| 24289 | 24327 | bool is_const = slice_is_const(return_type); |
| 24290 | 24328 | init_const_ptr_array(ira->codegen, ptr_val, array_val, index, is_const, PtrLenUnknown); |
| 24291 | 24329 | if (array_type->id == ZigTypeIdArray) { |
| 24292 | | ptr_val->data.x_ptr.mut = ptr_ptr->value.data.x_ptr.mut; |
| 24330 | ptr_val->data.x_ptr.mut = ptr_ptr->value->data.x_ptr.mut; |
| 24293 | 24331 | } else if (is_slice(array_type)) { |
| 24294 | 24332 | ptr_val->data.x_ptr.mut = parent_ptr->data.x_ptr.mut; |
| 24295 | 24333 | } else if (array_type->id == ZigTypeIdPointer) { |
| ... | ... | @@ -24329,7 +24367,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 24329 | 24367 | zig_panic("TODO"); |
| 24330 | 24368 | } |
| 24331 | 24369 | |
| 24332 | | ConstExprValue *len_val = out_val->data.x_struct.fields[slice_len_index]; |
| 24370 | ZigValue *len_val = out_val->data.x_struct.fields[slice_len_index]; |
| 24333 | 24371 | init_const_usize(ira->codegen, len_val, end_scalar - start_scalar); |
| 24334 | 24372 | |
| 24335 | 24373 | return result; |
| ... | ... | @@ -24337,7 +24375,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 24337 | 24375 | |
| 24338 | 24376 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 24339 | 24377 | return_type, nullptr, true, false, true); |
| 24340 | | if (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc)) { |
| 24378 | if (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc)) { |
| 24341 | 24379 | return result_loc; |
| 24342 | 24380 | } |
| 24343 | 24381 | return ir_build_slice_gen(ira, &instruction->base, return_type, |
| ... | ... | @@ -24347,7 +24385,7 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction |
| 24347 | 24385 | static IrInstruction *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstructionMemberCount *instruction) { |
| 24348 | 24386 | Error err; |
| 24349 | 24387 | IrInstruction *container = instruction->container->child; |
| 24350 | | if (type_is_invalid(container->value.type)) |
| 24388 | if (type_is_invalid(container->value->type)) |
| 24351 | 24389 | return ira->codegen->invalid_instruction; |
| 24352 | 24390 | ZigType *container_type = ir_resolve_type(ira, container); |
| 24353 | 24391 | |
| ... | ... | @@ -24448,7 +24486,7 @@ static IrInstruction *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstr |
| 24448 | 24486 | TypeStructField *field = container_type->data.structure.fields[member_index]; |
| 24449 | 24487 | |
| 24450 | 24488 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 24451 | | init_const_str_lit(ira->codegen, &result->value, field->name); |
| 24489 | init_const_str_lit(ira->codegen, result->value, field->name); |
| 24452 | 24490 | return result; |
| 24453 | 24491 | } else if (container_type->id == ZigTypeIdEnum) { |
| 24454 | 24492 | if (member_index >= container_type->data.enumeration.src_field_count) { |
| ... | ... | @@ -24460,7 +24498,7 @@ static IrInstruction *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstr |
| 24460 | 24498 | TypeEnumField *field = &container_type->data.enumeration.fields[member_index]; |
| 24461 | 24499 | |
| 24462 | 24500 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 24463 | | init_const_str_lit(ira->codegen, &result->value, field->name); |
| 24501 | init_const_str_lit(ira->codegen, result->value, field->name); |
| 24464 | 24502 | return result; |
| 24465 | 24503 | } else if (container_type->id == ZigTypeIdUnion) { |
| 24466 | 24504 | if (member_index >= container_type->data.unionation.src_field_count) { |
| ... | ... | @@ -24472,7 +24510,7 @@ static IrInstruction *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstr |
| 24472 | 24510 | TypeUnionField *field = &container_type->data.unionation.fields[member_index]; |
| 24473 | 24511 | |
| 24474 | 24512 | IrInstruction *result = ir_const(ira, &instruction->base, nullptr); |
| 24475 | | init_const_str_lit(ira->codegen, &result->value, field->name); |
| 24513 | init_const_str_lit(ira->codegen, result->value, field->name); |
| 24476 | 24514 | return result; |
| 24477 | 24515 | } else { |
| 24478 | 24516 | ir_add_error(ira, container_type_value, |
| ... | ... | @@ -24512,21 +24550,21 @@ static IrInstruction *ir_analyze_instruction_has_field(IrAnalyze *ira, IrInstruc |
| 24512 | 24550 | static IrInstruction *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstructionBreakpoint *instruction) { |
| 24513 | 24551 | IrInstruction *result = ir_build_breakpoint(&ira->new_irb, |
| 24514 | 24552 | instruction->base.scope, instruction->base.source_node); |
| 24515 | | result->value.type = ira->codegen->builtin_types.entry_void; |
| 24553 | result->value->type = ira->codegen->builtin_types.entry_void; |
| 24516 | 24554 | return result; |
| 24517 | 24555 | } |
| 24518 | 24556 | |
| 24519 | 24557 | static IrInstruction *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstructionReturnAddress *instruction) { |
| 24520 | 24558 | IrInstruction *result = ir_build_return_address(&ira->new_irb, |
| 24521 | 24559 | instruction->base.scope, instruction->base.source_node); |
| 24522 | | result->value.type = ira->codegen->builtin_types.entry_usize; |
| 24560 | result->value->type = ira->codegen->builtin_types.entry_usize; |
| 24523 | 24561 | return result; |
| 24524 | 24562 | } |
| 24525 | 24563 | |
| 24526 | 24564 | static IrInstruction *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstructionFrameAddress *instruction) { |
| 24527 | 24565 | IrInstruction *result = ir_build_frame_address(&ira->new_irb, |
| 24528 | 24566 | instruction->base.scope, instruction->base.source_node); |
| 24529 | | result->value.type = ira->codegen->builtin_types.entry_usize; |
| 24567 | result->value->type = ira->codegen->builtin_types.entry_usize; |
| 24530 | 24568 | return result; |
| 24531 | 24569 | } |
| 24532 | 24570 | |
| ... | ... | @@ -24542,7 +24580,7 @@ static IrInstruction *ir_analyze_instruction_frame_handle(IrAnalyze *ira, IrInst |
| 24542 | 24580 | ZigType *ptr_frame_type = get_pointer_to_type(ira->codegen, frame_type, false); |
| 24543 | 24581 | |
| 24544 | 24582 | IrInstruction *result = ir_build_handle(&ira->new_irb, instruction->base.scope, instruction->base.source_node); |
| 24545 | | result->value.type = ptr_frame_type; |
| 24583 | result->value->type = ptr_frame_type; |
| 24546 | 24584 | return result; |
| 24547 | 24585 | } |
| 24548 | 24586 | |
| ... | ... | @@ -24563,12 +24601,12 @@ static IrInstruction *ir_analyze_instruction_frame_type(IrAnalyze *ira, IrInstru |
| 24563 | 24601 | |
| 24564 | 24602 | static IrInstruction *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstructionFrameSizeSrc *instruction) { |
| 24565 | 24603 | IrInstruction *fn = instruction->fn->child; |
| 24566 | | if (type_is_invalid(fn->value.type)) |
| 24604 | if (type_is_invalid(fn->value->type)) |
| 24567 | 24605 | return ira->codegen->invalid_instruction; |
| 24568 | 24606 | |
| 24569 | | if (fn->value.type->id != ZigTypeIdFn) { |
| 24607 | if (fn->value->type->id != ZigTypeIdFn) { |
| 24570 | 24608 | ir_add_error(ira, fn, |
| 24571 | | buf_sprintf("expected function, found '%s'", buf_ptr(&fn->value.type->name))); |
| 24609 | buf_sprintf("expected function, found '%s'", buf_ptr(&fn->value->type->name))); |
| 24572 | 24610 | return ira->codegen->invalid_instruction; |
| 24573 | 24611 | } |
| 24574 | 24612 | |
| ... | ... | @@ -24576,7 +24614,7 @@ static IrInstruction *ir_analyze_instruction_frame_size(IrAnalyze *ira, IrInstru |
| 24576 | 24614 | |
| 24577 | 24615 | IrInstruction *result = ir_build_frame_size_gen(&ira->new_irb, instruction->base.scope, |
| 24578 | 24616 | instruction->base.source_node, fn); |
| 24579 | | result->value.type = ira->codegen->builtin_types.entry_usize; |
| 24617 | result->value->type = ira->codegen->builtin_types.entry_usize; |
| 24580 | 24618 | return result; |
| 24581 | 24619 | } |
| 24582 | 24620 | |
| ... | ... | @@ -24587,11 +24625,11 @@ static IrInstruction *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruct |
| 24587 | 24625 | // field: []align(@alignOf(Node)) Node, |
| 24588 | 24626 | // }; |
| 24589 | 24627 | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_num_lit_int); |
| 24590 | | result->value.special = ConstValSpecialLazy; |
| 24628 | result->value->special = ConstValSpecialLazy; |
| 24591 | 24629 | |
| 24592 | 24630 | LazyValueAlignOf *lazy_align_of = allocate<LazyValueAlignOf>(1); |
| 24593 | 24631 | lazy_align_of->ira = ira; |
| 24594 | | result->value.data.x_lazy = &lazy_align_of->base; |
| 24632 | result->value->data.x_lazy = &lazy_align_of->base; |
| 24595 | 24633 | lazy_align_of->base.id = LazyValueIdAlignOf; |
| 24596 | 24634 | |
| 24597 | 24635 | lazy_align_of->target_type = instruction->type_value->child; |
| ... | ... | @@ -24605,7 +24643,7 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr |
| 24605 | 24643 | Error err; |
| 24606 | 24644 | |
| 24607 | 24645 | IrInstruction *type_value = instruction->type_value->child; |
| 24608 | | if (type_is_invalid(type_value->value.type)) |
| 24646 | if (type_is_invalid(type_value->value->type)) |
| 24609 | 24647 | return ira->codegen->invalid_instruction; |
| 24610 | 24648 | |
| 24611 | 24649 | ZigType *dest_type = ir_resolve_type(ira, type_value); |
| ... | ... | @@ -24619,15 +24657,15 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr |
| 24619 | 24657 | } |
| 24620 | 24658 | |
| 24621 | 24659 | IrInstruction *op1 = instruction->op1->child; |
| 24622 | | if (type_is_invalid(op1->value.type)) |
| 24660 | if (type_is_invalid(op1->value->type)) |
| 24623 | 24661 | return ira->codegen->invalid_instruction; |
| 24624 | 24662 | |
| 24625 | 24663 | IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, dest_type); |
| 24626 | | if (type_is_invalid(casted_op1->value.type)) |
| 24664 | if (type_is_invalid(casted_op1->value->type)) |
| 24627 | 24665 | return ira->codegen->invalid_instruction; |
| 24628 | 24666 | |
| 24629 | 24667 | IrInstruction *op2 = instruction->op2->child; |
| 24630 | | if (type_is_invalid(op2->value.type)) |
| 24668 | if (type_is_invalid(op2->value->type)) |
| 24631 | 24669 | return ira->codegen->invalid_instruction; |
| 24632 | 24670 | |
| 24633 | 24671 | IrInstruction *casted_op2; |
| ... | ... | @@ -24638,20 +24676,20 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr |
| 24638 | 24676 | } else { |
| 24639 | 24677 | casted_op2 = ir_implicit_cast(ira, op2, dest_type); |
| 24640 | 24678 | } |
| 24641 | | if (type_is_invalid(casted_op2->value.type)) |
| 24679 | if (type_is_invalid(casted_op2->value->type)) |
| 24642 | 24680 | return ira->codegen->invalid_instruction; |
| 24643 | 24681 | |
| 24644 | 24682 | IrInstruction *result_ptr = instruction->result_ptr->child; |
| 24645 | | if (type_is_invalid(result_ptr->value.type)) |
| 24683 | if (type_is_invalid(result_ptr->value->type)) |
| 24646 | 24684 | return ira->codegen->invalid_instruction; |
| 24647 | 24685 | |
| 24648 | 24686 | ZigType *expected_ptr_type; |
| 24649 | | if (result_ptr->value.type->id == ZigTypeIdPointer) { |
| 24687 | if (result_ptr->value->type->id == ZigTypeIdPointer) { |
| 24650 | 24688 | uint32_t alignment; |
| 24651 | | if ((err = resolve_ptr_align(ira, result_ptr->value.type, &alignment))) |
| 24689 | if ((err = resolve_ptr_align(ira, result_ptr->value->type, &alignment))) |
| 24652 | 24690 | return ira->codegen->invalid_instruction; |
| 24653 | 24691 | expected_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_type, |
| 24654 | | false, result_ptr->value.type->data.pointer.is_volatile, |
| 24692 | false, result_ptr->value->type->data.pointer.is_volatile, |
| 24655 | 24693 | PtrLenSingle, |
| 24656 | 24694 | alignment, 0, 0, false); |
| 24657 | 24695 | } else { |
| ... | ... | @@ -24659,28 +24697,28 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr |
| 24659 | 24697 | } |
| 24660 | 24698 | |
| 24661 | 24699 | IrInstruction *casted_result_ptr = ir_implicit_cast(ira, result_ptr, expected_ptr_type); |
| 24662 | | if (type_is_invalid(casted_result_ptr->value.type)) |
| 24700 | if (type_is_invalid(casted_result_ptr->value->type)) |
| 24663 | 24701 | return ira->codegen->invalid_instruction; |
| 24664 | 24702 | |
| 24665 | 24703 | if (instr_is_comptime(casted_op1) && |
| 24666 | 24704 | instr_is_comptime(casted_op2) && |
| 24667 | 24705 | instr_is_comptime(casted_result_ptr)) |
| 24668 | 24706 | { |
| 24669 | | ConstExprValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad); |
| 24707 | ZigValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad); |
| 24670 | 24708 | if (op1_val == nullptr) |
| 24671 | 24709 | return ira->codegen->invalid_instruction; |
| 24672 | 24710 | |
| 24673 | | ConstExprValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); |
| 24711 | ZigValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad); |
| 24674 | 24712 | if (op2_val == nullptr) |
| 24675 | 24713 | return ira->codegen->invalid_instruction; |
| 24676 | 24714 | |
| 24677 | | ConstExprValue *result_val = ir_resolve_const(ira, casted_result_ptr, UndefBad); |
| 24715 | ZigValue *result_val = ir_resolve_const(ira, casted_result_ptr, UndefBad); |
| 24678 | 24716 | if (result_val == nullptr) |
| 24679 | 24717 | return ira->codegen->invalid_instruction; |
| 24680 | 24718 | |
| 24681 | 24719 | BigInt *op1_bigint = &op1_val->data.x_bigint; |
| 24682 | 24720 | BigInt *op2_bigint = &op2_val->data.x_bigint; |
| 24683 | | ConstExprValue *pointee_val = const_ptr_pointee(ira, ira->codegen, result_val, |
| 24721 | ZigValue *pointee_val = const_ptr_pointee(ira, ira->codegen, result_val, |
| 24684 | 24722 | casted_result_ptr->source_node); |
| 24685 | 24723 | if (pointee_val == nullptr) |
| 24686 | 24724 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -24716,12 +24754,12 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr |
| 24716 | 24754 | IrInstruction *result = ir_build_overflow_op(&ira->new_irb, |
| 24717 | 24755 | instruction->base.scope, instruction->base.source_node, |
| 24718 | 24756 | instruction->op, type_value, casted_op1, casted_op2, casted_result_ptr, dest_type); |
| 24719 | | result->value.type = ira->codegen->builtin_types.entry_bool; |
| 24757 | result->value->type = ira->codegen->builtin_types.entry_bool; |
| 24720 | 24758 | return result; |
| 24721 | 24759 | } |
| 24722 | 24760 | |
| 24723 | 24761 | static void ir_eval_mul_add(IrAnalyze *ira, IrInstructionMulAdd *source_instr, ZigType *float_type, |
| 24724 | | ConstExprValue *op1, ConstExprValue *op2, ConstExprValue *op3, ConstExprValue *out_val) { |
| 24762 | ZigValue *op1, ZigValue *op2, ZigValue *op3, ZigValue *out_val) { |
| 24725 | 24763 | if (float_type->id == ZigTypeIdComptimeFloat) { |
| 24726 | 24764 | f128M_mulAdd(&out_val->data.x_bigfloat.value, &op1->data.x_bigfloat.value, &op2->data.x_bigfloat.value, |
| 24727 | 24765 | &op3->data.x_bigfloat.value); |
| ... | ... | @@ -24749,7 +24787,7 @@ static void ir_eval_mul_add(IrAnalyze *ira, IrInstructionMulAdd *source_instr, Z |
| 24749 | 24787 | |
| 24750 | 24788 | static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructionMulAdd *instruction) { |
| 24751 | 24789 | IrInstruction *type_value = instruction->type_value->child; |
| 24752 | | if (type_is_invalid(type_value->value.type)) |
| 24790 | if (type_is_invalid(type_value->value->type)) |
| 24753 | 24791 | return ira->codegen->invalid_instruction; |
| 24754 | 24792 | |
| 24755 | 24793 | ZigType *expr_type = ir_resolve_type(ira, type_value); |
| ... | ... | @@ -24765,44 +24803,44 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi |
| 24765 | 24803 | } |
| 24766 | 24804 | |
| 24767 | 24805 | IrInstruction *op1 = instruction->op1->child; |
| 24768 | | if (type_is_invalid(op1->value.type)) |
| 24806 | if (type_is_invalid(op1->value->type)) |
| 24769 | 24807 | return ira->codegen->invalid_instruction; |
| 24770 | 24808 | |
| 24771 | 24809 | IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, expr_type); |
| 24772 | | if (type_is_invalid(casted_op1->value.type)) |
| 24810 | if (type_is_invalid(casted_op1->value->type)) |
| 24773 | 24811 | return ira->codegen->invalid_instruction; |
| 24774 | 24812 | |
| 24775 | 24813 | IrInstruction *op2 = instruction->op2->child; |
| 24776 | | if (type_is_invalid(op2->value.type)) |
| 24814 | if (type_is_invalid(op2->value->type)) |
| 24777 | 24815 | return ira->codegen->invalid_instruction; |
| 24778 | 24816 | |
| 24779 | 24817 | IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, expr_type); |
| 24780 | | if (type_is_invalid(casted_op2->value.type)) |
| 24818 | if (type_is_invalid(casted_op2->value->type)) |
| 24781 | 24819 | return ira->codegen->invalid_instruction; |
| 24782 | 24820 | |
| 24783 | 24821 | IrInstruction *op3 = instruction->op3->child; |
| 24784 | | if (type_is_invalid(op3->value.type)) |
| 24822 | if (type_is_invalid(op3->value->type)) |
| 24785 | 24823 | return ira->codegen->invalid_instruction; |
| 24786 | 24824 | |
| 24787 | 24825 | IrInstruction *casted_op3 = ir_implicit_cast(ira, op3, expr_type); |
| 24788 | | if (type_is_invalid(casted_op3->value.type)) |
| 24826 | if (type_is_invalid(casted_op3->value->type)) |
| 24789 | 24827 | return ira->codegen->invalid_instruction; |
| 24790 | 24828 | |
| 24791 | 24829 | if (instr_is_comptime(casted_op1) && |
| 24792 | 24830 | instr_is_comptime(casted_op2) && |
| 24793 | 24831 | instr_is_comptime(casted_op3)) { |
| 24794 | | ConstExprValue *op1_const = ir_resolve_const(ira, casted_op1, UndefBad); |
| 24832 | ZigValue *op1_const = ir_resolve_const(ira, casted_op1, UndefBad); |
| 24795 | 24833 | if (!op1_const) |
| 24796 | 24834 | return ira->codegen->invalid_instruction; |
| 24797 | | ConstExprValue *op2_const = ir_resolve_const(ira, casted_op2, UndefBad); |
| 24835 | ZigValue *op2_const = ir_resolve_const(ira, casted_op2, UndefBad); |
| 24798 | 24836 | if (!op2_const) |
| 24799 | 24837 | return ira->codegen->invalid_instruction; |
| 24800 | | ConstExprValue *op3_const = ir_resolve_const(ira, casted_op3, UndefBad); |
| 24838 | ZigValue *op3_const = ir_resolve_const(ira, casted_op3, UndefBad); |
| 24801 | 24839 | if (!op3_const) |
| 24802 | 24840 | return ira->codegen->invalid_instruction; |
| 24803 | 24841 | |
| 24804 | 24842 | IrInstruction *result = ir_const(ira, &instruction->base, expr_type); |
| 24805 | | ConstExprValue *out_val = &result->value; |
| 24843 | ZigValue *out_val = result->value; |
| 24806 | 24844 | |
| 24807 | 24845 | if (expr_type->id == ZigTypeIdVector) { |
| 24808 | 24846 | expand_undef_array(ira->codegen, op1_const); |
| ... | ... | @@ -24812,10 +24850,10 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi |
| 24812 | 24850 | expand_undef_array(ira->codegen, out_val); |
| 24813 | 24851 | size_t len = expr_type->data.vector.len; |
| 24814 | 24852 | for (size_t i = 0; i < len; i += 1) { |
| 24815 | | ConstExprValue *float_operand_op1 = &op1_const->data.x_array.data.s_none.elements[i]; |
| 24816 | | ConstExprValue *float_operand_op2 = &op2_const->data.x_array.data.s_none.elements[i]; |
| 24817 | | ConstExprValue *float_operand_op3 = &op3_const->data.x_array.data.s_none.elements[i]; |
| 24818 | | ConstExprValue *float_out_val = &out_val->data.x_array.data.s_none.elements[i]; |
| 24853 | ZigValue *float_operand_op1 = &op1_const->data.x_array.data.s_none.elements[i]; |
| 24854 | ZigValue *float_operand_op2 = &op2_const->data.x_array.data.s_none.elements[i]; |
| 24855 | ZigValue *float_operand_op3 = &op3_const->data.x_array.data.s_none.elements[i]; |
| 24856 | ZigValue *float_out_val = &out_val->data.x_array.data.s_none.elements[i]; |
| 24819 | 24857 | assert(float_operand_op1->type == float_type); |
| 24820 | 24858 | assert(float_operand_op2->type == float_type); |
| 24821 | 24859 | assert(float_operand_op3->type == float_type); |
| ... | ... | @@ -24835,13 +24873,13 @@ static IrInstruction *ir_analyze_instruction_mul_add(IrAnalyze *ira, IrInstructi |
| 24835 | 24873 | IrInstruction *result = ir_build_mul_add(&ira->new_irb, |
| 24836 | 24874 | instruction->base.scope, instruction->base.source_node, |
| 24837 | 24875 | type_value, casted_op1, casted_op2, casted_op3); |
| 24838 | | result->value.type = expr_type; |
| 24876 | result->value->type = expr_type; |
| 24839 | 24877 | return result; |
| 24840 | 24878 | } |
| 24841 | 24879 | |
| 24842 | 24880 | static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTestErrSrc *instruction) { |
| 24843 | 24881 | IrInstruction *base_ptr = instruction->base_ptr->child; |
| 24844 | | if (type_is_invalid(base_ptr->value.type)) |
| 24882 | if (type_is_invalid(base_ptr->value->type)) |
| 24845 | 24883 | return ira->codegen->invalid_instruction; |
| 24846 | 24884 | |
| 24847 | 24885 | IrInstruction *value; |
| ... | ... | @@ -24851,12 +24889,12 @@ static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruct |
| 24851 | 24889 | value = ir_get_deref(ira, &instruction->base, base_ptr, nullptr); |
| 24852 | 24890 | } |
| 24853 | 24891 | |
| 24854 | | ZigType *type_entry = value->value.type; |
| 24892 | ZigType *type_entry = value->value->type; |
| 24855 | 24893 | if (type_is_invalid(type_entry)) |
| 24856 | 24894 | return ira->codegen->invalid_instruction; |
| 24857 | 24895 | if (type_entry->id == ZigTypeIdErrorUnion) { |
| 24858 | 24896 | if (instr_is_comptime(value)) { |
| 24859 | | ConstExprValue *err_union_val = ir_resolve_const(ira, value, UndefBad); |
| 24897 | ZigValue *err_union_val = ir_resolve_const(ira, value, UndefBad); |
| 24860 | 24898 | if (!err_union_val) |
| 24861 | 24899 | return ira->codegen->invalid_instruction; |
| 24862 | 24900 | |
| ... | ... | @@ -24890,7 +24928,7 @@ static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruct |
| 24890 | 24928 | static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction *source_instr, |
| 24891 | 24929 | IrInstruction *base_ptr, bool initializing) |
| 24892 | 24930 | { |
| 24893 | | ZigType *ptr_type = base_ptr->value.type; |
| 24931 | ZigType *ptr_type = base_ptr->value->type; |
| 24894 | 24932 | |
| 24895 | 24933 | // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing. |
| 24896 | 24934 | assert(ptr_type->id == ZigTypeIdPointer); |
| ... | ... | @@ -24911,20 +24949,20 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction * |
| 24911 | 24949 | ptr_type->data.pointer.explicit_alignment, 0, 0, false); |
| 24912 | 24950 | |
| 24913 | 24951 | if (instr_is_comptime(base_ptr)) { |
| 24914 | | ConstExprValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad); |
| 24952 | ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad); |
| 24915 | 24953 | if (!ptr_val) |
| 24916 | 24954 | return ira->codegen->invalid_instruction; |
| 24917 | 24955 | if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar && |
| 24918 | 24956 | ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr) |
| 24919 | 24957 | { |
| 24920 | | ConstExprValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); |
| 24958 | ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); |
| 24921 | 24959 | if (err_union_val == nullptr) |
| 24922 | 24960 | return ira->codegen->invalid_instruction; |
| 24923 | 24961 | |
| 24924 | 24962 | if (initializing && err_union_val->special == ConstValSpecialUndef) { |
| 24925 | | ConstExprValue *vals = create_const_vals(2); |
| 24926 | | ConstExprValue *err_set_val = &vals[0]; |
| 24927 | | ConstExprValue *payload_val = &vals[1]; |
| 24963 | ZigValue *vals = create_const_vals(2); |
| 24964 | ZigValue *err_set_val = &vals[0]; |
| 24965 | ZigValue *payload_val = &vals[1]; |
| 24928 | 24966 | |
| 24929 | 24967 | err_set_val->special = ConstValSpecialUndef; |
| 24930 | 24968 | err_set_val->type = err_set_type; |
| ... | ... | @@ -24946,12 +24984,12 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction * |
| 24946 | 24984 | if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { |
| 24947 | 24985 | result = ir_build_unwrap_err_code(&ira->new_irb, source_instr->scope, |
| 24948 | 24986 | source_instr->source_node, base_ptr); |
| 24949 | | result->value.type = result_type; |
| 24950 | | result->value.special = ConstValSpecialStatic; |
| 24987 | result->value->type = result_type; |
| 24988 | result->value->special = ConstValSpecialStatic; |
| 24951 | 24989 | } else { |
| 24952 | 24990 | result = ir_const(ira, source_instr, result_type); |
| 24953 | 24991 | } |
| 24954 | | ConstExprValue *const_val = &result->value; |
| 24992 | ZigValue *const_val = result->value; |
| 24955 | 24993 | const_val->data.x_ptr.special = ConstPtrSpecialBaseErrorUnionCode; |
| 24956 | 24994 | const_val->data.x_ptr.data.base_err_union_code.err_union_val = err_union_val; |
| 24957 | 24995 | const_val->data.x_ptr.mut = ptr_val->data.x_ptr.mut; |
| ... | ... | @@ -24961,7 +24999,7 @@ static IrInstruction *ir_analyze_unwrap_err_code(IrAnalyze *ira, IrInstruction * |
| 24961 | 24999 | |
| 24962 | 25000 | IrInstruction *result = ir_build_unwrap_err_code(&ira->new_irb, |
| 24963 | 25001 | source_instr->scope, source_instr->source_node, base_ptr); |
| 24964 | | result->value.type = result_type; |
| 25002 | result->value->type = result_type; |
| 24965 | 25003 | return result; |
| 24966 | 25004 | } |
| 24967 | 25005 | |
| ... | ... | @@ -24969,7 +25007,7 @@ static IrInstruction *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, |
| 24969 | 25007 | IrInstructionUnwrapErrCode *instruction) |
| 24970 | 25008 | { |
| 24971 | 25009 | IrInstruction *base_ptr = instruction->err_union_ptr->child; |
| 24972 | | if (type_is_invalid(base_ptr->value.type)) |
| 25010 | if (type_is_invalid(base_ptr->value->type)) |
| 24973 | 25011 | return ira->codegen->invalid_instruction; |
| 24974 | 25012 | return ir_analyze_unwrap_err_code(ira, &instruction->base, base_ptr, false); |
| 24975 | 25013 | } |
| ... | ... | @@ -24977,7 +25015,7 @@ static IrInstruction *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, |
| 24977 | 25015 | static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruction *source_instr, |
| 24978 | 25016 | IrInstruction *base_ptr, bool safety_check_on, bool initializing) |
| 24979 | 25017 | { |
| 24980 | | ZigType *ptr_type = base_ptr->value.type; |
| 25018 | ZigType *ptr_type = base_ptr->value->type; |
| 24981 | 25019 | |
| 24982 | 25020 | // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing. |
| 24983 | 25021 | assert(ptr_type->id == ZigTypeIdPointer); |
| ... | ... | @@ -25000,17 +25038,17 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct |
| 25000 | 25038 | ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, |
| 25001 | 25039 | PtrLenSingle, 0, 0, 0, false); |
| 25002 | 25040 | if (instr_is_comptime(base_ptr)) { |
| 25003 | | ConstExprValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad); |
| 25041 | ZigValue *ptr_val = ir_resolve_const(ira, base_ptr, UndefBad); |
| 25004 | 25042 | if (!ptr_val) |
| 25005 | 25043 | return ira->codegen->invalid_instruction; |
| 25006 | 25044 | if (ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar) { |
| 25007 | | ConstExprValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); |
| 25045 | ZigValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node); |
| 25008 | 25046 | if (err_union_val == nullptr) |
| 25009 | 25047 | return ira->codegen->invalid_instruction; |
| 25010 | 25048 | if (initializing && err_union_val->special == ConstValSpecialUndef) { |
| 25011 | | ConstExprValue *vals = create_const_vals(2); |
| 25012 | | ConstExprValue *err_set_val = &vals[0]; |
| 25013 | | ConstExprValue *payload_val = &vals[1]; |
| 25049 | ZigValue *vals = create_const_vals(2); |
| 25050 | ZigValue *err_set_val = &vals[0]; |
| 25051 | ZigValue *payload_val = &vals[1]; |
| 25014 | 25052 | |
| 25015 | 25053 | err_set_val->special = ConstValSpecialStatic; |
| 25016 | 25054 | err_set_val->type = type_entry->data.error_union.err_set_type; |
| ... | ... | @@ -25036,14 +25074,14 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct |
| 25036 | 25074 | if (ptr_val->data.x_ptr.mut == ConstPtrMutInfer) { |
| 25037 | 25075 | result = ir_build_unwrap_err_payload(&ira->new_irb, source_instr->scope, |
| 25038 | 25076 | source_instr->source_node, base_ptr, safety_check_on, initializing); |
| 25039 | | result->value.type = result_type; |
| 25040 | | result->value.special = ConstValSpecialStatic; |
| 25077 | result->value->type = result_type; |
| 25078 | result->value->special = ConstValSpecialStatic; |
| 25041 | 25079 | } else { |
| 25042 | 25080 | result = ir_const(ira, source_instr, result_type); |
| 25043 | 25081 | } |
| 25044 | | result->value.data.x_ptr.special = ConstPtrSpecialRef; |
| 25045 | | result->value.data.x_ptr.data.ref.pointee = err_union_val->data.x_err_union.payload; |
| 25046 | | result->value.data.x_ptr.mut = ptr_val->data.x_ptr.mut; |
| 25082 | result->value->data.x_ptr.special = ConstPtrSpecialRef; |
| 25083 | result->value->data.x_ptr.data.ref.pointee = err_union_val->data.x_err_union.payload; |
| 25084 | result->value->data.x_ptr.mut = ptr_val->data.x_ptr.mut; |
| 25047 | 25085 | return result; |
| 25048 | 25086 | } |
| 25049 | 25087 | } |
| ... | ... | @@ -25051,7 +25089,7 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct |
| 25051 | 25089 | |
| 25052 | 25090 | IrInstruction *result = ir_build_unwrap_err_payload(&ira->new_irb, source_instr->scope, |
| 25053 | 25091 | source_instr->source_node, base_ptr, safety_check_on, initializing); |
| 25054 | | result->value.type = result_type; |
| 25092 | result->value->type = result_type; |
| 25055 | 25093 | return result; |
| 25056 | 25094 | } |
| 25057 | 25095 | |
| ... | ... | @@ -25060,7 +25098,7 @@ static IrInstruction *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, |
| 25060 | 25098 | { |
| 25061 | 25099 | assert(instruction->value->child); |
| 25062 | 25100 | IrInstruction *value = instruction->value->child; |
| 25063 | | if (type_is_invalid(value->value.type)) |
| 25101 | if (type_is_invalid(value->value->type)) |
| 25064 | 25102 | return ira->codegen->invalid_instruction; |
| 25065 | 25103 | |
| 25066 | 25104 | return ir_analyze_unwrap_error_payload(ira, &instruction->base, value, instruction->safety_check_on, false); |
| ... | ... | @@ -25071,11 +25109,11 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct |
| 25071 | 25109 | assert(proto_node->type == NodeTypeFnProto); |
| 25072 | 25110 | |
| 25073 | 25111 | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type); |
| 25074 | | result->value.special = ConstValSpecialLazy; |
| 25112 | result->value->special = ConstValSpecialLazy; |
| 25075 | 25113 | |
| 25076 | 25114 | LazyValueFnType *lazy_fn_type = allocate<LazyValueFnType>(1); |
| 25077 | 25115 | lazy_fn_type->ira = ira; |
| 25078 | | result->value.data.x_lazy = &lazy_fn_type->base; |
| 25116 | result->value->data.x_lazy = &lazy_fn_type->base; |
| 25079 | 25117 | lazy_fn_type->base.id = LazyValueIdFnType; |
| 25080 | 25118 | |
| 25081 | 25119 | if (proto_node->data.fn_proto.auto_err_set) { |
| ... | ... | @@ -25110,7 +25148,7 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct |
| 25110 | 25148 | } |
| 25111 | 25149 | |
| 25112 | 25150 | IrInstruction *param_type_value = instruction->param_types[param_index]->child; |
| 25113 | | if (type_is_invalid(param_type_value->value.type)) |
| 25151 | if (type_is_invalid(param_type_value->value->type)) |
| 25114 | 25152 | return ira->codegen->invalid_instruction; |
| 25115 | 25153 | if (ir_resolve_const(ira, param_type_value, LazyOk) == nullptr) |
| 25116 | 25154 | return ira->codegen->invalid_instruction; |
| ... | ... | @@ -25132,7 +25170,7 @@ static IrInstruction *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruct |
| 25132 | 25170 | |
| 25133 | 25171 | static IrInstruction *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstructionTestComptime *instruction) { |
| 25134 | 25172 | IrInstruction *value = instruction->value->child; |
| 25135 | | if (type_is_invalid(value->value.type)) |
| 25173 | if (type_is_invalid(value->value->type)) |
| 25136 | 25174 | return ira->codegen->invalid_instruction; |
| 25137 | 25175 | |
| 25138 | 25176 | return ir_const_bool(ira, &instruction->base, instr_is_comptime(value)); |
| ... | ... | @@ -25142,7 +25180,7 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 25142 | 25180 | IrInstructionCheckSwitchProngs *instruction) |
| 25143 | 25181 | { |
| 25144 | 25182 | IrInstruction *target_value = instruction->target_value->child; |
| 25145 | | ZigType *switch_type = target_value->value.type; |
| 25183 | ZigType *switch_type = target_value->value->type; |
| 25146 | 25184 | if (type_is_invalid(switch_type)) |
| 25147 | 25185 | return ira->codegen->invalid_instruction; |
| 25148 | 25186 | |
| ... | ... | @@ -25154,25 +25192,25 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 25154 | 25192 | IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i]; |
| 25155 | 25193 | |
| 25156 | 25194 | IrInstruction *start_value_uncasted = range->start->child; |
| 25157 | | if (type_is_invalid(start_value_uncasted->value.type)) |
| 25195 | if (type_is_invalid(start_value_uncasted->value->type)) |
| 25158 | 25196 | return ira->codegen->invalid_instruction; |
| 25159 | 25197 | IrInstruction *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type); |
| 25160 | | if (type_is_invalid(start_value->value.type)) |
| 25198 | if (type_is_invalid(start_value->value->type)) |
| 25161 | 25199 | return ira->codegen->invalid_instruction; |
| 25162 | 25200 | |
| 25163 | 25201 | IrInstruction *end_value_uncasted = range->end->child; |
| 25164 | | if (type_is_invalid(end_value_uncasted->value.type)) |
| 25202 | if (type_is_invalid(end_value_uncasted->value->type)) |
| 25165 | 25203 | return ira->codegen->invalid_instruction; |
| 25166 | 25204 | IrInstruction *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type); |
| 25167 | | if (type_is_invalid(end_value->value.type)) |
| 25205 | if (type_is_invalid(end_value->value->type)) |
| 25168 | 25206 | return ira->codegen->invalid_instruction; |
| 25169 | 25207 | |
| 25170 | 25208 | BigInt start_index; |
| 25171 | | bigint_init_bigint(&start_index, &start_value->value.data.x_enum_tag); |
| 25209 | bigint_init_bigint(&start_index, &start_value->value->data.x_enum_tag); |
| 25172 | 25210 | |
| 25173 | | assert(end_value->value.type->id == ZigTypeIdEnum); |
| 25211 | assert(end_value->value->type->id == ZigTypeIdEnum); |
| 25174 | 25212 | BigInt end_index; |
| 25175 | | bigint_init_bigint(&end_index, &end_value->value.data.x_enum_tag); |
| 25213 | bigint_init_bigint(&end_index, &end_value->value->data.x_enum_tag); |
| 25176 | 25214 | |
| 25177 | 25215 | BigInt field_index; |
| 25178 | 25216 | bigint_init_bigint(&field_index, &start_index); |
| ... | ... | @@ -25218,24 +25256,24 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 25218 | 25256 | IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i]; |
| 25219 | 25257 | |
| 25220 | 25258 | IrInstruction *start_value_uncasted = range->start->child; |
| 25221 | | if (type_is_invalid(start_value_uncasted->value.type)) |
| 25259 | if (type_is_invalid(start_value_uncasted->value->type)) |
| 25222 | 25260 | return ira->codegen->invalid_instruction; |
| 25223 | 25261 | IrInstruction *start_value = ir_implicit_cast(ira, start_value_uncasted, switch_type); |
| 25224 | | if (type_is_invalid(start_value->value.type)) |
| 25262 | if (type_is_invalid(start_value->value->type)) |
| 25225 | 25263 | return ira->codegen->invalid_instruction; |
| 25226 | 25264 | |
| 25227 | 25265 | IrInstruction *end_value_uncasted = range->end->child; |
| 25228 | | if (type_is_invalid(end_value_uncasted->value.type)) |
| 25266 | if (type_is_invalid(end_value_uncasted->value->type)) |
| 25229 | 25267 | return ira->codegen->invalid_instruction; |
| 25230 | 25268 | IrInstruction *end_value = ir_implicit_cast(ira, end_value_uncasted, switch_type); |
| 25231 | | if (type_is_invalid(end_value->value.type)) |
| 25269 | if (type_is_invalid(end_value->value->type)) |
| 25232 | 25270 | return ira->codegen->invalid_instruction; |
| 25233 | 25271 | |
| 25234 | | ir_assert(start_value->value.type->id == ZigTypeIdErrorSet, &instruction->base); |
| 25235 | | uint32_t start_index = start_value->value.data.x_err_set->value; |
| 25272 | ir_assert(start_value->value->type->id == ZigTypeIdErrorSet, &instruction->base); |
| 25273 | uint32_t start_index = start_value->value->data.x_err_set->value; |
| 25236 | 25274 | |
| 25237 | | ir_assert(end_value->value.type->id == ZigTypeIdErrorSet, &instruction->base); |
| 25238 | | uint32_t end_index = end_value->value.data.x_err_set->value; |
| 25275 | ir_assert(end_value->value->type->id == ZigTypeIdErrorSet, &instruction->base); |
| 25276 | uint32_t end_index = end_value->value->data.x_err_set->value; |
| 25239 | 25277 | |
| 25240 | 25278 | if (start_index != end_index) { |
| 25241 | 25279 | ir_add_error(ira, end_value, buf_sprintf("ranges not allowed when switching on errors")); |
| ... | ... | @@ -25276,24 +25314,24 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 25276 | 25314 | IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i]; |
| 25277 | 25315 | |
| 25278 | 25316 | IrInstruction *start_value = range->start->child; |
| 25279 | | if (type_is_invalid(start_value->value.type)) |
| 25317 | if (type_is_invalid(start_value->value->type)) |
| 25280 | 25318 | return ira->codegen->invalid_instruction; |
| 25281 | 25319 | IrInstruction *casted_start_value = ir_implicit_cast(ira, start_value, switch_type); |
| 25282 | | if (type_is_invalid(casted_start_value->value.type)) |
| 25320 | if (type_is_invalid(casted_start_value->value->type)) |
| 25283 | 25321 | return ira->codegen->invalid_instruction; |
| 25284 | 25322 | |
| 25285 | 25323 | IrInstruction *end_value = range->end->child; |
| 25286 | | if (type_is_invalid(end_value->value.type)) |
| 25324 | if (type_is_invalid(end_value->value->type)) |
| 25287 | 25325 | return ira->codegen->invalid_instruction; |
| 25288 | 25326 | IrInstruction *casted_end_value = ir_implicit_cast(ira, end_value, switch_type); |
| 25289 | | if (type_is_invalid(casted_end_value->value.type)) |
| 25327 | if (type_is_invalid(casted_end_value->value->type)) |
| 25290 | 25328 | return ira->codegen->invalid_instruction; |
| 25291 | 25329 | |
| 25292 | | ConstExprValue *start_val = ir_resolve_const(ira, casted_start_value, UndefBad); |
| 25330 | ZigValue *start_val = ir_resolve_const(ira, casted_start_value, UndefBad); |
| 25293 | 25331 | if (!start_val) |
| 25294 | 25332 | return ira->codegen->invalid_instruction; |
| 25295 | 25333 | |
| 25296 | | ConstExprValue *end_val = ir_resolve_const(ira, casted_end_value, UndefBad); |
| 25334 | ZigValue *end_val = ir_resolve_const(ira, casted_end_value, UndefBad); |
| 25297 | 25335 | if (!end_val) |
| 25298 | 25336 | return ira->codegen->invalid_instruction; |
| 25299 | 25337 | |
| ... | ... | @@ -25326,10 +25364,10 @@ static IrInstruction *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, |
| 25326 | 25364 | IrInstruction *value = range->start->child; |
| 25327 | 25365 | |
| 25328 | 25366 | IrInstruction *casted_value = ir_implicit_cast(ira, value, switch_type); |
| 25329 | | if (type_is_invalid(casted_value->value.type)) |
| 25367 | if (type_is_invalid(casted_value->value->type)) |
| 25330 | 25368 | return ira->codegen->invalid_instruction; |
| 25331 | 25369 | |
| 25332 | | ConstExprValue *const_expr_val = ir_resolve_const(ira, casted_value, UndefBad); |
| 25370 | ZigValue *const_expr_val = ir_resolve_const(ira, casted_value, UndefBad); |
| 25333 | 25371 | if (!const_expr_val) |
| 25334 | 25372 | return ira->codegen->invalid_instruction; |
| 25335 | 25373 | |
| ... | ... | @@ -25362,7 +25400,7 @@ static IrInstruction *ir_analyze_instruction_check_statement_is_void(IrAnalyze * |
| 25362 | 25400 | IrInstructionCheckStatementIsVoid *instruction) |
| 25363 | 25401 | { |
| 25364 | 25402 | IrInstruction *statement_value = instruction->statement_value->child; |
| 25365 | | ZigType *statement_type = statement_value->value.type; |
| 25403 | ZigType *statement_type = statement_value->value->type; |
| 25366 | 25404 | if (type_is_invalid(statement_type)) |
| 25367 | 25405 | return ira->codegen->invalid_instruction; |
| 25368 | 25406 | |
| ... | ... | @@ -25375,7 +25413,7 @@ static IrInstruction *ir_analyze_instruction_check_statement_is_void(IrAnalyze * |
| 25375 | 25413 | |
| 25376 | 25414 | static IrInstruction *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic *instruction) { |
| 25377 | 25415 | IrInstruction *msg = instruction->msg->child; |
| 25378 | | if (type_is_invalid(msg->value.type)) |
| 25416 | if (type_is_invalid(msg->value->type)) |
| 25379 | 25417 | return ir_unreach_error(ira); |
| 25380 | 25418 | |
| 25381 | 25419 | if (ir_should_inline(ira->new_irb.exec, instruction->base.scope)) { |
| ... | ... | @@ -25387,7 +25425,7 @@ static IrInstruction *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstruction |
| 25387 | 25425 | true, false, PtrLenUnknown, 0, 0, 0, false); |
| 25388 | 25426 | ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type); |
| 25389 | 25427 | IrInstruction *casted_msg = ir_implicit_cast(ira, msg, str_type); |
| 25390 | | if (type_is_invalid(casted_msg->value.type)) |
| 25428 | if (type_is_invalid(casted_msg->value->type)) |
| 25391 | 25429 | return ir_unreach_error(ira); |
| 25392 | 25430 | |
| 25393 | 25431 | IrInstruction *new_instruction = ir_build_panic(&ira->new_irb, instruction->base.scope, |
| ... | ... | @@ -25398,7 +25436,7 @@ static IrInstruction *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstruction |
| 25398 | 25436 | static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint32_t align_bytes, bool safety_check_on) { |
| 25399 | 25437 | Error err; |
| 25400 | 25438 | |
| 25401 | | ZigType *target_type = target->value.type; |
| 25439 | ZigType *target_type = target->value->type; |
| 25402 | 25440 | assert(!type_is_invalid(target_type)); |
| 25403 | 25441 | |
| 25404 | 25442 | ZigType *result_type; |
| ... | ... | @@ -25443,7 +25481,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3 |
| 25443 | 25481 | } |
| 25444 | 25482 | |
| 25445 | 25483 | if (instr_is_comptime(target)) { |
| 25446 | | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); |
| 25484 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 25447 | 25485 | if (!val) |
| 25448 | 25486 | return ira->codegen->invalid_instruction; |
| 25449 | 25487 | |
| ... | ... | @@ -25457,8 +25495,8 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3 |
| 25457 | 25495 | } |
| 25458 | 25496 | |
| 25459 | 25497 | IrInstruction *result = ir_const(ira, target, result_type); |
| 25460 | | copy_const_val(&result->value, val, true); |
| 25461 | | result->value.type = result_type; |
| 25498 | copy_const_val(result->value, val, true); |
| 25499 | result->value->type = result_type; |
| 25462 | 25500 | return result; |
| 25463 | 25501 | } |
| 25464 | 25502 | |
| ... | ... | @@ -25468,7 +25506,7 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3 |
| 25468 | 25506 | } else { |
| 25469 | 25507 | result = ir_build_cast(&ira->new_irb, target->scope, target->source_node, result_type, target, CastOpNoop); |
| 25470 | 25508 | } |
| 25471 | | result->value.type = result_type; |
| 25509 | result->value->type = result_type; |
| 25472 | 25510 | return result; |
| 25473 | 25511 | } |
| 25474 | 25512 | |
| ... | ... | @@ -25477,7 +25515,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_ |
| 25477 | 25515 | { |
| 25478 | 25516 | Error err; |
| 25479 | 25517 | |
| 25480 | | ZigType *src_type = ptr->value.type; |
| 25518 | ZigType *src_type = ptr->value->type; |
| 25481 | 25519 | assert(!type_is_invalid(src_type)); |
| 25482 | 25520 | |
| 25483 | 25521 | if (src_type == dest_type) { |
| ... | ... | @@ -25515,7 +25553,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_ |
| 25515 | 25553 | if (instr_is_comptime(ptr)) { |
| 25516 | 25554 | bool dest_allows_addr_zero = ptr_allows_addr_zero(dest_type); |
| 25517 | 25555 | UndefAllowed is_undef_allowed = dest_allows_addr_zero ? UndefOk : UndefBad; |
| 25518 | | ConstExprValue *val = ir_resolve_const(ira, ptr, is_undef_allowed); |
| 25556 | ZigValue *val = ir_resolve_const(ira, ptr, is_undef_allowed); |
| 25519 | 25557 | if (!val) |
| 25520 | 25558 | return ira->codegen->invalid_instruction; |
| 25521 | 25559 | |
| ... | ... | @@ -25531,7 +25569,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_ |
| 25531 | 25569 | } |
| 25532 | 25570 | |
| 25533 | 25571 | IrInstruction *result; |
| 25534 | | if (ptr->value.data.x_ptr.mut == ConstPtrMutInfer) { |
| 25572 | if (ptr->value->data.x_ptr.mut == ConstPtrMutInfer) { |
| 25535 | 25573 | result = ir_build_ptr_cast_gen(ira, source_instr, dest_type, ptr, safety_check_on); |
| 25536 | 25574 | |
| 25537 | 25575 | if ((err = type_resolve(ira->codegen, dest_type, ResolveStatusZeroBitsKnown))) |
| ... | ... | @@ -25539,8 +25577,8 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_ |
| 25539 | 25577 | } else { |
| 25540 | 25578 | result = ir_const(ira, source_instr, dest_type); |
| 25541 | 25579 | } |
| 25542 | | copy_const_val(&result->value, val, true); |
| 25543 | | result->value.type = dest_type; |
| 25580 | copy_const_val(result->value, val, true); |
| 25581 | result->value->type = dest_type; |
| 25544 | 25582 | |
| 25545 | 25583 | // Keep the bigger alignment, it can only help- |
| 25546 | 25584 | // unless the target is zero bits. |
| ... | ... | @@ -25584,7 +25622,7 @@ static IrInstruction *ir_analyze_ptr_cast(IrAnalyze *ira, IrInstruction *source_ |
| 25584 | 25622 | IrInstruction *result; |
| 25585 | 25623 | if (src_align_bytes > dest_align_bytes && type_has_bits(dest_type)) { |
| 25586 | 25624 | result = ir_align_cast(ira, casted_ptr, src_align_bytes, false); |
| 25587 | | if (type_is_invalid(result->value.type)) |
| 25625 | if (type_is_invalid(result->value->type)) |
| 25588 | 25626 | return ira->codegen->invalid_instruction; |
| 25589 | 25627 | } else { |
| 25590 | 25628 | result = casted_ptr; |
| ... | ... | @@ -25599,7 +25637,7 @@ static IrInstruction *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstruct |
| 25599 | 25637 | return ira->codegen->invalid_instruction; |
| 25600 | 25638 | |
| 25601 | 25639 | IrInstruction *ptr = instruction->ptr->child; |
| 25602 | | ZigType *src_type = ptr->value.type; |
| 25640 | ZigType *src_type = ptr->value->type; |
| 25603 | 25641 | if (type_is_invalid(src_type)) |
| 25604 | 25642 | return ira->codegen->invalid_instruction; |
| 25605 | 25643 | |
| ... | ... | @@ -25607,18 +25645,18 @@ static IrInstruction *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstruct |
| 25607 | 25645 | instruction->safety_check_on); |
| 25608 | 25646 | } |
| 25609 | 25647 | |
| 25610 | | static void buf_write_value_bytes_array(CodeGen *codegen, uint8_t *buf, ConstExprValue *val, size_t len) { |
| 25648 | static void buf_write_value_bytes_array(CodeGen *codegen, uint8_t *buf, ZigValue *val, size_t len) { |
| 25611 | 25649 | size_t buf_i = 0; |
| 25612 | 25650 | // TODO optimize the buf case |
| 25613 | 25651 | expand_undef_array(codegen, val); |
| 25614 | 25652 | for (size_t elem_i = 0; elem_i < val->type->data.array.len; elem_i += 1) { |
| 25615 | | ConstExprValue *elem = &val->data.x_array.data.s_none.elements[elem_i]; |
| 25653 | ZigValue *elem = &val->data.x_array.data.s_none.elements[elem_i]; |
| 25616 | 25654 | buf_write_value_bytes(codegen, &buf[buf_i], elem); |
| 25617 | 25655 | buf_i += type_size(codegen, elem->type); |
| 25618 | 25656 | } |
| 25619 | 25657 | } |
| 25620 | 25658 | |
| 25621 | | static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val) { |
| 25659 | static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ZigValue *val) { |
| 25622 | 25660 | if (val->special == ConstValSpecialUndef) { |
| 25623 | 25661 | expand_undef_struct(codegen, val); |
| 25624 | 25662 | val->special = ConstValSpecialStatic; |
| ... | ... | @@ -25679,7 +25717,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue |
| 25679 | 25717 | TypeStructField *struct_field = val->type->data.structure.fields[field_i]; |
| 25680 | 25718 | if (struct_field->gen_index == SIZE_MAX) |
| 25681 | 25719 | continue; |
| 25682 | | ConstExprValue *field_val = val->data.x_struct.fields[field_i]; |
| 25720 | ZigValue *field_val = val->data.x_struct.fields[field_i]; |
| 25683 | 25721 | size_t offset = struct_field->offset; |
| 25684 | 25722 | buf_write_value_bytes(codegen, buf + offset, field_val); |
| 25685 | 25723 | } |
| ... | ... | @@ -25754,7 +25792,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue |
| 25754 | 25792 | } |
| 25755 | 25793 | |
| 25756 | 25794 | static Error buf_read_value_bytes_array(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf, |
| 25757 | | ConstExprValue *val, ZigType *elem_type, size_t len) |
| 25795 | ZigValue *val, ZigType *elem_type, size_t len) |
| 25758 | 25796 | { |
| 25759 | 25797 | Error err; |
| 25760 | 25798 | uint64_t elem_size = type_size(codegen, elem_type); |
| ... | ... | @@ -25763,7 +25801,7 @@ static Error buf_read_value_bytes_array(IrAnalyze *ira, CodeGen *codegen, AstNod |
| 25763 | 25801 | case ConstArraySpecialNone: |
| 25764 | 25802 | val->data.x_array.data.s_none.elements = create_const_vals(len); |
| 25765 | 25803 | for (size_t i = 0; i < len; i++) { |
| 25766 | | ConstExprValue *elem = &val->data.x_array.data.s_none.elements[i]; |
| 25804 | ZigValue *elem = &val->data.x_array.data.s_none.elements[i]; |
| 25767 | 25805 | elem->special = ConstValSpecialStatic; |
| 25768 | 25806 | elem->type = elem_type; |
| 25769 | 25807 | if ((err = buf_read_value_bytes(ira, codegen, source_node, buf + (elem_size * i), elem))) |
| ... | ... | @@ -25778,7 +25816,7 @@ static Error buf_read_value_bytes_array(IrAnalyze *ira, CodeGen *codegen, AstNod |
| 25778 | 25816 | zig_unreachable(); |
| 25779 | 25817 | } |
| 25780 | 25818 | |
| 25781 | | static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf, ConstExprValue *val) { |
| 25819 | static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *source_node, uint8_t *buf, ZigValue *val) { |
| 25782 | 25820 | Error err; |
| 25783 | 25821 | src_assert(val->special == ConstValSpecialStatic, source_node); |
| 25784 | 25822 | switch (val->type->id) { |
| ... | ... | @@ -25850,7 +25888,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou |
| 25850 | 25888 | size_t src_field_count = val->type->data.structure.src_field_count; |
| 25851 | 25889 | val->data.x_struct.fields = alloc_const_vals_ptrs(src_field_count); |
| 25852 | 25890 | for (size_t field_i = 0; field_i < src_field_count; field_i += 1) { |
| 25853 | | ConstExprValue *field_val = val->data.x_struct.fields[field_i]; |
| 25891 | ZigValue *field_val = val->data.x_struct.fields[field_i]; |
| 25854 | 25892 | field_val->special = ConstValSpecialStatic; |
| 25855 | 25893 | TypeStructField *struct_field = val->type->data.structure.fields[field_i]; |
| 25856 | 25894 | field_val->type = struct_field->type_entry; |
| ... | ... | @@ -25887,7 +25925,7 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou |
| 25887 | 25925 | src_assert(field->gen_index != SIZE_MAX, source_node); |
| 25888 | 25926 | if (field->gen_index != gen_i) |
| 25889 | 25927 | break; |
| 25890 | | ConstExprValue *field_val = val->data.x_struct.fields[src_i]; |
| 25928 | ZigValue *field_val = val->data.x_struct.fields[src_i]; |
| 25891 | 25929 | field_val->special = ConstValSpecialStatic; |
| 25892 | 25930 | field_val->type = field->type_entry; |
| 25893 | 25931 | uint32_t packed_bits_size = type_size_bits(codegen, field->type_entry); |
| ... | ... | @@ -25941,7 +25979,7 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_ |
| 25941 | 25979 | { |
| 25942 | 25980 | Error err; |
| 25943 | 25981 | |
| 25944 | | ZigType *src_type = value->value.type; |
| 25982 | ZigType *src_type = value->value->type; |
| 25945 | 25983 | ir_assert(get_codegen_ptr_type(src_type) == nullptr, source_instr); |
| 25946 | 25984 | ir_assert(type_can_bit_cast(src_type), source_instr); |
| 25947 | 25985 | ir_assert(get_codegen_ptr_type(dest_type) == nullptr, source_instr); |
| ... | ... | @@ -25975,14 +26013,14 @@ static IrInstruction *ir_analyze_bit_cast(IrAnalyze *ira, IrInstruction *source_ |
| 25975 | 26013 | } |
| 25976 | 26014 | |
| 25977 | 26015 | if (instr_is_comptime(value)) { |
| 25978 | | ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); |
| 26016 | ZigValue *val = ir_resolve_const(ira, value, UndefBad); |
| 25979 | 26017 | if (!val) |
| 25980 | 26018 | return ira->codegen->invalid_instruction; |
| 25981 | 26019 | |
| 25982 | 26020 | IrInstruction *result = ir_const(ira, source_instr, dest_type); |
| 25983 | 26021 | uint8_t *buf = allocate_nonzero<uint8_t>(src_size_bytes); |
| 25984 | 26022 | buf_write_value_bytes(ira->codegen, buf, val); |
| 25985 | | if ((err = buf_read_value_bytes(ira, ira->codegen, source_instr->source_node, buf, &result->value))) |
| 26023 | if ((err = buf_read_value_bytes(ira, ira->codegen, source_instr->source_node, buf, result->value))) |
| 25986 | 26024 | return ira->codegen->invalid_instruction; |
| 25987 | 26025 | return result; |
| 25988 | 26026 | } |
| ... | ... | @@ -25997,11 +26035,11 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc |
| 25997 | 26035 | ir_assert(type_has_bits(ptr_type), source_instr); |
| 25998 | 26036 | |
| 25999 | 26037 | IrInstruction *casted_int = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_usize); |
| 26000 | | if (type_is_invalid(casted_int->value.type)) |
| 26038 | if (type_is_invalid(casted_int->value->type)) |
| 26001 | 26039 | return ira->codegen->invalid_instruction; |
| 26002 | 26040 | |
| 26003 | 26041 | if (instr_is_comptime(casted_int)) { |
| 26004 | | ConstExprValue *val = ir_resolve_const(ira, casted_int, UndefBad); |
| 26042 | ZigValue *val = ir_resolve_const(ira, casted_int, UndefBad); |
| 26005 | 26043 | if (!val) |
| 26006 | 26044 | return ira->codegen->invalid_instruction; |
| 26007 | 26045 | |
| ... | ... | @@ -26013,15 +26051,15 @@ static IrInstruction *ir_analyze_int_to_ptr(IrAnalyze *ira, IrInstruction *sourc |
| 26013 | 26051 | } |
| 26014 | 26052 | |
| 26015 | 26053 | IrInstruction *result = ir_const(ira, source_instr, ptr_type); |
| 26016 | | result->value.data.x_ptr.special = ConstPtrSpecialHardCodedAddr; |
| 26017 | | result->value.data.x_ptr.mut = ConstPtrMutRuntimeVar; |
| 26018 | | result->value.data.x_ptr.data.hard_coded_addr.addr = addr; |
| 26054 | result->value->data.x_ptr.special = ConstPtrSpecialHardCodedAddr; |
| 26055 | result->value->data.x_ptr.mut = ConstPtrMutRuntimeVar; |
| 26056 | result->value->data.x_ptr.data.hard_coded_addr.addr = addr; |
| 26019 | 26057 | return result; |
| 26020 | 26058 | } |
| 26021 | 26059 | |
| 26022 | 26060 | IrInstruction *result = ir_build_int_to_ptr(&ira->new_irb, source_instr->scope, |
| 26023 | 26061 | source_instr->source_node, nullptr, casted_int); |
| 26024 | | result->value.type = ptr_type; |
| 26062 | result->value->type = ptr_type; |
| 26025 | 26063 | return result; |
| 26026 | 26064 | } |
| 26027 | 26065 | |
| ... | ... | @@ -26048,7 +26086,7 @@ static IrInstruction *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstru |
| 26048 | 26086 | |
| 26049 | 26087 | |
| 26050 | 26088 | IrInstruction *target = instruction->target->child; |
| 26051 | | if (type_is_invalid(target->value.type)) |
| 26089 | if (type_is_invalid(target->value->type)) |
| 26052 | 26090 | return ira->codegen->invalid_instruction; |
| 26053 | 26091 | |
| 26054 | 26092 | return ir_analyze_int_to_ptr(ira, &instruction->base, target, dest_type); |
| ... | ... | @@ -26058,7 +26096,7 @@ static IrInstruction *ir_analyze_instruction_decl_ref(IrAnalyze *ira, |
| 26058 | 26096 | IrInstructionDeclRef *instruction) |
| 26059 | 26097 | { |
| 26060 | 26098 | IrInstruction *ref_instruction = ir_analyze_decl_ref(ira, &instruction->base, instruction->tld); |
| 26061 | | if (type_is_invalid(ref_instruction->value.type)) { |
| 26099 | if (type_is_invalid(ref_instruction->value->type)) { |
| 26062 | 26100 | return ira->codegen->invalid_instruction; |
| 26063 | 26101 | } |
| 26064 | 26102 | |
| ... | ... | @@ -26072,51 +26110,51 @@ static IrInstruction *ir_analyze_instruction_decl_ref(IrAnalyze *ira, |
| 26072 | 26110 | static IrInstruction *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstructionPtrToInt *instruction) { |
| 26073 | 26111 | Error err; |
| 26074 | 26112 | IrInstruction *target = instruction->target->child; |
| 26075 | | if (type_is_invalid(target->value.type)) |
| 26113 | if (type_is_invalid(target->value->type)) |
| 26076 | 26114 | return ira->codegen->invalid_instruction; |
| 26077 | 26115 | |
| 26078 | 26116 | ZigType *usize = ira->codegen->builtin_types.entry_usize; |
| 26079 | 26117 | |
| 26080 | 26118 | // We check size explicitly so we can use get_src_ptr_type here. |
| 26081 | | if (get_src_ptr_type(target->value.type) == nullptr) { |
| 26119 | if (get_src_ptr_type(target->value->type) == nullptr) { |
| 26082 | 26120 | ir_add_error(ira, target, |
| 26083 | | buf_sprintf("expected pointer, found '%s'", buf_ptr(&target->value.type->name))); |
| 26121 | buf_sprintf("expected pointer, found '%s'", buf_ptr(&target->value->type->name))); |
| 26084 | 26122 | return ira->codegen->invalid_instruction; |
| 26085 | 26123 | } |
| 26086 | 26124 | |
| 26087 | | if ((err = type_resolve(ira->codegen, target->value.type, ResolveStatusZeroBitsKnown))) |
| 26125 | if ((err = type_resolve(ira->codegen, target->value->type, ResolveStatusZeroBitsKnown))) |
| 26088 | 26126 | return ira->codegen->invalid_instruction; |
| 26089 | | if (!type_has_bits(target->value.type)) { |
| 26127 | if (!type_has_bits(target->value->type)) { |
| 26090 | 26128 | ir_add_error(ira, target, |
| 26091 | 26129 | buf_sprintf("pointer to size 0 type has no address")); |
| 26092 | 26130 | return ira->codegen->invalid_instruction; |
| 26093 | 26131 | } |
| 26094 | 26132 | |
| 26095 | 26133 | if (instr_is_comptime(target)) { |
| 26096 | | ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); |
| 26134 | ZigValue *val = ir_resolve_const(ira, target, UndefBad); |
| 26097 | 26135 | if (!val) |
| 26098 | 26136 | return ira->codegen->invalid_instruction; |
| 26099 | 26137 | if (val->type->id == ZigTypeIdPointer && val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) { |
| 26100 | 26138 | IrInstruction *result = ir_const(ira, &instruction->base, usize); |
| 26101 | | bigint_init_unsigned(&result->value.data.x_bigint, val->data.x_ptr.data.hard_coded_addr.addr); |
| 26102 | | result->value.type = usize; |
| 26139 | bigint_init_unsigned(&result->value->data.x_bigint, val->data.x_ptr.data.hard_coded_addr.addr); |
| 26140 | result->value->type = usize; |
| 26103 | 26141 | return result; |
| 26104 | 26142 | } |
| 26105 | 26143 | } |
| 26106 | 26144 | |
| 26107 | 26145 | IrInstruction *result = ir_build_ptr_to_int(&ira->new_irb, instruction->base.scope, |
| 26108 | 26146 | instruction->base.source_node, target); |
| 26109 | | result->value.type = usize; |
| 26147 | result->value->type = usize; |
| 26110 | 26148 | return result; |
| 26111 | 26149 | } |
| 26112 | 26150 | |
| 26113 | 26151 | static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtrType *instruction) { |
| 26114 | 26152 | IrInstruction *result = ir_const(ira, &instruction->base, ira->codegen->builtin_types.entry_type); |
| 26115 | | result->value.special = ConstValSpecialLazy; |
| 26153 | result->value->special = ConstValSpecialLazy; |
| 26116 | 26154 | |
| 26117 | 26155 | LazyValuePtrType *lazy_ptr_type = allocate<LazyValuePtrType>(1); |
| 26118 | 26156 | lazy_ptr_type->ira = ira; |
| 26119 | | result->value.data.x_lazy = &lazy_ptr_type->base; |
| 26157 | result->value->data.x_lazy = &lazy_ptr_type->base; |
| 26120 | 26158 | lazy_ptr_type->base.id = LazyValueIdPtrType; |
| 26121 | 26159 | |
| 26122 | 26160 | if (instruction->sentinel != nullptr) { |
| ... | ... | @@ -26147,15 +26185,15 @@ static IrInstruction *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruct |
| 26147 | 26185 | |
| 26148 | 26186 | static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstructionAlignCast *instruction) { |
| 26149 | 26187 | IrInstruction *target = instruction->target->child; |
| 26150 | | if (type_is_invalid(target->value.type)) |
| 26188 | if (type_is_invalid(target->value->type)) |
| 26151 | 26189 | return ira->codegen->invalid_instruction; |
| 26152 | 26190 | |
| 26153 | 26191 | ZigType *elem_type = nullptr; |
| 26154 | | if (is_slice(target->value.type)) { |
| 26155 | | ZigType *slice_ptr_type = target->value.type->data.structure.fields[slice_ptr_index]->type_entry; |
| 26192 | if (is_slice(target->value->type)) { |
| 26193 | ZigType *slice_ptr_type = target->value->type->data.structure.fields[slice_ptr_index]->type_entry; |
| 26156 | 26194 | elem_type = slice_ptr_type->data.pointer.child_type; |
| 26157 | | } else if (target->value.type->id == ZigTypeIdPointer) { |
| 26158 | | elem_type = target->value.type->data.pointer.child_type; |
| 26195 | } else if (target->value->type->id == ZigTypeIdPointer) { |
| 26196 | elem_type = target->value->type->data.pointer.child_type; |
| 26159 | 26197 | } |
| 26160 | 26198 | |
| 26161 | 26199 | uint32_t align_bytes; |
| ... | ... | @@ -26164,7 +26202,7 @@ static IrInstruction *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstru |
| 26164 | 26202 | return ira->codegen->invalid_instruction; |
| 26165 | 26203 | |
| 26166 | 26204 | IrInstruction *result = ir_align_cast(ira, target, align_bytes, true); |
| 26167 | | if (type_is_invalid(result->value.type)) |
| 26205 | if (type_is_invalid(result->value->type)) |
| 26168 | 26206 | return ira->codegen->invalid_instruction; |
| 26169 | 26207 | |
| 26170 | 26208 | return result; |
| ... | ... | @@ -26350,13 +26388,13 @@ static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstru |
| 26350 | 26388 | return ira->codegen->invalid_instruction; |
| 26351 | 26389 | |
| 26352 | 26390 | IrInstruction *ptr_inst = instruction->ptr->child; |
| 26353 | | if (type_is_invalid(ptr_inst->value.type)) |
| 26391 | if (type_is_invalid(ptr_inst->value->type)) |
| 26354 | 26392 | return ira->codegen->invalid_instruction; |
| 26355 | 26393 | |
| 26356 | 26394 | // TODO let this be volatile |
| 26357 | 26395 | ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false); |
| 26358 | 26396 | IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type); |
| 26359 | | if (type_is_invalid(casted_ptr->value.type)) |
| 26397 | if (type_is_invalid(casted_ptr->value->type)) |
| 26360 | 26398 | return ira->codegen->invalid_instruction; |
| 26361 | 26399 | |
| 26362 | 26400 | AtomicRmwOp op; |
| ... | ... | @@ -26375,11 +26413,11 @@ static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstru |
| 26375 | 26413 | } |
| 26376 | 26414 | |
| 26377 | 26415 | IrInstruction *operand = instruction->operand->child; |
| 26378 | | if (type_is_invalid(operand->value.type)) |
| 26416 | if (type_is_invalid(operand->value->type)) |
| 26379 | 26417 | return ira->codegen->invalid_instruction; |
| 26380 | 26418 | |
| 26381 | 26419 | IrInstruction *casted_operand = ir_implicit_cast(ira, operand, operand_type); |
| 26382 | | if (type_is_invalid(casted_operand->value.type)) |
| 26420 | if (type_is_invalid(casted_operand->value->type)) |
| 26383 | 26421 | return ira->codegen->invalid_instruction; |
| 26384 | 26422 | |
| 26385 | 26423 | AtomicOrder ordering; |
| ... | ... | @@ -26395,7 +26433,7 @@ static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstru |
| 26395 | 26433 | } |
| 26396 | 26434 | } |
| 26397 | 26435 | |
| 26398 | | if (instr_is_comptime(casted_operand) && instr_is_comptime(casted_ptr) && casted_ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar) |
| 26436 | if (instr_is_comptime(casted_operand) && instr_is_comptime(casted_ptr) && casted_ptr->value->data.x_ptr.mut == ConstPtrMutComptimeVar) |
| 26399 | 26437 | { |
| 26400 | 26438 | zig_panic("TODO compile-time execution of atomicRmw"); |
| 26401 | 26439 | } |
| ... | ... | @@ -26403,7 +26441,7 @@ static IrInstruction *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstru |
| 26403 | 26441 | IrInstruction *result = ir_build_atomic_rmw(&ira->new_irb, instruction->base.scope, |
| 26404 | 26442 | instruction->base.source_node, nullptr, casted_ptr, nullptr, casted_operand, nullptr, |
| 26405 | 26443 | op, ordering); |
| 26406 | | result->value.type = operand_type; |
| 26444 | result->value->type = operand_type; |
| 26407 | 26445 | return result; |
| 26408 | 26446 | } |
| 26409 | 26447 | |
| ... | ... | @@ -26413,12 +26451,12 @@ static IrInstruction *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstr |
| 26413 | 26451 | return ira->codegen->invalid_instruction; |
| 26414 | 26452 | |
| 26415 | 26453 | IrInstruction *ptr_inst = instruction->ptr->child; |
| 26416 | | if (type_is_invalid(ptr_inst->value.type)) |
| 26454 | if (type_is_invalid(ptr_inst->value->type)) |
| 26417 | 26455 | return ira->codegen->invalid_instruction; |
| 26418 | 26456 | |
| 26419 | 26457 | ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, true); |
| 26420 | 26458 | IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type); |
| 26421 | | if (type_is_invalid(casted_ptr->value.type)) |
| 26459 | if (type_is_invalid(casted_ptr->value->type)) |
| 26422 | 26460 | return ira->codegen->invalid_instruction; |
| 26423 | 26461 | |
| 26424 | 26462 | AtomicOrder ordering; |
| ... | ... | @@ -26438,13 +26476,13 @@ static IrInstruction *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstr |
| 26438 | 26476 | |
| 26439 | 26477 | if (instr_is_comptime(casted_ptr)) { |
| 26440 | 26478 | IrInstruction *result = ir_get_deref(ira, &instruction->base, casted_ptr, nullptr); |
| 26441 | | ir_assert(result->value.type != nullptr, &instruction->base); |
| 26479 | ir_assert(result->value->type != nullptr, &instruction->base); |
| 26442 | 26480 | return result; |
| 26443 | 26481 | } |
| 26444 | 26482 | |
| 26445 | 26483 | IrInstruction *result = ir_build_atomic_load(&ira->new_irb, instruction->base.scope, |
| 26446 | 26484 | instruction->base.source_node, nullptr, casted_ptr, nullptr, ordering); |
| 26447 | | result->value.type = operand_type; |
| 26485 | result->value->type = operand_type; |
| 26448 | 26486 | return result; |
| 26449 | 26487 | } |
| 26450 | 26488 | |
| ... | ... | @@ -26454,20 +26492,20 @@ static IrInstruction *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInst |
| 26454 | 26492 | return ira->codegen->invalid_instruction; |
| 26455 | 26493 | |
| 26456 | 26494 | IrInstruction *ptr_inst = instruction->ptr->child; |
| 26457 | | if (type_is_invalid(ptr_inst->value.type)) |
| 26495 | if (type_is_invalid(ptr_inst->value->type)) |
| 26458 | 26496 | return ira->codegen->invalid_instruction; |
| 26459 | 26497 | |
| 26460 | 26498 | ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false); |
| 26461 | 26499 | IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type); |
| 26462 | | if (type_is_invalid(casted_ptr->value.type)) |
| 26500 | if (type_is_invalid(casted_ptr->value->type)) |
| 26463 | 26501 | return ira->codegen->invalid_instruction; |
| 26464 | 26502 | |
| 26465 | 26503 | IrInstruction *value = instruction->value->child; |
| 26466 | | if (type_is_invalid(value->value.type)) |
| 26504 | if (type_is_invalid(value->value->type)) |
| 26467 | 26505 | return ira->codegen->invalid_instruction; |
| 26468 | 26506 | |
| 26469 | 26507 | IrInstruction *casted_value = ir_implicit_cast(ira, value, operand_type); |
| 26470 | | if (type_is_invalid(casted_value->value.type)) |
| 26508 | if (type_is_invalid(casted_value->value->type)) |
| 26471 | 26509 | return ira->codegen->invalid_instruction; |
| 26472 | 26510 | |
| 26473 | 26511 | |
| ... | ... | @@ -26488,25 +26526,25 @@ static IrInstruction *ir_analyze_instruction_atomic_store(IrAnalyze *ira, IrInst |
| 26488 | 26526 | |
| 26489 | 26527 | if (instr_is_comptime(casted_value) && instr_is_comptime(casted_ptr)) { |
| 26490 | 26528 | IrInstruction *result = ir_analyze_store_ptr(ira, &instruction->base, casted_ptr, value, false); |
| 26491 | | result->value.type = ira->codegen->builtin_types.entry_void; |
| 26529 | result->value->type = ira->codegen->builtin_types.entry_void; |
| 26492 | 26530 | return result; |
| 26493 | 26531 | } |
| 26494 | 26532 | |
| 26495 | 26533 | IrInstruction *result = ir_build_atomic_store(&ira->new_irb, instruction->base.scope, |
| 26496 | 26534 | instruction->base.source_node, nullptr, casted_ptr, casted_value, nullptr, ordering); |
| 26497 | | result->value.type = ira->codegen->builtin_types.entry_void; |
| 26535 | result->value->type = ira->codegen->builtin_types.entry_void; |
| 26498 | 26536 | return result; |
| 26499 | 26537 | } |
| 26500 | 26538 | |
| 26501 | 26539 | static IrInstruction *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstructionSaveErrRetAddr *instruction) { |
| 26502 | 26540 | IrInstruction *result = ir_build_save_err_ret_addr(&ira->new_irb, instruction->base.scope, |
| 26503 | 26541 | instruction->base.source_node); |
| 26504 | | result->value.type = ira->codegen->builtin_types.entry_void; |
| 26542 | result->value->type = ira->codegen->builtin_types.entry_void; |
| 26505 | 26543 | return result; |
| 26506 | 26544 | } |
| 26507 | 26545 | |
| 26508 | 26546 | static void ir_eval_float_op(IrAnalyze *ira, IrInstructionFloatOp *source_instr, ZigType *float_type, |
| 26509 | | ConstExprValue *op, ConstExprValue *out_val) { |
| 26547 | ZigValue *op, ZigValue *out_val) { |
| 26510 | 26548 | assert(ira && source_instr && float_type && out_val && op); |
| 26511 | 26549 | assert(float_type->id == ZigTypeIdFloat || |
| 26512 | 26550 | float_type->id == ZigTypeIdComptimeFloat); |
| ... | ... | @@ -26687,7 +26725,7 @@ static void ir_eval_float_op(IrAnalyze *ira, IrInstructionFloatOp *source_instr, |
| 26687 | 26725 | |
| 26688 | 26726 | static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstructionFloatOp *instruction) { |
| 26689 | 26727 | IrInstruction *type = instruction->type->child; |
| 26690 | | if (type_is_invalid(type->value.type)) |
| 26728 | if (type_is_invalid(type->value->type)) |
| 26691 | 26729 | return ira->codegen->invalid_instruction; |
| 26692 | 26730 | |
| 26693 | 26731 | ZigType *expr_type = ir_resolve_type(ira, type); |
| ... | ... | @@ -26702,11 +26740,11 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct |
| 26702 | 26740 | } |
| 26703 | 26741 | |
| 26704 | 26742 | IrInstruction *op1 = instruction->op1->child; |
| 26705 | | if (type_is_invalid(op1->value.type)) |
| 26743 | if (type_is_invalid(op1->value->type)) |
| 26706 | 26744 | return ira->codegen->invalid_instruction; |
| 26707 | 26745 | |
| 26708 | 26746 | IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, float_type); |
| 26709 | | if (type_is_invalid(casted_op1->value.type)) |
| 26747 | if (type_is_invalid(casted_op1->value->type)) |
| 26710 | 26748 | return ira->codegen->invalid_instruction; |
| 26711 | 26749 | |
| 26712 | 26750 | if (instr_is_comptime(casted_op1)) { |
| ... | ... | @@ -26719,12 +26757,12 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct |
| 26719 | 26757 | return ira->codegen->invalid_instruction; |
| 26720 | 26758 | } |
| 26721 | 26759 | |
| 26722 | | ConstExprValue *op1_const = ir_resolve_const(ira, casted_op1, UndefBad); |
| 26760 | ZigValue *op1_const = ir_resolve_const(ira, casted_op1, UndefBad); |
| 26723 | 26761 | if (!op1_const) |
| 26724 | 26762 | return ira->codegen->invalid_instruction; |
| 26725 | 26763 | |
| 26726 | 26764 | IrInstruction *result = ir_const(ira, &instruction->base, expr_type); |
| 26727 | | ConstExprValue *out_val = &result->value; |
| 26765 | ZigValue *out_val = result->value; |
| 26728 | 26766 | |
| 26729 | 26767 | if (expr_type->id == ZigTypeIdVector) { |
| 26730 | 26768 | expand_undef_array(ira->codegen, op1_const); |
| ... | ... | @@ -26732,8 +26770,8 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct |
| 26732 | 26770 | expand_undef_array(ira->codegen, out_val); |
| 26733 | 26771 | size_t len = expr_type->data.vector.len; |
| 26734 | 26772 | for (size_t i = 0; i < len; i += 1) { |
| 26735 | | ConstExprValue *float_operand_op1 = &op1_const->data.x_array.data.s_none.elements[i]; |
| 26736 | | ConstExprValue *float_out_val = &out_val->data.x_array.data.s_none.elements[i]; |
| 26773 | ZigValue *float_operand_op1 = &op1_const->data.x_array.data.s_none.elements[i]; |
| 26774 | ZigValue *float_out_val = &out_val->data.x_array.data.s_none.elements[i]; |
| 26737 | 26775 | assert(float_operand_op1->type == float_type); |
| 26738 | 26776 | assert(float_out_val->type == float_type); |
| 26739 | 26777 | ir_eval_float_op(ira, instruction, float_type, |
| ... | ... | @@ -26752,7 +26790,7 @@ static IrInstruction *ir_analyze_instruction_float_op(IrAnalyze *ira, IrInstruct |
| 26752 | 26790 | |
| 26753 | 26791 | IrInstruction *result = ir_build_float_op(&ira->new_irb, instruction->base.scope, |
| 26754 | 26792 | instruction->base.source_node, nullptr, casted_op1, instruction->op); |
| 26755 | | result->value.type = expr_type; |
| 26793 | result->value->type = expr_type; |
| 26756 | 26794 | return result; |
| 26757 | 26795 | } |
| 26758 | 26796 | |
| ... | ... | @@ -26764,16 +26802,16 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction |
| 26764 | 26802 | return ira->codegen->invalid_instruction; |
| 26765 | 26803 | |
| 26766 | 26804 | IrInstruction *uncasted_op = instruction->op->child; |
| 26767 | | if (type_is_invalid(uncasted_op->value.type)) |
| 26805 | if (type_is_invalid(uncasted_op->value->type)) |
| 26768 | 26806 | return ira->codegen->invalid_instruction; |
| 26769 | 26807 | |
| 26770 | 26808 | uint32_t vector_len; // UINT32_MAX means not a vector |
| 26771 | | if (uncasted_op->value.type->id == ZigTypeIdArray && |
| 26772 | | is_valid_vector_elem_type(uncasted_op->value.type->data.array.child_type)) |
| 26809 | if (uncasted_op->value->type->id == ZigTypeIdArray && |
| 26810 | is_valid_vector_elem_type(uncasted_op->value->type->data.array.child_type)) |
| 26773 | 26811 | { |
| 26774 | | vector_len = uncasted_op->value.type->data.array.len; |
| 26775 | | } else if (uncasted_op->value.type->id == ZigTypeIdVector) { |
| 26776 | | vector_len = uncasted_op->value.type->data.vector.len; |
| 26812 | vector_len = uncasted_op->value->type->data.array.len; |
| 26813 | } else if (uncasted_op->value->type->id == ZigTypeIdVector) { |
| 26814 | vector_len = uncasted_op->value->type->data.vector.len; |
| 26777 | 26815 | } else { |
| 26778 | 26816 | vector_len = UINT32_MAX; |
| 26779 | 26817 | } |
| ... | ... | @@ -26782,7 +26820,7 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction |
| 26782 | 26820 | ZigType *op_type = is_vector ? get_vector_type(ira->codegen, vector_len, int_type) : int_type; |
| 26783 | 26821 | |
| 26784 | 26822 | IrInstruction *op = ir_implicit_cast(ira, uncasted_op, op_type); |
| 26785 | | if (type_is_invalid(op->value.type)) |
| 26823 | if (type_is_invalid(op->value->type)) |
| 26786 | 26824 | return ira->codegen->invalid_instruction; |
| 26787 | 26825 | |
| 26788 | 26826 | if (int_type->data.integral.bit_count == 8 || int_type->data.integral.bit_count == 0) |
| ... | ... | @@ -26796,7 +26834,7 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction |
| 26796 | 26834 | } |
| 26797 | 26835 | |
| 26798 | 26836 | if (instr_is_comptime(op)) { |
| 26799 | | ConstExprValue *val = ir_resolve_const(ira, op, UndefOk); |
| 26837 | ZigValue *val = ir_resolve_const(ira, op, UndefOk); |
| 26800 | 26838 | if (val == nullptr) |
| 26801 | 26839 | return ira->codegen->invalid_instruction; |
| 26802 | 26840 | if (val->special == ConstValSpecialUndef) |
| ... | ... | @@ -26807,28 +26845,28 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction |
| 26807 | 26845 | uint8_t *buf = allocate_nonzero<uint8_t>(buf_size); |
| 26808 | 26846 | if (is_vector) { |
| 26809 | 26847 | expand_undef_array(ira->codegen, val); |
| 26810 | | result->value.data.x_array.data.s_none.elements = create_const_vals(op_type->data.vector.len); |
| 26848 | result->value->data.x_array.data.s_none.elements = create_const_vals(op_type->data.vector.len); |
| 26811 | 26849 | for (unsigned i = 0; i < op_type->data.vector.len; i += 1) { |
| 26812 | | ConstExprValue *op_elem_val = &val->data.x_array.data.s_none.elements[i]; |
| 26850 | ZigValue *op_elem_val = &val->data.x_array.data.s_none.elements[i]; |
| 26813 | 26851 | if ((err = ir_resolve_const_val(ira->codegen, ira->new_irb.exec, instruction->base.source_node, |
| 26814 | 26852 | op_elem_val, UndefOk))) |
| 26815 | 26853 | { |
| 26816 | 26854 | return ira->codegen->invalid_instruction; |
| 26817 | 26855 | } |
| 26818 | | ConstExprValue *result_elem_val = &result->value.data.x_array.data.s_none.elements[i]; |
| 26856 | ZigValue *result_elem_val = &result->value->data.x_array.data.s_none.elements[i]; |
| 26819 | 26857 | result_elem_val->type = int_type; |
| 26820 | 26858 | result_elem_val->special = op_elem_val->special; |
| 26821 | 26859 | if (op_elem_val->special == ConstValSpecialUndef) |
| 26822 | 26860 | continue; |
| 26823 | 26861 | |
| 26824 | 26862 | bigint_write_twos_complement(&op_elem_val->data.x_bigint, buf, int_type->data.integral.bit_count, true); |
| 26825 | | bigint_read_twos_complement(&result->value.data.x_array.data.s_none.elements[i].data.x_bigint, |
| 26863 | bigint_read_twos_complement(&result->value->data.x_array.data.s_none.elements[i].data.x_bigint, |
| 26826 | 26864 | buf, int_type->data.integral.bit_count, false, |
| 26827 | 26865 | int_type->data.integral.is_signed); |
| 26828 | 26866 | } |
| 26829 | 26867 | } else { |
| 26830 | 26868 | bigint_write_twos_complement(&val->data.x_bigint, buf, int_type->data.integral.bit_count, true); |
| 26831 | | bigint_read_twos_complement(&result->value.data.x_bigint, buf, int_type->data.integral.bit_count, false, |
| 26869 | bigint_read_twos_complement(&result->value->data.x_bigint, buf, int_type->data.integral.bit_count, false, |
| 26832 | 26870 | int_type->data.integral.is_signed); |
| 26833 | 26871 | } |
| 26834 | 26872 | free(buf); |
| ... | ... | @@ -26837,7 +26875,7 @@ static IrInstruction *ir_analyze_instruction_bswap(IrAnalyze *ira, IrInstruction |
| 26837 | 26875 | |
| 26838 | 26876 | IrInstruction *result = ir_build_bswap(&ira->new_irb, instruction->base.scope, |
| 26839 | 26877 | instruction->base.source_node, nullptr, op); |
| 26840 | | result->value.type = op_type; |
| 26878 | result->value->type = op_type; |
| 26841 | 26879 | return result; |
| 26842 | 26880 | } |
| 26843 | 26881 | |
| ... | ... | @@ -26847,17 +26885,17 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr |
| 26847 | 26885 | return ira->codegen->invalid_instruction; |
| 26848 | 26886 | |
| 26849 | 26887 | IrInstruction *op = ir_implicit_cast(ira, instruction->op->child, int_type); |
| 26850 | | if (type_is_invalid(op->value.type)) |
| 26888 | if (type_is_invalid(op->value->type)) |
| 26851 | 26889 | return ira->codegen->invalid_instruction; |
| 26852 | 26890 | |
| 26853 | 26891 | if (int_type->data.integral.bit_count == 0) { |
| 26854 | 26892 | IrInstruction *result = ir_const(ira, &instruction->base, int_type); |
| 26855 | | bigint_init_unsigned(&result->value.data.x_bigint, 0); |
| 26893 | bigint_init_unsigned(&result->value->data.x_bigint, 0); |
| 26856 | 26894 | return result; |
| 26857 | 26895 | } |
| 26858 | 26896 | |
| 26859 | 26897 | if (instr_is_comptime(op)) { |
| 26860 | | ConstExprValue *val = ir_resolve_const(ira, op, UndefOk); |
| 26898 | ZigValue *val = ir_resolve_const(ira, op, UndefOk); |
| 26861 | 26899 | if (val == nullptr) |
| 26862 | 26900 | return ira->codegen->invalid_instruction; |
| 26863 | 26901 | if (val->special == ConstValSpecialUndef) |
| ... | ... | @@ -26881,7 +26919,7 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr |
| 26881 | 26919 | } |
| 26882 | 26920 | } |
| 26883 | 26921 | |
| 26884 | | bigint_read_twos_complement(&result->value.data.x_bigint, |
| 26922 | bigint_read_twos_complement(&result->value->data.x_bigint, |
| 26885 | 26923 | result_buf, |
| 26886 | 26924 | int_type->data.integral.bit_count, |
| 26887 | 26925 | ira->codegen->is_big_endian, |
| ... | ... | @@ -26892,14 +26930,14 @@ static IrInstruction *ir_analyze_instruction_bit_reverse(IrAnalyze *ira, IrInstr |
| 26892 | 26930 | |
| 26893 | 26931 | IrInstruction *result = ir_build_bit_reverse(&ira->new_irb, instruction->base.scope, |
| 26894 | 26932 | instruction->base.source_node, nullptr, op); |
| 26895 | | result->value.type = int_type; |
| 26933 | result->value->type = int_type; |
| 26896 | 26934 | return result; |
| 26897 | 26935 | } |
| 26898 | 26936 | |
| 26899 | 26937 | |
| 26900 | 26938 | static IrInstruction *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstructionEnumToInt *instruction) { |
| 26901 | 26939 | IrInstruction *target = instruction->target->child; |
| 26902 | | if (type_is_invalid(target->value.type)) |
| 26940 | if (type_is_invalid(target->value->type)) |
| 26903 | 26941 | return ira->codegen->invalid_instruction; |
| 26904 | 26942 | |
| 26905 | 26943 | return ir_analyze_enum_to_int(ira, &instruction->base, target); |
| ... | ... | @@ -26924,11 +26962,11 @@ static IrInstruction *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstr |
| 26924 | 26962 | ZigType *tag_type = dest_type->data.enumeration.tag_int_type; |
| 26925 | 26963 | |
| 26926 | 26964 | IrInstruction *target = instruction->target->child; |
| 26927 | | if (type_is_invalid(target->value.type)) |
| 26965 | if (type_is_invalid(target->value->type)) |
| 26928 | 26966 | return ira->codegen->invalid_instruction; |
| 26929 | 26967 | |
| 26930 | 26968 | IrInstruction *casted_target = ir_implicit_cast(ira, target, tag_type); |
| 26931 | | if (type_is_invalid(casted_target->value.type)) |
| 26969 | if (type_is_invalid(casted_target->value->type)) |
| 26932 | 26970 | return ira->codegen->invalid_instruction; |
| 26933 | 26971 | |
| 26934 | 26972 | return ir_analyze_int_to_enum(ira, &instruction->base, casted_target, dest_type); |
| ... | ... | @@ -26995,33 +27033,33 @@ static IrInstruction *ir_analyze_instruction_undeclared_ident(IrAnalyze *ira, Ir |
| 26995 | 27033 | |
| 26996 | 27034 | static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstructionEndExpr *instruction) { |
| 26997 | 27035 | IrInstruction *value = instruction->value->child; |
| 26998 | | if (type_is_invalid(value->value.type)) |
| 27036 | if (type_is_invalid(value->value->type)) |
| 26999 | 27037 | return ira->codegen->invalid_instruction; |
| 27000 | 27038 | |
| 27001 | 27039 | bool was_written = instruction->result_loc->written; |
| 27002 | 27040 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 27003 | | value->value.type, value, false, false, true); |
| 27041 | value->value->type, value, false, false, true); |
| 27004 | 27042 | if (result_loc != nullptr) { |
| 27005 | | if (type_is_invalid(result_loc->value.type)) |
| 27043 | if (type_is_invalid(result_loc->value->type)) |
| 27006 | 27044 | return ira->codegen->invalid_instruction; |
| 27007 | | if (result_loc->value.type->id == ZigTypeIdUnreachable) |
| 27045 | if (result_loc->value->type->id == ZigTypeIdUnreachable) |
| 27008 | 27046 | return result_loc; |
| 27009 | 27047 | |
| 27010 | 27048 | if (!was_written || instruction->result_loc->id == ResultLocIdPeer) { |
| 27011 | 27049 | IrInstruction *store_ptr = ir_analyze_store_ptr(ira, &instruction->base, result_loc, value, |
| 27012 | 27050 | instruction->result_loc->allow_write_through_const); |
| 27013 | | if (type_is_invalid(store_ptr->value.type)) { |
| 27051 | if (type_is_invalid(store_ptr->value->type)) { |
| 27014 | 27052 | return ira->codegen->invalid_instruction; |
| 27015 | 27053 | } |
| 27016 | 27054 | } |
| 27017 | 27055 | |
| 27018 | | if (result_loc->value.data.x_ptr.mut == ConstPtrMutInfer && |
| 27056 | if (result_loc->value->data.x_ptr.mut == ConstPtrMutInfer && |
| 27019 | 27057 | instruction->result_loc->id != ResultLocIdPeer) |
| 27020 | 27058 | { |
| 27021 | 27059 | if (instr_is_comptime(value)) { |
| 27022 | | result_loc->value.data.x_ptr.mut = ConstPtrMutComptimeConst; |
| 27060 | result_loc->value->data.x_ptr.mut = ConstPtrMutComptimeConst; |
| 27023 | 27061 | } else { |
| 27024 | | result_loc->value.special = ConstValSpecialRuntime; |
| 27062 | result_loc->value->special = ConstValSpecialRuntime; |
| 27025 | 27063 | } |
| 27026 | 27064 | } |
| 27027 | 27065 | } |
| ... | ... | @@ -27031,12 +27069,12 @@ static IrInstruction *ir_analyze_instruction_end_expr(IrAnalyze *ira, IrInstruct |
| 27031 | 27069 | |
| 27032 | 27070 | static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrInstructionImplicitCast *instruction) { |
| 27033 | 27071 | IrInstruction *operand = instruction->operand->child; |
| 27034 | | if (type_is_invalid(operand->value.type)) |
| 27072 | if (type_is_invalid(operand->value->type)) |
| 27035 | 27073 | return operand; |
| 27036 | 27074 | |
| 27037 | 27075 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, |
| 27038 | | &instruction->result_loc_cast->base, operand->value.type, operand, false, false, true); |
| 27039 | | if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc))) |
| 27076 | &instruction->result_loc_cast->base, operand->value->type, operand, false, false, true); |
| 27077 | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) |
| 27040 | 27078 | return result_loc; |
| 27041 | 27079 | |
| 27042 | 27080 | if (instruction->result_loc_cast->parent->gen_instruction != nullptr) { |
| ... | ... | @@ -27051,12 +27089,12 @@ static IrInstruction *ir_analyze_instruction_implicit_cast(IrAnalyze *ira, IrIns |
| 27051 | 27089 | |
| 27052 | 27090 | static IrInstruction *ir_analyze_instruction_bit_cast_src(IrAnalyze *ira, IrInstructionBitCastSrc *instruction) { |
| 27053 | 27091 | IrInstruction *operand = instruction->operand->child; |
| 27054 | | if (type_is_invalid(operand->value.type)) |
| 27092 | if (type_is_invalid(operand->value->type)) |
| 27055 | 27093 | return operand; |
| 27056 | 27094 | |
| 27057 | 27095 | IrInstruction *result_loc = ir_resolve_result(ira, &instruction->base, |
| 27058 | | &instruction->result_loc_bit_cast->base, operand->value.type, operand, false, false, true); |
| 27059 | | if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc))) |
| 27096 | &instruction->result_loc_bit_cast->base, operand->value->type, operand, false, false, true); |
| 27097 | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) |
| 27060 | 27098 | return result_loc; |
| 27061 | 27099 | |
| 27062 | 27100 | if (instruction->result_loc_bit_cast->parent->gen_instruction != nullptr) { |
| ... | ... | @@ -27084,11 +27122,11 @@ static IrInstruction *ir_analyze_instruction_union_init_named_field(IrAnalyze *i |
| 27084 | 27122 | return ira->codegen->invalid_instruction; |
| 27085 | 27123 | |
| 27086 | 27124 | IrInstruction *field_result_loc = instruction->field_result_loc->child; |
| 27087 | | if (type_is_invalid(field_result_loc->value.type)) |
| 27125 | if (type_is_invalid(field_result_loc->value->type)) |
| 27088 | 27126 | return ira->codegen->invalid_instruction; |
| 27089 | 27127 | |
| 27090 | 27128 | IrInstruction *result_loc = instruction->result_loc->child; |
| 27091 | | if (type_is_invalid(result_loc->value.type)) |
| 27129 | if (type_is_invalid(result_loc->value->type)) |
| 27092 | 27130 | return ira->codegen->invalid_instruction; |
| 27093 | 27131 | |
| 27094 | 27132 | return ir_analyze_union_init(ira, &instruction->base, instruction->base.source_node, |
| ... | ... | @@ -27105,7 +27143,7 @@ static IrInstruction *ir_analyze_instruction_suspend_finish(IrAnalyze *ira, |
| 27105 | 27143 | IrInstructionSuspendFinish *instruction) |
| 27106 | 27144 | { |
| 27107 | 27145 | IrInstruction *begin_base = instruction->begin->base.child; |
| 27108 | | if (type_is_invalid(begin_base->value.type)) |
| 27146 | if (type_is_invalid(begin_base->value->type)) |
| 27109 | 27147 | return ira->codegen->invalid_instruction; |
| 27110 | 27148 | ir_assert(begin_base->id == IrInstructionIdSuspendBegin, &instruction->base); |
| 27111 | 27149 | IrInstructionSuspendBegin *begin = reinterpret_cast<IrInstructionSuspendBegin *>(begin_base); |
| ... | ... | @@ -27123,44 +27161,44 @@ static IrInstruction *ir_analyze_instruction_suspend_finish(IrAnalyze *ira, |
| 27123 | 27161 | static IrInstruction *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInstruction *source_instr, |
| 27124 | 27162 | IrInstruction *frame_ptr, ZigFn **target_fn) |
| 27125 | 27163 | { |
| 27126 | | if (type_is_invalid(frame_ptr->value.type)) |
| 27164 | if (type_is_invalid(frame_ptr->value->type)) |
| 27127 | 27165 | return ira->codegen->invalid_instruction; |
| 27128 | 27166 | |
| 27129 | 27167 | *target_fn = nullptr; |
| 27130 | 27168 | |
| 27131 | 27169 | ZigType *result_type; |
| 27132 | 27170 | IrInstruction *frame; |
| 27133 | | if (frame_ptr->value.type->id == ZigTypeIdPointer && |
| 27134 | | frame_ptr->value.type->data.pointer.ptr_len == PtrLenSingle && |
| 27135 | | frame_ptr->value.type->data.pointer.child_type->id == ZigTypeIdFnFrame) |
| 27171 | if (frame_ptr->value->type->id == ZigTypeIdPointer && |
| 27172 | frame_ptr->value->type->data.pointer.ptr_len == PtrLenSingle && |
| 27173 | frame_ptr->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame) |
| 27136 | 27174 | { |
| 27137 | | ZigFn *func = frame_ptr->value.type->data.pointer.child_type->data.frame.fn; |
| 27175 | ZigFn *func = frame_ptr->value->type->data.pointer.child_type->data.frame.fn; |
| 27138 | 27176 | result_type = func->type_entry->data.fn.fn_type_id.return_type; |
| 27139 | 27177 | *target_fn = func; |
| 27140 | 27178 | frame = frame_ptr; |
| 27141 | 27179 | } else { |
| 27142 | 27180 | frame = ir_get_deref(ira, source_instr, frame_ptr, nullptr); |
| 27143 | | if (frame->value.type->id == ZigTypeIdPointer && |
| 27144 | | frame->value.type->data.pointer.ptr_len == PtrLenSingle && |
| 27145 | | frame->value.type->data.pointer.child_type->id == ZigTypeIdFnFrame) |
| 27181 | if (frame->value->type->id == ZigTypeIdPointer && |
| 27182 | frame->value->type->data.pointer.ptr_len == PtrLenSingle && |
| 27183 | frame->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame) |
| 27146 | 27184 | { |
| 27147 | | ZigFn *func = frame->value.type->data.pointer.child_type->data.frame.fn; |
| 27185 | ZigFn *func = frame->value->type->data.pointer.child_type->data.frame.fn; |
| 27148 | 27186 | result_type = func->type_entry->data.fn.fn_type_id.return_type; |
| 27149 | 27187 | *target_fn = func; |
| 27150 | | } else if (frame->value.type->id != ZigTypeIdAnyFrame || |
| 27151 | | frame->value.type->data.any_frame.result_type == nullptr) |
| 27188 | } else if (frame->value->type->id != ZigTypeIdAnyFrame || |
| 27189 | frame->value->type->data.any_frame.result_type == nullptr) |
| 27152 | 27190 | { |
| 27153 | 27191 | ir_add_error(ira, source_instr, |
| 27154 | | buf_sprintf("expected anyframe->T, found '%s'", buf_ptr(&frame->value.type->name))); |
| 27192 | buf_sprintf("expected anyframe->T, found '%s'", buf_ptr(&frame->value->type->name))); |
| 27155 | 27193 | return ira->codegen->invalid_instruction; |
| 27156 | 27194 | } else { |
| 27157 | | result_type = frame->value.type->data.any_frame.result_type; |
| 27195 | result_type = frame->value->type->data.any_frame.result_type; |
| 27158 | 27196 | } |
| 27159 | 27197 | } |
| 27160 | 27198 | |
| 27161 | 27199 | ZigType *any_frame_type = get_any_frame_type(ira->codegen, result_type); |
| 27162 | 27200 | IrInstruction *casted_frame = ir_implicit_cast(ira, frame, any_frame_type); |
| 27163 | | if (type_is_invalid(casted_frame->value.type)) |
| 27201 | if (type_is_invalid(casted_frame->value->type)) |
| 27164 | 27202 | return ira->codegen->invalid_instruction; |
| 27165 | 27203 | |
| 27166 | 27204 | return casted_frame; |
| ... | ... | @@ -27168,14 +27206,14 @@ static IrInstruction *analyze_frame_ptr_to_anyframe_T(IrAnalyze *ira, IrInstruct |
| 27168 | 27206 | |
| 27169 | 27207 | static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstructionAwaitSrc *instruction) { |
| 27170 | 27208 | IrInstruction *operand = instruction->frame->child; |
| 27171 | | if (type_is_invalid(operand->value.type)) |
| 27209 | if (type_is_invalid(operand->value->type)) |
| 27172 | 27210 | return ira->codegen->invalid_instruction; |
| 27173 | 27211 | ZigFn *target_fn; |
| 27174 | 27212 | IrInstruction *frame = analyze_frame_ptr_to_anyframe_T(ira, &instruction->base, operand, &target_fn); |
| 27175 | | if (type_is_invalid(frame->value.type)) |
| 27213 | if (type_is_invalid(frame->value->type)) |
| 27176 | 27214 | return ira->codegen->invalid_instruction; |
| 27177 | 27215 | |
| 27178 | | ZigType *result_type = frame->value.type->data.any_frame.result_type; |
| 27216 | ZigType *result_type = frame->value->type->data.any_frame.result_type; |
| 27179 | 27217 | |
| 27180 | 27218 | ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); |
| 27181 | 27219 | ir_assert(fn_entry != nullptr, &instruction->base); |
| ... | ... | @@ -27195,7 +27233,7 @@ static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstruction |
| 27195 | 27233 | if (type_has_bits(result_type)) { |
| 27196 | 27234 | result_loc = ir_resolve_result(ira, &instruction->base, instruction->result_loc, |
| 27197 | 27235 | result_type, nullptr, true, true, true); |
| 27198 | | if (result_loc != nullptr && (type_is_invalid(result_loc->value.type) || instr_is_unreachable(result_loc))) |
| 27236 | if (result_loc != nullptr && (type_is_invalid(result_loc->value->type) || instr_is_unreachable(result_loc))) |
| 27199 | 27237 | return result_loc; |
| 27200 | 27238 | } else { |
| 27201 | 27239 | result_loc = nullptr; |
| ... | ... | @@ -27209,13 +27247,13 @@ static IrInstruction *ir_analyze_instruction_await(IrAnalyze *ira, IrInstruction |
| 27209 | 27247 | |
| 27210 | 27248 | static IrInstruction *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstructionResume *instruction) { |
| 27211 | 27249 | IrInstruction *frame_ptr = instruction->frame->child; |
| 27212 | | if (type_is_invalid(frame_ptr->value.type)) |
| 27250 | if (type_is_invalid(frame_ptr->value->type)) |
| 27213 | 27251 | return ira->codegen->invalid_instruction; |
| 27214 | 27252 | |
| 27215 | 27253 | IrInstruction *frame; |
| 27216 | | if (frame_ptr->value.type->id == ZigTypeIdPointer && |
| 27217 | | frame_ptr->value.type->data.pointer.ptr_len == PtrLenSingle && |
| 27218 | | frame_ptr->value.type->data.pointer.child_type->id == ZigTypeIdFnFrame) |
| 27254 | if (frame_ptr->value->type->id == ZigTypeIdPointer && |
| 27255 | frame_ptr->value->type->data.pointer.ptr_len == PtrLenSingle && |
| 27256 | frame_ptr->value->type->data.pointer.child_type->id == ZigTypeIdFnFrame) |
| 27219 | 27257 | { |
| 27220 | 27258 | frame = frame_ptr; |
| 27221 | 27259 | } else { |
| ... | ... | @@ -27224,7 +27262,7 @@ static IrInstruction *ir_analyze_instruction_resume(IrAnalyze *ira, IrInstructio |
| 27224 | 27262 | |
| 27225 | 27263 | ZigType *any_frame_type = get_any_frame_type(ira->codegen, nullptr); |
| 27226 | 27264 | IrInstruction *casted_frame = ir_implicit_cast(ira, frame, any_frame_type); |
| 27227 | | if (type_is_invalid(casted_frame->value.type)) |
| 27265 | if (type_is_invalid(casted_frame->value->type)) |
| 27228 | 27266 | return ira->codegen->invalid_instruction; |
| 27229 | 27267 | |
| 27230 | 27268 | return ir_build_resume(&ira->new_irb, instruction->base.scope, instruction->base.source_node, casted_frame); |
| ... | ... | @@ -27235,10 +27273,10 @@ static IrInstruction *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstr |
| 27235 | 27273 | return ir_const_void(ira, &instruction->base); |
| 27236 | 27274 | |
| 27237 | 27275 | IrInstruction *operand = instruction->operand->child; |
| 27238 | | if (type_is_invalid(operand->value.type)) |
| 27276 | if (type_is_invalid(operand->value->type)) |
| 27239 | 27277 | return ira->codegen->invalid_instruction; |
| 27240 | 27278 | |
| 27241 | | if (!type_has_bits(operand->value.type)) |
| 27279 | if (!type_has_bits(operand->value->type)) |
| 27242 | 27280 | return ir_const_void(ira, &instruction->base); |
| 27243 | 27281 | |
| 27244 | 27282 | ir_assert(instruction->spill_id == SpillIdRetErrCode, &instruction->base); |
| ... | ... | @@ -27251,10 +27289,10 @@ static IrInstruction *ir_analyze_instruction_spill_begin(IrAnalyze *ira, IrInstr |
| 27251 | 27289 | |
| 27252 | 27290 | static IrInstruction *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstructionSpillEnd *instruction) { |
| 27253 | 27291 | IrInstruction *operand = instruction->begin->operand->child; |
| 27254 | | if (type_is_invalid(operand->value.type)) |
| 27292 | if (type_is_invalid(operand->value->type)) |
| 27255 | 27293 | return ira->codegen->invalid_instruction; |
| 27256 | 27294 | |
| 27257 | | if (ir_should_inline(ira->new_irb.exec, instruction->base.scope) || !type_has_bits(operand->value.type)) |
| 27295 | if (ir_should_inline(ira->new_irb.exec, instruction->base.scope) || !type_has_bits(operand->value->type)) |
| 27258 | 27296 | return operand; |
| 27259 | 27297 | |
| 27260 | 27298 | ir_assert(instruction->begin->base.child->id == IrInstructionIdSpillBegin, &instruction->base); |
| ... | ... | @@ -27262,7 +27300,7 @@ static IrInstruction *ir_analyze_instruction_spill_end(IrAnalyze *ira, IrInstruc |
| 27262 | 27300 | |
| 27263 | 27301 | IrInstruction *result = ir_build_spill_end(&ira->new_irb, instruction->base.scope, |
| 27264 | 27302 | instruction->base.source_node, begin); |
| 27265 | | result->value.type = operand->value.type; |
| 27303 | result->value->type = operand->value->type; |
| 27266 | 27304 | return result; |
| 27267 | 27305 | } |
| 27268 | 27306 | |
| ... | ... | @@ -27601,7 +27639,7 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ |
| 27601 | 27639 | ira->new_irb.codegen = codegen; |
| 27602 | 27640 | ira->new_irb.exec = new_exec; |
| 27603 | 27641 | |
| 27604 | | ConstExprValue *vals = create_const_vals(ira->old_irb.exec->mem_slot_count); |
| 27642 | ZigValue *vals = create_const_vals(ira->old_irb.exec->mem_slot_count); |
| 27605 | 27643 | ira->exec_context.mem_slot_list.resize(ira->old_irb.exec->mem_slot_count); |
| 27606 | 27644 | for (size_t i = 0; i < ira->exec_context.mem_slot_list.length; i += 1) { |
| 27607 | 27645 | ira->exec_context.mem_slot_list.items[i] = &vals[i]; |
| ... | ... | @@ -27628,10 +27666,10 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ |
| 27628 | 27666 | } |
| 27629 | 27667 | IrInstruction *new_instruction = ir_analyze_instruction_base(ira, old_instruction); |
| 27630 | 27668 | if (new_instruction != nullptr) { |
| 27631 | | ir_assert(new_instruction->value.type != nullptr || new_instruction->value.type != nullptr, old_instruction); |
| 27669 | ir_assert(new_instruction->value->type != nullptr || new_instruction->value->type != nullptr, old_instruction); |
| 27632 | 27670 | old_instruction->child = new_instruction; |
| 27633 | 27671 | |
| 27634 | | if (type_is_invalid(new_instruction->value.type)) { |
| 27672 | if (type_is_invalid(new_instruction->value->type)) { |
| 27635 | 27673 | if (new_exec->first_err_trace_msg != nullptr) { |
| 27636 | 27674 | ira->codegen->trace_err = new_exec->first_err_trace_msg; |
| 27637 | 27675 | } else { |
| ... | ... | @@ -27648,7 +27686,7 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ |
| 27648 | 27686 | } |
| 27649 | 27687 | |
| 27650 | 27688 | // unreachable instructions do their own control flow. |
| 27651 | | if (new_instruction->value.type->id == ZigTypeIdUnreachable) |
| 27689 | if (new_instruction->value->type->id == ZigTypeIdUnreachable) |
| 27652 | 27690 | continue; |
| 27653 | 27691 | } |
| 27654 | 27692 | |
| ... | ... | @@ -27947,7 +27985,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La |
| 27947 | 27985 | return get_fn_type(ira->codegen, &fn_type_id); |
| 27948 | 27986 | } |
| 27949 | 27987 | |
| 27950 | | static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) { |
| 27988 | static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { |
| 27951 | 27989 | Error err; |
| 27952 | 27990 | if (val->special != ConstValSpecialLazy) |
| 27953 | 27991 | return ErrorNone; |
| ... | ... | @@ -27958,8 +27996,8 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) { |
| 27958 | 27996 | LazyValueAlignOf *lazy_align_of = reinterpret_cast<LazyValueAlignOf *>(val->data.x_lazy); |
| 27959 | 27997 | IrAnalyze *ira = lazy_align_of->ira; |
| 27960 | 27998 | |
| 27961 | | if (lazy_align_of->target_type->value.special == ConstValSpecialStatic) { |
| 27962 | | switch (lazy_align_of->target_type->value.data.x_type->id) { |
| 27999 | if (lazy_align_of->target_type->value->special == ConstValSpecialStatic) { |
| 28000 | switch (lazy_align_of->target_type->value->data.x_type->id) { |
| 27963 | 28001 | case ZigTypeIdInvalid: |
| 27964 | 28002 | zig_unreachable(); |
| 27965 | 28003 | case ZigTypeIdMetaType: |
| ... | ... | @@ -27975,7 +28013,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) { |
| 27975 | 28013 | case ZigTypeIdOpaque: |
| 27976 | 28014 | ir_add_error(ira, lazy_align_of->target_type, |
| 27977 | 28015 | buf_sprintf("no align available for type '%s'", |
| 27978 | | buf_ptr(&lazy_align_of->target_type->value.data.x_type->name))); |
| 28016 | buf_ptr(&lazy_align_of->target_type->value->data.x_type->name))); |
| 27979 | 28017 | return ErrorSemanticAnalyzeFail; |
| 27980 | 28018 | case ZigTypeIdBool: |
| 27981 | 28019 | case ZigTypeIdInt: |
| ... | ... | @@ -27997,7 +28035,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) { |
| 27997 | 28035 | } |
| 27998 | 28036 | |
| 27999 | 28037 | uint32_t align_in_bytes; |
| 28000 | | if ((err = type_val_resolve_abi_align(ira->codegen, &lazy_align_of->target_type->value, |
| 28038 | if ((err = type_val_resolve_abi_align(ira->codegen, lazy_align_of->target_type->value, |
| 28001 | 28039 | &align_in_bytes))) |
| 28002 | 28040 | { |
| 28003 | 28041 | return err; |
| ... | ... | @@ -28012,8 +28050,8 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) { |
| 28012 | 28050 | LazyValueSizeOf *lazy_size_of = reinterpret_cast<LazyValueSizeOf *>(val->data.x_lazy); |
| 28013 | 28051 | IrAnalyze *ira = lazy_size_of->ira; |
| 28014 | 28052 | |
| 28015 | | if (lazy_size_of->target_type->value.special == ConstValSpecialStatic) { |
| 28016 | | switch (lazy_size_of->target_type->value.data.x_type->id) { |
| 28053 | if (lazy_size_of->target_type->value->special == ConstValSpecialStatic) { |
| 28054 | switch (lazy_size_of->target_type->value->data.x_type->id) { |
| 28017 | 28055 | case ZigTypeIdInvalid: // handled above |
| 28018 | 28056 | zig_unreachable(); |
| 28019 | 28057 | case ZigTypeIdUnreachable: |
| ... | ... | @@ -28024,7 +28062,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) { |
| 28024 | 28062 | case ZigTypeIdOpaque: |
| 28025 | 28063 | ir_add_error(ira, lazy_size_of->target_type, |
| 28026 | 28064 | buf_sprintf("no size available for type '%s'", |
| 28027 | | buf_ptr(&lazy_size_of->target_type->value.data.x_type->name))); |
| 28065 | buf_ptr(&lazy_size_of->target_type->value->data.x_type->name))); |
| 28028 | 28066 | return ErrorSemanticAnalyzeFail; |
| 28029 | 28067 | case ZigTypeIdMetaType: |
| 28030 | 28068 | case ZigTypeIdEnumLiteral: |
| ... | ... | @@ -28052,7 +28090,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) { |
| 28052 | 28090 | |
| 28053 | 28091 | size_t abi_size; |
| 28054 | 28092 | size_t size_in_bits; |
| 28055 | | if ((err = type_val_resolve_abi_size(ira->codegen, source_node, &lazy_size_of->target_type->value, |
| 28093 | if ((err = type_val_resolve_abi_size(ira->codegen, source_node, lazy_size_of->target_type->value, |
| 28056 | 28094 | &abi_size, &size_in_bits))) |
| 28057 | 28095 | { |
| 28058 | 28096 | return err; |
| ... | ... | @@ -28071,12 +28109,12 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) { |
| 28071 | 28109 | if (type_is_invalid(elem_type)) |
| 28072 | 28110 | return ErrorSemanticAnalyzeFail; |
| 28073 | 28111 | |
| 28074 | | ConstExprValue *sentinel_val; |
| 28112 | ZigValue *sentinel_val; |
| 28075 | 28113 | if (lazy_slice_type->sentinel != nullptr) { |
| 28076 | | if (type_is_invalid(lazy_slice_type->sentinel->value.type)) |
| 28114 | if (type_is_invalid(lazy_slice_type->sentinel->value->type)) |
| 28077 | 28115 | return ErrorSemanticAnalyzeFail; |
| 28078 | 28116 | IrInstruction *sentinel = ir_implicit_cast(ira, lazy_slice_type->sentinel, elem_type); |
| 28079 | | if (type_is_invalid(sentinel->value.type)) |
| 28117 | if (type_is_invalid(sentinel->value->type)) |
| 28080 | 28118 | return ErrorSemanticAnalyzeFail; |
| 28081 | 28119 | sentinel_val = ir_resolve_const(ira, sentinel, UndefBad); |
| 28082 | 28120 | if (sentinel_val == nullptr) |
| ... | ... | @@ -28149,12 +28187,12 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) { |
| 28149 | 28187 | if (type_is_invalid(elem_type)) |
| 28150 | 28188 | return ErrorSemanticAnalyzeFail; |
| 28151 | 28189 | |
| 28152 | | ConstExprValue *sentinel_val; |
| 28190 | ZigValue *sentinel_val; |
| 28153 | 28191 | if (lazy_ptr_type->sentinel != nullptr) { |
| 28154 | | if (type_is_invalid(lazy_ptr_type->sentinel->value.type)) |
| 28192 | if (type_is_invalid(lazy_ptr_type->sentinel->value->type)) |
| 28155 | 28193 | return ErrorSemanticAnalyzeFail; |
| 28156 | 28194 | IrInstruction *sentinel = ir_implicit_cast(ira, lazy_ptr_type->sentinel, elem_type); |
| 28157 | | if (type_is_invalid(sentinel->value.type)) |
| 28195 | if (type_is_invalid(sentinel->value->type)) |
| 28158 | 28196 | return ErrorSemanticAnalyzeFail; |
| 28159 | 28197 | sentinel_val = ir_resolve_const(ira, sentinel, UndefBad); |
| 28160 | 28198 | if (sentinel_val == nullptr) |
| ... | ... | @@ -28276,7 +28314,7 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ConstExprValue *val) { |
| 28276 | 28314 | zig_unreachable(); |
| 28277 | 28315 | } |
| 28278 | 28316 | |
| 28279 | | Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ConstExprValue *val) { |
| 28317 | Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ZigValue *val) { |
| 28280 | 28318 | Error err; |
| 28281 | 28319 | if ((err = ir_resolve_lazy_raw(source_node, val))) { |
| 28282 | 28320 | if (codegen->trace_err != nullptr && source_node != nullptr && !source_node->already_traced_this_node) { |