From 79356b86ea990379432cb29aef3135e50318e79e Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Fri, 4 Dec 2015 00:25:48 -0500 Subject: [PATCH] the -Wpedantic ISO C standard forbids conversion of object pointer to function pointer type, so try to avoid it sometimes --- src/ccall.cpp | 7 +++---- src/cgutils.cpp | 18 +++++++++++++----- src/codegen.cpp | 6 ++++-- src/dump.c | 11 +++++++---- 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/ccall.cpp b/src/ccall.cpp index dadd27112bf62..308a17d1dea05 100644 --- a/src/ccall.cpp +++ b/src/ccall.cpp @@ -17,8 +17,6 @@ static Value *runtime_sym_lookup(PointerType *funcptype, const char *f_lib, cons // *llvmgv = jl_load_and_lookup(f_lib, f_name, libptrgv); // } // return (*llvmgv) - Constant *initnul = ConstantPointerNull::get((PointerType*)T_pint8); - void *libsym = NULL; bool runtime_lib = false; GlobalVariable *libptrgv; @@ -43,7 +41,7 @@ static Value *runtime_sym_lookup(PointerType *funcptype, const char *f_lib, cons if (libptrgv == NULL) { libptrgv = new GlobalVariable(*jl_Module, T_pint8, false, GlobalVariable::PrivateLinkage, - initnul, f_lib); + ConstantPointerNull::get((PointerType*)T_pint8), f_lib); libMapGV[f_lib] = libptrgv; libsym = jl_get_library(f_lib); assert(libsym != NULL); @@ -65,12 +63,13 @@ static Value *runtime_sym_lookup(PointerType *funcptype, const char *f_lib, cons assert(libsym != NULL); GlobalVariable *llvmgv = symMapGV[f_name]; + Constant *initnul = ConstantPointerNull::get((PointerType*)T_pvoidfunc); if (llvmgv == NULL) { // MCJIT forces this to have external linkage eventually, so we would clobber // the symbol of the actual function. std::string name = f_name; name = "ccall_" + name; - llvmgv = new GlobalVariable(*jl_Module, T_pint8, + llvmgv = new GlobalVariable(*jl_Module, T_pvoidfunc, false, GlobalVariable::PrivateLinkage, initnul, name); symMapGV[f_name] = llvmgv; diff --git a/src/cgutils.cpp b/src/cgutils.cpp index a992b4a065fec..5e5fb5574f07e 100644 --- a/src/cgutils.cpp +++ b/src/cgutils.cpp @@ -427,6 +427,7 @@ static Value *literal_static_pointer_val(const void *p, Type *t) } static std::vector jl_sysimg_gvars; +static std::vector jl_sysimg_fvars; extern "C" int32_t jl_get_llvm_gv(jl_value_t *p) { @@ -446,13 +447,20 @@ extern "C" { static void jl_gen_llvm_globaldata(llvm::Module *mod, ValueToValueMapTy &VMap, const char *sysimg_data, size_t sysimg_len) { - ArrayType *atype = ArrayType::get(T_psize, jl_sysimg_gvars.size()); + ArrayType *gvars_type = ArrayType::get(T_psize, jl_sysimg_gvars.size()); addComdat(new GlobalVariable(*mod, - atype, + gvars_type, true, GlobalVariable::ExternalLinkage, - MapValue(ConstantArray::get(atype, ArrayRef(jl_sysimg_gvars)), VMap), + MapValue(ConstantArray::get(gvars_type, ArrayRef(jl_sysimg_gvars)), VMap), "jl_sysimg_gvars")); + ArrayType *fvars_type = ArrayType::get(T_pvoidfunc, jl_sysimg_fvars.size()); + addComdat(new GlobalVariable(*mod, + fvars_type, + true, + GlobalVariable::ExternalLinkage, + MapValue(ConstantArray::get(fvars_type, ArrayRef(jl_sysimg_fvars)), VMap), + "jl_sysimg_fvars")); addComdat(new GlobalVariable(*mod, T_size, true, @@ -614,8 +622,8 @@ static int32_t jl_assign_functionID(Function *functionObject) // give the function an index in the constant lookup table if (!imaging_mode) return 0; - jl_sysimg_gvars.push_back(ConstantExpr::getBitCast(functionObject,T_psize)); - return jl_sysimg_gvars.size(); + jl_sysimg_fvars.push_back(ConstantExpr::getBitCast(functionObject, T_pvoidfunc)); + return jl_sysimg_fvars.size(); } static Value *julia_gv(const char *cname, void *addr) diff --git a/src/codegen.cpp b/src/codegen.cpp index f1f2f3e71a1ba..8d15152f8856e 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -358,6 +358,7 @@ static Type *T_ppjlvalue; static Type* jl_parray_llvmt; static FunctionType *jl_func_sig; static Type *jl_pfptr_llvmt; +static Type *T_pvoidfunc; static IntegerType *T_int1; static IntegerType *T_int8; @@ -5515,9 +5516,10 @@ static void init_julia_llvm_env(Module *m) T_float64 = Type::getDoubleTy(getGlobalContext()); T_pfloat64 = PointerType::get(T_float64, 0); T_void = Type::getVoidTy(jl_LLVMContext); + T_pvoidfunc = FunctionType::get(T_void, /*isVarArg*/false)->getPointerTo(); // This type is used to create undef Values for use in struct declarations to skip indices - NoopType = ArrayType::get(T_int1,0); + NoopType = ArrayType::get(T_int1, 0); // add needed base definitions to our LLVM environment StructType *valueSt = StructType::create(getGlobalContext(), "jl_value_t"); @@ -6048,7 +6050,7 @@ static void init_julia_llvm_env(Module *m) dlsym_args.push_back(T_pint8); dlsym_args.push_back(PointerType::get(T_pint8,0)); jldlsym_func = - Function::Create(FunctionType::get(T_pint8, dlsym_args, false), + Function::Create(FunctionType::get(T_pvoidfunc, dlsym_args, false), Function::ExternalLinkage, "jl_load_and_lookup", m); add_named_global(jldlsym_func, (void*)&jl_load_and_lookup); diff --git a/src/dump.c b/src/dump.c index c0a3fd390243c..70917a63a70bd 100644 --- a/src/dump.c +++ b/src/dump.c @@ -200,6 +200,7 @@ static void write_float64(ios_t *s, double x) static void jl_serialize_value_(ios_t *s, jl_value_t *v); static jl_value_t *jl_deserialize_value(ios_t *s, jl_value_t **loc); jl_value_t ***sysimg_gvars = NULL; +void **sysimg_fvars = NULL; #ifdef HAVE_CPUID extern void jl_cpuid(int32_t CPUInfo[4], int32_t InfoType); @@ -230,6 +231,7 @@ static int jl_load_sysimg_so(void) // in --build mode only use sysimg data, not precompiled native code if (!imaging_mode && jl_options.use_precompiled==JL_OPTIONS_USE_PRECOMPILED_YES) { sysimg_gvars = (jl_value_t***)jl_dlsym(jl_sysimg_handle, "jl_sysimg_gvars"); + sysimg_fvars = (void**)jl_dlsym(jl_sysimg_handle, "jl_sysimg_fvars"); globalUnique = *(size_t*)jl_dlsym(jl_sysimg_handle, "jl_globalUnique"); #ifdef JULIA_ENABLE_THREADING size_t tls_getter_idx = *(size_t*)jl_dlsym(jl_sysimg_handle, @@ -412,21 +414,22 @@ static void jl_delayed_fptrs(jl_lambda_info_t *li, int32_t func, int32_t cfunc) static void jl_update_all_fptrs(void) { //jl_printf(JL_STDOUT, "delayed_fptrs_n: %d\n", delayed_fptrs_n); - jl_value_t ***gvars = sysimg_gvars; - if (gvars == 0) return; + void **fvars = sysimg_fvars; + if (fvars == 0) return; // jl_fptr_to_llvm needs to decompress some ASTs, therefore this needs to be NULL // to skip trying to restore GlobalVariable pointers in jl_deserialize_gv sysimg_gvars = NULL; + sysimg_fvars = NULL; size_t i; for (i = 0; i < delayed_fptrs_n; i++) { jl_lambda_info_t *li = delayed_fptrs[i].li; int32_t func = delayed_fptrs[i].func-1; if (func >= 0) { - jl_fptr_to_llvm((void*)gvars[func], li, 0); + jl_fptr_to_llvm(fvars[func], li, 0); } int32_t cfunc = delayed_fptrs[i].cfunc-1; if (cfunc >= 0) { - jl_fptr_to_llvm((void*)gvars[cfunc], li, 1); + jl_fptr_to_llvm(fvars[cfunc], li, 1); } } delayed_fptrs_n = 0;