Skip to content

Commit 8da0a21

Browse files
Use the most recent declaration as the canonical one for lifetimebound
1 parent dd8f37a commit 8da0a21

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

clang/lib/Sema/CheckExprLifetime.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ static bool isNormalAssignmentOperator(const FunctionDecl *FD) {
499499
}
500500

501501
bool implicitObjectParamIsLifetimeBound(const FunctionDecl *FD) {
502+
FD = FD->getMostRecentDecl();
502503
const TypeSourceInfo *TSI = FD->getTypeSourceInfo();
503504
if (!TSI)
504505
return false;
@@ -611,7 +612,7 @@ static void visitFunctionCallArguments(IndirectLocalPath &Path, Expr *Call,
611612
}
612613
}
613614

614-
const FunctionDecl *CanonCallee = Callee->getCanonicalDecl();
615+
const FunctionDecl *CanonCallee = Callee->getMostRecentDecl();
615616
unsigned NP = std::min(Callee->getNumParams(), CanonCallee->getNumParams());
616617
for (unsigned I = 0, N = std::min<unsigned>(NP, Args.size()); I != N; ++I) {
617618
Expr *Arg = Args[I];
@@ -1100,6 +1101,7 @@ static bool pathOnlyHandlesGslPointer(const IndirectLocalPath &Path) {
11001101
}
11011102

11021103
static bool isAssignmentOperatorLifetimeBound(CXXMethodDecl *CMD) {
1104+
CMD = CMD->getMostRecentDecl();
11031105
return CMD && isNormalAssignmentOperator(CMD) && CMD->param_size() == 1 &&
11041106
CMD->getParamDecl(0)->hasAttr<LifetimeBoundAttr>();
11051107
}

clang/lib/Sema/SemaDecl.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3264,7 +3264,8 @@ static void propagateAttributes(ParmVarDecl *toDecl,
32643264

32653265
/// mergeParamDeclAttributes - Copy attributes from the old parameter
32663266
/// to the new one.
3267-
static void mergeParamDeclAttributes(ParmVarDecl *newDecl, ParmVarDecl *oldDecl,
3267+
static void mergeParamDeclAttributes(ParmVarDecl *newDecl,
3268+
const ParmVarDecl *oldDecl,
32683269
Sema &S) {
32693270
// C++11 [dcl.attr.depend]p2:
32703271
// The first declaration of a function shall specify the
@@ -3284,20 +3285,12 @@ static void mergeParamDeclAttributes(ParmVarDecl *newDecl, ParmVarDecl *oldDecl,
32843285
diag::note_carries_dependency_missing_first_decl) << 1/*Param*/;
32853286
}
32863287

3287-
// Forward propagation (from old parameter to new)
32883288
propagateAttributes(
32893289
newDecl, oldDecl, [&S](ParmVarDecl *toDecl, const ParmVarDecl *fromDecl) {
32903290
unsigned found = 0;
32913291
found += propagateAttribute<InheritableParamAttr>(toDecl, fromDecl, S);
3292-
return found;
3293-
});
3294-
3295-
// Backward propagation (from new parameter to old)
3296-
propagateAttributes(
3297-
oldDecl, newDecl, [&S](ParmVarDecl *toDecl, const ParmVarDecl *fromDecl) {
3298-
unsigned found = 0;
32993292
// Propagate the lifetimebound attribute from parameters to the
3300-
// canonical declaration. Note that this doesn't include the implicit
3293+
// most recent declaration. Note that this doesn't include the implicit
33013294
// 'this' parameter, as the attribute is applied to the function type in
33023295
// that case.
33033296
found += propagateAttribute<LifetimeBoundAttr>(toDecl, fromDecl, S);
@@ -4356,8 +4349,8 @@ void Sema::mergeObjCMethodDecls(ObjCMethodDecl *newMethod,
43564349
mergeDeclAttributes(newMethod, oldMethod, MergeKind);
43574350

43584351
// Merge attributes from the parameters.
4359-
ObjCMethodDecl::param_iterator oi = oldMethod->param_begin(),
4360-
oe = oldMethod->param_end();
4352+
ObjCMethodDecl::param_const_iterator oi = oldMethod->param_begin(),
4353+
oe = oldMethod->param_end();
43614354
for (ObjCMethodDecl::param_iterator
43624355
ni = newMethod->param_begin(), ne = newMethod->param_end();
43634356
ni != ne && oi != oe; ++ni, ++oi)
@@ -6981,6 +6974,7 @@ static void checkInheritableAttr(Sema &S, NamedDecl &ND) {
69816974
static void checkLifetimeBoundAttr(Sema &S, NamedDecl &ND) {
69826975
// Check the attributes on the function type and function params, if any.
69836976
if (const auto *FD = dyn_cast<FunctionDecl>(&ND)) {
6977+
FD = FD->getMostRecentDecl();
69846978
// Don't declare this variable in the second operand of the for-statement;
69856979
// GCC miscompiles that by ending its lifetime before evaluating the
69866980
// third operand. See gcc.gnu.org/PR86769.

0 commit comments

Comments
 (0)