Suppress noisy pointer_nullability_analysis logging by default.
These occur for unhandled AST nodes/cases, and we recover.
We should fix these all eventually, but many of them are low-priority and
these messages interfere with testing the tool on large TUs.
They can be enabled with LLVM flags `-debug` or
`-debug-only=pointer_nullability_analysis.cc`
PiperOrigin-RevId: 551796388
Change-Id: I28cea6c03bb3d72c842e86d1df2fa08ce6e9e428
diff --git a/nullability/BUILD b/nullability/BUILD
index c5b4784..5a6b904 100644
--- a/nullability/BUILD
+++ b/nullability/BUILD
@@ -49,6 +49,7 @@
"@llvm-project//clang:ast",
"@llvm-project//clang:ast_matchers",
"@llvm-project//clang:basic",
+ "@llvm-project//llvm:Support",
],
)
diff --git a/nullability/pointer_nullability_analysis.cc b/nullability/pointer_nullability_analysis.cc
index 5d27558..2bac60b 100644
--- a/nullability/pointer_nullability_analysis.cc
+++ b/nullability/pointer_nullability_analysis.cc
@@ -30,6 +30,7 @@
#include "clang/Analysis/FlowSensitive/Value.h"
#include "clang/Basic/LLVM.h"
#include "clang/Basic/Specifiers.h"
+#include "llvm/Support/Debug.h"
namespace clang::tidy::nullability {
@@ -41,6 +42,8 @@
using dataflow::TransferState;
using dataflow::Value;
+#define DEBUG_TYPE "pointer_nullability_analysis.cc"
+
namespace {
TypeNullability prepend(NullabilityKind Head, const TypeNullability &Tail) {
@@ -58,16 +61,18 @@
ExpectedSize != Nullability.size()) {
// A nullability vector must have one entry per pointer in the type.
// If this is violated, we probably failed to handle some AST node.
- llvm::dbgs()
- << "=== Nullability vector has wrong number of entries: ===\n";
- llvm::dbgs() << "Expression: \n";
- dump(E, llvm::dbgs());
- llvm::dbgs() << "\nNullability (" << Nullability.size()
- << " pointers): " << nullabilityToString(Nullability)
- << "\n";
- llvm::dbgs() << "\nType (" << ExpectedSize << " pointers): \n";
- dump(exprType(E), llvm::dbgs());
- llvm::dbgs() << "=================================\n";
+ LLVM_DEBUG({
+ llvm::dbgs()
+ << "=== Nullability vector has wrong number of entries: ===\n";
+ llvm::dbgs() << "Expression: \n";
+ dump(E, llvm::dbgs());
+ llvm::dbgs() << "\nNullability (" << Nullability.size()
+ << " pointers): " << nullabilityToString(Nullability)
+ << "\n";
+ llvm::dbgs() << "\nType (" << ExpectedSize << " pointers): \n";
+ dump(exprType(E), llvm::dbgs());
+ llvm::dbgs() << "=================================\n";
+ });
// We can't meaningfully interpret the vector, so discard it.
// TODO: fix all broken cases and upgrade to CHECK or DCHECK or so.
@@ -86,9 +91,11 @@
// computed the child nullability. However, this is not true in all test
// cases. So, we return unspecified nullability annotations.
// TODO: fix this issue, and CHECK() instead.
- llvm::dbgs() << "=== Missing child nullability: ===\n";
- dump(E, llvm::dbgs());
- llvm::dbgs() << "==================================\n";
+ LLVM_DEBUG({
+ llvm::dbgs() << "=== Missing child nullability: ===\n";
+ dump(E, llvm::dbgs());
+ llvm::dbgs() << "==================================\n";
+ });
return unspecifiedNullability(E);
});