@@ -1622,9 +1622,9 @@ void CheerpWriter::compileEqualPointersComparison(const llvm::Value* lhs, const
16221622 isInlineable (*cast<Instruction>(lhs), PA));
16231623 assert (rhsKind != COMPLETE_OBJECT || !isa<Instruction>(rhs) ||
16241624 isInlineable (*cast<Instruction>(rhs), PA));
1625- compilePointerBase (lhs);
1625+ compilePointerBase (lhs, false , true );
16261626 stream << compareString;
1627- compilePointerBase (rhs);
1627+ compilePointerBase (rhs, false , true );
16281628 stream << joinString;
16291629 compilePointerOffset (lhs, COMPARISON);
16301630 stream << compareString;
@@ -1634,9 +1634,9 @@ void CheerpWriter::compileEqualPointersComparison(const llvm::Value* lhs, const
16341634 {
16351635 assert (lhsKind != COMPLETE_OBJECT);
16361636 assert (rhsKind != COMPLETE_OBJECT);
1637- compilePointerBase (lhs);
1637+ compilePointerBase (lhs, false , true );
16381638 stream << compareString;
1639- compilePointerBase (rhs);
1639+ compilePointerBase (rhs, false , true );
16401640 stream << joinString;
16411641 compilePointerOffset (lhs, COMPARISON);
16421642 stream << compareString;
@@ -1732,6 +1732,7 @@ void CheerpWriter::compileCompleteObject(const Value* p, const Value* offset)
17321732 return ;
17331733 }
17341734
1735+
17351736 const llvm::Instruction* I = dyn_cast<Instruction>(p);
17361737 if (I && !isInlineable (*I, PA) &&
17371738 (isGEP (I) || isBitCast (I)) && PA.getPointerKindAssert (I) == COMPLETE_OBJECT)
@@ -1960,9 +1961,32 @@ void CheerpWriter::compileHeapAccess(const Value* p, Type* t, uint32_t offset)
19601961 stream << pointerShiftOperator () << shift;
19611962 stream << ' ]' ;
19621963}
1963- void CheerpWriter::compilePointerBase (const Value* p, bool forEscapingPointer)
1964+ void CheerpWriter::compilePointerBase (const Value* p, bool forEscapingPointer, bool useGPET )
19641965{
1965- compilePointerBaseTyped (p, p->getType ()->getPointerElementType (), forEscapingPointer);
1966+ if (const IntrinsicInst* II=dyn_cast<IntrinsicInst>(p))
1967+ {
1968+ switch (II->getIntrinsicID ())
1969+ {
1970+ case Intrinsic::cheerp_upcast_collapsed:
1971+ case Intrinsic::cheerp_typed_ptrcast:
1972+ case Intrinsic::cheerp_cast_user:
1973+ return compilePointerBaseTyped (II->getOperand (0 ), II->getParamElementType (0 ), forEscapingPointer);
1974+ default :
1975+ break ;
1976+ }
1977+ }
1978+
1979+ POINTER_KIND kind = PA.getPointerKind (p);
1980+
1981+ if (kind != RAW && (kind != CONSTANT || isa<ConstantPointerNull>(p)))
1982+ {
1983+ // point element type is not used in this case, so it can be null
1984+ compilePointerBaseTyped (p, nullptr , forEscapingPointer);
1985+ }
1986+ else if (useGPET || isa<BitCastInst>(p) || isa<UndefValue>(p))
1987+ compilePointerBaseTyped (p, p->getType ()->getPointerElementType (), forEscapingPointer);
1988+ else
1989+ llvm::report_fatal_error (" Missing typed ptrcast intrinsic and no GPET allowed" );
19661990}
19671991
19681992void CheerpWriter::compilePointerBaseTyped (const Value* p, Type* elementType, bool forEscapingPointer)
@@ -2018,6 +2042,7 @@ void CheerpWriter::compilePointerBaseTyped(const Value* p, Type* elementType, bo
20182042 case Intrinsic::cheerp_upcast_collapsed:
20192043 case Intrinsic::cheerp_typed_ptrcast:
20202044 case Intrinsic::cheerp_cast_user:
2045+ assert (elementType == II->getParamElementType (0 ));
20212046 return compilePointerBaseTyped (II->getOperand (0 ), II->getParamElementType (0 ));
20222047 case Intrinsic::cheerp_make_regular:
20232048 return compileCompleteObject (II->getOperand (0 ));
@@ -2171,7 +2196,7 @@ void CheerpWriter::compilePointerOffset(const Value* p, PARENT_PRIORITY parentPr
21712196 // null must be handled first, even if it is bytelayout
21722197 else if (kind == CONSTANT || isa<UndefValue>(p))
21732198 {
2174- if (const IntToPtrInst* ITP = dyn_cast<IntToPtrInst> (p))
2199+ if (const IntToPtrInst* ITP = getAsIntToPtrInst (p))
21752200 {
21762201 ConstantInt* CI = cast<ConstantInt>(ITP->getOperand (0 ));
21772202 stream << CI->getSExtValue ();
@@ -3034,10 +3059,10 @@ void CheerpWriter::compileMethodArgs(User::const_op_iterator it, User::const_op_
30343059 (argKind == COMPLETE_OBJECT && curKind == BYTE_LAYOUT))
30353060 {
30363061 if (F && PA.getConstantOffsetForPointer (&*arg_it))
3037- compilePointerBase (*cur, true );
3062+ compilePointerBase (*cur, true , true );
30383063 else
30393064 {
3040- compilePointerBase (*cur, true );
3065+ compilePointerBase (*cur, true , true );
30413066 stream << ' ,' ;
30423067 compilePointerOffset (*cur, LOWEST, true );
30433068 }
0 commit comments