Index: llvm/unittests/CodeGen/AsmPrinterDwarfTest.cpp =================================================================== --- llvm/unittests/CodeGen/AsmPrinterDwarfTest.cpp +++ llvm/unittests/CodeGen/AsmPrinterDwarfTest.cpp @@ -50,19 +50,21 @@ if (!AsmPrinterFixtureBase::init(TripleStr, DwarfVersion, DwarfFormat)) return false; - // Create a symbol which will be emitted in the tests and associate it - // with a section because that is required in some code paths. + // AsmPrinter::emitDwarfSymbolReference(Label, true) gets the associated + // section from `Label` to find its BeginSymbol. + // Prepare the test symbol `Val` accordingly. Val = TestPrinter->getCtx().createTempSymbol(); - Sec = TestPrinter->getCtx().getELFSection(".tst", ELF::SHT_PROGBITS, 0); + MCSection *Sec = + TestPrinter->getCtx().getELFSection(".tst", ELF::SHT_PROGBITS, 0); SecBeginSymbol = Sec->getBeginSymbol(); TestPrinter->getMS().SwitchSection(Sec); - TestPrinter->getMS().emitLabel(Val); + Val->setFragment(&Sec->getDummyFragment()); + return true; } MCSymbol *Val = nullptr; - MCSection *Sec = nullptr; MCSymbol *SecBeginSymbol = nullptr; }; @@ -345,24 +347,28 @@ return false; Hi = TestPrinter->getCtx().createTempSymbol(); - Lo = TestPrinter->getCtx().createTempSymbol(); - Sec = TestPrinter->getCtx().getELFSection(".tst", ELF::SHT_PROGBITS, 0); - TestPrinter->getMS().SwitchSection(Sec); return true; } MCSymbol *Hi = nullptr; - MCSymbol *Lo = nullptr; - MCSection *Sec = nullptr; }; TEST_F(AsmPrinterEmitDwarfUnitLengthAsHiLoDiffTest, DWARF32) { if (!init("x86_64-pc-linux", /*DwarfVersion=*/4, dwarf::DWARF32)) return; - EXPECT_CALL(TestPrinter->getMS(), emitAbsoluteSymbolDiff(Hi, _, 4)); + InSequence S; + const MCSymbol *Lo = nullptr; + EXPECT_CALL(TestPrinter->getMS(), emitAbsoluteSymbolDiff(Hi, _, 4)) + .WillOnce(SaveArg<1>(&Lo)); + MCSymbol *LTmp = nullptr; + EXPECT_CALL(TestPrinter->getMS(), emitLabel(_, _)) + .WillOnce(SaveArg<0>(<mp)); + TestPrinter->getAP()->emitDwarfUnitLength(Hi, ""); + EXPECT_NE(Lo, nullptr); + EXPECT_EQ(Lo, LTmp); } TEST_F(AsmPrinterEmitDwarfUnitLengthAsHiLoDiffTest, DWARF64) { @@ -371,9 +377,16 @@ InSequence S; EXPECT_CALL(TestPrinter->getMS(), emitIntValue(dwarf::DW_LENGTH_DWARF64, 4)); - EXPECT_CALL(TestPrinter->getMS(), emitAbsoluteSymbolDiff(Hi, _, 8)); + const MCSymbol *Lo = nullptr; + EXPECT_CALL(TestPrinter->getMS(), emitAbsoluteSymbolDiff(Hi, _, 8)) + .WillOnce(SaveArg<1>(&Lo)); + MCSymbol *LTmp = nullptr; + EXPECT_CALL(TestPrinter->getMS(), emitLabel(_, _)) + .WillOnce(SaveArg<0>(<mp)); TestPrinter->getAP()->emitDwarfUnitLength(Hi, ""); + EXPECT_NE(Lo, nullptr); + EXPECT_EQ(Lo, LTmp); } class AsmPrinterHandlerTest : public AsmPrinterFixtureBase { Index: llvm/unittests/CodeGen/TestAsmPrinter.h =================================================================== --- llvm/unittests/CodeGen/TestAsmPrinter.h +++ llvm/unittests/CodeGen/TestAsmPrinter.h @@ -38,6 +38,7 @@ // The following are mock methods to be used in tests. + MOCK_METHOD2(emitLabel, void(MCSymbol *Symbol, SMLoc Loc)); MOCK_METHOD2(emitIntValue, void(uint64_t Value, unsigned Size)); MOCK_METHOD3(emitValueImpl, void(const MCExpr *Value, unsigned Size, SMLoc Loc));