{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/11858","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/11858/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/11858/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/11858/events","html_url":"https://github.com/JuliaLang/julia/issues/11858","id":91003003,"number":11858,"title":"Segfault in 0.4-dev with constructors from iterated tuple","user":{"login":"samuelpowell","id":6370657,"avatar_url":"https://avatars.githubusercontent.com/u/6370657?v=3","gravatar_id":"","url":"https://api.github.com/users/samuelpowell","html_url":"https://github.com/samuelpowell","followers_url":"https://api.github.com/users/samuelpowell/followers","following_url":"https://api.github.com/users/samuelpowell/following{/other_user}","gists_url":"https://api.github.com/users/samuelpowell/gists{/gist_id}","starred_url":"https://api.github.com/users/samuelpowell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/samuelpowell/subscriptions","organizations_url":"https://api.github.com/users/samuelpowell/orgs","repos_url":"https://api.github.com/users/samuelpowell/repos","events_url":"https://api.github.com/users/samuelpowell/events{/privacy}","received_events_url":"https://api.github.com/users/samuelpowell/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-06-25T15:54:16Z","updated_at":"2015-06-26T03:04:10Z","closed_at":null,"body":"Under 0.3.9 the following code:\r\n\r\n```\r\njulia> type Foo{T<:FloatingPoint}\r\n       \tx::T\r\n       \ty::T\r\n       end\r\n\r\njulia> type Bar{T<:FloatingPoint}\r\n       \tx::T\r\n       \ty::T\r\n       end\r\n\r\njulia> for Baz in (Foo, Bar)\r\n       \tBaz{T<:Number, S<:Number}(x::T, y::S) = Baz(promote(x,y)...)\r\n       end\r\n\r\njulia> Foo(1.1,1)\r\n```\r\n\r\nproduces the expected output, ```Foo{Float64}(1.1,1.0)```. Under (three day old) master, Julia segfaults as follows:\r\n\r\n```\r\nsignal (11): Segmentation fault: 11\r\njl_is_type at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/jltypes.c:68\r\njl_inst_concrete_tupletype_v at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/jltypes.c:2125\r\narg_type_tuple at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/gf.c:1337\r\njl_apply_generic at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/gf.c:1629\r\ncall at none:2\r\njl_apply at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/gf.c:1632\r\njl_apply at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/interpreter.c:55\r\neval at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/interpreter.c:212\r\njl_toplevel_eval_flex at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/toplevel.c:517\r\njl_toplevel_eval_in at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/builtins.c:547\r\neval_user_input at REPL.jl:62\r\njlcall_eval_user_input_21475 at  (unknown line)\r\njl_apply at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/./julia.h:1298\r\nanonymous at task.jl:91\r\njl_apply at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/task.c:235\r\n```\r\n\r\nVersion information:\r\n\r\n```\r\nJulia Version 0.4.0-dev+5511\r\nCommit 1e081b7 (2015-06-22 05:05 UTC)\r\nPlatform Info:\r\n  System: Darwin (x86_64-apple-darwin13.4.0)\r\n  CPU: Intel(R) Core(TM) i5-4258U CPU @ 2.40GHz\r\n  WORD_SIZE: 64\r\n  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)\r\n  LAPACK: libopenblas\r\n  LIBM: libopenlibm\r\n  LLVM: libLLVM-3.3\r\n```"},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/115482155","html_url":"https://github.com/JuliaLang/julia/issues/11858#issuecomment-115482155","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/11858","id":115482155,"user":{"login":"yuyichao","id":712232,"avatar_url":"https://avatars.githubusercontent.com/u/712232?v=3","gravatar_id":"","url":"https://api.github.com/users/yuyichao","html_url":"https://github.com/yuyichao","followers_url":"https://api.github.com/users/yuyichao/followers","following_url":"https://api.github.com/users/yuyichao/following{/other_user}","gists_url":"https://api.github.com/users/yuyichao/gists{/gist_id}","starred_url":"https://api.github.com/users/yuyichao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yuyichao/subscriptions","organizations_url":"https://api.github.com/users/yuyichao/orgs","repos_url":"https://api.github.com/users/yuyichao/repos","events_url":"https://api.github.com/users/yuyichao/events{/privacy}","received_events_url":"https://api.github.com/users/yuyichao/received_events","type":"User","site_admin":false},"created_at":"2015-06-26T03:04:10Z","updated_at":"2015-06-26T03:04:10Z","body":"I've just rebased on master and I don't get the segfault anymore either.\r\nHowever, the code generated is still wrong.\r\n\r\nWith the test script\r\n\r\n```julia\r\n#!/usr/bin/julia -f\r\n\r\ntype Foo{T<:FloatingPoint}\r\n    x::T\r\n    y::T\r\nend\r\n\r\ntype Bar{T<:FloatingPoint}\r\n    x::T\r\n    y::T\r\nend\r\n\r\nfor Baz in (Foo, Bar)\r\n    Baz(x, y) = Baz(float(x), float(y))\r\nend\r\n\r\n@code_llvm Foo(1.1, 1)\r\nprintln(Foo(1.1, 1))\r\nFoo(1.1, 1)\r\n```\r\n\r\nIt outputs\r\n\r\n```llvm\r\ndefine %jl_value_t* @julia_call_21349(%jl_value_t*, %jl_value_t**, i32) {\r\ntop:\r\n  %3 = getelementptr inbounds %jl_value_t* %0, i64 1, i32 0\r\n  %4 = bitcast %jl_value_t** %3 to %jl_value_t***\r\n  %5 = load %jl_value_t*** %4, align 8\r\n  %6 = alloca [7 x %jl_value_t*], align 8\r\n  %.sub = getelementptr inbounds [7 x %jl_value_t*]* %6, i64 0, i64 0\r\n  %7 = getelementptr [7 x %jl_value_t*]* %6, i64 0, i64 2\r\n  %8 = getelementptr [7 x %jl_value_t*]* %6, i64 0, i64 4\r\n  %9 = bitcast [7 x %jl_value_t*]* %6 to i64*\r\n  store i64 10, i64* %9, align 8\r\n  %10 = getelementptr [7 x %jl_value_t*]* %6, i64 0, i64 1\r\n  %11 = bitcast %jl_value_t** %10 to %jl_value_t***\r\n  %12 = load %jl_value_t*** @jl_pgcstack, align 8\r\n  store %jl_value_t** %12, %jl_value_t*** %11, align 8\r\n  store %jl_value_t** %.sub, %jl_value_t*** @jl_pgcstack, align 8\r\n  store %jl_value_t* null, %jl_value_t** %7, align 8\r\n  %13 = getelementptr [7 x %jl_value_t*]* %6, i64 0, i64 3\r\n  store %jl_value_t* null, %jl_value_t** %13, align 8\r\n  store %jl_value_t* null, %jl_value_t** %8, align 8\r\n  %14 = getelementptr [7 x %jl_value_t*]* %6, i64 0, i64 5\r\n  store %jl_value_t* null, %jl_value_t** %14, align 8\r\n  %15 = getelementptr [7 x %jl_value_t*]* %6, i64 0, i64 6\r\n  store %jl_value_t* null, %jl_value_t** %15, align 8\r\n  %16 = load %jl_value_t** %1, align 8\r\n  store %jl_value_t* %16, %jl_value_t** %7, align 8\r\n  %17 = getelementptr %jl_value_t** %1, i64 1\r\n  %18 = load %jl_value_t** %17, align 8\r\n  store %jl_value_t* %18, %jl_value_t** %13, align 8\r\n  %19 = getelementptr %jl_value_t** %5, i64 1\r\n  %20 = bitcast %jl_value_t** %19 to %jl_value_t***\r\n  %21 = load %jl_value_t*** %20, align 8\r\n  %22 = load %jl_value_t** %21, align 8\r\n  %23 = icmp eq %jl_value_t* %22, null\r\n  br i1 %23, label %err, label %ok\r\n\r\nerr:                                              ; preds = %top\r\n  call void @jl_undefined_var_error(%jl_value_t* inttoptr (i64 140737353370112 to %jl_value_t*))\r\n  unreachable\r\n\r\nok:                                               ; preds = %top\r\n  %24 = getelementptr %jl_value_t** %1, i64 3\r\n  %25 = bitcast %jl_value_t** %24 to i64**\r\n  %26 = load i64** %25, align 8\r\n  %27 = load i64* %26, align 16\r\n  %28 = getelementptr %jl_value_t** %1, i64 2\r\n  %29 = bitcast %jl_value_t** %28 to i64**\r\n  %30 = load i64** %29, align 8\r\n  %31 = load i64* %30, align 16\r\n  store %jl_value_t* %22, %jl_value_t** %8, align 8\r\n  %32 = sitofp i64 %31 to double\r\n  %33 = call %jl_value_t* @jl_gc_alloc_1w()\r\n  %34 = getelementptr inbounds %jl_value_t* %33, i64 -1, i32 0\r\n  store %jl_value_t* inttoptr (i64 140728650802864 to %jl_value_t*), %jl_value_t** %34, align 8\r\n  %35 = bitcast %jl_value_t* %33 to double*\r\n  store double %32, double* %35, align 16\r\n  store %jl_value_t* %33, %jl_value_t** %14, align 8\r\n  %36 = sitofp i64 %27 to double\r\n  %37 = call %jl_value_t* @jl_gc_alloc_1w()\r\n  %38 = getelementptr inbounds %jl_value_t* %37, i64 -1, i32 0\r\n  store %jl_value_t* inttoptr (i64 140728650802864 to %jl_value_t*), %jl_value_t** %38, align 8\r\n  %39 = bitcast %jl_value_t* %37 to double*\r\n  store double %36, double* %39, align 16\r\n  store %jl_value_t* %37, %jl_value_t** %15, align 8\r\n  %40 = call %jl_value_t* @jl_apply_generic(%jl_value_t* inttoptr (i64 140728679102864 to %jl_value_t*), %jl_value_t** %8, i32 3)\r\n  %41 = load %jl_value_t*** %11, align 8\r\n  store %jl_value_t** %41, %jl_value_t*** @jl_pgcstack, align 8\r\n  ret %jl_value_t* %40\r\n}\r\nFoo{Float64}(1.0,1.40737353118368e14)\r\n```\r\n\r\n1. Notice that the output is wrong.\r\n2. The codegen generates a load of `args[3]` although `nargs` is only `3`.\r\n\r\n    ```llvm\r\n    ok:                                               ; preds = %top\r\n      %24 = getelementptr %jl_value_t** %1, i64 3\r\n    ```\r\n\r\n    From the corruption of the output, I guess this should have been a load of `args[1]`\r\n\r\n@vtjnash I would guess this might have sth related to your recent codegen changes?\r\n@Keno Just a head up in case this is the breakage you are having.\r\n"}}