From 9abe7fe219e0416556ae21091a9b0ef8e6cce994 Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Sun, 28 Jun 2015 00:14:08 -0400 Subject: [PATCH] Fix #11904 and also fix #11874 When in branches that type inference knows are dead, type information can be inaccurate and codegen basically just needs to bail out as fast as possible. --- src/intrinsics.cpp | 2 +- test/core.jl | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/intrinsics.cpp b/src/intrinsics.cpp index 621a36a038039..90a1f33f84e03 100644 --- a/src/intrinsics.cpp +++ b/src/intrinsics.cpp @@ -265,7 +265,7 @@ static Value *emit_unbox(Type *to, Value *x, jl_value_t *jt) return UndefValue::get(to); } if (ty != jl_pvalue_llvmt) { - if (to->isAggregateType()) { + if (ty->isPointerTy() && to->isAggregateType()) { x = builder.CreateLoad(x); // something stack allocated ty = x->getType(); } diff --git a/test/core.jl b/test/core.jl index 2a09924136a60..0f6dfc01a4e08 100644 --- a/test/core.jl +++ b/test/core.jl @@ -3033,3 +3033,30 @@ f11858(Any[Foo11858, Bar11858, g11858]) @test g11858(1) == 1.0 @test Foo11858(1).x == 1.0 @test Bar11858(1).x == 1.0 + +# issue 11904 +@noinline throw_error() = error() +foo11904(x::Int) = x +@inline function foo11904{S}(x::Nullable{S}) + if isbits(S) + Nullable(foo11904(x.value), x.isnull) + else + throw_error() + end +end + +@test !foo11904(Nullable(1)).isnull + +# issue 11874 +immutable Foo11874 + x::Int +end + +function bar11874(x) + y::Foo11874 + y=x +end + +Base.convert(::Type{Foo11874},x::Int) = float(x) + +@test_throws TypeError bar11874(1)