diff --git a/lib/AsmParser/LLParser.cpp b/lib/AsmParser/LLParser.cpp index da8cb4da23e..27dbf8871a6 100644 --- a/lib/AsmParser/LLParser.cpp +++ b/lib/AsmParser/LLParser.cpp @@ -238,6 +238,9 @@ bool LLParser::ParseUnnamedType() { std::map >::iterator FI = ForwardRefTypeIDs.find(TypeID); if (FI != ForwardRefTypeIDs.end()) { + if (FI->second.first.get() == Ty) + return Error(TypeLoc, "self referential type is invalid"); + cast(FI->second.first.get())->refineAbstractTypeTo(Ty); Ty = FI->second.first.get(); ForwardRefTypeIDs.erase(FI); @@ -275,6 +278,9 @@ bool LLParser::ParseNamedType() { std::map >::iterator FI = ForwardRefTypes.find(Name); if (FI != ForwardRefTypes.end()) { + if (FI->second.first.get() == Ty) + return Error(NameLoc, "self referential type is invalid"); + cast(FI->second.first.get())->refineAbstractTypeTo(Ty); Ty = FI->second.first.get(); ForwardRefTypes.erase(FI);