@@ -403,13 +403,17 @@ static void visitFunctionCallArguments(IndirectLocalPath &Path, Expr *Call,
403
403
visitLocalsRetainedByInitializer (Path, Arg, Visit, true );
404
404
Path.pop_back ();
405
405
};
406
- auto VisitGSLPointerArg = [&](const Decl *D , Expr *Arg, bool Value ) {
406
+ auto VisitGSLPointerArg = [&](const FunctionDecl *Callee , Expr *Arg) {
407
407
// We are not interested in the temporary base objects of gsl Pointers:
408
408
// Temp().ptr; // Here ptr might not dangle.
409
409
if (isa<MemberExpr>(Arg->IgnoreImpCasts ()))
410
410
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 ())) {
413
417
for (const IndirectLocalPathEntry &PE : llvm::reverse (Path)) {
414
418
if (PE.Kind == IndirectLocalPathEntry::GslReferenceInit ||
415
419
PE.Kind == IndirectLocalPathEntry::LifetimeBoundCall)
@@ -420,9 +424,10 @@ static void visitFunctionCallArguments(IndirectLocalPath &Path, Expr *Call,
420
424
break ;
421
425
}
422
426
}
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});
426
431
if (Arg->isGLValue ())
427
432
visitLocalsRetainedByReferenceBinding (Path, Arg, RK_ReferenceBinding,
428
433
Visit);
@@ -453,8 +458,7 @@ static void visitFunctionCallArguments(IndirectLocalPath &Path, Expr *Call,
453
458
else if (EnableGSLAnalysis) {
454
459
if (auto *CME = dyn_cast<CXXMethodDecl>(Callee);
455
460
CME && shouldTrackImplicitObjectArg (CME))
456
- VisitGSLPointerArg (Callee, ObjectArg,
457
- !Callee->getReturnType ()->isReferenceType ());
461
+ VisitGSLPointerArg (Callee, ObjectArg);
458
462
}
459
463
}
460
464
@@ -465,13 +469,11 @@ static void visitFunctionCallArguments(IndirectLocalPath &Path, Expr *Call,
465
469
VisitLifetimeBoundArg (Callee->getParamDecl (I), Args[I]);
466
470
else if (EnableGSLAnalysis && I == 0 ) {
467
471
if (shouldTrackFirstArgument (Callee)) {
468
- VisitGSLPointerArg (Callee, Args[0 ],
469
- !Callee->getReturnType ()->isReferenceType ());
472
+ VisitGSLPointerArg (Callee, Args[0 ]);
470
473
} else if (auto *CCE = dyn_cast<CXXConstructExpr>(Call);
471
474
CCE &&
472
475
CCE->getConstructor ()->getParent ()->hasAttr <PointerAttr>()) {
473
- VisitGSLPointerArg (CCE->getConstructor ()->getParamDecl (0 ), Args[0 ],
474
- true );
476
+ VisitGSLPointerArg (CCE->getConstructor (), Args[0 ]);
475
477
}
476
478
}
477
479
}
0 commit comments