================
@@ -7,8 +7,51 @@
 
//===----------------------------------------------------------------------===//
 
 #include "clang/Analysis/Analyses/LifetimeSafety/Origins.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/AST/TypeBase.h"
+#include "clang/Analysis/Analyses/LifetimeSafety/LifetimeAnnotations.h"
+#include "clang/Analysis/Analyses/LifetimeSafety/LifetimeStats.h"
+#include "llvm/ADT/StringMap.h"
 
 namespace clang::lifetimes::internal {
+namespace {
+bool isPointerType(QualType QT) {
+  return QT->isPointerOrReferenceType() || isGslPointerType(QT);
+}
+// Check if a type has an origin.
+bool hasOrigin(const Expr *E) {
+  return E->isGLValue() || isPointerType(E->getType());
+}
+/// An utility class to traverse the function body in the analysis
+/// context and collect the count of expressions with missing origins.
+class MissingOriginCollector
+    : public RecursiveASTVisitor<MissingOriginCollector> {
+public:
+  MissingOriginCollector(
+      const llvm::DenseMap<const clang::Expr *, OriginID> &ExprToOriginId,
+      llvm::StringMap<unsigned> &MissingOriginCount)
+      : ExprToOriginId(ExprToOriginId), MissingOriginCount(MissingOriginCount) 
{
+  }
+  bool VisitExpr(Expr *E) {
+    if (!hasOrigin(E))
+      return true;
+    // Check if we have an origin for this expression.
+    auto It = this->ExprToOriginId.find(E);
+    if (It == this->ExprToOriginId.end()) {
----------------
usx95 wrote:

This is `!ExprToOriginId.contains(E)`​

https://github.com/llvm/llvm-project/pull/166568
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to