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