[clang] [clang] Merge lifetimebound and GSL code paths for lifetime analysis (PR #104906)

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 20 14:17:02 PDT 2024


================
@@ -478,22 +444,38 @@ static void visitLifetimeBoundArguments(IndirectLocalPath &Path, Expr *Call,
       CheckCoroObjArg = false;
     if (implicitObjectParamIsLifetimeBound(Callee) || CheckCoroObjArg)
       VisitLifetimeBoundArg(Callee, ObjectArg);
+    else if (EnableGSLAnalysis) {
+      if (auto *CME = dyn_cast<CXXMethodDecl>(Callee);
+          CME && shouldTrackImplicitObjectArg(CME))
+        VisitGSLPointerArg(Callee, ObjectArg,
+                           !Callee->getReturnType()->isReferenceType());
+    }
   }
 
   for (unsigned I = 0,
                 N = std::min<unsigned>(Callee->getNumParams(), Args.size());
        I != N; ++I) {
     if (CheckCoroCall || Callee->getParamDecl(I)->hasAttr<LifetimeBoundAttr>())
       VisitLifetimeBoundArg(Callee->getParamDecl(I), Args[I]);
+    else if (EnableGSLAnalysis && I == 0) {
+      if (shouldTrackFirstArgument(Callee)) { // gsl
+        VisitGSLPointerArg(Callee, Args[0],
+                           !Callee->getReturnType()->isReferenceType());
+      } else {
+        if (auto *CCE = dyn_cast<CXXConstructExpr>(Call);
----------------
usx95 wrote:

nit: `else if` instead of a new `else` block to be consistent

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


More information about the cfe-commits mailing list