diff --git a/clang-tools-extra/clangd/FindTarget.cpp b/clang-tools-extra/clangd/FindTarget.cpp --- a/clang-tools-extra/clangd/FindTarget.cpp +++ b/clang-tools-extra/clangd/FindTarget.cpp @@ -288,7 +288,7 @@ for (const DesignatedInitExpr::Designator &D : llvm::reverse(DIE->designators())) if (D.isFieldDesignator()) { - Outer.add(D.getField(), Flags); + Outer.add(D.getFieldDecl(), Flags); // We don't know which designator was intended, we assume the outer. break; } @@ -808,7 +808,7 @@ Refs.push_back(ReferenceLoc{NestedNameSpecifierLoc(), D.getFieldLoc(), /*IsDecl=*/false, - {D.getField()}}); + {D.getFieldDecl()}}); } } diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp --- a/clang-tools-extra/clangd/XRefs.cpp +++ b/clang-tools-extra/clangd/XRefs.cpp @@ -1905,7 +1905,7 @@ // In .foo.bar we want to jump to bar's type, so find *last* field. for (auto &D : llvm::reverse(S->designators())) if (D.isFieldDesignator()) - if (const auto *FD = D.getField()) + if (const auto *FD = D.getFieldDecl()) return FD->getType(); return QualType(); } diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h --- a/clang/include/clang/AST/Expr.h +++ b/clang/include/clang/AST/Expr.h @@ -5164,7 +5164,7 @@ //===------------------------------------------------------------------===// // FieldDesignatorInfo - /// Initializes a field designator. + /// Creates a field designator. static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, SourceLocation FieldLoc) { @@ -5175,15 +5175,14 @@ const IdentifierInfo *getFieldName() const; - FieldDecl *getField() const { + FieldDecl *getFieldDecl() const { assert(isFieldDesignator() && "Only valid on a field designator"); if (FieldInfo.NameOrField & 0x01) return nullptr; - else - return reinterpret_cast(FieldInfo.NameOrField); + return reinterpret_cast(FieldInfo.NameOrField); } - void setField(FieldDecl *FD) { + void setFieldDecl(FieldDecl *FD) { assert(isFieldDesignator() && "Only valid on a field designator"); FieldInfo.NameOrField = reinterpret_cast(FD); } @@ -5201,7 +5200,7 @@ //===------------------------------------------------------------------===// // ArrayOrRangeDesignator - /// Initializes an array designator. + /// Creates an array designator. static Designator CreateArrayDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation RBracketLoc) { @@ -5211,7 +5210,7 @@ return D; } - /// Initializes a GNU array-range designator. + /// Creates a GNU array-range designator. static Designator CreateArrayRangeDesignator(unsigned Index, SourceLocation LBracketLoc, SourceLocation EllipsisLoc, @@ -5247,12 +5246,6 @@ return ArrayOrRangeInfo.RBracketLoc; } - unsigned xgetFirstExprIndex() const { - assert((isArrayDesignator() || isArrayRangeDesignator()) && - "Only valid on an array or array-range designator"); - return ArrayOrRangeInfo.Index; - } - SourceLocation getBeginLoc() const LLVM_READONLY { if (isFieldDesignator()) return getDotLoc().isInvalid() ? getFieldLoc() : getDotLoc(); diff --git a/clang/include/clang/Sema/Designator.h b/clang/include/clang/Sema/Designator.h --- a/clang/include/clang/Sema/Designator.h +++ b/clang/include/clang/Sema/Designator.h @@ -21,7 +21,6 @@ class Expr; class IdentifierInfo; -class Sema; /// Designator - A designator in a C99 designated initializer. /// @@ -40,17 +39,17 @@ /// A field designator, e.g., ".x = 42". struct FieldDesignatorInfo { /// Refers to the field being initialized. - const IdentifierInfo *II; + const IdentifierInfo *FieldName; /// The location of the '.' in the designated initializer. SourceLocation DotLoc; /// The location of the field name in the designated initializer. - SourceLocation NameLoc; + SourceLocation FieldLoc; - FieldDesignatorInfo(const IdentifierInfo *II, SourceLocation DotLoc, - SourceLocation NameLoc) - : II(II), DotLoc(DotLoc), NameLoc(NameLoc) {} + FieldDesignatorInfo(const IdentifierInfo *FieldName, SourceLocation DotLoc, + SourceLocation FieldLoc) + : FieldName(FieldName), DotLoc(DotLoc), FieldLoc(FieldLoc) {} }; /// An array designator, e.g., "[42] = 0". @@ -112,17 +111,18 @@ //===--------------------------------------------------------------------===// // FieldDesignatorInfo - static Designator CreateFieldDesignator(const IdentifierInfo *II, + /// Creates a field designator. + static Designator CreateFieldDesignator(const IdentifierInfo *FieldName, SourceLocation DotLoc, - SourceLocation NameLoc) { + SourceLocation FieldLoc) { Designator D(FieldDesignator); - new (&D.FieldInfo) FieldDesignatorInfo(II, DotLoc, NameLoc); + new (&D.FieldInfo) FieldDesignatorInfo(FieldName, DotLoc, FieldLoc); return D; } - const IdentifierInfo *getField() const { + const IdentifierInfo *getFieldDecl() const { assert(isFieldDesignator() && "Invalid accessor"); - return FieldInfo.II; + return FieldInfo.FieldName; } SourceLocation getDotLoc() const { @@ -132,12 +132,13 @@ SourceLocation getFieldLoc() const { assert(isFieldDesignator() && "Invalid accessor"); - return FieldInfo.NameLoc; + return FieldInfo.FieldLoc; } //===--------------------------------------------------------------------===// // ArrayDesignatorInfo: + /// Creates an array designator. static Designator CreateArrayDesignator(Expr *Index, SourceLocation LBracketLoc) { Designator D(ArrayDesignator); @@ -167,6 +168,7 @@ //===--------------------------------------------------------------------===// // ArrayRangeDesignatorInfo: + /// Creates a GNU array-range designator. static Designator CreateArrayRangeDesignator(Expr *Start, Expr *End, SourceLocation LBracketLoc, SourceLocation EllipsisLoc) { diff --git a/clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h b/clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h --- a/clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h +++ b/clang/include/clang/Tooling/Refactoring/RecursiveSymbolVisitor.h @@ -124,10 +124,11 @@ bool VisitDesignatedInitExpr(const DesignatedInitExpr *E) { for (const DesignatedInitExpr::Designator &D : E->designators()) { - if (D.isFieldDesignator() && D.getField()) { - const FieldDecl *Decl = D.getField(); - if (!visit(Decl, D.getFieldLoc(), D.getFieldLoc())) - return false; + if (D.isFieldDesignator()) { + if (const FieldDecl *Decl = D.getFieldDecl()) { + if (!visit(Decl, D.getFieldLoc(), D.getFieldLoc())) + return false; + } } } return true; diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp --- a/clang/lib/AST/Expr.cpp +++ b/clang/lib/AST/Expr.cpp @@ -4407,7 +4407,7 @@ assert(isFieldDesignator() && "Only valid on a field designator"); if (FieldInfo.NameOrField & 0x01) return reinterpret_cast(FieldInfo.NameOrField & ~0x01); - return getField()->getIdentifier(); + return getFieldDecl()->getIdentifier(); } DesignatedInitExpr::DesignatedInitExpr(const ASTContext &C, QualType Ty, diff --git a/clang/lib/Index/IndexBody.cpp b/clang/lib/Index/IndexBody.cpp --- a/clang/lib/Index/IndexBody.cpp +++ b/clang/lib/Index/IndexBody.cpp @@ -203,9 +203,12 @@ bool VisitDesignatedInitExpr(DesignatedInitExpr *E) { for (DesignatedInitExpr::Designator &D : llvm::reverse(E->designators())) { - if (D.isFieldDesignator() && D.getField()) - return IndexCtx.handleReference(D.getField(), D.getFieldLoc(), Parent, - ParentDC, SymbolRoleSet(), {}, E); + if (D.isFieldDesignator()) { + if (const FieldDecl *FD = D.getFieldDecl()) { + return IndexCtx.handleReference(FD, D.getFieldLoc(), Parent, + ParentDC, SymbolRoleSet(), {}, E); + } + } } return true; } @@ -417,10 +420,12 @@ auto visitSyntacticDesignatedInitExpr = [&](DesignatedInitExpr *E) -> bool { for (DesignatedInitExpr::Designator &D : llvm::reverse(E->designators())) { - if (D.isFieldDesignator() && D.getField()) - return IndexCtx.handleReference(D.getField(), D.getFieldLoc(), - Parent, ParentDC, SymbolRoleSet(), - {}, E); + if (D.isFieldDesignator()) { + if (const FieldDecl *FD = D.getFieldDecl()) { + return IndexCtx.handleReference(FD, D.getFieldLoc(), Parent, + ParentDC, SymbolRoleSet(), {}, E); + } + } } return true; }; diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -6423,7 +6423,7 @@ assert(D.isFieldDesignator()); auto *RD = getAsRecordDecl(BaseType); if (RD && RD->isCompleteDefinition()) { - for (const auto *Member : RD->lookup(D.getField())) + for (const auto *Member : RD->lookup(D.getFieldDecl())) if (const FieldDecl *FD = llvm::dyn_cast(Member)) { NextType = FD->getType(); break; diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -2370,7 +2370,7 @@ Replacements.push_back(Designator::CreateFieldDesignator( (IdentifierInfo *)nullptr, SourceLocation(), SourceLocation())); assert(isa(*PI)); - Replacements.back().setField(cast(*PI)); + Replacements.back().setFieldDecl(cast(*PI)); } // Expand the current designator into the set of replacement @@ -2591,7 +2591,7 @@ return true; } - FieldDecl *KnownField = D->getField(); + FieldDecl *KnownField = D->getFieldDecl(); if (!KnownField) { const IdentifierInfo *FieldName = D->getFieldName(); DeclContext::lookup_result Lookup = RT->getDecl()->lookup(FieldName); @@ -2762,7 +2762,7 @@ // Update the designator with the field declaration. if (!VerifyOnly) - D->setField(*Field); + D->setFieldDecl(*Field); // Make sure that our non-designated initializer list has space // for a subobject corresponding to this field. @@ -3251,7 +3251,7 @@ if (D.isFieldDesignator()) { Designators.push_back(ASTDesignator::CreateFieldDesignator( - D.getField(), D.getDotLoc(), D.getFieldLoc())); + D.getFieldDecl(), D.getDotLoc(), D.getFieldLoc())); } else if (D.isArrayDesignator()) { Expr *Index = static_cast(D.getArrayIndex()); llvm::APSInt IndexValue; diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -11663,10 +11663,10 @@ if (D.isFieldDesignator()) { Desig.AddDesignator(Designator::CreateFieldDesignator( D.getFieldName(), D.getDotLoc(), D.getFieldLoc())); - if (D.getField()) { + if (D.getFieldDecl()) { FieldDecl *Field = cast_or_null( - getDerived().TransformDecl(D.getFieldLoc(), D.getField())); - if (Field != D.getField()) + getDerived().TransformDecl(D.getFieldLoc(), D.getFieldDecl())); + if (Field != D.getFieldDecl()) // Rebuild the expression when the transformed FieldDecl is // different to the already assigned FieldDecl. ExprChanged = true; diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp --- a/clang/lib/Serialization/ASTReaderStmt.cpp +++ b/clang/lib/Serialization/ASTReaderStmt.cpp @@ -1218,7 +1218,7 @@ SourceLocation FieldLoc = readSourceLocation(); Designators.push_back(Designator::CreateFieldDesignator( Field->getIdentifier(), DotLoc, FieldLoc)); - Designators.back().setField(Field); + Designators.back().setFieldDecl(Field); break; } diff --git a/clang/lib/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp --- a/clang/lib/Serialization/ASTWriterStmt.cpp +++ b/clang/lib/Serialization/ASTWriterStmt.cpp @@ -1087,7 +1087,7 @@ Record.push_back(E->usesGNUSyntax()); for (const DesignatedInitExpr::Designator &D : E->designators()) { if (D.isFieldDesignator()) { - if (FieldDecl *Field = D.getField()) { + if (FieldDecl *Field = D.getFieldDecl()) { Record.push_back(serialization::DESIG_FIELD_DECL); Record.AddDeclRef(Field); } else { diff --git a/clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp b/clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp --- a/clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp +++ b/clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp @@ -228,16 +228,17 @@ bool VisitDesignatedInitExpr(const DesignatedInitExpr *E) { for (const DesignatedInitExpr::Designator &D : E->designators()) { - if (D.isFieldDesignator() && D.getField()) { - const FieldDecl *Decl = D.getField(); - if (isInUSRSet(Decl)) { - auto StartLoc = D.getFieldLoc(); - auto EndLoc = D.getFieldLoc(); - RenameInfos.push_back({StartLoc, EndLoc, - /*FromDecl=*/nullptr, - /*Context=*/nullptr, - /*Specifier=*/nullptr, - /*IgnorePrefixQualifiers=*/true}); + if (D.isFieldDesignator()) { + if (const FieldDecl *Decl = D.getFieldDecl()) { + if (isInUSRSet(Decl)) { + auto StartLoc = D.getFieldLoc(); + auto EndLoc = D.getFieldLoc(); + RenameInfos.push_back({StartLoc, EndLoc, + /*FromDecl=*/nullptr, + /*Context=*/nullptr, + /*Specifier=*/nullptr, + /*IgnorePrefixQualifiers=*/true}); + } } } } diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -2857,7 +2857,7 @@ for (const DesignatedInitExpr::Designator &D : llvm::reverse(E->designators())) { if (D.isFieldDesignator()) { - if (FieldDecl *Field = D.getField()) + if (const FieldDecl *Field = D.getFieldDecl()) AddMemberRef(Field, D.getFieldLoc()); continue; }