@@ -403,13 +403,17 @@ static void visitFunctionCallArguments(IndirectLocalPath &Path, Expr *Call,
403403 visitLocalsRetainedByInitializer (Path, Arg, Visit, true );
404404 Path.pop_back ();
405405 };
406- auto VisitGSLPointerArg = [&](const Decl *D , Expr *Arg, bool Value ) {
406+ auto VisitGSLPointerArg = [&](const FunctionDecl *Callee , Expr *Arg) {
407407 // We are not interested in the temporary base objects of gsl Pointers:
408408 // Temp().ptr; // Here ptr might not dangle.
409409 if (isa<MemberExpr>(Arg->IgnoreImpCasts ()))
410410 return ;
411- // Once we initialized a value with a reference, it can no longer dangle.
412- if (!Value) {
411+ auto ReturnType = Callee->getReturnType ();
412+
413+ // Once we initialized a value with a non gsl-owner reference, it can no
414+ // longer dangle.
415+ if (ReturnType->isReferenceType () &&
416+ !isRecordWithAttr<OwnerAttr>(ReturnType->getPointeeType ())) {
413417 for (const IndirectLocalPathEntry &PE : llvm::reverse (Path)) {
414418 if (PE.Kind == IndirectLocalPathEntry::GslReferenceInit ||
415419 PE.Kind == IndirectLocalPathEntry::LifetimeBoundCall)
@@ -420,9 +424,10 @@ static void visitFunctionCallArguments(IndirectLocalPath &Path, Expr *Call,
420424 break ;
421425 }
422426 }
423- Path.push_back ({Value ? IndirectLocalPathEntry::GslPointerInit
424- : IndirectLocalPathEntry::GslReferenceInit,
425- Arg, D});
427+ Path.push_back ({ReturnType->isReferenceType ()
428+ ? IndirectLocalPathEntry::GslReferenceInit
429+ : IndirectLocalPathEntry::GslPointerInit,
430+ Arg, Callee});
426431 if (Arg->isGLValue ())
427432 visitLocalsRetainedByReferenceBinding (Path, Arg, RK_ReferenceBinding,
428433 Visit);
@@ -453,8 +458,7 @@ static void visitFunctionCallArguments(IndirectLocalPath &Path, Expr *Call,
453458 else if (EnableGSLAnalysis) {
454459 if (auto *CME = dyn_cast<CXXMethodDecl>(Callee);
455460 CME && shouldTrackImplicitObjectArg (CME))
456- VisitGSLPointerArg (Callee, ObjectArg,
457- !Callee->getReturnType ()->isReferenceType ());
461+ VisitGSLPointerArg (Callee, ObjectArg);
458462 }
459463 }
460464
@@ -465,13 +469,11 @@ static void visitFunctionCallArguments(IndirectLocalPath &Path, Expr *Call,
465469 VisitLifetimeBoundArg (Callee->getParamDecl (I), Args[I]);
466470 else if (EnableGSLAnalysis && I == 0 ) {
467471 if (shouldTrackFirstArgument (Callee)) {
468- VisitGSLPointerArg (Callee, Args[0 ],
469- !Callee->getReturnType ()->isReferenceType ());
472+ VisitGSLPointerArg (Callee, Args[0 ]);
470473 } else if (auto *CCE = dyn_cast<CXXConstructExpr>(Call);
471474 CCE &&
472475 CCE->getConstructor ()->getParent ()->hasAttr <PointerAttr>()) {
473- VisitGSLPointerArg (CCE->getConstructor ()->getParamDecl (0 ), Args[0 ],
474- true );
476+ VisitGSLPointerArg (CCE->getConstructor (), Args[0 ]);
475477 }
476478 }
477479 }
0 commit comments