From 4831e0aa88debb3b7d0528bfd85db73a6a03aeff Mon Sep 17 00:00:00 2001 From: Jay Foad Date: Tue, 5 Nov 2024 09:41:10 +0000 Subject: [IR] Disallow recursive types (#114799) StructType::setBody is the only mechanism that can potentially create recursion in the type system. Add a runtime check that it is not actually used to create recursion. If the check fails, report an error from LLParser, BitcodeReader and IRLinker. In all other cases assert that the check succeeds. In future StructType::setBody will be removed in favor of specifying the body when the type is created, so any performance hit from this runtime check will be temporary. --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp') diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 446c98c..3e82aa7 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -2659,7 +2659,8 @@ Error BitcodeReader::parseTypeTableBody() { } if (EltTys.size() != Record.size()-1) return error("Invalid named struct record"); - Res->setBody(EltTys, Record[0]); + if (auto E = Res->setBodyOrError(EltTys, Record[0])) + return E; ContainedIDs.append(Record.begin() + 1, Record.end()); ResultTy = Res; break; -- cgit v1.1