[clang] Thread safety analysis: provide printSCFG definition. (PR #80277)

Haojian Wu via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 23 06:23:44 PST 2024


https://github.com/hokein updated https://github.com/llvm/llvm-project/pull/80277

>From bb1a8f86e0b9ce3748af03625757d20900e053fc Mon Sep 17 00:00:00 2001
From: Haojian Wu <hokein.wu at gmail.com>
Date: Thu, 1 Feb 2024 12:41:29 +0100
Subject: [PATCH 1/2] Thread safety analysis: provide printSCFG definition.

I'm calling this function when investigating the issue (https://github.com/llvm/llvm-project/issues/78131), and I'm
surprised to see the definition is commented out.

I think it makes sense to provide the definition even though the
implementation is not stable.
---
 clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h | 1 +
 clang/lib/Analysis/ThreadSafetyCommon.cpp                  | 2 --
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h b/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
index 13e37ac2b56b64..4edd3374dd61bf 100644
--- a/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
+++ b/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
@@ -528,6 +528,7 @@ class SExprBuilder {
 };
 
 // Dump an SCFG to llvm::errs().
+// The implementation is not stable, and used for debugging only.
 void printSCFG(CFGWalker &Walker);
 
 } // namespace threadSafety
diff --git a/clang/lib/Analysis/ThreadSafetyCommon.cpp b/clang/lib/Analysis/ThreadSafetyCommon.cpp
index 2fe0f85897c3bc..fc5b7d3b6f1977 100644
--- a/clang/lib/Analysis/ThreadSafetyCommon.cpp
+++ b/clang/lib/Analysis/ThreadSafetyCommon.cpp
@@ -995,7 +995,6 @@ void SExprBuilder::exitCFG(const CFGBlock *Last) {
   IncompleteArgs.clear();
 }
 
-/*
 namespace {
 
 class TILPrinter :
@@ -1016,4 +1015,3 @@ void printSCFG(CFGWalker &Walker) {
 
 } // namespace threadSafety
 } // namespace clang
-*/

>From 0a230f8cca97922a5f32155a432859fea65a84d4 Mon Sep 17 00:00:00 2001
From: Haojian Wu <hokein.wu at gmail.com>
Date: Fri, 23 Feb 2024 15:21:53 +0100
Subject: [PATCH 2/2] printSCFG function is available for debug-only.

---
 clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h | 3 ++-
 clang/lib/Analysis/ThreadSafetyCommon.cpp                  | 2 ++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h b/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
index 4edd3374dd61bf..7bdb9052e57e74 100644
--- a/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
+++ b/clang/include/clang/Analysis/Analyses/ThreadSafetyCommon.h
@@ -527,9 +527,10 @@ class SExprBuilder {
   BlockInfo *CurrentBlockInfo = nullptr;
 };
 
+#ifndef NDEBUG
 // Dump an SCFG to llvm::errs().
-// The implementation is not stable, and used for debugging only.
 void printSCFG(CFGWalker &Walker);
+#endif // NDEBUG
 
 } // namespace threadSafety
 } // namespace clang
diff --git a/clang/lib/Analysis/ThreadSafetyCommon.cpp b/clang/lib/Analysis/ThreadSafetyCommon.cpp
index fc5b7d3b6f1977..33f1f466df2444 100644
--- a/clang/lib/Analysis/ThreadSafetyCommon.cpp
+++ b/clang/lib/Analysis/ThreadSafetyCommon.cpp
@@ -995,6 +995,7 @@ void SExprBuilder::exitCFG(const CFGBlock *Last) {
   IncompleteArgs.clear();
 }
 
+#ifndef NDEBUG
 namespace {
 
 class TILPrinter :
@@ -1015,3 +1016,4 @@ void printSCFG(CFGWalker &Walker) {
 
 } // namespace threadSafety
 } // namespace clang
+#endif // NDEBUG



More information about the cfe-commits mailing list