@@ -50,19 +50,21 @@ class AsmPrinterEmitDwarfSymbolReferenceTest : public AsmPrinterFixtureBase {
5050 if (!AsmPrinterFixtureBase::init (TripleStr, DwarfVersion, DwarfFormat))
5151 return false ;
5252
53- // Create a symbol which will be emitted in the tests and associate it
54- // with a section because that is required in some code paths.
53+ // AsmPrinter::emitDwarfSymbolReference(Label, true) gets the associated
54+ // section from `Label` to find its BeginSymbol.
55+ // Prepare the test symbol `Val` accordingly.
5556
5657 Val = TestPrinter->getCtx ().createTempSymbol ();
57- Sec = TestPrinter->getCtx ().getELFSection (" .tst" , ELF::SHT_PROGBITS, 0 );
58+ MCSection *Sec =
59+ TestPrinter->getCtx ().getELFSection (" .tst" , ELF::SHT_PROGBITS, 0 );
5860 SecBeginSymbol = Sec->getBeginSymbol ();
5961 TestPrinter->getMS ().SwitchSection (Sec);
60- TestPrinter->getMS ().emitLabel (Val);
62+ Val->setFragment (&Sec->getDummyFragment ());
63+
6164 return true ;
6265 }
6366
6467 MCSymbol *Val = nullptr ;
65- MCSection *Sec = nullptr ;
6668 MCSymbol *SecBeginSymbol = nullptr ;
6769};
6870
@@ -326,32 +328,49 @@ class AsmPrinterEmitDwarfUnitLengthAsHiLoDiffTest
326328 if (!AsmPrinterFixtureBase::init (TripleStr, DwarfVersion, DwarfFormat))
327329 return false ;
328330
329- Hi = TestPrinter->getCtx ().createTempSymbol ();
330- Lo = TestPrinter->getCtx ().createTempSymbol ();
331331 return true ;
332332 }
333-
334- MCSymbol *Hi = nullptr ;
335- MCSymbol *Lo = nullptr ;
336333};
337334
338335TEST_F (AsmPrinterEmitDwarfUnitLengthAsHiLoDiffTest, DWARF32) {
339336 if (!init (" x86_64-pc-linux" , /* DwarfVersion=*/ 4 , dwarf::DWARF32))
340337 return ;
341338
342- EXPECT_CALL (TestPrinter->getMS (), emitAbsoluteSymbolDiff (Hi, Lo, 4 ));
343- TestPrinter->getAP ()->emitDwarfUnitLength (Hi, Lo, " " );
339+ InSequence S;
340+ const MCSymbol *Hi = nullptr ;
341+ const MCSymbol *Lo = nullptr ;
342+ EXPECT_CALL (TestPrinter->getMS (), emitAbsoluteSymbolDiff (_, _, 4 ))
343+ .WillOnce (DoAll (SaveArg<0 >(&Hi), SaveArg<1 >(&Lo)));
344+ MCSymbol *LTmp = nullptr ;
345+ EXPECT_CALL (TestPrinter->getMS (), emitLabel (_, _))
346+ .WillOnce (SaveArg<0 >(<mp));
347+
348+ MCSymbol *HTmp = TestPrinter->getAP ()->emitDwarfUnitLength (" " , " " );
349+ EXPECT_NE (Lo, nullptr );
350+ EXPECT_EQ (Lo, LTmp);
351+ EXPECT_NE (Hi, nullptr );
352+ EXPECT_EQ (Hi, HTmp);
344353}
345354
346355TEST_F (AsmPrinterEmitDwarfUnitLengthAsHiLoDiffTest, DWARF64) {
347356 if (!init (" x86_64-pc-linux" , /* DwarfVersion=*/ 4 , dwarf::DWARF64))
348357 return ;
349358
350359 InSequence S;
360+ const MCSymbol *Hi = nullptr ;
361+ const MCSymbol *Lo = nullptr ;
351362 EXPECT_CALL (TestPrinter->getMS (), emitIntValue (dwarf::DW_LENGTH_DWARF64, 4 ));
352- EXPECT_CALL (TestPrinter->getMS (), emitAbsoluteSymbolDiff (Hi, Lo, 8 ));
353-
354- TestPrinter->getAP ()->emitDwarfUnitLength (Hi, Lo, " " );
363+ EXPECT_CALL (TestPrinter->getMS (), emitAbsoluteSymbolDiff (_, _, 8 ))
364+ .WillOnce (DoAll (SaveArg<0 >(&Hi), SaveArg<1 >(&Lo)));
365+ MCSymbol *LTmp = nullptr ;
366+ EXPECT_CALL (TestPrinter->getMS (), emitLabel (_, _))
367+ .WillOnce (SaveArg<0 >(<mp));
368+
369+ MCSymbol *HTmp = TestPrinter->getAP ()->emitDwarfUnitLength (" " , " " );
370+ EXPECT_NE (Lo, nullptr );
371+ EXPECT_EQ (Lo, LTmp);
372+ EXPECT_NE (Hi, nullptr );
373+ EXPECT_EQ (Hi, HTmp);
355374}
356375
357376class AsmPrinterHandlerTest : public AsmPrinterFixtureBase {
0 commit comments