@@ -3227,44 +3227,46 @@ void Sema::mergeDeclAttributes(NamedDecl *New, Decl *Old,
32273227 if (!foundAny) New->dropAttrs();
32283228}
32293229
3230+ // Returns the number of added attributes.
32303231template <class T>
3231- static unsigned propagateAttribute(ParmVarDecl *toDecl ,
3232- const ParmVarDecl *fromDecl , Sema &S) {
3232+ static unsigned propagateAttribute(ParmVarDecl *To ,
3233+ const ParmVarDecl *From , Sema &S) {
32333234 unsigned found = 0;
3234- for (const auto *I : fromDecl ->specific_attrs<T>()) {
3235- if (!DeclHasAttr(toDecl , I)) {
3235+ for (const auto *I : From ->specific_attrs<T>()) {
3236+ if (!DeclHasAttr(To , I)) {
32363237 T *newAttr = cast<T>(I->clone(S.Context));
32373238 newAttr->setInherited(true);
3238- toDecl ->addAttr(newAttr);
3239+ To ->addAttr(newAttr);
32393240 ++found;
32403241 }
32413242 }
32423243 return found;
32433244}
32443245
32453246template <class F>
3246- static void propagateAttributes(ParmVarDecl *toDecl ,
3247- const ParmVarDecl *fromDecl , F &&propagator) {
3248- if (!fromDecl ->hasAttrs()) {
3247+ static void propagateAttributes(ParmVarDecl *To ,
3248+ const ParmVarDecl *From , F &&propagator) {
3249+ if (!From ->hasAttrs()) {
32493250 return;
32503251 }
32513252
3252- bool foundAny = toDecl ->hasAttrs();
3253+ bool foundAny = To ->hasAttrs();
32533254
32543255 // Ensure that any moving of objects within the allocated map is
32553256 // done before we process them.
32563257 if (!foundAny)
3257- toDecl ->setAttrs(AttrVec());
3258+ To ->setAttrs(AttrVec());
32583259
3259- foundAny |= std::forward<F>(propagator)(toDecl, fromDecl ) != 0;
3260+ foundAny |= std::forward<F>(propagator)(To, From ) != 0;
32603261
32613262 if (!foundAny)
3262- toDecl ->dropAttrs();
3263+ To ->dropAttrs();
32633264}
32643265
32653266/// mergeParamDeclAttributes - Copy attributes from the old parameter
32663267/// to the new one.
3267- static void mergeParamDeclAttributes(ParmVarDecl *newDecl, ParmVarDecl *oldDecl,
3268+ static void mergeParamDeclAttributes(ParmVarDecl *newDecl,
3269+ const ParmVarDecl *oldDecl,
32683270 Sema &S) {
32693271 // C++11 [dcl.attr.depend]p2:
32703272 // The first declaration of a function shall specify the
@@ -3284,23 +3286,15 @@ static void mergeParamDeclAttributes(ParmVarDecl *newDecl, ParmVarDecl *oldDecl,
32843286 diag::note_carries_dependency_missing_first_decl) << 1/*Param*/;
32853287 }
32863288
3287- // Forward propagation (from old parameter to new)
32883289 propagateAttributes(
3289- newDecl, oldDecl, [&S](ParmVarDecl *toDecl, const ParmVarDecl *fromDecl) {
3290- unsigned found = 0;
3291- 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) {
3290+ newDecl, oldDecl, [&S](ParmVarDecl *To, const ParmVarDecl *From) {
32983291 unsigned found = 0;
3292+ found += propagateAttribute<InheritableParamAttr>(To, From, S);
32993293 // Propagate the lifetimebound attribute from parameters to the
3300- // canonical declaration. Note that this doesn't include the implicit
3294+ // most recent declaration. Note that this doesn't include the implicit
33013295 // 'this' parameter, as the attribute is applied to the function type in
33023296 // that case.
3303- found += propagateAttribute<LifetimeBoundAttr>(toDecl, fromDecl , S);
3297+ found += propagateAttribute<LifetimeBoundAttr>(To, From , S);
33043298 return found;
33053299 });
33063300}
@@ -4356,8 +4350,8 @@ void Sema::mergeObjCMethodDecls(ObjCMethodDecl *newMethod,
43564350 mergeDeclAttributes(newMethod, oldMethod, MergeKind);
43574351
43584352 // Merge attributes from the parameters.
4359- ObjCMethodDecl::param_iterator oi = oldMethod->param_begin(),
4360- oe = oldMethod->param_end();
4353+ ObjCMethodDecl::param_const_iterator oi = oldMethod->param_begin(),
4354+ oe = oldMethod->param_end();
43614355 for (ObjCMethodDecl::param_iterator
43624356 ni = newMethod->param_begin(), ne = newMethod->param_end();
43634357 ni != ne && oi != oe; ++ni, ++oi)
@@ -6981,6 +6975,7 @@ static void checkInheritableAttr(Sema &S, NamedDecl &ND) {
69816975static void checkLifetimeBoundAttr(Sema &S, NamedDecl &ND) {
69826976 // Check the attributes on the function type and function params, if any.
69836977 if (const auto *FD = dyn_cast<FunctionDecl>(&ND)) {
6978+ FD = FD->getMostRecentDecl();
69846979 // Don't declare this variable in the second operand of the for-statement;
69856980 // GCC miscompiles that by ending its lifetime before evaluating the
69866981 // third operand. See gcc.gnu.org/PR86769.
0 commit comments