diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2022-07-04 19:20:19 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2023-02-08 19:02:26 +0000 |
commit | 81ad626541db97eb356e2c1d4a20eb2a26a766ab (patch) | |
tree | 311b6a8987c32b1e1dcbab65c54cfac3fdb56175 /contrib/llvm-project/llvm/lib/Bitcode/Reader/MetadataLoader.cpp | |
parent | 5fff09660e06a66bed6482da9c70df328e16bbb6 (diff) | |
parent | 145449b1e420787bb99721a429341fa6be3adfb6 (diff) |
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Bitcode/Reader/MetadataLoader.cpp')
-rw-r--r-- | contrib/llvm-project/llvm/lib/Bitcode/Reader/MetadataLoader.cpp | 90 |
1 files changed, 47 insertions, 43 deletions
diff --git a/contrib/llvm-project/llvm/lib/Bitcode/Reader/MetadataLoader.cpp b/contrib/llvm-project/llvm/lib/Bitcode/Reader/MetadataLoader.cpp index 0f4111514057..0d57ae4ef9df 100644 --- a/contrib/llvm-project/llvm/lib/Bitcode/Reader/MetadataLoader.cpp +++ b/contrib/llvm-project/llvm/lib/Bitcode/Reader/MetadataLoader.cpp @@ -9,74 +9,60 @@ #include "MetadataLoader.h" #include "ValueList.h" -#include "llvm/ADT/APFloat.h" #include "llvm/ADT/APInt.h" #include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/BitmaskEnum.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/None.h" -#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/Optional.h" +#include "llvm/ADT/STLFunctionalExtras.h" #include "llvm/ADT/SmallString.h" +#include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/Twine.h" +#include "llvm/ADT/ilist_iterator.h" +#include "llvm/ADT/iterator_range.h" +#include "llvm/BinaryFormat/Dwarf.h" #include "llvm/Bitcode/BitcodeReader.h" #include "llvm/Bitcode/LLVMBitCodes.h" #include "llvm/Bitstream/BitstreamReader.h" -#include "llvm/IR/Argument.h" -#include "llvm/IR/Attributes.h" #include "llvm/IR/AutoUpgrade.h" #include "llvm/IR/BasicBlock.h" -#include "llvm/IR/CallingConv.h" -#include "llvm/IR/Comdat.h" -#include "llvm/IR/Constant.h" #include "llvm/IR/Constants.h" -#include "llvm/IR/DebugInfo.h" #include "llvm/IR/DebugInfoMetadata.h" -#include "llvm/IR/DebugLoc.h" -#include "llvm/IR/DerivedTypes.h" -#include "llvm/IR/DiagnosticPrinter.h" #include "llvm/IR/Function.h" -#include "llvm/IR/GVMaterializer.h" -#include "llvm/IR/GlobalAlias.h" -#include "llvm/IR/GlobalIFunc.h" #include "llvm/IR/GlobalObject.h" -#include "llvm/IR/GlobalValue.h" #include "llvm/IR/GlobalVariable.h" -#include "llvm/IR/InlineAsm.h" -#include "llvm/IR/InstrTypes.h" #include "llvm/IR/Instruction.h" -#include "llvm/IR/Instructions.h" #include "llvm/IR/IntrinsicInst.h" -#include "llvm/IR/Intrinsics.h" #include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Metadata.h" #include "llvm/IR/Module.h" -#include "llvm/IR/ModuleSummaryIndex.h" -#include "llvm/IR/OperandTraits.h" #include "llvm/IR/TrackingMDRef.h" #include "llvm/IR/Type.h" -#include "llvm/IR/ValueHandle.h" -#include "llvm/Support/AtomicOrdering.h" #include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Compiler.h" -#include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" -#include "llvm/Support/ManagedStatic.h" -#include "llvm/Support/MemoryBuffer.h" -#include "llvm/Support/raw_ostream.h" +#include "llvm/Support/type_traits.h" + #include <algorithm> #include <cassert> #include <cstddef> #include <cstdint> #include <deque> +#include <iterator> #include <limits> -#include <map> #include <string> -#include <system_error> #include <tuple> +#include <type_traits> #include <utility> #include <vector> +namespace llvm { +class Argument; +} using namespace llvm; @@ -678,8 +664,8 @@ public: bool hasSeenOldLoopTags() const { return HasSeenOldLoopTags; } - Error parseMetadataAttachment( - Function &F, const SmallVectorImpl<Instruction *> &InstructionList); + Error parseMetadataAttachment(Function &F, + ArrayRef<Instruction *> InstructionList); Error parseMetadataKinds(); @@ -1233,14 +1219,16 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata( break; } - Type *Ty = getTypeByID(Record[0]); + unsigned TyID = Record[0]; + Type *Ty = getTypeByID(TyID); if (Ty->isMetadataTy() || Ty->isVoidTy()) { dropRecord(); break; } MetadataList.assignValue( - LocalAsMetadata::get(ValueList.getValueFwdRef(Record[1], Ty)), + LocalAsMetadata::get(ValueList.getValueFwdRef( + Record[1], Ty, TyID, /*ConstExprInsertBB*/ nullptr)), NextMetadataNo); NextMetadataNo++; break; @@ -1253,14 +1241,15 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata( unsigned Size = Record.size(); SmallVector<Metadata *, 8> Elts; for (unsigned i = 0; i != Size; i += 2) { - Type *Ty = getTypeByID(Record[i]); + unsigned TyID = Record[i]; + Type *Ty = getTypeByID(TyID); if (!Ty) return error("Invalid record"); if (Ty->isMetadataTy()) Elts.push_back(getMD(Record[i + 1])); else if (!Ty->isVoidTy()) { - auto *MD = - ValueAsMetadata::get(ValueList.getValueFwdRef(Record[i + 1], Ty)); + auto *MD = ValueAsMetadata::get(ValueList.getValueFwdRef( + Record[i + 1], Ty, TyID, /*ConstExprInsertBB*/ nullptr)); assert(isa<ConstantAsMetadata>(MD) && "Expected non-function-local metadata"); Elts.push_back(MD); @@ -1275,12 +1264,14 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata( if (Record.size() != 2) return error("Invalid record"); - Type *Ty = getTypeByID(Record[0]); + unsigned TyID = Record[0]; + Type *Ty = getTypeByID(TyID); if (Ty->isMetadataTy() || Ty->isVoidTy()) return error("Invalid record"); MetadataList.assignValue( - ValueAsMetadata::get(ValueList.getValueFwdRef(Record[1], Ty)), + ValueAsMetadata::get(ValueList.getValueFwdRef( + Record[1], Ty, TyID, /*ConstExprInsertBB*/ nullptr)), NextMetadataNo); NextMetadataNo++; break; @@ -1514,6 +1505,15 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata( Tag == dwarf::DW_TAG_structure_type || Tag == dwarf::DW_TAG_union_type)) { Flags = Flags | DINode::FlagFwdDecl; + if (Name) { + // This is a hack around preserving template parameters for simplified + // template names - it should probably be replaced with a + // DICompositeType flag specifying whether template parameters are + // required on declarations of this type. + StringRef NameStr = Name->getString(); + if (!NameStr.contains('<') || NameStr.startswith("_STN|")) + TemplateParams = getMDOrNull(Record[14]); + } } else { BaseType = getDITypeRefOrNull(Record[6]); OffsetInBits = Record[9]; @@ -1700,6 +1700,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata( bool HasThisAdj = true; bool HasThrownTypes = true; bool HasAnnotations = false; + bool HasTargetFuncName = false; unsigned OffsetA = 0; unsigned OffsetB = 0; if (!HasSPFlags) { @@ -1713,6 +1714,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata( HasThrownTypes = Record.size() >= 21; } else { HasAnnotations = Record.size() >= 19; + HasTargetFuncName = Record.size() >= 20; } Metadata *CUorFn = getMDOrNull(Record[12 + OffsetB]); DISubprogram *SP = GET_OR_DISTINCT( @@ -1737,7 +1739,9 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata( HasThrownTypes ? getMDOrNull(Record[17 + OffsetB]) : nullptr, // thrownTypes HasAnnotations ? getMDOrNull(Record[18 + OffsetB]) - : nullptr // annotations + : nullptr, // annotations + HasTargetFuncName ? getMDString(Record[19 + OffsetB]) + : nullptr // targetFuncName )); MetadataList.assignValue(SP, NextMetadataNo); NextMetadataNo++; @@ -2047,8 +2051,8 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata( break; } case bitc::METADATA_IMPORTED_ENTITY: { - if (Record.size() < 6 && Record.size() > 8) - return error("Invalid record"); + if (Record.size() < 6 || Record.size() > 8) + return error("Invalid DIImportedEntity record"); IsDistinct = Record[0]; bool HasFile = (Record.size() >= 7); @@ -2181,7 +2185,7 @@ Error MetadataLoader::MetadataLoaderImpl::parseGlobalObjectAttachment( /// Parse metadata attachments. Error MetadataLoader::MetadataLoaderImpl::parseMetadataAttachment( - Function &F, const SmallVectorImpl<Instruction *> &InstructionList) { + Function &F, ArrayRef<Instruction *> InstructionList) { if (Error Err = Stream.EnterSubBlock(bitc::METADATA_ATTACHMENT_ID)) return Err; @@ -2357,7 +2361,7 @@ DISubprogram *MetadataLoader::lookupSubprogramForFunction(Function *F) { } Error MetadataLoader::parseMetadataAttachment( - Function &F, const SmallVectorImpl<Instruction *> &InstructionList) { + Function &F, ArrayRef<Instruction *> InstructionList) { return Pimpl->parseMetadataAttachment(F, InstructionList); } |