17999b4faSZachary Turner //===- NativeSymbolReuseTest.cpp ------------------------------------------===//
27999b4faSZachary Turner //
32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
67999b4faSZachary Turner //
77999b4faSZachary Turner //===----------------------------------------------------------------------===//
87999b4faSZachary Turner
97999b4faSZachary Turner #include "llvm/DebugInfo/PDB/PDB.h"
107999b4faSZachary Turner
11*eb4c8608Sserge-sans-paille #include "llvm/DebugInfo/PDB/ConcreteSymbolEnumerator.h"
12*eb4c8608Sserge-sans-paille #include "llvm/DebugInfo/PDB/IPDBLineNumber.h"
137999b4faSZachary Turner #include "llvm/DebugInfo/PDB/IPDBSession.h"
147999b4faSZachary Turner #include "llvm/DebugInfo/PDB/Native/NativeSession.h"
157999b4faSZachary Turner #include "llvm/DebugInfo/PDB/PDBSymbolCompiland.h"
167999b4faSZachary Turner #include "llvm/DebugInfo/PDB/PDBSymbolExe.h"
17*eb4c8608Sserge-sans-paille #include "llvm/DebugInfo/PDB/PDBSymbolTypeFunctionSig.h"
187999b4faSZachary Turner #include "llvm/Support/Path.h"
197999b4faSZachary Turner
207999b4faSZachary Turner #include "llvm/Testing/Support/Error.h"
217999b4faSZachary Turner #include "llvm/Testing/Support/SupportHelpers.h"
227999b4faSZachary Turner
237999b4faSZachary Turner #include "gtest/gtest.h"
247999b4faSZachary Turner
257999b4faSZachary Turner using namespace llvm;
267999b4faSZachary Turner using namespace llvm::pdb;
277999b4faSZachary Turner
2895dd7a25SFangrui Song extern const char *TestMainArgv0;
2995dd7a25SFangrui Song
TEST(NativeSymbolReuseTest,GlobalSymbolReuse)307999b4faSZachary Turner TEST(NativeSymbolReuseTest, GlobalSymbolReuse) {
3195dd7a25SFangrui Song SmallString<128> InputsDir = unittest::getInputFileDirectory(TestMainArgv0);
327999b4faSZachary Turner llvm::sys::path::append(InputsDir, "empty.pdb");
337999b4faSZachary Turner
347999b4faSZachary Turner std::unique_ptr<IPDBSession> S;
357999b4faSZachary Turner Error E = pdb::loadDataForPDB(PDB_ReaderType::Native, InputsDir, S);
367999b4faSZachary Turner
377999b4faSZachary Turner ASSERT_THAT_ERROR(std::move(E), Succeeded());
387999b4faSZachary Turner
397999b4faSZachary Turner SymIndexId GlobalId;
407999b4faSZachary Turner {
417999b4faSZachary Turner auto GS1 = S->getGlobalScope();
427999b4faSZachary Turner auto GS2 = S->getGlobalScope();
437999b4faSZachary Turner
447999b4faSZachary Turner GlobalId = GS1->getSymIndexId();
457999b4faSZachary Turner SymIndexId Id2 = GS1->getSymIndexId();
467999b4faSZachary Turner EXPECT_EQ(GlobalId, Id2);
477999b4faSZachary Turner }
487999b4faSZachary Turner
497999b4faSZachary Turner {
507999b4faSZachary Turner auto GS3 = S->getGlobalScope();
517999b4faSZachary Turner
527999b4faSZachary Turner SymIndexId Id3 = GS3->getSymIndexId();
537999b4faSZachary Turner EXPECT_EQ(GlobalId, Id3);
547999b4faSZachary Turner }
557999b4faSZachary Turner }
567999b4faSZachary Turner
TEST(NativeSymbolReuseTest,CompilandSymbolReuse)577999b4faSZachary Turner TEST(NativeSymbolReuseTest, CompilandSymbolReuse) {
5895dd7a25SFangrui Song SmallString<128> InputsDir = unittest::getInputFileDirectory(TestMainArgv0);
597999b4faSZachary Turner llvm::sys::path::append(InputsDir, "empty.pdb");
607999b4faSZachary Turner
617999b4faSZachary Turner std::unique_ptr<IPDBSession> S;
627999b4faSZachary Turner Error E = pdb::loadDataForPDB(PDB_ReaderType::Native, InputsDir, S);
637999b4faSZachary Turner
647999b4faSZachary Turner ASSERT_THAT_ERROR(std::move(E), Succeeded());
657999b4faSZachary Turner
667999b4faSZachary Turner auto GS = S->getGlobalScope();
677999b4faSZachary Turner
687999b4faSZachary Turner std::vector<SymIndexId> CompilandIds;
697999b4faSZachary Turner {
707999b4faSZachary Turner auto Compilands = GS->findAllChildren<PDBSymbolCompiland>();
717999b4faSZachary Turner ASSERT_NE(nullptr, Compilands);
72d62d052cSZachary Turner ASSERT_EQ(2U, Compilands->getChildCount());
737999b4faSZachary Turner std::vector<SymIndexId> Ids2;
747999b4faSZachary Turner
757999b4faSZachary Turner // First try resetting the enumerator, then try destroying the enumerator
767999b4faSZachary Turner // and constructing another one.
777999b4faSZachary Turner while (auto Compiland = Compilands->getNext())
787999b4faSZachary Turner CompilandIds.push_back(Compiland->getSymIndexId());
797999b4faSZachary Turner Compilands->reset();
807999b4faSZachary Turner while (auto Compiland = Compilands->getNext())
817999b4faSZachary Turner Ids2.push_back(Compiland->getSymIndexId());
827999b4faSZachary Turner
837999b4faSZachary Turner EXPECT_EQ(CompilandIds, Ids2);
847999b4faSZachary Turner }
857999b4faSZachary Turner
867999b4faSZachary Turner {
877999b4faSZachary Turner auto Compilands = GS->findAllChildren<PDBSymbolCompiland>();
887999b4faSZachary Turner ASSERT_NE(nullptr, Compilands);
897999b4faSZachary Turner ASSERT_EQ(2U, Compilands->getChildCount());
907999b4faSZachary Turner
917999b4faSZachary Turner std::vector<SymIndexId> Ids3;
927999b4faSZachary Turner while (auto Compiland = Compilands->getNext())
937999b4faSZachary Turner Ids3.push_back(Compiland->getSymIndexId());
947999b4faSZachary Turner
957999b4faSZachary Turner EXPECT_EQ(CompilandIds, Ids3);
967999b4faSZachary Turner }
977999b4faSZachary Turner }
987999b4faSZachary Turner
TEST(NativeSymbolReuseTest,CompilandSymbolReuseBackwards)997999b4faSZachary Turner TEST(NativeSymbolReuseTest, CompilandSymbolReuseBackwards) {
10095dd7a25SFangrui Song SmallString<128> InputsDir = unittest::getInputFileDirectory(TestMainArgv0);
1017999b4faSZachary Turner llvm::sys::path::append(InputsDir, "empty.pdb");
1027999b4faSZachary Turner
1037999b4faSZachary Turner std::unique_ptr<IPDBSession> S;
1047999b4faSZachary Turner Error E = pdb::loadDataForPDB(PDB_ReaderType::Native, InputsDir, S);
1057999b4faSZachary Turner
1067999b4faSZachary Turner ASSERT_THAT_ERROR(std::move(E), Succeeded());
1077999b4faSZachary Turner
1087999b4faSZachary Turner auto GS = S->getGlobalScope();
1097999b4faSZachary Turner
1107999b4faSZachary Turner // This time do the first iteration backwards, and make sure that when you
1117999b4faSZachary Turner // then iterate them forwards, the IDs come out in reverse.
1127999b4faSZachary Turner std::vector<SymIndexId> CompilandIds;
1137999b4faSZachary Turner {
1147999b4faSZachary Turner auto Compilands = GS->findAllChildren<PDBSymbolCompiland>();
1157999b4faSZachary Turner ASSERT_NE(nullptr, Compilands);
1167999b4faSZachary Turner ASSERT_EQ(2U, Compilands->getChildCount());
1177999b4faSZachary Turner
1187999b4faSZachary Turner std::vector<SymIndexId> Ids2;
1197999b4faSZachary Turner
1207999b4faSZachary Turner for (int I = Compilands->getChildCount() - 1; I >= 0; --I) {
1217999b4faSZachary Turner auto Compiland = Compilands->getChildAtIndex(I);
1227999b4faSZachary Turner CompilandIds.push_back(Compiland->getSymIndexId());
1237999b4faSZachary Turner }
1247999b4faSZachary Turner
1257999b4faSZachary Turner while (auto Compiland = Compilands->getNext())
1267999b4faSZachary Turner Ids2.push_back(Compiland->getSymIndexId());
1277999b4faSZachary Turner
1287999b4faSZachary Turner auto ReversedIter = llvm::reverse(Ids2);
1297999b4faSZachary Turner std::vector<SymIndexId> Reversed{ReversedIter.begin(), ReversedIter.end()};
1307999b4faSZachary Turner EXPECT_EQ(CompilandIds, Reversed);
1317999b4faSZachary Turner }
1327999b4faSZachary Turner }
133