1 //===- llvm/unittest/DebugInfo/PDB/PDBApiTest.cpp -------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include <unordered_map>
11 
12 #include "llvm/ADT/STLExtras.h"
13 #include "llvm/DebugInfo/PDB/IPDBEnumChildren.h"
14 #include "llvm/DebugInfo/PDB/IPDBRawSymbol.h"
15 #include "llvm/DebugInfo/PDB/IPDBSession.h"
16 #include "llvm/DebugInfo/PDB/IPDBSourceFile.h"
17 #include "llvm/DebugInfo/PDB/IPDBTable.h"
18 
19 #include "llvm/DebugInfo/PDB/PDBSymbol.h"
20 #include "llvm/DebugInfo/PDB/PDBSymbolAnnotation.h"
21 #include "llvm/DebugInfo/PDB/PDBSymbolBlock.h"
22 #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
23 #include "llvm/DebugInfo/PDB/PDBSymbolCompilandDetails.h"
24 #include "llvm/DebugInfo/PDB/PDBSymbolCompilandEnv.h"
25 #include "llvm/DebugInfo/PDB/PDBSymbolCustom.h"
26 #include "llvm/DebugInfo/PDB/PDBSymbolData.h"
27 #include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
28 #include "llvm/DebugInfo/PDB/PDBSymbolFunc.h"
29 #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugEnd.h"
30 #include "llvm/DebugInfo/PDB/PDBSymbolFuncDebugStart.h"
31 #include "llvm/DebugInfo/PDB/PDBSymbolLabel.h"
32 #include "llvm/DebugInfo/PDB/PDBSymbolPublicSymbol.h"
33 #include "llvm/DebugInfo/PDB/PDBSymbolThunk.h"
34 #include "llvm/DebugInfo/PDB/PDBSymbolTypeArray.h"
35 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBaseClass.h"
36 #include "llvm/DebugInfo/PDB/PDBSymbolTypeBuiltin.h"
37 #include "llvm/DebugInfo/PDB/PDBSymbolTypeCustom.h"
38 #include "llvm/DebugInfo/PDB/PDBSymbolTypeDimension.h"
39 #include "llvm/DebugInfo/PDB/PDBSymbolTypeEnum.h"
40 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFriend.h"
41 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionArg.h"
42 #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
43 #include "llvm/DebugInfo/PDB/PDBSymbolTypeManaged.h"
44 #include "llvm/DebugInfo/PDB/PDBSymbolTypePointer.h"
45 #include "llvm/DebugInfo/PDB/PDBSymbolTypeTypedef.h"
46 #include "llvm/DebugInfo/PDB/PDBSymbolTypeUDT.h"
47 #include "llvm/DebugInfo/PDB/PDBSymbolTypeVTable.h"
48 #include "llvm/DebugInfo/PDB/PDBSymbolTypeVTableShape.h"
49 #include "llvm/DebugInfo/PDB/PDBSymbolUnknown.h"
50 #include "llvm/DebugInfo/PDB/PDBSymbolUsingNamespace.h"
51 #include "llvm/DebugInfo/PDB/PDBTypes.h"
52 #include "gtest/gtest.h"
53 using namespace llvm;
54 using namespace llvm::pdb;
55 
56 namespace {
57 
58 #define MOCK_SYMBOL_ACCESSOR(Func)                                             \
59   decltype(std::declval<IPDBRawSymbol>().Func()) Func() const override {       \
60     typedef decltype(IPDBRawSymbol::Func()) ReturnType;                        \
61     return ReturnType();                                                       \
62   }
63 
64 class MockSession : public IPDBSession {
65   uint64_t getLoadAddress() const override { return 0; }
66   void setLoadAddress(uint64_t Address) override {}
67   std::unique_ptr<PDBSymbolExe> getGlobalScope() override { return nullptr; }
68   std::unique_ptr<PDBSymbol> getSymbolById(uint32_t SymbolId) const override {
69     return nullptr;
70   }
71   std::unique_ptr<IPDBSourceFile>
72   getSourceFileById(uint32_t SymbolId) const override {
73     return nullptr;
74   }
75 
76   std::unique_ptr<PDBSymbol>
77   findSymbolByAddress(uint64_t Address, PDB_SymType Type) const override {
78     return nullptr;
79   }
80   std::unique_ptr<IPDBEnumLineNumbers>
81   findLineNumbers(const PDBSymbolCompiland &Compiland,
82                   const IPDBSourceFile &File) const override {
83     return nullptr;
84   }
85   std::unique_ptr<IPDBEnumLineNumbers>
86   findLineNumbersByAddress(uint64_t Address, uint32_t Length) const override {
87     return nullptr;
88   }
89   std::unique_ptr<IPDBEnumSourceFiles>
90   findSourceFiles(const PDBSymbolCompiland *Compiland, llvm::StringRef Pattern,
91                   PDB_NameSearchFlags Flags) const override {
92     return nullptr;
93   }
94   std::unique_ptr<IPDBSourceFile>
95   findOneSourceFile(const PDBSymbolCompiland *Compiland,
96                     llvm::StringRef Pattern,
97                     PDB_NameSearchFlags Flags) const override {
98     return nullptr;
99   }
100   std::unique_ptr<IPDBEnumChildren<PDBSymbolCompiland>>
101   findCompilandsForSourceFile(llvm::StringRef Pattern,
102                               PDB_NameSearchFlags Flags) const override {
103     return nullptr;
104   }
105   std::unique_ptr<PDBSymbolCompiland>
106   findOneCompilandForSourceFile(llvm::StringRef Pattern,
107                                 PDB_NameSearchFlags Flags) const override {
108     return nullptr;
109   }
110 
111   std::unique_ptr<IPDBEnumSourceFiles> getAllSourceFiles() const override {
112     return nullptr;
113   }
114   std::unique_ptr<IPDBEnumSourceFiles> getSourceFilesForCompiland(
115       const PDBSymbolCompiland &Compiland) const override {
116     return nullptr;
117   }
118 
119   std::unique_ptr<IPDBEnumDataStreams> getDebugStreams() const override {
120     return nullptr;
121   }
122 
123   std::unique_ptr<IPDBEnumTables> getEnumTables() const override {
124     return nullptr;
125   }
126 };
127 
128 class MockRawSymbol : public IPDBRawSymbol {
129 public:
130   MockRawSymbol(PDB_SymType SymType)
131       : Type(SymType) {}
132 
133   void dump(raw_ostream &OS, int Indent) const override {}
134 
135   std::unique_ptr<IPDBEnumSymbols>
136   findChildren(PDB_SymType Type) const override {
137     return nullptr;
138   }
139   std::unique_ptr<IPDBEnumSymbols>
140   findChildren(PDB_SymType Type, StringRef Name,
141                PDB_NameSearchFlags Flags) const override {
142     return nullptr;
143   }
144   std::unique_ptr<IPDBEnumSymbols>
145   findChildrenByAddr(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags,
146                      uint32_t Section, uint32_t Offset) const {
147     return nullptr;
148   }
149   std::unique_ptr<IPDBEnumSymbols>
150   findChildrenByVA(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags,
151                    uint64_t VA) const override {
152     return nullptr;
153   }
154   std::unique_ptr<IPDBEnumSymbols>
155   findChildrenByRVA(PDB_SymType Type, StringRef Name, PDB_NameSearchFlags Flags,
156                     uint32_t RVA) const override {
157     return nullptr;
158   }
159   std::unique_ptr<IPDBEnumSymbols>
160   findInlineFramesByAddr(uint32_t Section, uint32_t Offset) const override {
161     return nullptr;
162   }
163   std::unique_ptr<IPDBEnumSymbols>
164   findInlineFramesByRVA(uint32_t RVA) const override {
165     return nullptr;
166   }
167   std::unique_ptr<IPDBEnumSymbols>
168   findInlineFramesByVA(uint64_t VA) const override {
169     return nullptr;
170   }
171   std::unique_ptr<IPDBEnumLineNumbers> findInlineeLines() const override {
172     return nullptr;
173   }
174   std::unique_ptr<IPDBEnumLineNumbers>
175   findInlineeLinesByAddr(uint32_t Section, uint32_t Offset,
176                          uint32_t Length) const override {
177     return nullptr;
178   }
179   std::unique_ptr<IPDBEnumLineNumbers>
180   findInlineeLinesByRVA(uint32_t RVA, uint32_t Length) const override {
181     return nullptr;
182   }
183   std::unique_ptr<IPDBEnumLineNumbers>
184   findInlineeLinesByVA(uint64_t VA, uint32_t Length) const override {
185     return nullptr;
186   }
187 
188   void getDataBytes(llvm::SmallVector<uint8_t, 32> &bytes) const override {}
189   void getFrontEndVersion(VersionInfo &Version) const override {}
190   void getBackEndVersion(VersionInfo &Version) const override {}
191 
192   PDB_SymType getSymTag() const override { return Type; }
193 
194   std::string getUndecoratedNameEx(PDB_UndnameFlags Flags) const override {
195     return {};
196   }
197 
198   MOCK_SYMBOL_ACCESSOR(getAccess)
199   MOCK_SYMBOL_ACCESSOR(getAddressOffset)
200   MOCK_SYMBOL_ACCESSOR(getAddressSection)
201   MOCK_SYMBOL_ACCESSOR(getAge)
202   MOCK_SYMBOL_ACCESSOR(getArrayIndexTypeId)
203   MOCK_SYMBOL_ACCESSOR(getBaseDataOffset)
204   MOCK_SYMBOL_ACCESSOR(getBaseDataSlot)
205   MOCK_SYMBOL_ACCESSOR(getBaseSymbolId)
206   MOCK_SYMBOL_ACCESSOR(getBuiltinType)
207   MOCK_SYMBOL_ACCESSOR(getBitPosition)
208   MOCK_SYMBOL_ACCESSOR(getCallingConvention)
209   MOCK_SYMBOL_ACCESSOR(getClassParentId)
210   MOCK_SYMBOL_ACCESSOR(getCompilerName)
211   MOCK_SYMBOL_ACCESSOR(getCount)
212   MOCK_SYMBOL_ACCESSOR(getCountLiveRanges)
213   MOCK_SYMBOL_ACCESSOR(getLanguage)
214   MOCK_SYMBOL_ACCESSOR(getLexicalParentId)
215   MOCK_SYMBOL_ACCESSOR(getLibraryName)
216   MOCK_SYMBOL_ACCESSOR(getLiveRangeStartAddressOffset)
217   MOCK_SYMBOL_ACCESSOR(getLiveRangeStartAddressSection)
218   MOCK_SYMBOL_ACCESSOR(getLiveRangeStartRelativeVirtualAddress)
219   MOCK_SYMBOL_ACCESSOR(getLocalBasePointerRegisterId)
220   MOCK_SYMBOL_ACCESSOR(getLowerBoundId)
221   MOCK_SYMBOL_ACCESSOR(getMemorySpaceKind)
222   MOCK_SYMBOL_ACCESSOR(getName)
223   MOCK_SYMBOL_ACCESSOR(getNumberOfAcceleratorPointerTags)
224   MOCK_SYMBOL_ACCESSOR(getNumberOfColumns)
225   MOCK_SYMBOL_ACCESSOR(getNumberOfModifiers)
226   MOCK_SYMBOL_ACCESSOR(getNumberOfRegisterIndices)
227   MOCK_SYMBOL_ACCESSOR(getNumberOfRows)
228   MOCK_SYMBOL_ACCESSOR(getObjectFileName)
229   MOCK_SYMBOL_ACCESSOR(getOemId)
230   MOCK_SYMBOL_ACCESSOR(getOemSymbolId)
231   MOCK_SYMBOL_ACCESSOR(getOffsetInUdt)
232   MOCK_SYMBOL_ACCESSOR(getPlatform)
233   MOCK_SYMBOL_ACCESSOR(getRank)
234   MOCK_SYMBOL_ACCESSOR(getRegisterId)
235   MOCK_SYMBOL_ACCESSOR(getRegisterType)
236   MOCK_SYMBOL_ACCESSOR(getRelativeVirtualAddress)
237   MOCK_SYMBOL_ACCESSOR(getSamplerSlot)
238   MOCK_SYMBOL_ACCESSOR(getSignature)
239   MOCK_SYMBOL_ACCESSOR(getSizeInUdt)
240   MOCK_SYMBOL_ACCESSOR(getSlot)
241   MOCK_SYMBOL_ACCESSOR(getSourceFileName)
242   MOCK_SYMBOL_ACCESSOR(getStride)
243   MOCK_SYMBOL_ACCESSOR(getSubTypeId)
244   MOCK_SYMBOL_ACCESSOR(getSymbolsFileName)
245   MOCK_SYMBOL_ACCESSOR(getSymIndexId)
246   MOCK_SYMBOL_ACCESSOR(getTargetOffset)
247   MOCK_SYMBOL_ACCESSOR(getTargetRelativeVirtualAddress)
248   MOCK_SYMBOL_ACCESSOR(getTargetVirtualAddress)
249   MOCK_SYMBOL_ACCESSOR(getTargetSection)
250   MOCK_SYMBOL_ACCESSOR(getTextureSlot)
251   MOCK_SYMBOL_ACCESSOR(getTimeStamp)
252   MOCK_SYMBOL_ACCESSOR(getToken)
253   MOCK_SYMBOL_ACCESSOR(getTypeId)
254   MOCK_SYMBOL_ACCESSOR(getUavSlot)
255   MOCK_SYMBOL_ACCESSOR(getUndecoratedName)
256   MOCK_SYMBOL_ACCESSOR(getUnmodifiedTypeId)
257   MOCK_SYMBOL_ACCESSOR(getUpperBoundId)
258   MOCK_SYMBOL_ACCESSOR(getVirtualBaseDispIndex)
259   MOCK_SYMBOL_ACCESSOR(getVirtualBaseOffset)
260   MOCK_SYMBOL_ACCESSOR(getVirtualTableShapeId)
261   MOCK_SYMBOL_ACCESSOR(getDataKind)
262   MOCK_SYMBOL_ACCESSOR(getGuid)
263   MOCK_SYMBOL_ACCESSOR(getOffset)
264   MOCK_SYMBOL_ACCESSOR(getThisAdjust)
265   MOCK_SYMBOL_ACCESSOR(getVirtualBasePointerOffset)
266   MOCK_SYMBOL_ACCESSOR(getLocationType)
267   MOCK_SYMBOL_ACCESSOR(getMachineType)
268   MOCK_SYMBOL_ACCESSOR(getThunkOrdinal)
269   MOCK_SYMBOL_ACCESSOR(getLength)
270   MOCK_SYMBOL_ACCESSOR(getVirtualBaseTableType)
271   MOCK_SYMBOL_ACCESSOR(getLiveRangeLength)
272   MOCK_SYMBOL_ACCESSOR(getVirtualAddress)
273   MOCK_SYMBOL_ACCESSOR(getUdtKind)
274   MOCK_SYMBOL_ACCESSOR(hasConstructor)
275   MOCK_SYMBOL_ACCESSOR(hasCustomCallingConvention)
276   MOCK_SYMBOL_ACCESSOR(hasFarReturn)
277   MOCK_SYMBOL_ACCESSOR(isCode)
278   MOCK_SYMBOL_ACCESSOR(isCompilerGenerated)
279   MOCK_SYMBOL_ACCESSOR(isConstType)
280   MOCK_SYMBOL_ACCESSOR(isEditAndContinueEnabled)
281   MOCK_SYMBOL_ACCESSOR(isFunction)
282   MOCK_SYMBOL_ACCESSOR(getAddressTaken)
283   MOCK_SYMBOL_ACCESSOR(getNoStackOrdering)
284   MOCK_SYMBOL_ACCESSOR(hasAlloca)
285   MOCK_SYMBOL_ACCESSOR(hasAssignmentOperator)
286   MOCK_SYMBOL_ACCESSOR(hasCTypes)
287   MOCK_SYMBOL_ACCESSOR(hasCastOperator)
288   MOCK_SYMBOL_ACCESSOR(hasDebugInfo)
289   MOCK_SYMBOL_ACCESSOR(hasEH)
290   MOCK_SYMBOL_ACCESSOR(hasEHa)
291   MOCK_SYMBOL_ACCESSOR(hasFramePointer)
292   MOCK_SYMBOL_ACCESSOR(hasInlAsm)
293   MOCK_SYMBOL_ACCESSOR(hasInlineAttribute)
294   MOCK_SYMBOL_ACCESSOR(hasInterruptReturn)
295   MOCK_SYMBOL_ACCESSOR(hasLongJump)
296   MOCK_SYMBOL_ACCESSOR(hasManagedCode)
297   MOCK_SYMBOL_ACCESSOR(hasNestedTypes)
298   MOCK_SYMBOL_ACCESSOR(hasNoInlineAttribute)
299   MOCK_SYMBOL_ACCESSOR(hasNoReturnAttribute)
300   MOCK_SYMBOL_ACCESSOR(hasOptimizedCodeDebugInfo)
301   MOCK_SYMBOL_ACCESSOR(hasOverloadedOperator)
302   MOCK_SYMBOL_ACCESSOR(hasSEH)
303   MOCK_SYMBOL_ACCESSOR(hasSecurityChecks)
304   MOCK_SYMBOL_ACCESSOR(hasSetJump)
305   MOCK_SYMBOL_ACCESSOR(hasStrictGSCheck)
306   MOCK_SYMBOL_ACCESSOR(isAcceleratorGroupSharedLocal)
307   MOCK_SYMBOL_ACCESSOR(isAcceleratorPointerTagLiveRange)
308   MOCK_SYMBOL_ACCESSOR(isAcceleratorStubFunction)
309   MOCK_SYMBOL_ACCESSOR(isAggregated)
310   MOCK_SYMBOL_ACCESSOR(isIntroVirtualFunction)
311   MOCK_SYMBOL_ACCESSOR(isCVTCIL)
312   MOCK_SYMBOL_ACCESSOR(isConstructorVirtualBase)
313   MOCK_SYMBOL_ACCESSOR(isCxxReturnUdt)
314   MOCK_SYMBOL_ACCESSOR(isDataAligned)
315   MOCK_SYMBOL_ACCESSOR(isHLSLData)
316   MOCK_SYMBOL_ACCESSOR(isHotpatchable)
317   MOCK_SYMBOL_ACCESSOR(isIndirectVirtualBaseClass)
318   MOCK_SYMBOL_ACCESSOR(isInterfaceUdt)
319   MOCK_SYMBOL_ACCESSOR(isIntrinsic)
320   MOCK_SYMBOL_ACCESSOR(isLTCG)
321   MOCK_SYMBOL_ACCESSOR(isLocationControlFlowDependent)
322   MOCK_SYMBOL_ACCESSOR(isMSILNetmodule)
323   MOCK_SYMBOL_ACCESSOR(isMatrixRowMajor)
324   MOCK_SYMBOL_ACCESSOR(isManagedCode)
325   MOCK_SYMBOL_ACCESSOR(isMSILCode)
326   MOCK_SYMBOL_ACCESSOR(isMultipleInheritance)
327   MOCK_SYMBOL_ACCESSOR(isNaked)
328   MOCK_SYMBOL_ACCESSOR(isNested)
329   MOCK_SYMBOL_ACCESSOR(isOptimizedAway)
330   MOCK_SYMBOL_ACCESSOR(isPacked)
331   MOCK_SYMBOL_ACCESSOR(isPointerBasedOnSymbolValue)
332   MOCK_SYMBOL_ACCESSOR(isPointerToDataMember)
333   MOCK_SYMBOL_ACCESSOR(isPointerToMemberFunction)
334   MOCK_SYMBOL_ACCESSOR(isPureVirtual)
335   MOCK_SYMBOL_ACCESSOR(isRValueReference)
336   MOCK_SYMBOL_ACCESSOR(isRefUdt)
337   MOCK_SYMBOL_ACCESSOR(isReference)
338   MOCK_SYMBOL_ACCESSOR(isRestrictedType)
339   MOCK_SYMBOL_ACCESSOR(isReturnValue)
340   MOCK_SYMBOL_ACCESSOR(isSafeBuffers)
341   MOCK_SYMBOL_ACCESSOR(isScoped)
342   MOCK_SYMBOL_ACCESSOR(isSdl)
343   MOCK_SYMBOL_ACCESSOR(isSingleInheritance)
344   MOCK_SYMBOL_ACCESSOR(isSplitted)
345   MOCK_SYMBOL_ACCESSOR(isStatic)
346   MOCK_SYMBOL_ACCESSOR(hasPrivateSymbols)
347   MOCK_SYMBOL_ACCESSOR(isUnalignedType)
348   MOCK_SYMBOL_ACCESSOR(isUnreached)
349   MOCK_SYMBOL_ACCESSOR(isValueUdt)
350   MOCK_SYMBOL_ACCESSOR(isVirtual)
351   MOCK_SYMBOL_ACCESSOR(isVirtualBaseClass)
352   MOCK_SYMBOL_ACCESSOR(isVirtualInheritance)
353   MOCK_SYMBOL_ACCESSOR(isVolatileType)
354   MOCK_SYMBOL_ACCESSOR(getValue)
355   MOCK_SYMBOL_ACCESSOR(wasInlined)
356   MOCK_SYMBOL_ACCESSOR(getUnused)
357 
358 private:
359   PDB_SymType Type;
360 };
361 
362 class PDBApiTest : public testing::Test {
363 public:
364   std::unordered_map<PDB_SymType, std::unique_ptr<PDBSymbol>> SymbolMap;
365 
366   void SetUp() override {
367     Session.reset(new MockSession());
368 
369     InsertItemWithTag(PDB_SymType::None);
370     InsertItemWithTag(PDB_SymType::Exe);
371     InsertItemWithTag(PDB_SymType::Compiland);
372     InsertItemWithTag(PDB_SymType::CompilandDetails);
373     InsertItemWithTag(PDB_SymType::CompilandEnv);
374     InsertItemWithTag(PDB_SymType::Function);
375     InsertItemWithTag(PDB_SymType::Block);
376     InsertItemWithTag(PDB_SymType::Data);
377     InsertItemWithTag(PDB_SymType::Annotation);
378     InsertItemWithTag(PDB_SymType::Label);
379     InsertItemWithTag(PDB_SymType::PublicSymbol);
380     InsertItemWithTag(PDB_SymType::UDT);
381     InsertItemWithTag(PDB_SymType::Enum);
382     InsertItemWithTag(PDB_SymType::FunctionSig);
383     InsertItemWithTag(PDB_SymType::PointerType);
384     InsertItemWithTag(PDB_SymType::ArrayType);
385     InsertItemWithTag(PDB_SymType::BuiltinType);
386     InsertItemWithTag(PDB_SymType::Typedef);
387     InsertItemWithTag(PDB_SymType::BaseClass);
388     InsertItemWithTag(PDB_SymType::Friend);
389     InsertItemWithTag(PDB_SymType::FunctionArg);
390     InsertItemWithTag(PDB_SymType::FuncDebugStart);
391     InsertItemWithTag(PDB_SymType::FuncDebugEnd);
392     InsertItemWithTag(PDB_SymType::UsingNamespace);
393     InsertItemWithTag(PDB_SymType::VTableShape);
394     InsertItemWithTag(PDB_SymType::VTable);
395     InsertItemWithTag(PDB_SymType::Custom);
396     InsertItemWithTag(PDB_SymType::Thunk);
397     InsertItemWithTag(PDB_SymType::CustomType);
398     InsertItemWithTag(PDB_SymType::ManagedType);
399     InsertItemWithTag(PDB_SymType::Dimension);
400     InsertItemWithTag(PDB_SymType::Max);
401   }
402 
403   template <class ExpectedType> void VerifyDyncast(PDB_SymType Tag) {
404     for (auto item = SymbolMap.begin(); item != SymbolMap.end(); ++item) {
405       EXPECT_EQ(item->first == Tag, llvm::isa<ExpectedType>(*item->second));
406     }
407   }
408 
409   void VerifyUnknownDyncasts() {
410     for (auto item = SymbolMap.begin(); item != SymbolMap.end(); ++item) {
411       bool should_match = false;
412       if (item->first == PDB_SymType::None || item->first >= PDB_SymType::Max)
413         should_match = true;
414 
415       EXPECT_EQ(should_match, llvm::isa<PDBSymbolUnknown>(*item->second));
416     }
417   }
418 
419 private:
420   std::unique_ptr<IPDBSession> Session;
421 
422   void InsertItemWithTag(PDB_SymType Tag) {
423     auto RawSymbol = llvm::make_unique<MockRawSymbol>(Tag);
424     auto Symbol = PDBSymbol::create(*Session, std::move(RawSymbol));
425     SymbolMap.insert(std::make_pair(Tag, std::move(Symbol)));
426   }
427 };
428 
429 TEST_F(PDBApiTest, Dyncast) {
430 
431   // Most of the types have a one-to-one mapping between Tag and concrete type.
432   VerifyDyncast<PDBSymbolExe>(PDB_SymType::Exe);
433   VerifyDyncast<PDBSymbolCompiland>(PDB_SymType::Compiland);
434   VerifyDyncast<PDBSymbolCompilandDetails>(PDB_SymType::CompilandDetails);
435   VerifyDyncast<PDBSymbolCompilandEnv>(PDB_SymType::CompilandEnv);
436   VerifyDyncast<PDBSymbolFunc>(PDB_SymType::Function);
437   VerifyDyncast<PDBSymbolBlock>(PDB_SymType::Block);
438   VerifyDyncast<PDBSymbolData>(PDB_SymType::Data);
439   VerifyDyncast<PDBSymbolAnnotation>(PDB_SymType::Annotation);
440   VerifyDyncast<PDBSymbolLabel>(PDB_SymType::Label);
441   VerifyDyncast<PDBSymbolPublicSymbol>(PDB_SymType::PublicSymbol);
442   VerifyDyncast<PDBSymbolTypeUDT>(PDB_SymType::UDT);
443   VerifyDyncast<PDBSymbolTypeEnum>(PDB_SymType::Enum);
444   VerifyDyncast<PDBSymbolTypeFunctionSig>(PDB_SymType::FunctionSig);
445   VerifyDyncast<PDBSymbolTypePointer>(PDB_SymType::PointerType);
446   VerifyDyncast<PDBSymbolTypeArray>(PDB_SymType::ArrayType);
447   VerifyDyncast<PDBSymbolTypeBuiltin>(PDB_SymType::BuiltinType);
448   VerifyDyncast<PDBSymbolTypeTypedef>(PDB_SymType::Typedef);
449   VerifyDyncast<PDBSymbolTypeBaseClass>(PDB_SymType::BaseClass);
450   VerifyDyncast<PDBSymbolTypeFriend>(PDB_SymType::Friend);
451   VerifyDyncast<PDBSymbolTypeFunctionArg>(PDB_SymType::FunctionArg);
452   VerifyDyncast<PDBSymbolFuncDebugStart>(PDB_SymType::FuncDebugStart);
453   VerifyDyncast<PDBSymbolFuncDebugEnd>(PDB_SymType::FuncDebugEnd);
454   VerifyDyncast<PDBSymbolUsingNamespace>(PDB_SymType::UsingNamespace);
455   VerifyDyncast<PDBSymbolTypeVTableShape>(PDB_SymType::VTableShape);
456   VerifyDyncast<PDBSymbolTypeVTable>(PDB_SymType::VTable);
457   VerifyDyncast<PDBSymbolCustom>(PDB_SymType::Custom);
458   VerifyDyncast<PDBSymbolThunk>(PDB_SymType::Thunk);
459   VerifyDyncast<PDBSymbolTypeCustom>(PDB_SymType::CustomType);
460   VerifyDyncast<PDBSymbolTypeManaged>(PDB_SymType::ManagedType);
461   VerifyDyncast<PDBSymbolTypeDimension>(PDB_SymType::Dimension);
462 
463   VerifyUnknownDyncasts();
464 }
465 
466 } // end anonymous namespace
467