@@ -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, false , true );
1625+ compilePointerBase (lhs, /* forEscapingPointer */ false , /* useGPET */ true );
16261626 stream << compareString;
1627- compilePointerBase (rhs, false , true );
1627+ compilePointerBase (rhs, /* forEscapingPointer */ false , /* useGPET */ 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, false , true );
1637+ compilePointerBase (lhs, /* forEscapingPointer */ false , /* useGPET */ true );
16381638 stream << compareString;
1639- compilePointerBase (rhs, false , true );
1639+ compilePointerBase (rhs, /* forEscapingPointer */ false , /* useGPET */ true );
16401640 stream << joinString;
16411641 compilePointerOffset (lhs, COMPARISON);
16421642 stream << compareString;
@@ -1732,7 +1732,6 @@ void CheerpWriter::compileCompleteObject(const Value* p, const Value* offset)
17321732 return ;
17331733 }
17341734
1735-
17361735 const llvm::Instruction* I = dyn_cast<Instruction>(p);
17371736 if (I && !isInlineable (*I, PA) &&
17381737 (isGEP (I) || isBitCast (I)) && PA.getPointerKindAssert (I) == COMPLETE_OBJECT)
@@ -2017,6 +2016,11 @@ void CheerpWriter::compilePointerBase(const Value* p, bool forEscapingPointer, b
20172016
20182017 POINTER_KIND kind = PA.getPointerKind (p);
20192018
2019+ // This condition is true if we can safely pass a nullptr element type to compilePointerBaseType.
2020+ // The logic should work as follows:
2021+ // 1. if kind == RAW, it is not safe to pass nullptr
2022+ // 2. if kind == CONSTANT, it is not safe to pass nullptr *unless* it is a null pointer constant
2023+ // 3. otherwise, it is safe to pass nullptr
20202024 if (kind != RAW && (kind != CONSTANT || isa<ConstantPointerNull>(p)))
20212025 {
20222026 // point element type is not used in this case, so it can be null
@@ -2032,12 +2036,13 @@ void CheerpWriter::compilePointerBase(const Value* p, bool forEscapingPointer, b
20322036 compilePointerBaseTyped (p, T, forEscapingPointer);
20332037 else
20342038 {
2039+ #ifndef NDEBUG
20352040 p->dump ();
20362041 if (const Instruction* i = dyn_cast<Instruction>(p))
20372042 i->getParent ()->getParent ()->dump ();
2043+ #endif
20382044 llvm::report_fatal_error (" Missing typed ptrcast intrinsic and no GPET allowed" );
20392045 }
2040-
20412046 }
20422047}
20432048
0 commit comments