mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
Fixed intToPtr to fn type when the address is hardcoded (#1842)
* Fixed intToPtr to fn type * Added test * Import inttoptr.zig in behavior.zig
This commit is contained in:
parent
260c3d9cc0
commit
45e72c0b39
@ -12495,6 +12495,7 @@ static IrInstruction *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruct
|
||||
case ReqCompTimeNo:
|
||||
if (casted_init_value->value.special == ConstValSpecialStatic &&
|
||||
casted_init_value->value.type->id == ZigTypeIdFn &&
|
||||
casted_init_value->value.data.x_ptr.special != ConstPtrSpecialHardCodedAddr &&
|
||||
casted_init_value->value.data.x_ptr.data.fn.fn_entry->fn_inline == FnInlineAlways)
|
||||
{
|
||||
var_class_requires_const = true;
|
||||
|
||||
@ -42,6 +42,7 @@ comptime {
|
||||
_ = @import("cases/if.zig");
|
||||
_ = @import("cases/import.zig");
|
||||
_ = @import("cases/incomplete_struct_param_tld.zig");
|
||||
_ = @import("cases/inttoptr.zig");
|
||||
_ = @import("cases/ir_block_deps.zig");
|
||||
_ = @import("cases/math.zig");
|
||||
_ = @import("cases/merge_error_sets.zig");
|
||||
|
||||
13
test/cases/inttoptr.zig
Normal file
13
test/cases/inttoptr.zig
Normal file
@ -0,0 +1,13 @@
|
||||
const builtin = @import("builtin");
|
||||
const std = @import("std");
|
||||
const assertOrPanic = std.debug.assertOrPanic;
|
||||
|
||||
test "casting random address to function pointer" {
|
||||
randomAddressToFunction();
|
||||
comptime randomAddressToFunction();
|
||||
}
|
||||
|
||||
fn randomAddressToFunction() void {
|
||||
var addr: usize = 0xdeadbeef;
|
||||
var ptr = @intToPtr(fn () void, addr);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user