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