@@ -1577,13 +1577,11 @@ static IrInstruction *ir_build_set_runtime_safety(IrBuilder *irb, Scope *scope,
1577
1577
}
1578
1578
1579
1579
static IrInstruction *ir_build_set_float_mode(IrBuilder *irb, Scope *scope, AstNode *source_node,
1580
- IrInstruction *scope_value, IrInstruction * mode_value)
1580
+ IrInstruction *mode_value)
1581
1581
{
1582
1582
IrInstructionSetFloatMode *instruction = ir_build_instruction<IrInstructionSetFloatMode>(irb, scope, source_node);
1583
- instruction->scope_value = scope_value;
1584
1583
instruction->mode_value = mode_value;
1585
1584
1586
- ir_ref_instruction(scope_value, irb->current_basic_block);
1587
1585
ir_ref_instruction(mode_value, irb->current_basic_block);
1588
1586
1589
1587
return &instruction->base;
@@ -3959,12 +3957,7 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
3959
3957
if (arg0_value == irb->codegen->invalid_instruction)
3960
3958
return arg0_value;
3961
3959
3962
- AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
3963
- IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
3964
- if (arg1_value == irb->codegen->invalid_instruction)
3965
- return arg1_value;
3966
-
3967
- IrInstruction *set_float_mode = ir_build_set_float_mode(irb, scope, node, arg0_value, arg1_value);
3960
+ IrInstruction *set_float_mode = ir_build_set_float_mode(irb, scope, node, arg0_value);
3968
3961
return ir_lval_wrap(irb, scope, set_float_mode, lval);
3969
3962
}
3970
3963
case BuiltinFnIdSizeof:
@@ -15379,6 +15372,7 @@ static ZigType *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstructionSet
15379
15372
ir_build_const_from(ira, &instruction->base);
15380
15373
return ira->codegen->builtin_types.entry_void;
15381
15374
}
15375
+
15382
15376
static ZigType *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,
15383
15377
IrInstructionSetRuntimeSafety *set_runtime_safety_instruction)
15384
15378
{
@@ -15439,14 +15433,6 @@ static ZigType *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,
15439
15433
static ZigType *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
15440
15434
IrInstructionSetFloatMode *instruction)
15441
15435
{
15442
- IrInstruction *target_instruction = instruction->scope_value->other;
15443
- ZigType *target_type = target_instruction->value.type;
15444
- if (type_is_invalid(target_type))
15445
- return ira->codegen->builtin_types.entry_invalid;
15446
- ConstExprValue *target_val = ir_resolve_const(ira, target_instruction, UndefBad);
15447
- if (!target_val)
15448
- return ira->codegen->builtin_types.entry_invalid;
15449
-
15450
15436
if (ira->new_irb.exec->is_inline) {
15451
15437
// ignore setFloatMode when running functions at compile time
15452
15438
ir_build_const_from(ira, &instruction->base);
@@ -15455,40 +15441,34 @@ static ZigType *ir_analyze_instruction_set_float_mode(IrAnalyze *ira,
15455
15441
15456
15442
bool *fast_math_on_ptr;
15457
15443
AstNode **fast_math_set_node_ptr;
15458
- if (target_type->id == ZigTypeIdBlock) {
15459
- ScopeBlock *block_scope = (ScopeBlock *)target_val->data.x_block;
15460
- fast_math_on_ptr = &block_scope->fast_math_on;
15461
- fast_math_set_node_ptr = &block_scope->fast_math_set_node;
15462
- } else if (target_type->id == ZigTypeIdFn) {
15463
- assert(target_val->data.x_ptr.special == ConstPtrSpecialFunction);
15464
- ZigFn *target_fn = target_val->data.x_ptr.data.fn.fn_entry;
15465
- assert(target_fn->def_scope);
15466
- fast_math_on_ptr = &target_fn->def_scope->fast_math_on;
15467
- fast_math_set_node_ptr = &target_fn->def_scope->fast_math_set_node;
15468
- } else if (target_type->id == ZigTypeIdMetaType) {
15469
- ScopeDecls *decls_scope;
15470
- ZigType *type_arg = target_val->data.x_type;
15471
- if (type_arg->id == ZigTypeIdStruct) {
15472
- decls_scope = type_arg->data.structure.decls_scope;
15473
- } else if (type_arg->id == ZigTypeIdEnum) {
15474
- decls_scope = type_arg->data.enumeration.decls_scope;
15475
- } else if (type_arg->id == ZigTypeIdUnion) {
15476
- decls_scope = type_arg->data.unionation.decls_scope;
15444
+
15445
+ Scope *scope = instruction->base.scope;
15446
+ while (scope != nullptr) {
15447
+ if (scope->id == ScopeIdBlock) {
15448
+ ScopeBlock *block_scope = (ScopeBlock *)scope;
15449
+ fast_math_on_ptr = &block_scope->fast_math_on;
15450
+ fast_math_set_node_ptr = &block_scope->fast_math_set_node;
15451
+ break;
15452
+ } else if (scope->id == ScopeIdFnDef) {
15453
+ ScopeFnDef *def_scope = (ScopeFnDef *)scope;
15454
+ ZigFn *target_fn = def_scope->fn_entry;
15455
+ assert(target_fn->def_scope != nullptr);
15456
+ fast_math_on_ptr = &target_fn->def_scope->fast_math_on;
15457
+ fast_math_set_node_ptr = &target_fn->def_scope->fast_math_set_node;
15458
+ break;
15459
+ } else if (scope->id == ScopeIdDecls) {
15460
+ ScopeDecls *decls_scope = (ScopeDecls *)scope;
15461
+ fast_math_on_ptr = &decls_scope->fast_math_on;
15462
+ fast_math_set_node_ptr = &decls_scope->fast_math_set_node;
15463
+ break;
15477
15464
} else {
15478
- ir_add_error_node(ira, target_instruction->source_node,
15479
- buf_sprintf("expected scope reference, found type '%s'", buf_ptr(&type_arg->name)));
15480
- return ira->codegen->builtin_types.entry_invalid;
15465
+ scope = scope->parent;
15466
+ continue;
15481
15467
}
15482
- fast_math_on_ptr = &decls_scope->fast_math_on;
15483
- fast_math_set_node_ptr = &decls_scope->fast_math_set_node;
15484
- } else {
15485
- ir_add_error_node(ira, target_instruction->source_node,
15486
- buf_sprintf("expected scope reference, found type '%s'", buf_ptr(&target_type->name)));
15487
- return ira->codegen->builtin_types.entry_invalid;
15488
15468
}
15469
+ assert(scope != nullptr);
15489
15470
15490
15471
IrInstruction *float_mode_value = instruction->mode_value->other;
15491
-
15492
15472
FloatMode float_mode_scalar;
15493
15473
if (!ir_resolve_float_mode(ira, float_mode_value, &float_mode_scalar))
15494
15474
return ira->codegen->builtin_types.entry_invalid;
0 commit comments