================
@@ -39,6 +46,17 @@ OriginID OriginManager::get(const Expr &E) {
   auto It = ExprToOriginID.find(&E);
   if (It != ExprToOriginID.end())
     return It->second;
+
+  // if the expression has no specific origin, increment the missing origin
+  // counter.
+  std::string ExprStr(E.getStmtClassName());
+  ExprStr = ExprStr + "<" + E.getType().getAsString() + ">";
+  auto CountIt = ExprTypeToMissingOriginCount.find(ExprStr);
+  if (CountIt == ExprTypeToMissingOriginCount.end()) {
+    ExprTypeToMissingOriginCount[ExprStr] = 1;
+  } else {
+    CountIt->second++;
+  }
----------------
usx95 wrote:

Couple of concerns and suggestions:
- This is quite expensive to do as it involves serialising expressions as 
`strings`. This should be done only when required.
- This captures the expressions which we tried to `get` but could not. This 
misses those expressions which we never called `get` as well.
- I would suggest to collect this in a black-box fashion. We do this collection 
at the end of the analysis (and not during the analysis). We have something 
like `OriginManager::collectMissingOrigins(Stmt* FunctionBody, 
LifetimeSafetyStats &Stats)`.  This can be called from 
`LifetimeSafetyAnalysis::collectStats(LifetimeSafetyStats &)`. You can get the 
function body from `AC.getBody().
- Now in `OriginManager::collectMissingOrigins`, we can use a 
`RecursiveASTVisitor` to visit all expressions in the function body, and for 
each expression, if it should `hasOrigin` then we can query the origins to see 
if we have it or not.
- (you can inline `hasOrigin` from FactsGenerator.cpp at the moment. at this 
point this is just `E->isGLValue() || isPointerType(E->getType())`)

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