@@ -1961,9 +1961,48 @@ void CheerpWriter::compileHeapAccess(const Value* p, Type* t, uint32_t offset)
19611961 stream << pointerShiftOperator () << shift;
19621962 stream << ' ]' ;
19631963}
1964+
1965+ // This function is not complete, but it is good enough to pass the tests and build cheerpj
1966+ static Type* getRawType (const Value* p)
1967+ {
1968+ if (const IntrinsicInst* II = dyn_cast<IntrinsicInst>(p))
1969+ {
1970+ switch (II ->getIntrinsicID ())
1971+ {
1972+ case Intrinsic::cheerp_upcast_collapsed:
1973+ case Intrinsic::cheerp_typed_ptrcast:
1974+ case Intrinsic::cheerp_cast_user:
1975+ return II ->getParamElementType (0 );
1976+ default :
1977+ break ;
1978+ }
1979+ }
1980+ else if (const SelectInst* SI = dyn_cast<SelectInst>(p))
1981+ {
1982+ Type* CommonType = nullptr ;
1983+
1984+ for (unsigned int i = 1 ; i < SI ->getNumOperands (); i++) {
1985+ Type* T = getRawType (SI ->getOperand (i));
1986+
1987+ if (!T || (CommonType && T != CommonType))
1988+ return nullptr ;
1989+
1990+ CommonType = T;
1991+ }
1992+
1993+ return CommonType;
1994+ }
1995+ else if (const GetElementPtrInst* GEPI = dyn_cast<GetElementPtrInst>(p))
1996+ {
1997+ return GEPI ->getResultElementType ();
1998+ }
1999+
2000+ return nullptr ;
2001+ }
2002+
19642003void CheerpWriter::compilePointerBase (const Value* p, bool forEscapingPointer, bool useGPET)
19652004{
1966- if (const IntrinsicInst* II = dyn_cast<IntrinsicInst>(p))
2005+ if (const IntrinsicInst* II = dyn_cast<IntrinsicInst>(p))
19672006 {
19682007 switch (II ->getIntrinsicID ())
19692008 {
@@ -1986,7 +2025,20 @@ void CheerpWriter::compilePointerBase(const Value* p, bool forEscapingPointer, b
19862025 else if (useGPET || isa<BitCastInst>(p) || isa<UndefValue>(p))
19872026 compilePointerBaseTyped (p, p->getType ()->getPointerElementType (), forEscapingPointer);
19882027 else
1989- llvm::report_fatal_error (" Missing typed ptrcast intrinsic and no GPET allowed" );
2028+ {
2029+ Type* T = getRawType (p);
2030+
2031+ if (T)
2032+ compilePointerBaseTyped (p, T, forEscapingPointer);
2033+ else
2034+ {
2035+ p->dump ();
2036+ if (const Instruction* i = dyn_cast<Instruction>(p))
2037+ i->getParent ()->getParent ()->dump ();
2038+ llvm::report_fatal_error (" Missing typed ptrcast intrinsic and no GPET allowed" );
2039+ }
2040+
2041+ }
19902042}
19912043
19922044void CheerpWriter::compilePointerBaseTyped (const Value* p, Type* elementType, bool forEscapingPointer)
0 commit comments