[llvm] [RemoveDIs] Add additional debug-mode verifier checks (PR #84308)

Orlando Cazalet-Hyams via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 7 03:27:58 PST 2024


https://github.com/OCHyams created https://github.com/llvm/llvm-project/pull/84308

Separated from #83251

>From c2babba42a8d3d177a45c6c0b834860683e957bd Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams <orlando.hyams at sony.com>
Date: Thu, 7 Mar 2024 11:25:45 +0000
Subject: [PATCH 1/2] verifier changes base

---
 llvm/lib/IR/Verifier.cpp | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index e0de179e57146fe..5dec4f14c5dbfdf 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -3017,6 +3017,17 @@ void Verifier::visitBasicBlock(BasicBlock &BB) {
     Check(I.getParent() == &BB, "Instruction has bogus parent pointer!");
   }
 
+  Check(BB.IsNewDbgInfoFormat == BB.getParent()->IsNewDbgInfoFormat,
+        "BB debug format (new=" + std::to_string(BB.IsNewDbgInfoFormat) +
+            ") should match parent " + BB.getName() + " in " +
+            BB.getParent()->getName());
+  Check(BB.getParent()->IsNewDbgInfoFormat ==
+            BB.getParent()->getParent()->IsNewDbgInfoFormat,
+        "Fn debug format (new=" +
+            std::to_string(BB.getParent()->IsNewDbgInfoFormat) +
+            ") should match parent " + BB.getParent()->getName() + " in " +
+            BB.getParent()->getParent()->getName());
+
   // Confirm that no issues arise from the debug program.
   if (BB.IsNewDbgInfoFormat)
     CheckDI(!BB.getTrailingDPValues(), "Basic Block has trailing DbgRecords!",

>From c195081e5fb8747367dac38af4566e40619c139d Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams <orlando.hyams at sony.com>
Date: Wed, 6 Mar 2024 11:15:01 +0000
Subject: [PATCH 2/2] move verifier code around, make it idiomatic

---
 llvm/lib/IR/Verifier.cpp | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 5dec4f14c5dbfdf..e6e617cc40cb2d5 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -2674,6 +2674,11 @@ void Verifier::visitFunction(const Function &F) {
   Check(verifyAttributeCount(Attrs, FT->getNumParams()),
         "Attribute after last parameter!", &F);
 
+  Check(F.IsNewDbgInfoFormat == F.getParent()->IsNewDbgInfoFormat,
+        "Fn debug format should match parent", &F,
+        F.IsNewDbgInfoFormat, F.getParent(),
+        F.getParent()->IsNewDbgInfoFormat);
+
   bool IsIntrinsic = F.isIntrinsic();
 
   // Check function attributes.
@@ -3018,15 +3023,9 @@ void Verifier::visitBasicBlock(BasicBlock &BB) {
   }
 
   Check(BB.IsNewDbgInfoFormat == BB.getParent()->IsNewDbgInfoFormat,
-        "BB debug format (new=" + std::to_string(BB.IsNewDbgInfoFormat) +
-            ") should match parent " + BB.getName() + " in " +
-            BB.getParent()->getName());
-  Check(BB.getParent()->IsNewDbgInfoFormat ==
-            BB.getParent()->getParent()->IsNewDbgInfoFormat,
-        "Fn debug format (new=" +
-            std::to_string(BB.getParent()->IsNewDbgInfoFormat) +
-            ") should match parent " + BB.getParent()->getName() + " in " +
-            BB.getParent()->getParent()->getName());
+        "BB debug format should match parent", &BB,
+        BB.IsNewDbgInfoFormat, BB.getParent(),
+        BB.getParent()->IsNewDbgInfoFormat);
 
   // Confirm that no issues arise from the debug program.
   if (BB.IsNewDbgInfoFormat)



More information about the llvm-commits mailing list