Skip to content

Taking a slice of certain comptime arrays with a sentinel causes the compiler to segfault #5276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
alexnask opened this issue May 5, 2020 · 0 comments
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Milestone

Comments

@alexnask
Copy link
Contributor

alexnask commented May 5, 2020

I can currently reproduce this with arrays initialized as undefined and arrays returned by @typeName and string literals but not with arrays initialized from literals.

comptime {
    const arr: [100]u16 = undefined;
    const slice = arr[0..12:0];
}

comptime {
    const str = "abcdefg";
    const slice = str[0..1:12];
}

pub fn main() void {
    comptime {
        const arr = @typeName(@TypeOf(main));
        const slice = arr[0..2:0];
    }
}

gdb backtrace

(gdb) run run /mnt/c/dev/test.zig                                                                                                                                                            
Starting program: /mnt/c/dev/zig/build-linux/zig run /mnt/c/dev/test.zig                                                                                                                     
[Thread debugging using libthread_db enabled]                                                                                                                                                
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".                                                                                                                   
                                                                                                                                                                                             
Program received signal SIGSEGV, Segmentation fault.                                                                                                                                         
0x0000000009269e57 in const_values_equal (g=0x10b01620, a=0x10b22900, b=0x420) at /mnt/c/dev/zig/src/analyze.cpp:6876                                                                        
6876        if (a->type->id != b->type->id) return false;                                                                                                                                    
(gdb) bt                                                                                                                                                                                     
#0  0x0000000009269e57 in const_values_equal (g=0x10b01620, a=0x10b22900, b=0x420) at /mnt/c/dev/zig/src/analyze.cpp:6876                                                                    
#1  0x0000000009207c7b in ir_analyze_instruction_slice (ira=0x10bfa1e0, instruction=0x10bf8f20) at /mnt/c/dev/zig/src/ir.cpp:27265                                                           
#2  0x0000000009213e0b in ir_analyze_instruction_base (ira=0x10bfa1e0, instruction=0x10bf8f20) at /mnt/c/dev/zig/src/ir.cpp:30521                                                            
#3  0x0000000009214899 in ir_analyze (codegen=0x10b01620, old_exec=0x10bf4670, new_exec=0x10bfa130, expected_type=0x10b1d070, expected_type_source_node=0x0, result_ptr=0x10b22220)          
    at /mnt/c/dev/zig/src/ir.cpp:30724                                                                                                                                                       
#4  0x00000000091d184c in ir_eval_const_value (codegen=0x10b01620, scope=0x10b51af0, node=0x10b52410, return_ptr=0x10b22220, backward_branch_count=0x7ffffffed138,                           
    backward_branch_quota=0x7ffffffed140, fn_entry=0x0, c_import_buf=0x0, source_node=0x10b52410, exec_name=0x0, parent_exec=0x0, expected_type_source_node=0x0, undef_allowed=UndefBad)     
    at /mnt/c/dev/zig/src/ir.cpp:13353                                                                                                                                                       
#5  0x0000000009257901 in analyze_const_value (g=0x10b01620, scope=0x10b51af0, node=0x10b52410, type_entry=0x10b1d070, type_name=0x0, undef=UndefBad) at /mnt/c/dev/zig/src/analyze.cpp:1141 
#6  0x000000000925f8f1 in resolve_decl_comptime (g=0x10b01620, tld_comptime=0x10b52670) at /mnt/c/dev/zig/src/analyze.cpp:3610                                                               
#7  0x000000000926176d in resolve_top_level_decl (g=0x10b01620, tld=0x10b52670, source_node=0x0, allow_lazy=false) at /mnt/c/dev/zig/src/analyze.cpp:4215                                    
#8  0x00000000092643a5 in semantic_analyze (g=0x10b01620) at /mnt/c/dev/zig/src/analyze.cpp:5069                                                                                             
#9  0x000000000918e02e in gen_root_source (g=0x10b01620) at /mnt/c/dev/zig/src/codegen.cpp:9772                                                                                              
#10 0x00000000091927e2 in codegen_build_and_link (g=0x10b01620) at /mnt/c/dev/zig/src/codegen.cpp:10886                                                                                      
#11 0x0000000009161e3a in main0 (argc=3, argv=0x7ffffffedbd8) at /mnt/c/dev/zig/src/main.cpp:1671                                                                                            
#12 0x00000000091629be in main (argc=3, argv=0x7ffffffedbd8) at /mnt/c/dev/zig/src/main.cpp:1858                                                                                             
(gdb) f 0                                                                                                                                                                                    
#0  0x0000000009269e57 in const_values_equal (g=0x10b01620, a=0x10b22900, b=0x420) at /mnt/c/dev/zig/src/analyze.cpp:6876                                                                    
6876        if (a->type->id != b->type->id) return false;                                                                                                                                    
(gdb) p b                                                                                                                                                                                    
$1 = (ZigValue *) 0x420                                                                                                                                                                      
@Vexu Vexu added bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend. labels May 5, 2020
@Vexu Vexu added this to the 0.7.0 milestone May 5, 2020
@alexnask alexnask changed the title Taking a slice of a certain comptime arrays with a sentinel causes the compiler to segfault Taking a slice of certain comptime arrays with a sentinel causes the compiler to segfault May 5, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Aug 13, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Nov 6, 2020
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
Vexu added a commit to Vexu/zig that referenced this issue Dec 31, 2022
Vexu added a commit to Vexu/zig that referenced this issue Dec 31, 2022
@andrewrk andrewrk modified the milestones: 0.12.0, 0.11.0 Jan 1, 2023
TUSF pushed a commit to TUSF/zig that referenced this issue May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants