aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Bitcode/Reader/BitcodeReader.cpp
diff options
context:
space:
mode:
authorJay Foad <jay.foad@amd.com>2024-11-05 09:41:10 +0000
committerGitHub <noreply@github.com>2024-11-05 09:41:10 +0000
commit4831e0aa88debb3b7d0528bfd85db73a6a03aeff (patch)
tree0b8bfd1dbc3210638c1fbe534f7011c31ec41685 /llvm/lib/Bitcode/Reader/BitcodeReader.cpp
parent72f362170fbe7834febfe08d8bd1f7ba935ddbc9 (diff)
downloadllvm-4831e0aa88debb3b7d0528bfd85db73a6a03aeff.zip
llvm-4831e0aa88debb3b7d0528bfd85db73a6a03aeff.tar.gz
llvm-4831e0aa88debb3b7d0528bfd85db73a6a03aeff.tar.bz2
[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.
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r--llvm/lib/Bitcode/Reader/BitcodeReader.cpp3
1 files changed, 2 insertions, 1 deletions
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;