[clang] [LifetimeSafety] Implement a basic use-after-free diagnostic (PR #149731)

Gábor Horváth via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 25 10:27:28 PDT 2025


================
@@ -19,14 +19,35 @@
 #define LLVM_CLANG_ANALYSIS_ANALYSES_LIFETIMESAFETY_H
 #include "clang/Analysis/AnalysisDeclContext.h"
 #include "clang/Analysis/CFG.h"
+#include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/DenseMapInfo.h"
+#include "llvm/ADT/ImmutableMap.h"
 #include "llvm/ADT/ImmutableSet.h"
 #include "llvm/ADT/StringMap.h"
 #include <memory>
 
 namespace clang::lifetimes {
 
+/// Enum to track the confidence level of a potential error.
+enum class Confidence {
+  None,
+  Maybe,   // Reported as a potential error (-Wlifetime-safety-strict)
+  Definite // Reported as a definite error (-Wlifetime-safety-permissive)
+};
+
+class LifetimeSafetyReporter {
----------------
Xazax-hun wrote:

I don't have a strong opinion here but a potential alternative is to just use the regular diagnostics interface of Sema directly and if we want to do testing we can use a different diagnostic consumer like `TextDiagnosticBuffer` or `IgnoringDiagConsumer`. 

https://github.com/llvm/llvm-project/pull/149731


More information about the cfe-commits mailing list