From ecb2e895dcf7d9bc7f17d226b2faeadc3a6bcb6b Mon Sep 17 00:00:00 2001 From: Jeffrey Lin Date: Mon, 3 Feb 2020 10:21:16 +0000 Subject: [PATCH] src/codegen.cpp: fix segfault on `@code_native` with eltype (#34434) (#34458) --- src/codegen.cpp | 3 ++- stdlib/InteractiveUtils/test/runtests.jl | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/codegen.cpp b/src/codegen.cpp index e1281dbf3fcc3d..28782023477301 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -1684,7 +1684,7 @@ void *jl_get_llvmf_decl(jl_method_instance_t *mi, size_t world, bool getwrapper, // internal error return NULL; - const jl_llvm_functions_t &decls = codeinst->functionObjectsDecls; + jl_llvm_functions_t decls = codeinst->functionObjectsDecls; if (decls.functionObject == NULL && codeinst->invoke == jl_fptr_const_return && jl_is_method(mi->def.method)) { // normally we don't generate native code for these functions, so need an exception here // This leaks a bit of memory to cache native code that we'll never actually need @@ -1698,6 +1698,7 @@ void *jl_get_llvmf_decl(jl_method_instance_t *mi, size_t world, bool getwrapper, if (codeinst == NULL) // internal error return NULL; + decls = codeinst->functionObjectsDecls; } JL_UNLOCK(&codegen_lock); } diff --git a/stdlib/InteractiveUtils/test/runtests.jl b/stdlib/InteractiveUtils/test/runtests.jl index 0cbd98bcc7b582..820323d986410c 100644 --- a/stdlib/InteractiveUtils/test/runtests.jl +++ b/stdlib/InteractiveUtils/test/runtests.jl @@ -446,3 +446,9 @@ end # buildbot path updating file, ln = functionloc(versioninfo, Tuple{}) @test isfile(file) + +@testset "Issue #34434" begin + io = IOBuffer() + code_native(io, eltype, Tuple{Int}) + @test occursin("eltype", String(take!(io))) +end