diff --git a/llvm/lib/CheerpUtils/TypeOptimizer.cpp b/llvm/lib/CheerpUtils/TypeOptimizer.cpp index a6d5f3ec2de6..42d803eced60 100644 --- a/llvm/lib/CheerpUtils/TypeOptimizer.cpp +++ b/llvm/lib/CheerpUtils/TypeOptimizer.cpp @@ -290,7 +290,10 @@ bool TypeOptimizer::isUnsafeDowncastSource(StructType* st) bool TypeOptimizer::canCollapseStruct(llvm::StructType* st, llvm::StructType* newStruct, llvm::Type* newType) { if (newStruct == nullptr) + { + assert(st->isLiteral()); return false; + } // Stop if the element is just a int8, we may be dealing with an empty struct // Empty structs are unsafe as the int8 inside is just a placeholder and will be replaced // by a different type in a derived class @@ -447,7 +450,8 @@ TypeOptimizer::TypeMappingInfo TypeOptimizer::rewriteType(Type* t) return CacheAndReturn(newType, TypeMappingInfo::BYTE_LAYOUT_TO_ARRAY); } - // Generate a new type inconditionally, it may end up being the same as the old one + // Generate a new type if it's not a literal struct. It may end up being the same as the old one + // In case of literal, it will be created as a literal at the end. StructType* newStruct=nullptr; if (!st->isLiteral()) newStruct=StructType::create(st->getContext());