[clang] [clang][dataflow] Extend debug output for `Environment`. (PR #79982)

2024-01-30 Thread via cfe-commits

https://github.com/martinboehme closed 
https://github.com/llvm/llvm-project/pull/79982
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][dataflow] Extend debug output for `Environment`. (PR #79982)

2024-01-30 Thread Yitzhak Mandelbaum via cfe-commits

https://github.com/ymand approved this pull request.


https://github.com/llvm/llvm-project/pull/79982
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][dataflow] Extend debug output for `Environment`. (PR #79982)

2024-01-30 Thread Gábor Horváth via cfe-commits

https://github.com/Xazax-hun approved this pull request.


https://github.com/llvm/llvm-project/pull/79982
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][dataflow] Extend debug output for `Environment`. (PR #79982)

2024-01-30 Thread via cfe-commits

https://github.com/martinboehme edited 
https://github.com/llvm/llvm-project/pull/79982
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][dataflow] Extend debug output for `Environment`. (PR #79982)

2024-01-30 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-analysis

@llvm/pr-subscribers-clang

Author: None (martinboehme)


Changes

*  Print `ReturnLoc`, `ReturnVal`, and `ThisPointeeLoc` if applicable.

*  For entries in `LocToVal` that correspond to declarations, print the names
   of the declarations next to them.

I've removed the FIXME because all relevant fields are now being dumped. I'm
not sure we actually need the capability for the caller to specify which fields
to dump, so I've simply deleted this part of the comment.


---
Full diff: https://github.com/llvm/llvm-project/pull/79982.diff


1 Files Affected:

- (modified) clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp (+30-6) 


``diff
diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index acb38e576474..01db65866d13 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -1009,12 +1009,15 @@ bool Environment::allows(const Formula &F) const {
 }
 
 void Environment::dump(raw_ostream &OS) const {
-  // FIXME: add printing for remaining fields and allow caller to decide what
-  // fields are printed.
-  OS << "DeclToLoc:\n";
-  for (auto [D, L] : DeclToLoc)
-OS << "  [" << D->getNameAsString() << ", " << L << "]\n";
+  llvm::DenseMap LocToName;
+  if (ThisPointeeLoc != nullptr)
+LocToName[ThisPointeeLoc] = "this";
 
+  OS << "DeclToLoc:\n";
+  for (auto [D, L] : DeclToLoc) {
+auto Iter = LocToName.insert({L, D->getNameAsString()}).first;
+OS << "  [" << Iter->second << ", " << L << "]\n";
+  }
   OS << "ExprToLoc:\n";
   for (auto [E, L] : ExprToLoc)
 OS << "  [" << E << ", " << L << "]\n";
@@ -1025,7 +1028,28 @@ void Environment::dump(raw_ostream &OS) const {
 
   OS << "LocToVal:\n";
   for (auto [L, V] : LocToVal) {
-OS << "  [" << L << ", " << V << ": " << *V << "]\n";
+OS << "  [" << L;
+if (auto Iter = LocToName.find(L); Iter != LocToName.end())
+  OS << " (" << Iter->second << ")";
+OS << ", " << V << ": " << *V << "]\n";
+  }
+
+  if (const FunctionDecl *Func = getCurrentFunc()) {
+if (Func->getReturnType()->isReferenceType()) {
+  OS << "ReturnLoc: " << ReturnLoc;
+  if (auto Iter = LocToName.find(ReturnLoc); Iter != LocToName.end())
+OS << " (" << Iter->second << ")";
+  OS << "\n";
+} else if (!Func->getReturnType()->isVoidType()) {
+  if (ReturnVal == nullptr)
+OS << "ReturnVal: nullptr\n";
+  else
+OS << "ReturnVal: " << *ReturnVal << "\n";
+}
+
+if (isa(Func)) {
+  OS << "ThisPointeeLoc: " << ThisPointeeLoc << "\n";
+}
   }
 
   OS << "\n";

``




https://github.com/llvm/llvm-project/pull/79982
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][dataflow] Extend debug output for `Environment`. (PR #79982)

2024-01-30 Thread via cfe-commits

https://github.com/martinboehme created 
https://github.com/llvm/llvm-project/pull/79982

*  Print `ReturnLoc`, `ReturnVal`, and `ThisPointeeLoc` if applicable.

*  For entries in `LocToVal` that correspond to declarations, print the names
   of the declarations next to them.

I've removed the FIXME because all relevant fields are now being dumped. I'm
not sure we actually need the capability for the caller to specify which fields
to dump, so I've simply deleted this part of the comment.


>From e65a6325a8d8f85a69926db51499656d62e1c032 Mon Sep 17 00:00:00 2001
From: Martin Braenne 
Date: Tue, 30 Jan 2024 11:18:51 +
Subject: [PATCH] [clang][dataflow] Extend debug output for `Environment`.

*  Print `ReturnLoc`, `ReturnVal`, and `ThisPointeeLoc` if applicable.

*  For entries in `LocToVal` that correspond to declarations, print the names
   of the declarations next to them.

I've removed the FIXME because all relevant fields are now being dumped. I'm
not sure we actually need the capability for the caller to specify which fields
to dump, so I've simply deleted this part of the comment.
---
 .../FlowSensitive/DataflowEnvironment.cpp | 36 +++
 1 file changed, 30 insertions(+), 6 deletions(-)

diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index acb38e576474..01db65866d13 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -1009,12 +1009,15 @@ bool Environment::allows(const Formula &F) const {
 }
 
 void Environment::dump(raw_ostream &OS) const {
-  // FIXME: add printing for remaining fields and allow caller to decide what
-  // fields are printed.
-  OS << "DeclToLoc:\n";
-  for (auto [D, L] : DeclToLoc)
-OS << "  [" << D->getNameAsString() << ", " << L << "]\n";
+  llvm::DenseMap LocToName;
+  if (ThisPointeeLoc != nullptr)
+LocToName[ThisPointeeLoc] = "this";
 
+  OS << "DeclToLoc:\n";
+  for (auto [D, L] : DeclToLoc) {
+auto Iter = LocToName.insert({L, D->getNameAsString()}).first;
+OS << "  [" << Iter->second << ", " << L << "]\n";
+  }
   OS << "ExprToLoc:\n";
   for (auto [E, L] : ExprToLoc)
 OS << "  [" << E << ", " << L << "]\n";
@@ -1025,7 +1028,28 @@ void Environment::dump(raw_ostream &OS) const {
 
   OS << "LocToVal:\n";
   for (auto [L, V] : LocToVal) {
-OS << "  [" << L << ", " << V << ": " << *V << "]\n";
+OS << "  [" << L;
+if (auto Iter = LocToName.find(L); Iter != LocToName.end())
+  OS << " (" << Iter->second << ")";
+OS << ", " << V << ": " << *V << "]\n";
+  }
+
+  if (const FunctionDecl *Func = getCurrentFunc()) {
+if (Func->getReturnType()->isReferenceType()) {
+  OS << "ReturnLoc: " << ReturnLoc;
+  if (auto Iter = LocToName.find(ReturnLoc); Iter != LocToName.end())
+OS << " (" << Iter->second << ")";
+  OS << "\n";
+} else if (!Func->getReturnType()->isVoidType()) {
+  if (ReturnVal == nullptr)
+OS << "ReturnVal: nullptr\n";
+  else
+OS << "ReturnVal: " << *ReturnVal << "\n";
+}
+
+if (isa(Func)) {
+  OS << "ThisPointeeLoc: " << ThisPointeeLoc << "\n";
+}
   }
 
   OS << "\n";

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits