Skip to content

Commit

Permalink
Merge pull request #23617 from JuliaLang/yyc/codegen/NI
Browse files Browse the repository at this point in the history
Fix invalid `ptrtoint` on non-integral pointers
  • Loading branch information
yuyichao authored Sep 8, 2017
2 parents 87d8af7 + cadbe23 commit 943c8e5
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/llvm-late-gc-lowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ struct LateLowerGCFrame: public FunctionPass {
Type *T_int8;
Type *T_int32;
Type *T_pint8;
Type *T_pjlvalue;
Type *T_pjlvalue_der;
Type *T_ppjlvalue_der;
MDNode *tbaa_gcframe;
Expand Down Expand Up @@ -1156,7 +1157,9 @@ bool LateLowerGCFrame::CleanupIR(Function &F) {
(gc_use_func != nullptr && callee == gc_use_func)) {
/* No replacement */
} else if (pointer_from_objref_func != nullptr && callee == pointer_from_objref_func) {
auto *ptr = new PtrToIntInst(CI->getOperand(0), CI->getType(), "", CI);
auto *obj = CI->getOperand(0);
auto *ASCI = new AddrSpaceCastInst(obj, T_pjlvalue, "", CI);
auto *ptr = new PtrToIntInst(ASCI, CI->getType(), "", CI);
ptr->takeName(CI);
CI->replaceAllUsesWith(ptr);
} else if (alloc_obj_func && callee == alloc_obj_func) {
Expand Down Expand Up @@ -1447,7 +1450,7 @@ bool LateLowerGCFrame::DefineFunctions(Module &M) {
addRetNoAlias(big_alloc_func);
}
auto T_jlvalue = cast<PointerType>(T_prjlvalue)->getElementType();
auto T_pjlvalue = PointerType::get(T_jlvalue, 0);
T_pjlvalue = PointerType::get(T_jlvalue, 0);
T_ppjlvalue = PointerType::get(T_pjlvalue, 0);
T_pjlvalue_der = PointerType::get(T_jlvalue, AddressSpace::Derived);
T_ppjlvalue_der = PointerType::get(T_prjlvalue, AddressSpace::Derived);
Expand All @@ -1456,7 +1459,7 @@ bool LateLowerGCFrame::DefineFunctions(Module &M) {
else if (ptls_getter) {
auto functype = ptls_getter->getFunctionType();
T_ppjlvalue = cast<PointerType>(functype->getReturnType())->getElementType();
auto T_pjlvalue = cast<PointerType>(T_ppjlvalue)->getElementType();
T_pjlvalue = cast<PointerType>(T_ppjlvalue)->getElementType();
auto T_jlvalue = cast<PointerType>(T_pjlvalue)->getElementType();
T_prjlvalue = PointerType::get(T_jlvalue, AddressSpace::Tracked);
T_pjlvalue_der = PointerType::get(T_jlvalue, AddressSpace::Derived);
Expand All @@ -1465,6 +1468,7 @@ bool LateLowerGCFrame::DefineFunctions(Module &M) {
else {
T_ppjlvalue = nullptr;
T_prjlvalue = nullptr;
T_pjlvalue = nullptr;
T_pjlvalue_der = nullptr;
T_ppjlvalue_der = nullptr;
}
Expand Down

0 comments on commit 943c8e5

Please sign in to comment.