Skip to content

Commit c83ec84

Browse files
authored
[clang][dataflow] Extend debug output for Environment. (#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. Some examples of the output: ![image](https://github.com/llvm/llvm-project/assets/29098113/17d0978f-b86d-4555-8a61-d1f2021f8d59) ![image](https://github.com/llvm/llvm-project/assets/29098113/021dbb24-5fe2-4720-8a08-f48dcf4b88f8)
1 parent 9594746 commit c83ec84

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,12 +1009,15 @@ bool Environment::allows(const Formula &F) const {
10091009
}
10101010

10111011
void Environment::dump(raw_ostream &OS) const {
1012-
// FIXME: add printing for remaining fields and allow caller to decide what
1013-
// fields are printed.
1014-
OS << "DeclToLoc:\n";
1015-
for (auto [D, L] : DeclToLoc)
1016-
OS << " [" << D->getNameAsString() << ", " << L << "]\n";
1012+
llvm::DenseMap<const StorageLocation *, std::string> LocToName;
1013+
if (ThisPointeeLoc != nullptr)
1014+
LocToName[ThisPointeeLoc] = "this";
10171015

1016+
OS << "DeclToLoc:\n";
1017+
for (auto [D, L] : DeclToLoc) {
1018+
auto Iter = LocToName.insert({L, D->getNameAsString()}).first;
1019+
OS << " [" << Iter->second << ", " << L << "]\n";
1020+
}
10181021
OS << "ExprToLoc:\n";
10191022
for (auto [E, L] : ExprToLoc)
10201023
OS << " [" << E << ", " << L << "]\n";
@@ -1025,7 +1028,28 @@ void Environment::dump(raw_ostream &OS) const {
10251028

10261029
OS << "LocToVal:\n";
10271030
for (auto [L, V] : LocToVal) {
1028-
OS << " [" << L << ", " << V << ": " << *V << "]\n";
1031+
OS << " [" << L;
1032+
if (auto Iter = LocToName.find(L); Iter != LocToName.end())
1033+
OS << " (" << Iter->second << ")";
1034+
OS << ", " << V << ": " << *V << "]\n";
1035+
}
1036+
1037+
if (const FunctionDecl *Func = getCurrentFunc()) {
1038+
if (Func->getReturnType()->isReferenceType()) {
1039+
OS << "ReturnLoc: " << ReturnLoc;
1040+
if (auto Iter = LocToName.find(ReturnLoc); Iter != LocToName.end())
1041+
OS << " (" << Iter->second << ")";
1042+
OS << "\n";
1043+
} else if (!Func->getReturnType()->isVoidType()) {
1044+
if (ReturnVal == nullptr)
1045+
OS << "ReturnVal: nullptr\n";
1046+
else
1047+
OS << "ReturnVal: " << *ReturnVal << "\n";
1048+
}
1049+
1050+
if (isa<CXXMethodDecl>(Func)) {
1051+
OS << "ThisPointeeLoc: " << ThisPointeeLoc << "\n";
1052+
}
10291053
}
10301054

10311055
OS << "\n";

0 commit comments

Comments
 (0)