mirror of
https://github.com/ziglang/zig.git
synced 2025-12-23 22:53:06 +00:00
parent
2b4bf1e7ce
commit
c47211cc60
18
src/ir.cpp
18
src/ir.cpp
@ -22949,12 +22949,20 @@ static IrInstruction *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstruction
|
||||
if (parent_ptr == nullptr)
|
||||
return ira->codegen->invalid_instruction;
|
||||
|
||||
array_val = const_ptr_pointee(ira, ira->codegen, parent_ptr, instruction->base.source_node);
|
||||
if (array_val == nullptr)
|
||||
return ira->codegen->invalid_instruction;
|
||||
|
||||
rel_end = child_array_type->data.array.len;
|
||||
abs_offset = 0;
|
||||
if (parent_ptr->special == ConstValSpecialUndef) {
|
||||
array_val = nullptr;
|
||||
abs_offset = 0;
|
||||
rel_end = SIZE_MAX;
|
||||
ptr_is_undef = true;
|
||||
} else {
|
||||
array_val = const_ptr_pointee(ira, ira->codegen, parent_ptr, instruction->base.source_node);
|
||||
if (array_val == nullptr)
|
||||
return ira->codegen->invalid_instruction;
|
||||
|
||||
rel_end = child_array_type->data.array.len;
|
||||
abs_offset = 0;
|
||||
}
|
||||
} else {
|
||||
array_val = const_ptr_pointee(ira, ira->codegen, &ptr_ptr->value, instruction->base.source_node);
|
||||
if (array_val == nullptr)
|
||||
|
||||
@ -2,6 +2,16 @@ const tests = @import("tests.zig");
|
||||
const builtin = @import("builtin");
|
||||
|
||||
pub fn addCases(cases: *tests.CompileErrorContext) void {
|
||||
cases.add(
|
||||
"slicing of global undefined pointer",
|
||||
\\var buf: *[1]u8 = undefined;
|
||||
\\export fn entry() void {
|
||||
\\ _ = buf[0..1];
|
||||
\\}
|
||||
,
|
||||
"tmp.zig:3:12: error: non-zero length slice of undefined pointer",
|
||||
);
|
||||
|
||||
cases.add(
|
||||
"using invalid types in function call raises an error",
|
||||
\\const MenuEffect = enum {};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user