From ba064ad4d0ffb484a90f04aecf40a03860d276b3 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Fri, 3 Jul 2015 18:39:38 -0400 Subject: [PATCH] fix #12003 julia_const_to_llvm sometimes returned a GlobalVariable instead of the expected Constant. should only return a GlobalVariable at the outermost level. --- src/intrinsics.cpp | 9 ++++++--- test/core.jl | 5 +++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/intrinsics.cpp b/src/intrinsics.cpp index 90a1f33f84e03..b2808ab9f28a1 100644 --- a/src/intrinsics.cpp +++ b/src/intrinsics.cpp @@ -128,7 +128,7 @@ static Value *uint_cnvt(Type *to, Value *x) } #define LLVM_FP(a,b) APFloat(a,b) -static Constant *julia_const_to_llvm(jl_value_t *e) +static Constant *julia_const_to_llvm(jl_value_t *e, bool nested=false) { jl_value_t *jt = jl_typeof(e); jl_datatype_t *bt = (jl_datatype_t*)jt; @@ -212,7 +212,7 @@ static Constant *julia_const_to_llvm(jl_value_t *e) else if (f == jl_false) val = ConstantInt::get(T_int8,0); else - val = julia_const_to_llvm(f); + val = julia_const_to_llvm(f, true); if (val == NULL) { JL_GC_POP(); return NULL; @@ -238,7 +238,10 @@ static Constant *julia_const_to_llvm(jl_value_t *e) assert(at); init = ConstantArray::get(at, ArrayRef(fields,llvm_nf)); } - return new GlobalVariable(*jl_Module, t, true, GlobalVariable::ExternalLinkage, init); + if (nested) + return init; + else + return new GlobalVariable(*jl_Module, t, true, GlobalVariable::ExternalLinkage, init); } return NULL; } diff --git a/test/core.jl b/test/core.jl index 00629221c876c..ad1f88d875fe6 100644 --- a/test/core.jl +++ b/test/core.jl @@ -3101,3 +3101,8 @@ function find_tvar10930(arg) return 1 end @test find_tvar10930(Vararg{Int}) === 1 + +# issue #12003 +const DATE12003 = DateTime(1917,1,1) +failure12003(dt=DATE12003) = Dates.year(dt) +@test isa(failure12003(), Integer)