Skip to content

Commit

Permalink
the -Wpedantic ISO C standard forbids conversion of object pointer to…
Browse files Browse the repository at this point in the history
… function pointer type, so try to avoid it sometimes
  • Loading branch information
vtjnash committed Dec 4, 2015
1 parent a4d03d2 commit 79356b8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
7 changes: 3 additions & 4 deletions src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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;
Expand Down
18 changes: 13 additions & 5 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ static Value *literal_static_pointer_val(const void *p, Type *t)
}

static std::vector<Constant*> jl_sysimg_gvars;
static std::vector<Constant*> jl_sysimg_fvars;

extern "C" int32_t jl_get_llvm_gv(jl_value_t *p)
{
Expand All @@ -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<Constant*>(jl_sysimg_gvars)), VMap),
MapValue(ConstantArray::get(gvars_type, ArrayRef<Constant*>(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<Constant*>(jl_sysimg_fvars)), VMap),
"jl_sysimg_fvars"));
addComdat(new GlobalVariable(*mod,
T_size,
true,
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 7 additions & 4 deletions src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 79356b8

Please sign in to comment.