[PATCH] D153851: [clang][dataflow] Output debug info if `getChild()` doesn't find field.

Martin Böhme via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 27 03:06:52 PDT 2023


mboehme created this revision.
Herald added subscribers: martong, xazax.hun.
Herald added a reviewer: NoQ.
Herald added a project: All.
mboehme requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Depends On D153409 <https://reviews.llvm.org/D153409>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153851

Files:
  clang/include/clang/Analysis/FlowSensitive/StorageLocation.h


Index: clang/include/clang/Analysis/FlowSensitive/StorageLocation.h
===================================================================
--- clang/include/clang/Analysis/FlowSensitive/StorageLocation.h
+++ clang/include/clang/Analysis/FlowSensitive/StorageLocation.h
@@ -17,6 +17,9 @@
 #include "clang/AST/Decl.h"
 #include "clang/AST/Type.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/Support/Debug.h"
+
+#define DEBUG_TYPE "dataflow"
 
 namespace clang {
 namespace dataflow {
@@ -85,6 +88,17 @@
   /// Returns the child storage location for `D`.
   StorageLocation &getChild(const ValueDecl &D) const {
     auto It = Children.find(&D);
+    LLVM_DEBUG({
+      if (It == Children.end()) {
+        llvm::dbgs() << "Couldn't find child " << D.getNameAsString()
+                     << " on StorageLocation " << this << " of type "
+                     << getType() << "\n";
+        llvm::dbgs() << "Existing children:\n";
+        for ([[maybe_unused]] auto [Field, Loc] : Children) {
+          llvm::dbgs() << Field->getNameAsString() << "\n";
+        }
+      }
+    });
     assert(It != Children.end());
     return *It->second;
   }
@@ -100,4 +114,6 @@
 } // namespace dataflow
 } // namespace clang
 
+#undef DEBUG_TYPE
+
 #endif // LLVM_CLANG_ANALYSIS_FLOWSENSITIVE_STORAGELOCATION_H


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153851.534892.patch
Type: text/x-patch
Size: 1303 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230627/47d40506/attachment.bin>


More information about the cfe-commits mailing list