From: Erich Keane Date: Tue, 3 Jul 2018 20:30:34 +0000 (+0000) Subject: Fix allocation of Nullability attribute. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=83dc9e5eeb282d9fea92251023c292c24d94fec7;p=clang Fix allocation of Nullability attribute. Existing code always allocates for on the declarator's attribute pool, but sometimes adds it to the declspec. This patch ensures that the correct pool is used. Discovered while testing: https://reviews.llvm.org/D48788 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@336225 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Parse/ParseObjc.cpp b/lib/Parse/ParseObjc.cpp index ff33d5fb96..81b930a228 100644 --- a/lib/Parse/ParseObjc.cpp +++ b/lib/Parse/ParseObjc.cpp @@ -381,25 +381,23 @@ static void addContextSensitiveTypeNullability(Parser &P, SourceLocation nullabilityLoc, bool &addedToDeclSpec) { // Create the attribute. - auto getNullabilityAttr = [&]() -> AttributeList * { - return D.getAttributePool().create( - P.getNullabilityKeyword(nullability), - SourceRange(nullabilityLoc), - nullptr, SourceLocation(), - nullptr, 0, - AttributeList::AS_ContextSensitiveKeyword); + auto getNullabilityAttr = [&](AttributePool &Pool) -> AttributeList * { + return Pool.create(P.getNullabilityKeyword(nullability), + SourceRange(nullabilityLoc), nullptr, SourceLocation(), + nullptr, 0, AttributeList::AS_ContextSensitiveKeyword); }; if (D.getNumTypeObjects() > 0) { // Add the attribute to the declarator chunk nearest the declarator. - auto nullabilityAttr = getNullabilityAttr(); + auto nullabilityAttr = getNullabilityAttr(D.getAttributePool()); DeclaratorChunk &chunk = D.getTypeObject(0); nullabilityAttr->setNext(chunk.getAttrListRef()); chunk.getAttrListRef() = nullabilityAttr; } else if (!addedToDeclSpec) { // Otherwise, just put it on the declaration specifiers (if one // isn't there already). - D.getMutableDeclSpec().addAttributes(getNullabilityAttr()); + D.getMutableDeclSpec().addAttributes( + getNullabilityAttr(D.getDeclSpec().getAttributePool())); addedToDeclSpec = true; } }