[PATCH] D96710: [DebugInfo] Improve tests for AsmPrinter::emitDwarfUnitLength()

Igor Kudrin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 15 07:06:49 PST 2021


ikudrin created this revision.
ikudrin added reviewers: shchenz, MaskRay, dblaikie.
ikudrin added projects: LLVM, debug-info.
ikudrin requested review of this revision.

This is a follow-up for D96409 <https://reviews.llvm.org/D96409> to add checks for the label that is used as a lower bound for the unit length.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96710

Files:
  llvm/unittests/CodeGen/AsmPrinterDwarfTest.cpp
  llvm/unittests/CodeGen/TestAsmPrinter.h


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));
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>(&LTmp));
+
   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>(&LTmp));
 
   TestPrinter->getAP()->emitDwarfUnitLength(Hi, "");
+  EXPECT_NE(Lo, nullptr);
+  EXPECT_EQ(Lo, LTmp);
 }
 
 class AsmPrinterHandlerTest : public AsmPrinterFixtureBase {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96710.323741.patch
Type: text/x-patch
Size: 3415 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210215/9ad6f034/attachment.bin>


More information about the llvm-commits mailing list