| author | |
| committer | |
| log | 45e72c0b3944b2fa6d06c7018e9648b4ae60006a |
| tree | 10e8ac90465e7bb81005607890b1caf2c4d47e1a |
| parent | 260c3d9cc0c85c1c4dce98bda9e15ca49ca87d74 |
* Fixed intToPtr to fn type
* Added test
* Import inttoptr.zig in behavior.zig
3 files changed, 15 insertions(+), 0 deletions(-)
src/ir.cpp+1| ... | @@ -12495,6 +12495,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruct | ... | @@ -12495,6 +12495,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruct |
| 12495 | case ReqCompTimeNo: | 12495 | case ReqCompTimeNo: |
| 12496 | if (casted_init_value->value.special == ConstValSpecialStatic && | 12496 | if (casted_init_value->value.special == ConstValSpecialStatic && |
| 12497 | casted_init_value->value.type->id == ZigTypeIdFn && | 12497 | casted_init_value->value.type->id == ZigTypeIdFn && |
| 12498 | casted_init_value->value.data.x_ptr.special != ConstPtrSpecialHardCodedAddr && | ||
| 12498 | casted_init_value->value.data.x_ptr.data.fn.fn_entry->fn_inline == FnInlineAlways) | 12499 | casted_init_value->value.data.x_ptr.data.fn.fn_entry->fn_inline == FnInlineAlways) |
| 12499 | { | 12500 | { |
| 12500 | var_class_requires_const = true; | 12501 | var_class_requires_const = true; |
test/behavior.zig+1| ... | @@ -42,6 +42,7 @@ comptime { | ... | @@ -42,6 +42,7 @@ comptime { |
| 42 | _ = @import("cases/if.zig"); | 42 | _ = @import("cases/if.zig"); |
| 43 | _ = @import("cases/import.zig"); | 43 | _ = @import("cases/import.zig"); |
| 44 | _ = @import("cases/incomplete_struct_param_tld.zig"); | 44 | _ = @import("cases/incomplete_struct_param_tld.zig"); |
| 45 | _ = @import("cases/inttoptr.zig"); | ||
| 45 | _ = @import("cases/ir_block_deps.zig"); | 46 | _ = @import("cases/ir_block_deps.zig"); |
| 46 | _ = @import("cases/math.zig"); | 47 | _ = @import("cases/math.zig"); |
| 47 | _ = @import("cases/merge_error_sets.zig"); | 48 | _ = @import("cases/merge_error_sets.zig"); |
test/cases/inttoptr.zig created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | const builtin = @import("builtin"); | ||
| 2 | const std = @import("std"); | ||
| 3 | const assertOrPanic = std.debug.assertOrPanic; | ||
| 4 | |||
| 5 | test "casting random address to function pointer" { | ||
| 6 | randomAddressToFunction(); | ||
| 7 | comptime randomAddressToFunction(); | ||
| 8 | } | ||
| 9 | |||
| 10 | fn randomAddressToFunction() void { | ||
| 11 | var addr: usize = 0xdeadbeef; | ||
| 12 | var ptr = @intToPtr(fn () void, addr); | ||
| 13 | } | ||