Skip to content

Conversation

kristate
Copy link
Contributor

Thanks to DutchGh0s on IRC.

@andrewrk andrewrk merged commit 0839ed1 into ziglang:master Aug 26, 2018
@andrewrk
Copy link
Member

Argh, I think I pulled the trigger too fast. I think that const_ptr_pointee might actually need to assert that its return value is not null, and the problem DutchGh0s ran into was a different thing. Do we have a test case that triggered the issue?

andrewrk added a commit that referenced this pull request Aug 26, 2018
…ect against dereferencing null pointers;"

This reverts commit 0839ed1.

I realized too late there is a better fix. See PR #1419
@andrewrk
Copy link
Member

See 68e2794. If this assert trips, the problem is elsewhere.

@kristate
Copy link
Contributor Author

@andrewrk I think that it is okay that const_ptr_pointee returns nullptr in some instances -- problem is outside of const_ptr_pointee

@kristate
Copy link
Contributor Author

btw, here is the backtrace that I am getting on his code on 68e2794:

    frame #0: 0x00007fff5b831b66 libsystem_kernel.dylib`__pthread_kill + 10
  * frame #1: 0x00007fff5b9fc080 libsystem_pthread.dylib`pthread_kill + 333
    frame #2: 0x00007fff5b78d1ae libsystem_c.dylib`abort + 127
    frame #3: 0x00007fff5b7551ac libsystem_c.dylib`__assert_rtn + 320
    frame #4: 0x0000000100054788 zig`const_ptr_pointee(g=0x0000000106806000, const_val=0x000000010ac0f958) at ir.cpp:181
    frame #5: 0x000000010005942f zig`ir_get_deref(ira=0x000000010ac0cf20, source_instruction=0x000000010ac03c10, ptr=0x000000010ac0f940) at ir.cpp:10989
    frame #6: 0x0000000100082218 zig`ir_analyze_instruction_load_ptr(ira=0x000000010ac0cf20, load_ptr_instruction=0x000000010ac03c10) at ir.cpp:14951
    frame #7: 0x0000000100080702 zig`ir_analyze_instruction_nocast(ira=0x000000010ac0cf20, instruction=0x000000010ac03c10) at ir.cpp:20908
    frame #8: 0x0000000100059a0d zig`ir_analyze_instruction(ira=0x000000010ac0cf20, instruction=0x000000010ac03c10) at ir.cpp:21164
    frame #9: 0x0000000100058963 zig`ir_analyze(codegen=0x0000000106806000, old_exec=0x000000010ac03420, new_exec=0x000000010ac0ce30, expected_type=0x000000010540e7a0, expected_type_source_node=0x000000010552a630) at ir.cpp:21219
    frame #10: 0x00000001000585c3 zig`ir_eval_const_value(codegen=0x0000000106806000, scope=0x000000010ac02b70, node=0x000000010552a630, expected_type=0x000000010540e7a0, backward_branch_count=0x00007ffeefbfe448, backward_branch_quota=1000, fn_entry=0x000000010abfb730, c_import_buf=0x0000000000000000, source_node=0x0000000105525dd0, exec_name=0x0000000000000000, parent_exec=0x000000010abfb560) at ir.cpp:9690
    frame #11: 0x00000001000ac1d0 zig`ir_analyze_fn_call(ira=0x000000010abfb650, call_instruction=0x000000010abfa550, fn_entry=0x000000010abfb730, fn_type=0x000000010abfba90, fn_ref=0x000000010abfbbb0, first_arg_ptr=0x0000000000000000, comptime_fn_call=true, fn_inline=FnInlineAuto) at ir.cpp:13183
    frame #12: 0x0000000100085db8 zig`ir_analyze_instruction_call(ira=0x000000010abfb650, call_instruction=0x000000010abfa550) at ir.cpp:13607
    frame #13: 0x000000010008077f zig`ir_analyze_instruction_nocast(ira=0x000000010abfb650, instruction=0x000000010abfa550) at ir.cpp:20918
    frame #14: 0x0000000100059a0d zig`ir_analyze_instruction(ira=0x000000010abfb650, instruction=0x000000010abfa550) at ir.cpp:21164
    frame #15: 0x0000000100058963 zig`ir_analyze(codegen=0x0000000106806000, old_exec=0x000000010abf9640, new_exec=0x000000010abfb560, expected_type=0x0000000105407eb0, expected_type_source_node=0x0000000105525b90) at ir.cpp:21219
    frame #16: 0x00000001000585c3 zig`ir_eval_const_value(codegen=0x0000000106806000, scope=0x000000010abf8d90, node=0x0000000105525b90, expected_type=0x0000000105407eb0, backward_branch_count=0x00007ffeefbfe448, backward_branch_quota=1000, fn_entry=0x000000010abf6aa0, c_import_buf=0x0000000000000000, source_node=0x0000000105524ed0, exec_name=0x0000000000000000, parent_exec=0x000000010abf68d0) at ir.cpp:9690
    frame #17: 0x00000001000ac1d0 zig`ir_analyze_fn_call(ira=0x000000010abf69c0, call_instruction=0x000000010abf6680, fn_entry=0x000000010abf6aa0, fn_type=0x000000010abf7660, fn_ref=0x000000010abf7780, first_arg_ptr=0x0000000000000000, comptime_fn_call=true, fn_inline=FnInlineAuto) at ir.cpp:13183
    frame #18: 0x0000000100085db8 zig`ir_analyze_instruction_call(ira=0x000000010abf69c0, call_instruction=0x000000010abf6680) at ir.cpp:13607
    frame #19: 0x000000010008077f zig`ir_analyze_instruction_nocast(ira=0x000000010abf69c0, instruction=0x000000010abf6680) at ir.cpp:20918
    frame #20: 0x0000000100059a0d zig`ir_analyze_instruction(ira=0x000000010abf69c0, instruction=0x000000010abf6680) at ir.cpp:21164
    frame #21: 0x0000000100058963 zig`ir_analyze(codegen=0x0000000106806000, old_exec=0x000000010abf6120, new_exec=0x000000010abf68d0, expected_type=0x0000000105407eb0, expected_type_source_node=0x0000000105524ed0) at ir.cpp:21219
    frame #22: 0x00000001000585c3 zig`ir_eval_const_value(codegen=0x0000000106806000, scope=0x000000010abf5710, node=0x0000000105524ed0, expected_type=0x0000000105407eb0, backward_branch_count=0x00007ffeefbfe448, backward_branch_quota=1000, fn_entry=0x0000000000000000, c_import_buf=0x0000000000000000, source_node=0x0000000105524ed0, exec_name=0x0000000000000000, parent_exec=0x0000000000000000) at ir.cpp:9690
    frame #23: 0x000000010000a735 zig`analyze_const_value(g=0x0000000106806000, scope=0x000000010abf5710, node=0x0000000105524ed0, type_entry=0x0000000105407eb0, type_name=0x0000000000000000) at analyze.cpp:1264
    frame #24: 0x000000010000a625 zig`analyze_type_expr(g=0x0000000106806000, scope=0x000000010abf5710, node=0x0000000105524ed0) at analyze.cpp:1270
    frame #25: 0x000000010001cebd zig`analyze_fn_type(g=0x0000000106806000, proto_node=0x0000000105524c50, child_scope=0x000000010abf5710, fn_entry=0x000000010abf53a0) at analyze.cpp:1641
    frame #26: 0x000000010000d391 zig`resolve_decl_fn(g=0x0000000106806000, tld_fn=0x000000010abf43e0) at analyze.cpp:3180
    frame #27: 0x000000010000b4f3 zig`resolve_top_level_decl(g=0x0000000106806000, tld=0x000000010abf43e0, pointer_only=false, source_node=0x000000010552d9b0) at analyze.cpp:3673
    frame #28: 0x00000001000aa768 zig`ir_analyze_decl_ref(ira=0x000000010abe59f0, source_instruction=0x000000010abe3140, tld=0x000000010abf43e0) at ir.cpp:14504
    frame #29: 0x00000001000842d0 zig`ir_analyze_instruction_field_ptr(ira=0x000000010abe59f0, field_ptr_instruction=0x000000010abe3140) at ir.cpp:14684
    frame #30: 0x0000000100080766 zig`ir_analyze_instruction_nocast(ira=0x000000010abe59f0, instruction=0x000000010abe3140) at ir.cpp:20916
    frame #31: 0x0000000100059a0d zig`ir_analyze_instruction(ira=0x000000010abe59f0, instruction=0x000000010abe3140) at ir.cpp:21164
    frame #32: 0x0000000100058963 zig`ir_analyze(codegen=0x0000000106806000, old_exec=0x000000010abdee00, new_exec=0x000000010abdeee8, expected_type=0x000000010540e7a0, expected_type_source_node=0x000000010552cff0) at ir.cpp:21219
    frame #33: 0x0000000100011570 zig`analyze_fn_ir(g=0x0000000106806000, fn_table_entry=0x000000010abded90, return_type_node=0x000000010552cff0) at analyze.cpp:4048
    frame #34: 0x00000001000114c1 zig`analyze_fn_body(g=0x0000000106806000, fn_table_entry=0x000000010abded90) at analyze.cpp:4136
    frame #35: 0x00000001000126a3 zig`semantic_analyze(g=0x0000000106806000) at analyze.cpp:4341
    frame #36: 0x0000000100032cd4 zig`gen_root_source(g=0x0000000106806000) at codegen.cpp:7162
    frame #37: 0x0000000100032788 zig`codegen_build(g=0x0000000106806000) at codegen.cpp:7669
    frame #38: 0x00000001000c65d7 zig`main(argc=3, argv=0x00007ffeefbff910) at main.cpp:907
    frame #39: 0x00007fff5b6e1015 libdyld.dylib`start + 1

@kristate
Copy link
Contributor Author

@andrewrk

17:37 <andrewrk> kristate, 68e279 should trip the assert for the bug. do we have a test case? 
17:38 <kristate> andrewrk: the test case was/is a somewhat long file from DutchGh0s 
17:38 <kristate> I will post it in its entirety 

This is the file that trips assert: dutchgh0s_issue1419.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants