{"action":"closed","issue":{"url":"https://api.github.com/repos/TheDan64/inkwell/issues/33","repository_url":"https://api.github.com/repos/TheDan64/inkwell","labels_url":"https://api.github.com/repos/TheDan64/inkwell/issues/33/labels{/name}","comments_url":"https://api.github.com/repos/TheDan64/inkwell/issues/33/comments","events_url":"https://api.github.com/repos/TheDan64/inkwell/issues/33/events","html_url":"https://github.com/TheDan64/inkwell/issues/33","id":298049712,"number":33,"title":"Segmentation fault when calling Builder::build_in_bounds_gep","user":{"login":"Redrield","id":8991639,"avatar_url":"https://avatars0.githubusercontent.com/u/8991639?v=4","gravatar_id":"","url":"https://api.github.com/users/Redrield","html_url":"https://github.com/Redrield","followers_url":"https://api.github.com/users/Redrield/followers","following_url":"https://api.github.com/users/Redrield/following{/other_user}","gists_url":"https://api.github.com/users/Redrield/gists{/gist_id}","starred_url":"https://api.github.com/users/Redrield/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Redrield/subscriptions","organizations_url":"https://api.github.com/users/Redrield/orgs","repos_url":"https://api.github.com/users/Redrield/repos","events_url":"https://api.github.com/users/Redrield/events{/privacy}","received_events_url":"https://api.github.com/users/Redrield/received_events","type":"User","site_admin":false},"labels":[{"id":635498893,"url":"https://api.github.com/repos/TheDan64/inkwell/labels/bug","name":"bug","color":"ee0701","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/TheDan64/inkwell/milestones/1","html_url":"https://github.com/TheDan64/inkwell/milestone/1","labels_url":"https://api.github.com/repos/TheDan64/inkwell/milestones/1/labels","id":2612076,"number":1,"title":"0.1.0","description":"Initial release of inkwell","creator":{"login":"TheDan64","id":3749239,"avatar_url":"https://avatars2.githubusercontent.com/u/3749239?v=4","gravatar_id":"","url":"https://api.github.com/users/TheDan64","html_url":"https://github.com/TheDan64","followers_url":"https://api.github.com/users/TheDan64/followers","following_url":"https://api.github.com/users/TheDan64/following{/other_user}","gists_url":"https://api.github.com/users/TheDan64/gists{/gist_id}","starred_url":"https://api.github.com/users/TheDan64/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TheDan64/subscriptions","organizations_url":"https://api.github.com/users/TheDan64/orgs","repos_url":"https://api.github.com/users/TheDan64/repos","events_url":"https://api.github.com/users/TheDan64/events{/privacy}","received_events_url":"https://api.github.com/users/TheDan64/received_events","type":"User","site_admin":false},"open_issues":6,"closed_issues":6,"state":"open","created_at":"2017-06-29T12:53:37Z","updated_at":"2018-02-21T21:54:36Z","due_on":null,"closed_at":null},"comments":1,"created_at":"2018-02-18T01:00:25Z","updated_at":"2018-02-21T21:54:36Z","closed_at":"2018-02-21T21:54:36Z","author_association":"NONE","body":"In an attempt to get around #32, I've been trying to get a program working that can call printf with a string array. Looking at working IR, I see that to convert from an array to a pointer, an inbounds GEP instruction is used. This is the code I came up with to replicate that.\r\n\r\n```Rust\r\nextern crate inkwell;\r\nextern crate pest;\r\n\r\nuse inkwell::context::Context;\r\nuse inkwell::targets::{InitializationConfig, Target};\r\nuse inkwell::AddressSpace;\r\nuse inkwell::module::Linkage;\r\nuse inkwell::values::IntValue;\r\n\r\nuse std::path::Path;\r\n\r\nfn main() {\r\n    Target::initialize_native(&InitializationConfig::default()).unwrap();\r\n    let ctx = Context::create();\r\n    let module = ctx.create_module(\"program\");\r\n    let builder = ctx.create_builder();\r\n\r\n    let str_type = ctx.i8_type().ptr_type(AddressSpace::Generic);\r\n    let i32_type = ctx.i32_type();\r\n\r\n    let my_message = \"Hello, World!\\n\\0\";\r\n    let arr_type = ctx.i8_type().array_type(my_message.len() as u32);\r\n\r\n    let mut chars = Vec::with_capacity(my_message.len());\r\n\r\n    for ch in my_message.chars() {\r\n        chars.push(ctx.i8_type().const_int(ch as u64, false));\r\n    }\r\n\r\n    let global = module.add_global(&arr_type, Some(AddressSpace::Generic), \"message\");\r\n    let oof: Vec<&IntValue> = chars.iter().map(|x| x).collect();\r\n\r\n    let str_array = arr_type.const_array(&oof[..]);\r\n\r\n    global.set_initializer(&str_array);\r\n\r\n    let printf_type = i32_type.fn_type(&[&str_type], true);\r\n    let printf = module.add_function(\"printf\", &printf_type, Some(&Linkage::ExternalLinkage));\r\n\r\n    let main_fn_type = i32_type.fn_type(&[&i32_type, &str_type.ptr_type(AddressSpace::Generic)], false);\r\n\r\n    let main_fn = module.add_function(\"main\", &main_fn_type, None);\r\n    let block = ctx.append_basic_block(&main_fn, \"entry\");\r\n    builder.position_at_end(&block);\r\n\r\n    let value = builder.build_in_bounds_gep(&global.as_pointer_value(), &oof[..], \"\");\r\n\r\n    builder.build_call(&printf, &[&value], \"\", false);\r\n    builder.build_return(Some(&i32_type.const_int(0, false)));\r\n\r\n//    println!(\"{:?}\", module.print_to_string());\r\n    module.print_to_file(Path::new(\"test.ll\"));\r\n}\r\n```\r\nAt the line where `value` is bound, the program exits with a SIGSEGV\r\n\r\nEnvironment\r\n\r\nOperating system: Arch Linux\r\nKernel version: 4.15.3-1-ARCH\r\nLLVM version: 5.0.1-2\r\nInkwell version: 0.1.0#eafca272\r\nrustc -vV output:\r\n\r\n```\r\nrustc 1.25.0-nightly (3ec5a99aa 2018-02-14)\r\nbinary: rustc\r\ncommit-hash: 3ec5a99aaa0084d97a9e845b34fdf03d1462c475\r\ncommit-date: 2018-02-14\r\nhost: x86_64-unknown-linux-gnu\r\nrelease: 1.25.0-nightly\r\nLLVM version: 6.0\r\n```"}}
{"actor":{"display_login":"Redrield"}}