From 5093d6d864e1984c8ad2dacab5088ee1849c0c00 Mon Sep 17 00:00:00 2001 From: Mark Peerdeman Date: Fri, 2 Feb 2024 11:37:46 +0100 Subject: [PATCH] fixup! Fix to TypeOptimizer to allow literal structs. --- llvm/lib/CheerpUtils/TypeOptimizer.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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());