-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[PATCH 2/6] [clang] Improve nested name specifier AST representation #148012
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: users/mizvekov/name-qualification-refactor
Are you sure you want to change the base?
[PATCH 2/6] [clang] Improve nested name specifier AST representation #148012
Conversation
@llvm/pr-subscribers-debuginfo @llvm/pr-subscribers-backend-webassembly Author: Matheus Izvekov (mizvekov) ChangesOther changes Second patch in the series starting at #147835 Patch is 800.27 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/148012.diff 173 Files Affected:
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index bae004896c11f..599155c5c9950 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -221,6 +221,19 @@ extern const internal::VariadicDynCastAllOfMatcher<Decl, TypedefNameDecl>
extern const internal::VariadicDynCastAllOfMatcher<Decl, TypeAliasDecl>
typeAliasDecl;
+/// \brief Matches shadow declarations introduced into a scope by a
+/// (resolved) using declaration.
+///
+/// Given
+/// \code
+/// namespace n { int f; }
+/// namespace declToImport { using n::f; }
+/// \endcode
+/// usingShadowDecl()
+/// matches \code f \endcode
+extern const internal::VariadicDynCastAllOfMatcher<Decl, UsingShadowDecl>
+ usingShadowDecl;
+
/// Matches type alias template declarations.
///
/// typeAliasTemplateDecl() matches
@@ -3718,7 +3731,7 @@ extern const internal::VariadicOperatorMatcherFunc<1, 1> unless;
/// Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>,
/// Matcher<TagType>, Matcher<TemplateSpecializationType>,
/// Matcher<TemplateTypeParmType>, Matcher<TypedefType>,
-/// Matcher<UnresolvedUsingType>
+/// Matcher<UnresolvedUsingType>, Matcher<UsingType>
inline internal::PolymorphicMatcher<
internal::HasDeclarationMatcher,
void(internal::HasDeclarationSupportedTypes), internal::Matcher<Decl>>
@@ -4353,7 +4366,13 @@ AST_POLYMORPHIC_MATCHER_P(throughUsingDecl,
AST_POLYMORPHIC_SUPPORTED_TYPES(DeclRefExpr,
UsingType),
internal::Matcher<UsingShadowDecl>, Inner) {
- const NamedDecl *FoundDecl = Node.getFoundDecl();
+ const NamedDecl *FoundDecl;
+ if constexpr (std::is_same_v<NodeType, UsingType>) {
+ FoundDecl = Node.getDecl();
+ } else {
+ static_assert(std::is_same_v<NodeType, DeclRefExpr>);
+ FoundDecl = Node.getFoundDecl();
+ }
if (const UsingShadowDecl *UsingDecl = dyn_cast<UsingShadowDecl>(FoundDecl))
return Inner.matches(*UsingDecl, Finder, Builder);
return false;
@@ -6982,37 +7001,6 @@ AST_POLYMORPHIC_MATCHER_P2(
InnerMatcher.matches(Args[Index], Finder, Builder);
}
-/// Matches C or C++ elaborated `TypeLoc`s.
-///
-/// Given
-/// \code
-/// struct s {};
-/// struct s ss;
-/// \endcode
-/// elaboratedTypeLoc()
-/// matches the `TypeLoc` of the variable declaration of `ss`.
-extern const internal::VariadicDynCastAllOfMatcher<TypeLoc, ElaboratedTypeLoc>
- elaboratedTypeLoc;
-
-/// Matches elaborated `TypeLoc`s that have a named `TypeLoc` matching
-/// `InnerMatcher`.
-///
-/// Given
-/// \code
-/// template <typename T>
-/// class C {};
-/// class C<int> c;
-///
-/// class D {};
-/// class D d;
-/// \endcode
-/// elaboratedTypeLoc(hasNamedTypeLoc(templateSpecializationTypeLoc()));
-/// matches the `TypeLoc` of the variable declaration of `c`, but not `d`.
-AST_MATCHER_P(ElaboratedTypeLoc, hasNamedTypeLoc, internal::Matcher<TypeLoc>,
- InnerMatcher) {
- return InnerMatcher.matches(Node.getNamedTypeLoc(), Finder, Builder);
-}
-
/// Matches type \c bool.
///
/// Given
@@ -7279,7 +7267,7 @@ extern const AstTypeMatcher<DecltypeType> decltypeType;
AST_TYPE_TRAVERSE_MATCHER(hasDeducedType, getDeducedType,
AST_POLYMORPHIC_SUPPORTED_TYPES(AutoType));
-/// Matches \c DecltypeType or \c UsingType nodes to find the underlying type.
+/// Matches \c QualType nodes to find the underlying type.
///
/// Given
/// \code
@@ -7289,10 +7277,13 @@ AST_TYPE_TRAVERSE_MATCHER(hasDeducedType, getDeducedType,
/// decltypeType(hasUnderlyingType(isInteger()))
/// matches the type of "a"
///
-/// Usable as: Matcher<DecltypeType>, Matcher<UsingType>
-AST_TYPE_TRAVERSE_MATCHER(hasUnderlyingType, getUnderlyingType,
- AST_POLYMORPHIC_SUPPORTED_TYPES(DecltypeType,
- UsingType));
+/// Usable as: Matcher<QualType>
+AST_MATCHER_P(Type, hasUnderlyingType, internal::Matcher<QualType>, Inner) {
+ QualType QT = Node.getLocallyUnqualifiedSingleStepDesugaredType();
+ if (QT == QualType(&Node, 0))
+ return false;
+ return Inner.matches(QT, Finder, Builder);
+}
/// Matches \c FunctionType nodes.
///
@@ -7571,27 +7562,7 @@ extern const AstTypeMatcher<RecordType> recordType;
/// and \c c.
extern const AstTypeMatcher<TagType> tagType;
-/// Matches types specified with an elaborated type keyword or with a
-/// qualified name.
-///
-/// Given
-/// \code
-/// namespace N {
-/// namespace M {
-/// class D {};
-/// }
-/// }
-/// class C {};
-///
-/// class C c;
-/// N::M::D d;
-/// \endcode
-///
-/// \c elaboratedType() matches the type of the variable declarations of both
-/// \c c and \c d.
-extern const AstTypeMatcher<ElaboratedType> elaboratedType;
-
-/// Matches ElaboratedTypes whose qualifier, a NestedNameSpecifier,
+/// Matches Types whose qualifier, a NestedNameSpecifier,
/// matches \c InnerMatcher if the qualifier exists.
///
/// Given
@@ -7606,34 +7577,14 @@ extern const AstTypeMatcher<ElaboratedType> elaboratedType;
///
/// \c elaboratedType(hasQualifier(hasPrefix(specifiesNamespace(hasName("N"))))
/// matches the type of the variable declaration of \c d.
-AST_MATCHER_P(ElaboratedType, hasQualifier,
- internal::Matcher<NestedNameSpecifier>, InnerMatcher) {
- if (const NestedNameSpecifier *Qualifier = Node.getQualifier())
- return InnerMatcher.matches(*Qualifier, Finder, Builder);
+AST_MATCHER_P(Type, hasQualifier, internal::Matcher<NestedNameSpecifier>,
+ InnerMatcher) {
+ if (NestedNameSpecifier Qualifier = Node.getPrefix())
+ return InnerMatcher.matches(Qualifier, Finder, Builder);
return false;
}
-/// Matches ElaboratedTypes whose named type matches \c InnerMatcher.
-///
-/// Given
-/// \code
-/// namespace N {
-/// namespace M {
-/// class D {};
-/// }
-/// }
-/// N::M::D d;
-/// \endcode
-///
-/// \c elaboratedType(namesType(recordType(
-/// hasDeclaration(namedDecl(hasName("D")))))) matches the type of the variable
-/// declaration of \c d.
-AST_MATCHER_P(ElaboratedType, namesType, internal::Matcher<QualType>,
- InnerMatcher) {
- return InnerMatcher.matches(Node.getNamedType(), Finder, Builder);
-}
-
/// Matches types specified through a using declaration.
///
/// Given
@@ -7802,7 +7753,7 @@ AST_MATCHER_FUNCTION_P_OVERLOAD(
/// matches "A::"
AST_MATCHER_P(NestedNameSpecifier, specifiesType,
internal::Matcher<QualType>, InnerMatcher) {
- if (!Node.getAsType())
+ if (Node.getKind() != NestedNameSpecifier::Kind::Type)
return false;
return InnerMatcher.matches(QualType(Node.getAsType(), 0), Finder, Builder);
}
@@ -7820,8 +7771,12 @@ AST_MATCHER_P(NestedNameSpecifier, specifiesType,
/// matches "A::"
AST_MATCHER_P(NestedNameSpecifierLoc, specifiesTypeLoc,
internal::Matcher<TypeLoc>, InnerMatcher) {
- return Node && Node.getNestedNameSpecifier()->getAsType() &&
- InnerMatcher.matches(Node.getTypeLoc(), Finder, Builder);
+ if (!Node)
+ return false;
+ TypeLoc TL = Node.getAsTypeLoc();
+ if (!TL)
+ return false;
+ return InnerMatcher.matches(TL, Finder, Builder);
}
/// Matches on the prefix of a \c NestedNameSpecifier.
@@ -7836,10 +7791,21 @@ AST_MATCHER_P(NestedNameSpecifierLoc, specifiesTypeLoc,
AST_MATCHER_P_OVERLOAD(NestedNameSpecifier, hasPrefix,
internal::Matcher<NestedNameSpecifier>, InnerMatcher,
0) {
- const NestedNameSpecifier *NextNode = Node.getPrefix();
+ NestedNameSpecifier NextNode = std::nullopt;
+ switch (Node.getKind()) {
+ case NestedNameSpecifier::Kind::Namespace:
+ NextNode = Node.getAsNamespaceAndPrefix().Prefix;
+ break;
+ case NestedNameSpecifier::Kind::Type:
+ NextNode = Node.getAsType()->getPrefix();
+ break;
+ default:
+ break;
+ }
+
if (!NextNode)
return false;
- return InnerMatcher.matches(*NextNode, Finder, Builder);
+ return InnerMatcher.matches(NextNode, Finder, Builder);
}
/// Matches on the prefix of a \c NestedNameSpecifierLoc.
@@ -7854,7 +7820,12 @@ AST_MATCHER_P_OVERLOAD(NestedNameSpecifier, hasPrefix,
AST_MATCHER_P_OVERLOAD(NestedNameSpecifierLoc, hasPrefix,
internal::Matcher<NestedNameSpecifierLoc>, InnerMatcher,
1) {
- NestedNameSpecifierLoc NextNode = Node.getPrefix();
+ NestedNameSpecifierLoc NextNode;
+ if (TypeLoc TL = Node.getAsTypeLoc())
+ NextNode = TL.getPrefix();
+ else
+ NextNode = Node.getAsNamespaceAndPrefix().Prefix;
+
if (!NextNode)
return false;
return InnerMatcher.matches(NextNode, Finder, Builder);
@@ -7872,9 +7843,13 @@ AST_MATCHER_P_OVERLOAD(NestedNameSpecifierLoc, hasPrefix,
/// matches "ns::"
AST_MATCHER_P(NestedNameSpecifier, specifiesNamespace,
internal::Matcher<NamespaceDecl>, InnerMatcher) {
- if (!Node.getAsNamespace())
+ if (Node.getKind() != NestedNameSpecifier::Kind::Namespace)
+ return false;
+ const auto *Namespace =
+ dyn_cast<NamespaceDecl>(Node.getAsNamespaceAndPrefix().Namespace);
+ if (!Namespace)
return false;
- return InnerMatcher.matches(*Node.getAsNamespace(), Finder, Builder);
+ return InnerMatcher.matches(*Namespace, Finder, Builder);
}
/// Matches attributes.
diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
index 667a044abcef1..399af3d888551 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -1013,10 +1013,7 @@ class HasDeclarationMatcher : public MatcherInterface<T> {
// First, for any types that have a declaration, extract the declaration and
// match on it.
if (const auto *S = dyn_cast<TagType>(&Node)) {
- return matchesDecl(S->getDecl(), Finder, Builder);
- }
- if (const auto *S = dyn_cast<InjectedClassNameType>(&Node)) {
- return matchesDecl(S->getDecl(), Finder, Builder);
+ return matchesDecl(S->getOriginalDecl(), Finder, Builder);
}
if (const auto *S = dyn_cast<TemplateTypeParmType>(&Node)) {
return matchesDecl(S->getDecl(), Finder, Builder);
@@ -1027,6 +1024,9 @@ class HasDeclarationMatcher : public MatcherInterface<T> {
if (const auto *S = dyn_cast<UnresolvedUsingType>(&Node)) {
return matchesDecl(S->getDecl(), Finder, Builder);
}
+ if (const auto *S = dyn_cast<UsingType>(&Node)) {
+ return matchesDecl(S->getDecl(), Finder, Builder);
+ }
if (const auto *S = dyn_cast<ObjCObjectType>(&Node)) {
return matchesDecl(S->getInterface(), Finder, Builder);
}
@@ -1062,12 +1062,6 @@ class HasDeclarationMatcher : public MatcherInterface<T> {
Builder);
}
- // FIXME: We desugar elaborated types. This makes the assumption that users
- // do never want to match on whether a type is elaborated - there are
- // arguments for both sides; for now, continue desugaring.
- if (const auto *S = dyn_cast<ElaboratedType>(&Node)) {
- return matchesSpecialized(S->desugar(), Finder, Builder);
- }
// Similarly types found via using declarations.
// These are *usually* meaningless sugar, and this matches the historical
// behavior prior to the introduction of UsingType.
@@ -1207,8 +1201,8 @@ using AdaptativeDefaultToTypes =
/// All types that are supported by HasDeclarationMatcher above.
using HasDeclarationSupportedTypes =
TypeList<CallExpr, CXXConstructExpr, CXXNewExpr, DeclRefExpr, EnumType,
- ElaboratedType, InjectedClassNameType, LabelStmt, AddrLabelExpr,
- MemberExpr, QualType, RecordType, TagType,
+ InjectedClassNameType, LabelStmt, AddrLabelExpr, MemberExpr,
+ QualType, RecordType, TagType, UsingType,
TemplateSpecializationType, TemplateTypeParmType, TypedefType,
UnresolvedUsingType, ObjCIvarRefExpr, ObjCInterfaceDecl>;
@@ -1785,7 +1779,7 @@ class LocMatcher : public MatcherInterface<TLoc> {
private:
static DynTypedNode extract(const NestedNameSpecifierLoc &Loc) {
- return DynTypedNode::create(*Loc.getNestedNameSpecifier());
+ return DynTypedNode::create(Loc.getNestedNameSpecifier());
}
};
diff --git a/clang/include/clang/Analysis/FlowSensitive/ASTOps.h b/clang/include/clang/Analysis/FlowSensitive/ASTOps.h
index 8c7ee86d15c06..a404b06cd62ca 100644
--- a/clang/include/clang/Analysis/FlowSensitive/ASTOps.h
+++ b/clang/include/clang/Analysis/FlowSensitive/ASTOps.h
@@ -112,8 +112,14 @@ class AnalysisASTVisitor : public DynamicRecursiveASTVisitor {
// fields that are only used in these.
// Note: The operand of the `noexcept` operator is an unevaluated operand, but
// nevertheless it appears in the Clang CFG, so we don't exclude it here.
- bool TraverseDecltypeTypeLoc(DecltypeTypeLoc) override { return true; }
- bool TraverseTypeOfExprTypeLoc(TypeOfExprTypeLoc) override { return true; }
+ bool TraverseDecltypeTypeLoc(DecltypeTypeLoc,
+ bool TraverseQualifier) override {
+ return true;
+ }
+ bool TraverseTypeOfExprTypeLoc(TypeOfExprTypeLoc,
+ bool TraverseQualifier) override {
+ return true;
+ }
bool TraverseCXXTypeidExpr(CXXTypeidExpr *TIE) override {
if (TIE->isPotentiallyEvaluated())
return DynamicRecursiveASTVisitor::TraverseCXXTypeidExpr(TIE);
diff --git a/clang/include/clang/Basic/DeclNodes.td b/clang/include/clang/Basic/DeclNodes.td
index f1ebaf1db3fc0..b4c02949426a1 100644
--- a/clang/include/clang/Basic/DeclNodes.td
+++ b/clang/include/clang/Basic/DeclNodes.td
@@ -15,81 +15,80 @@ def PragmaComment : DeclNode<Decl>;
def PragmaDetectMismatch : DeclNode<Decl>;
def ExternCContext : DeclNode<Decl>, DeclContext;
def Named : DeclNode<Decl, "named declarations", 1>;
- def Namespace : DeclNode<Named, "namespaces">, DeclContext;
- def UsingDirective : DeclNode<Named>;
- def NamespaceAlias : DeclNode<Named>;
- def Label : DeclNode<Named, "labels">;
- def Type : DeclNode<Named, "types", 1>;
- def TypedefName : DeclNode<Type, "typedefs", 1>;
- def Typedef : DeclNode<TypedefName>;
- def TypeAlias : DeclNode<TypedefName>;
- def ObjCTypeParam : DeclNode<TypedefName>;
- def UnresolvedUsingTypename : DeclNode<Type>;
- def Tag : DeclNode<Type, "tag types", 1>, DeclContext;
- def Enum : DeclNode<Tag, "enums">;
- def Record : DeclNode<Tag, "structs, unions, classes">;
- def CXXRecord : DeclNode<Record, "classes">;
- def ClassTemplateSpecialization : DeclNode<CXXRecord>;
- def ClassTemplatePartialSpecialization
- : DeclNode<ClassTemplateSpecialization>;
- def TemplateTypeParm : DeclNode<Type>;
- def Value : DeclNode<Named, "value declarations", 1>;
- def EnumConstant : DeclNode<Value, "enumerators">;
- def UnresolvedUsingValue : DeclNode<Value>;
- def IndirectField : DeclNode<Value>;
- def Binding : DeclNode<Value>;
- def OMPDeclareReduction : DeclNode<Value>, DeclContext;
- def OMPDeclareMapper : DeclNode<Value>, DeclContext;
- def MSGuid : DeclNode<Value>;
- def UnnamedGlobalConstant : DeclNode<Value>;
- def TemplateParamObject : DeclNode<Value>;
- def Declarator : DeclNode<Value, "declarators", 1>;
- def Field : DeclNode<Declarator, "non-static data members">;
- def ObjCIvar : DeclNode<Field>;
- def ObjCAtDefsField : DeclNode<Field>;
- def MSProperty : DeclNode<Declarator>;
- def Function : DeclNode<Declarator, "functions">, DeclContext;
- def CXXDeductionGuide : DeclNode<Function>;
- def CXXMethod : DeclNode<Function>;
- def CXXConstructor : DeclNode<CXXMethod>;
- def CXXDestructor : DeclNode<CXXMethod>;
- def CXXConversion : DeclNode<CXXMethod>;
- def Var : DeclNode<Declarator, "variables">;
- def VarTemplateSpecialization : DeclNode<Var>;
- def VarTemplatePartialSpecialization
- : DeclNode<VarTemplateSpecialization>;
- def ImplicitParam : DeclNode<Var>;
- def ParmVar : DeclNode<Var, "parameters">;
- def Decomposition : DeclNode<Var>;
- def OMPCapturedExpr : DeclNode<Var>;
- def NonTypeTemplateParm : DeclNode<Declarator>;
- def Template : DeclNode<Named, "templates", 1>;
- def RedeclarableTemplate : DeclNode<Template, "redeclarable templates", 1>;
- def FunctionTemplate : DeclNode<RedeclarableTemplate>;
- def ClassTemplate : DeclNode<RedeclarableTemplate>;
- def VarTemplate : DeclNode<RedeclarableTemplate>;
- def TypeAliasTemplate : DeclNode<RedeclarableTemplate>;
- def TemplateTemplateParm : DeclNode<Template>;
- def BuiltinTemplate : DeclNode<Template>;
- def Concept : DeclNode<Template>;
- def BaseUsing : DeclNode<Named, "", 1>;
- def Using : DeclNode<BaseUsing>;
- def UsingEnum : DeclNode<BaseUsing>;
- def UsingPack : DeclNode<Named>;
- def UsingShadow : DeclNode<Named>;
- def ConstructorUsingShadow : DeclNode<UsingShadow>;
- def UnresolvedUsingIfExists : DeclNode<Named>;
- def ObjCMethod : DeclNode<Named, "Objective-C methods">, DeclContext;
- def ObjCContainer : DeclNode<Named, "Objective-C containers", 1>, DeclContext;
- def ObjCCategory : DeclNode<ObjCContainer>;
- def ObjCProtocol : DeclNode<ObjCContainer, "Objective-C protocols">;
- def ObjCInterface : DeclNode<ObjCContainer, "Objective-C interfaces">;
- def ObjCImpl
- : DeclNode<ObjCContainer, "Objective-C implementation declarations", 1>;
- def ObjCCategoryImpl : DeclNode<ObjCImpl>;
- def ObjCImplementation : DeclNode<ObjCImpl>;
- def ObjCProperty : DeclNode<Named, "Objective-C properties">;
- def ObjCCompatibleAlias : DeclNode<Named>;
+def NamespaceBase : DeclNode<Named, "namespace declarations", 1>;
+def Namespace : DeclNode<NamespaceBase, "namespaces">, DeclContext;
+def NamespaceAlias : DeclNode<NamespaceBase>;
+def UsingDirective : DeclNode<Named>;
+def Label : DeclNode<Named, "labels">;
+def Type : DeclNode<Named, "types", 1>;
+def TypedefName : DeclNode<Type, "typedefs", 1>;
+def Typedef : DeclNode<TypedefName>;
+def TypeAlias : DeclNode<TypedefName>;
+def ObjCTypeParam : DeclNode<TypedefName>;
+def UnresolvedUsingTypename : DeclNode<Type>;
+def Tag : DeclNode<Type, "tag types", 1>, DeclContext;
+def Enum : DeclNode<Tag, "enums">;
+def Record : DeclNode<Tag, "structs, unions, classes">;
+def CXXRecord : DeclNode<Record, "classes">;
+def ClassTemplateSpecialization : DeclNode<CXXRecord>;
+def ClassTemplatePartialSpecialization : DeclNode<ClassTemplateSpecialization>;
+def TemplateTypeParm : DeclNode<Type>;
+def Value : DeclNode<Named, "value declarations", 1>;
+def EnumConstant : DeclNode<Value, "enumerators">;
+def UnresolvedUsingValue : DeclNode<Value>;
+def IndirectField : DeclNode<Value>;
+def Binding : DeclNode<Value>;
+def OMPDeclareReduction : DeclNode<Value>, DeclContext;
+def OMPDeclareMapper : DeclNode<Value>, DeclContext;
+def MSGuid : DeclNode<Value>;
+def UnnamedGlobalConstant : DeclNode<Value>;
+def TemplateParamObject : DeclNode<Value>;
+def Declarator : DeclNode<Value, "declarators", 1>;
+def Field : DeclNode<Declarator, "non-static data members">;
+def ObjCIvar : DeclNode<Field>;
+def ObjCAtDefsField : DeclNode<Field>;
+def MSProperty : DeclNode<Declarator>;
+def Function : DeclNode<Declarator, "functions">, DeclContext;
+def CXXDeductionGuide : DeclNode<Function>;
+def CXXMethod : DeclNode<Function>;
+def CXXConstructor : DeclNode<CXXMethod>;
+def CXXDestructor : DeclNode<CXXMethod>;
+def CXXConversion : DeclNode<CXXMethod>;
+def Var : DeclNode<Declarator, "variables">;
+def VarTemplateSpecialization : DeclNode<Var>;
+def VarTemplatePartialSpecialization : DeclNode<VarTemplateSpecialization>;
+def ImplicitParam : DeclNode<Var>;
+def ParmVar : DeclNode<Var, "parameters">;
+def Decomposition : DeclNode<Var>;
+def OMPCapturedExpr : DeclNode<Var>;
+def NonTypeTemplateParm : DeclNode<Declarator>;
+def Template : DeclNode<Named, "templates", 1>;
+def RedeclarableTemplate : DeclNode<Template, "redeclarable templates", 1>;
+def FunctionTemplate : DeclNode<RedeclarableTemplate>;
+def ClassTemplate : DeclNode<RedeclarableTemplate>;
+def VarTemplate : DeclNode<R...
[truncated]
|
@llvm/pr-subscribers-clang-codegen Author: Matheus Izvekov (mizvekov) ChangesOther changes Second patch in the series starting at #147835 Patch is 800.27 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/148012.diff 173 Files Affected:
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index bae004896c11f..599155c5c9950 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -221,6 +221,19 @@ extern const internal::VariadicDynCastAllOfMatcher<Decl, TypedefNameDecl>
extern const internal::VariadicDynCastAllOfMatcher<Decl, TypeAliasDecl>
typeAliasDecl;
+/// \brief Matches shadow declarations introduced into a scope by a
+/// (resolved) using declaration.
+///
+/// Given
+/// \code
+/// namespace n { int f; }
+/// namespace declToImport { using n::f; }
+/// \endcode
+/// usingShadowDecl()
+/// matches \code f \endcode
+extern const internal::VariadicDynCastAllOfMatcher<Decl, UsingShadowDecl>
+ usingShadowDecl;
+
/// Matches type alias template declarations.
///
/// typeAliasTemplateDecl() matches
@@ -3718,7 +3731,7 @@ extern const internal::VariadicOperatorMatcherFunc<1, 1> unless;
/// Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>,
/// Matcher<TagType>, Matcher<TemplateSpecializationType>,
/// Matcher<TemplateTypeParmType>, Matcher<TypedefType>,
-/// Matcher<UnresolvedUsingType>
+/// Matcher<UnresolvedUsingType>, Matcher<UsingType>
inline internal::PolymorphicMatcher<
internal::HasDeclarationMatcher,
void(internal::HasDeclarationSupportedTypes), internal::Matcher<Decl>>
@@ -4353,7 +4366,13 @@ AST_POLYMORPHIC_MATCHER_P(throughUsingDecl,
AST_POLYMORPHIC_SUPPORTED_TYPES(DeclRefExpr,
UsingType),
internal::Matcher<UsingShadowDecl>, Inner) {
- const NamedDecl *FoundDecl = Node.getFoundDecl();
+ const NamedDecl *FoundDecl;
+ if constexpr (std::is_same_v<NodeType, UsingType>) {
+ FoundDecl = Node.getDecl();
+ } else {
+ static_assert(std::is_same_v<NodeType, DeclRefExpr>);
+ FoundDecl = Node.getFoundDecl();
+ }
if (const UsingShadowDecl *UsingDecl = dyn_cast<UsingShadowDecl>(FoundDecl))
return Inner.matches(*UsingDecl, Finder, Builder);
return false;
@@ -6982,37 +7001,6 @@ AST_POLYMORPHIC_MATCHER_P2(
InnerMatcher.matches(Args[Index], Finder, Builder);
}
-/// Matches C or C++ elaborated `TypeLoc`s.
-///
-/// Given
-/// \code
-/// struct s {};
-/// struct s ss;
-/// \endcode
-/// elaboratedTypeLoc()
-/// matches the `TypeLoc` of the variable declaration of `ss`.
-extern const internal::VariadicDynCastAllOfMatcher<TypeLoc, ElaboratedTypeLoc>
- elaboratedTypeLoc;
-
-/// Matches elaborated `TypeLoc`s that have a named `TypeLoc` matching
-/// `InnerMatcher`.
-///
-/// Given
-/// \code
-/// template <typename T>
-/// class C {};
-/// class C<int> c;
-///
-/// class D {};
-/// class D d;
-/// \endcode
-/// elaboratedTypeLoc(hasNamedTypeLoc(templateSpecializationTypeLoc()));
-/// matches the `TypeLoc` of the variable declaration of `c`, but not `d`.
-AST_MATCHER_P(ElaboratedTypeLoc, hasNamedTypeLoc, internal::Matcher<TypeLoc>,
- InnerMatcher) {
- return InnerMatcher.matches(Node.getNamedTypeLoc(), Finder, Builder);
-}
-
/// Matches type \c bool.
///
/// Given
@@ -7279,7 +7267,7 @@ extern const AstTypeMatcher<DecltypeType> decltypeType;
AST_TYPE_TRAVERSE_MATCHER(hasDeducedType, getDeducedType,
AST_POLYMORPHIC_SUPPORTED_TYPES(AutoType));
-/// Matches \c DecltypeType or \c UsingType nodes to find the underlying type.
+/// Matches \c QualType nodes to find the underlying type.
///
/// Given
/// \code
@@ -7289,10 +7277,13 @@ AST_TYPE_TRAVERSE_MATCHER(hasDeducedType, getDeducedType,
/// decltypeType(hasUnderlyingType(isInteger()))
/// matches the type of "a"
///
-/// Usable as: Matcher<DecltypeType>, Matcher<UsingType>
-AST_TYPE_TRAVERSE_MATCHER(hasUnderlyingType, getUnderlyingType,
- AST_POLYMORPHIC_SUPPORTED_TYPES(DecltypeType,
- UsingType));
+/// Usable as: Matcher<QualType>
+AST_MATCHER_P(Type, hasUnderlyingType, internal::Matcher<QualType>, Inner) {
+ QualType QT = Node.getLocallyUnqualifiedSingleStepDesugaredType();
+ if (QT == QualType(&Node, 0))
+ return false;
+ return Inner.matches(QT, Finder, Builder);
+}
/// Matches \c FunctionType nodes.
///
@@ -7571,27 +7562,7 @@ extern const AstTypeMatcher<RecordType> recordType;
/// and \c c.
extern const AstTypeMatcher<TagType> tagType;
-/// Matches types specified with an elaborated type keyword or with a
-/// qualified name.
-///
-/// Given
-/// \code
-/// namespace N {
-/// namespace M {
-/// class D {};
-/// }
-/// }
-/// class C {};
-///
-/// class C c;
-/// N::M::D d;
-/// \endcode
-///
-/// \c elaboratedType() matches the type of the variable declarations of both
-/// \c c and \c d.
-extern const AstTypeMatcher<ElaboratedType> elaboratedType;
-
-/// Matches ElaboratedTypes whose qualifier, a NestedNameSpecifier,
+/// Matches Types whose qualifier, a NestedNameSpecifier,
/// matches \c InnerMatcher if the qualifier exists.
///
/// Given
@@ -7606,34 +7577,14 @@ extern const AstTypeMatcher<ElaboratedType> elaboratedType;
///
/// \c elaboratedType(hasQualifier(hasPrefix(specifiesNamespace(hasName("N"))))
/// matches the type of the variable declaration of \c d.
-AST_MATCHER_P(ElaboratedType, hasQualifier,
- internal::Matcher<NestedNameSpecifier>, InnerMatcher) {
- if (const NestedNameSpecifier *Qualifier = Node.getQualifier())
- return InnerMatcher.matches(*Qualifier, Finder, Builder);
+AST_MATCHER_P(Type, hasQualifier, internal::Matcher<NestedNameSpecifier>,
+ InnerMatcher) {
+ if (NestedNameSpecifier Qualifier = Node.getPrefix())
+ return InnerMatcher.matches(Qualifier, Finder, Builder);
return false;
}
-/// Matches ElaboratedTypes whose named type matches \c InnerMatcher.
-///
-/// Given
-/// \code
-/// namespace N {
-/// namespace M {
-/// class D {};
-/// }
-/// }
-/// N::M::D d;
-/// \endcode
-///
-/// \c elaboratedType(namesType(recordType(
-/// hasDeclaration(namedDecl(hasName("D")))))) matches the type of the variable
-/// declaration of \c d.
-AST_MATCHER_P(ElaboratedType, namesType, internal::Matcher<QualType>,
- InnerMatcher) {
- return InnerMatcher.matches(Node.getNamedType(), Finder, Builder);
-}
-
/// Matches types specified through a using declaration.
///
/// Given
@@ -7802,7 +7753,7 @@ AST_MATCHER_FUNCTION_P_OVERLOAD(
/// matches "A::"
AST_MATCHER_P(NestedNameSpecifier, specifiesType,
internal::Matcher<QualType>, InnerMatcher) {
- if (!Node.getAsType())
+ if (Node.getKind() != NestedNameSpecifier::Kind::Type)
return false;
return InnerMatcher.matches(QualType(Node.getAsType(), 0), Finder, Builder);
}
@@ -7820,8 +7771,12 @@ AST_MATCHER_P(NestedNameSpecifier, specifiesType,
/// matches "A::"
AST_MATCHER_P(NestedNameSpecifierLoc, specifiesTypeLoc,
internal::Matcher<TypeLoc>, InnerMatcher) {
- return Node && Node.getNestedNameSpecifier()->getAsType() &&
- InnerMatcher.matches(Node.getTypeLoc(), Finder, Builder);
+ if (!Node)
+ return false;
+ TypeLoc TL = Node.getAsTypeLoc();
+ if (!TL)
+ return false;
+ return InnerMatcher.matches(TL, Finder, Builder);
}
/// Matches on the prefix of a \c NestedNameSpecifier.
@@ -7836,10 +7791,21 @@ AST_MATCHER_P(NestedNameSpecifierLoc, specifiesTypeLoc,
AST_MATCHER_P_OVERLOAD(NestedNameSpecifier, hasPrefix,
internal::Matcher<NestedNameSpecifier>, InnerMatcher,
0) {
- const NestedNameSpecifier *NextNode = Node.getPrefix();
+ NestedNameSpecifier NextNode = std::nullopt;
+ switch (Node.getKind()) {
+ case NestedNameSpecifier::Kind::Namespace:
+ NextNode = Node.getAsNamespaceAndPrefix().Prefix;
+ break;
+ case NestedNameSpecifier::Kind::Type:
+ NextNode = Node.getAsType()->getPrefix();
+ break;
+ default:
+ break;
+ }
+
if (!NextNode)
return false;
- return InnerMatcher.matches(*NextNode, Finder, Builder);
+ return InnerMatcher.matches(NextNode, Finder, Builder);
}
/// Matches on the prefix of a \c NestedNameSpecifierLoc.
@@ -7854,7 +7820,12 @@ AST_MATCHER_P_OVERLOAD(NestedNameSpecifier, hasPrefix,
AST_MATCHER_P_OVERLOAD(NestedNameSpecifierLoc, hasPrefix,
internal::Matcher<NestedNameSpecifierLoc>, InnerMatcher,
1) {
- NestedNameSpecifierLoc NextNode = Node.getPrefix();
+ NestedNameSpecifierLoc NextNode;
+ if (TypeLoc TL = Node.getAsTypeLoc())
+ NextNode = TL.getPrefix();
+ else
+ NextNode = Node.getAsNamespaceAndPrefix().Prefix;
+
if (!NextNode)
return false;
return InnerMatcher.matches(NextNode, Finder, Builder);
@@ -7872,9 +7843,13 @@ AST_MATCHER_P_OVERLOAD(NestedNameSpecifierLoc, hasPrefix,
/// matches "ns::"
AST_MATCHER_P(NestedNameSpecifier, specifiesNamespace,
internal::Matcher<NamespaceDecl>, InnerMatcher) {
- if (!Node.getAsNamespace())
+ if (Node.getKind() != NestedNameSpecifier::Kind::Namespace)
+ return false;
+ const auto *Namespace =
+ dyn_cast<NamespaceDecl>(Node.getAsNamespaceAndPrefix().Namespace);
+ if (!Namespace)
return false;
- return InnerMatcher.matches(*Node.getAsNamespace(), Finder, Builder);
+ return InnerMatcher.matches(*Namespace, Finder, Builder);
}
/// Matches attributes.
diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
index 667a044abcef1..399af3d888551 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -1013,10 +1013,7 @@ class HasDeclarationMatcher : public MatcherInterface<T> {
// First, for any types that have a declaration, extract the declaration and
// match on it.
if (const auto *S = dyn_cast<TagType>(&Node)) {
- return matchesDecl(S->getDecl(), Finder, Builder);
- }
- if (const auto *S = dyn_cast<InjectedClassNameType>(&Node)) {
- return matchesDecl(S->getDecl(), Finder, Builder);
+ return matchesDecl(S->getOriginalDecl(), Finder, Builder);
}
if (const auto *S = dyn_cast<TemplateTypeParmType>(&Node)) {
return matchesDecl(S->getDecl(), Finder, Builder);
@@ -1027,6 +1024,9 @@ class HasDeclarationMatcher : public MatcherInterface<T> {
if (const auto *S = dyn_cast<UnresolvedUsingType>(&Node)) {
return matchesDecl(S->getDecl(), Finder, Builder);
}
+ if (const auto *S = dyn_cast<UsingType>(&Node)) {
+ return matchesDecl(S->getDecl(), Finder, Builder);
+ }
if (const auto *S = dyn_cast<ObjCObjectType>(&Node)) {
return matchesDecl(S->getInterface(), Finder, Builder);
}
@@ -1062,12 +1062,6 @@ class HasDeclarationMatcher : public MatcherInterface<T> {
Builder);
}
- // FIXME: We desugar elaborated types. This makes the assumption that users
- // do never want to match on whether a type is elaborated - there are
- // arguments for both sides; for now, continue desugaring.
- if (const auto *S = dyn_cast<ElaboratedType>(&Node)) {
- return matchesSpecialized(S->desugar(), Finder, Builder);
- }
// Similarly types found via using declarations.
// These are *usually* meaningless sugar, and this matches the historical
// behavior prior to the introduction of UsingType.
@@ -1207,8 +1201,8 @@ using AdaptativeDefaultToTypes =
/// All types that are supported by HasDeclarationMatcher above.
using HasDeclarationSupportedTypes =
TypeList<CallExpr, CXXConstructExpr, CXXNewExpr, DeclRefExpr, EnumType,
- ElaboratedType, InjectedClassNameType, LabelStmt, AddrLabelExpr,
- MemberExpr, QualType, RecordType, TagType,
+ InjectedClassNameType, LabelStmt, AddrLabelExpr, MemberExpr,
+ QualType, RecordType, TagType, UsingType,
TemplateSpecializationType, TemplateTypeParmType, TypedefType,
UnresolvedUsingType, ObjCIvarRefExpr, ObjCInterfaceDecl>;
@@ -1785,7 +1779,7 @@ class LocMatcher : public MatcherInterface<TLoc> {
private:
static DynTypedNode extract(const NestedNameSpecifierLoc &Loc) {
- return DynTypedNode::create(*Loc.getNestedNameSpecifier());
+ return DynTypedNode::create(Loc.getNestedNameSpecifier());
}
};
diff --git a/clang/include/clang/Analysis/FlowSensitive/ASTOps.h b/clang/include/clang/Analysis/FlowSensitive/ASTOps.h
index 8c7ee86d15c06..a404b06cd62ca 100644
--- a/clang/include/clang/Analysis/FlowSensitive/ASTOps.h
+++ b/clang/include/clang/Analysis/FlowSensitive/ASTOps.h
@@ -112,8 +112,14 @@ class AnalysisASTVisitor : public DynamicRecursiveASTVisitor {
// fields that are only used in these.
// Note: The operand of the `noexcept` operator is an unevaluated operand, but
// nevertheless it appears in the Clang CFG, so we don't exclude it here.
- bool TraverseDecltypeTypeLoc(DecltypeTypeLoc) override { return true; }
- bool TraverseTypeOfExprTypeLoc(TypeOfExprTypeLoc) override { return true; }
+ bool TraverseDecltypeTypeLoc(DecltypeTypeLoc,
+ bool TraverseQualifier) override {
+ return true;
+ }
+ bool TraverseTypeOfExprTypeLoc(TypeOfExprTypeLoc,
+ bool TraverseQualifier) override {
+ return true;
+ }
bool TraverseCXXTypeidExpr(CXXTypeidExpr *TIE) override {
if (TIE->isPotentiallyEvaluated())
return DynamicRecursiveASTVisitor::TraverseCXXTypeidExpr(TIE);
diff --git a/clang/include/clang/Basic/DeclNodes.td b/clang/include/clang/Basic/DeclNodes.td
index f1ebaf1db3fc0..b4c02949426a1 100644
--- a/clang/include/clang/Basic/DeclNodes.td
+++ b/clang/include/clang/Basic/DeclNodes.td
@@ -15,81 +15,80 @@ def PragmaComment : DeclNode<Decl>;
def PragmaDetectMismatch : DeclNode<Decl>;
def ExternCContext : DeclNode<Decl>, DeclContext;
def Named : DeclNode<Decl, "named declarations", 1>;
- def Namespace : DeclNode<Named, "namespaces">, DeclContext;
- def UsingDirective : DeclNode<Named>;
- def NamespaceAlias : DeclNode<Named>;
- def Label : DeclNode<Named, "labels">;
- def Type : DeclNode<Named, "types", 1>;
- def TypedefName : DeclNode<Type, "typedefs", 1>;
- def Typedef : DeclNode<TypedefName>;
- def TypeAlias : DeclNode<TypedefName>;
- def ObjCTypeParam : DeclNode<TypedefName>;
- def UnresolvedUsingTypename : DeclNode<Type>;
- def Tag : DeclNode<Type, "tag types", 1>, DeclContext;
- def Enum : DeclNode<Tag, "enums">;
- def Record : DeclNode<Tag, "structs, unions, classes">;
- def CXXRecord : DeclNode<Record, "classes">;
- def ClassTemplateSpecialization : DeclNode<CXXRecord>;
- def ClassTemplatePartialSpecialization
- : DeclNode<ClassTemplateSpecialization>;
- def TemplateTypeParm : DeclNode<Type>;
- def Value : DeclNode<Named, "value declarations", 1>;
- def EnumConstant : DeclNode<Value, "enumerators">;
- def UnresolvedUsingValue : DeclNode<Value>;
- def IndirectField : DeclNode<Value>;
- def Binding : DeclNode<Value>;
- def OMPDeclareReduction : DeclNode<Value>, DeclContext;
- def OMPDeclareMapper : DeclNode<Value>, DeclContext;
- def MSGuid : DeclNode<Value>;
- def UnnamedGlobalConstant : DeclNode<Value>;
- def TemplateParamObject : DeclNode<Value>;
- def Declarator : DeclNode<Value, "declarators", 1>;
- def Field : DeclNode<Declarator, "non-static data members">;
- def ObjCIvar : DeclNode<Field>;
- def ObjCAtDefsField : DeclNode<Field>;
- def MSProperty : DeclNode<Declarator>;
- def Function : DeclNode<Declarator, "functions">, DeclContext;
- def CXXDeductionGuide : DeclNode<Function>;
- def CXXMethod : DeclNode<Function>;
- def CXXConstructor : DeclNode<CXXMethod>;
- def CXXDestructor : DeclNode<CXXMethod>;
- def CXXConversion : DeclNode<CXXMethod>;
- def Var : DeclNode<Declarator, "variables">;
- def VarTemplateSpecialization : DeclNode<Var>;
- def VarTemplatePartialSpecialization
- : DeclNode<VarTemplateSpecialization>;
- def ImplicitParam : DeclNode<Var>;
- def ParmVar : DeclNode<Var, "parameters">;
- def Decomposition : DeclNode<Var>;
- def OMPCapturedExpr : DeclNode<Var>;
- def NonTypeTemplateParm : DeclNode<Declarator>;
- def Template : DeclNode<Named, "templates", 1>;
- def RedeclarableTemplate : DeclNode<Template, "redeclarable templates", 1>;
- def FunctionTemplate : DeclNode<RedeclarableTemplate>;
- def ClassTemplate : DeclNode<RedeclarableTemplate>;
- def VarTemplate : DeclNode<RedeclarableTemplate>;
- def TypeAliasTemplate : DeclNode<RedeclarableTemplate>;
- def TemplateTemplateParm : DeclNode<Template>;
- def BuiltinTemplate : DeclNode<Template>;
- def Concept : DeclNode<Template>;
- def BaseUsing : DeclNode<Named, "", 1>;
- def Using : DeclNode<BaseUsing>;
- def UsingEnum : DeclNode<BaseUsing>;
- def UsingPack : DeclNode<Named>;
- def UsingShadow : DeclNode<Named>;
- def ConstructorUsingShadow : DeclNode<UsingShadow>;
- def UnresolvedUsingIfExists : DeclNode<Named>;
- def ObjCMethod : DeclNode<Named, "Objective-C methods">, DeclContext;
- def ObjCContainer : DeclNode<Named, "Objective-C containers", 1>, DeclContext;
- def ObjCCategory : DeclNode<ObjCContainer>;
- def ObjCProtocol : DeclNode<ObjCContainer, "Objective-C protocols">;
- def ObjCInterface : DeclNode<ObjCContainer, "Objective-C interfaces">;
- def ObjCImpl
- : DeclNode<ObjCContainer, "Objective-C implementation declarations", 1>;
- def ObjCCategoryImpl : DeclNode<ObjCImpl>;
- def ObjCImplementation : DeclNode<ObjCImpl>;
- def ObjCProperty : DeclNode<Named, "Objective-C properties">;
- def ObjCCompatibleAlias : DeclNode<Named>;
+def NamespaceBase : DeclNode<Named, "namespace declarations", 1>;
+def Namespace : DeclNode<NamespaceBase, "namespaces">, DeclContext;
+def NamespaceAlias : DeclNode<NamespaceBase>;
+def UsingDirective : DeclNode<Named>;
+def Label : DeclNode<Named, "labels">;
+def Type : DeclNode<Named, "types", 1>;
+def TypedefName : DeclNode<Type, "typedefs", 1>;
+def Typedef : DeclNode<TypedefName>;
+def TypeAlias : DeclNode<TypedefName>;
+def ObjCTypeParam : DeclNode<TypedefName>;
+def UnresolvedUsingTypename : DeclNode<Type>;
+def Tag : DeclNode<Type, "tag types", 1>, DeclContext;
+def Enum : DeclNode<Tag, "enums">;
+def Record : DeclNode<Tag, "structs, unions, classes">;
+def CXXRecord : DeclNode<Record, "classes">;
+def ClassTemplateSpecialization : DeclNode<CXXRecord>;
+def ClassTemplatePartialSpecialization : DeclNode<ClassTemplateSpecialization>;
+def TemplateTypeParm : DeclNode<Type>;
+def Value : DeclNode<Named, "value declarations", 1>;
+def EnumConstant : DeclNode<Value, "enumerators">;
+def UnresolvedUsingValue : DeclNode<Value>;
+def IndirectField : DeclNode<Value>;
+def Binding : DeclNode<Value>;
+def OMPDeclareReduction : DeclNode<Value>, DeclContext;
+def OMPDeclareMapper : DeclNode<Value>, DeclContext;
+def MSGuid : DeclNode<Value>;
+def UnnamedGlobalConstant : DeclNode<Value>;
+def TemplateParamObject : DeclNode<Value>;
+def Declarator : DeclNode<Value, "declarators", 1>;
+def Field : DeclNode<Declarator, "non-static data members">;
+def ObjCIvar : DeclNode<Field>;
+def ObjCAtDefsField : DeclNode<Field>;
+def MSProperty : DeclNode<Declarator>;
+def Function : DeclNode<Declarator, "functions">, DeclContext;
+def CXXDeductionGuide : DeclNode<Function>;
+def CXXMethod : DeclNode<Function>;
+def CXXConstructor : DeclNode<CXXMethod>;
+def CXXDestructor : DeclNode<CXXMethod>;
+def CXXConversion : DeclNode<CXXMethod>;
+def Var : DeclNode<Declarator, "variables">;
+def VarTemplateSpecialization : DeclNode<Var>;
+def VarTemplatePartialSpecialization : DeclNode<VarTemplateSpecialization>;
+def ImplicitParam : DeclNode<Var>;
+def ParmVar : DeclNode<Var, "parameters">;
+def Decomposition : DeclNode<Var>;
+def OMPCapturedExpr : DeclNode<Var>;
+def NonTypeTemplateParm : DeclNode<Declarator>;
+def Template : DeclNode<Named, "templates", 1>;
+def RedeclarableTemplate : DeclNode<Template, "redeclarable templates", 1>;
+def FunctionTemplate : DeclNode<RedeclarableTemplate>;
+def ClassTemplate : DeclNode<RedeclarableTemplate>;
+def VarTemplate : DeclNode<R...
[truncated]
|
@llvm/pr-subscribers-backend-sparc Author: Matheus Izvekov (mizvekov) ChangesOther changes Second patch in the series starting at #147835 Patch is 800.27 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/148012.diff 173 Files Affected:
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index bae004896c11f..599155c5c9950 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -221,6 +221,19 @@ extern const internal::VariadicDynCastAllOfMatcher<Decl, TypedefNameDecl>
extern const internal::VariadicDynCastAllOfMatcher<Decl, TypeAliasDecl>
typeAliasDecl;
+/// \brief Matches shadow declarations introduced into a scope by a
+/// (resolved) using declaration.
+///
+/// Given
+/// \code
+/// namespace n { int f; }
+/// namespace declToImport { using n::f; }
+/// \endcode
+/// usingShadowDecl()
+/// matches \code f \endcode
+extern const internal::VariadicDynCastAllOfMatcher<Decl, UsingShadowDecl>
+ usingShadowDecl;
+
/// Matches type alias template declarations.
///
/// typeAliasTemplateDecl() matches
@@ -3718,7 +3731,7 @@ extern const internal::VariadicOperatorMatcherFunc<1, 1> unless;
/// Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>,
/// Matcher<TagType>, Matcher<TemplateSpecializationType>,
/// Matcher<TemplateTypeParmType>, Matcher<TypedefType>,
-/// Matcher<UnresolvedUsingType>
+/// Matcher<UnresolvedUsingType>, Matcher<UsingType>
inline internal::PolymorphicMatcher<
internal::HasDeclarationMatcher,
void(internal::HasDeclarationSupportedTypes), internal::Matcher<Decl>>
@@ -4353,7 +4366,13 @@ AST_POLYMORPHIC_MATCHER_P(throughUsingDecl,
AST_POLYMORPHIC_SUPPORTED_TYPES(DeclRefExpr,
UsingType),
internal::Matcher<UsingShadowDecl>, Inner) {
- const NamedDecl *FoundDecl = Node.getFoundDecl();
+ const NamedDecl *FoundDecl;
+ if constexpr (std::is_same_v<NodeType, UsingType>) {
+ FoundDecl = Node.getDecl();
+ } else {
+ static_assert(std::is_same_v<NodeType, DeclRefExpr>);
+ FoundDecl = Node.getFoundDecl();
+ }
if (const UsingShadowDecl *UsingDecl = dyn_cast<UsingShadowDecl>(FoundDecl))
return Inner.matches(*UsingDecl, Finder, Builder);
return false;
@@ -6982,37 +7001,6 @@ AST_POLYMORPHIC_MATCHER_P2(
InnerMatcher.matches(Args[Index], Finder, Builder);
}
-/// Matches C or C++ elaborated `TypeLoc`s.
-///
-/// Given
-/// \code
-/// struct s {};
-/// struct s ss;
-/// \endcode
-/// elaboratedTypeLoc()
-/// matches the `TypeLoc` of the variable declaration of `ss`.
-extern const internal::VariadicDynCastAllOfMatcher<TypeLoc, ElaboratedTypeLoc>
- elaboratedTypeLoc;
-
-/// Matches elaborated `TypeLoc`s that have a named `TypeLoc` matching
-/// `InnerMatcher`.
-///
-/// Given
-/// \code
-/// template <typename T>
-/// class C {};
-/// class C<int> c;
-///
-/// class D {};
-/// class D d;
-/// \endcode
-/// elaboratedTypeLoc(hasNamedTypeLoc(templateSpecializationTypeLoc()));
-/// matches the `TypeLoc` of the variable declaration of `c`, but not `d`.
-AST_MATCHER_P(ElaboratedTypeLoc, hasNamedTypeLoc, internal::Matcher<TypeLoc>,
- InnerMatcher) {
- return InnerMatcher.matches(Node.getNamedTypeLoc(), Finder, Builder);
-}
-
/// Matches type \c bool.
///
/// Given
@@ -7279,7 +7267,7 @@ extern const AstTypeMatcher<DecltypeType> decltypeType;
AST_TYPE_TRAVERSE_MATCHER(hasDeducedType, getDeducedType,
AST_POLYMORPHIC_SUPPORTED_TYPES(AutoType));
-/// Matches \c DecltypeType or \c UsingType nodes to find the underlying type.
+/// Matches \c QualType nodes to find the underlying type.
///
/// Given
/// \code
@@ -7289,10 +7277,13 @@ AST_TYPE_TRAVERSE_MATCHER(hasDeducedType, getDeducedType,
/// decltypeType(hasUnderlyingType(isInteger()))
/// matches the type of "a"
///
-/// Usable as: Matcher<DecltypeType>, Matcher<UsingType>
-AST_TYPE_TRAVERSE_MATCHER(hasUnderlyingType, getUnderlyingType,
- AST_POLYMORPHIC_SUPPORTED_TYPES(DecltypeType,
- UsingType));
+/// Usable as: Matcher<QualType>
+AST_MATCHER_P(Type, hasUnderlyingType, internal::Matcher<QualType>, Inner) {
+ QualType QT = Node.getLocallyUnqualifiedSingleStepDesugaredType();
+ if (QT == QualType(&Node, 0))
+ return false;
+ return Inner.matches(QT, Finder, Builder);
+}
/// Matches \c FunctionType nodes.
///
@@ -7571,27 +7562,7 @@ extern const AstTypeMatcher<RecordType> recordType;
/// and \c c.
extern const AstTypeMatcher<TagType> tagType;
-/// Matches types specified with an elaborated type keyword or with a
-/// qualified name.
-///
-/// Given
-/// \code
-/// namespace N {
-/// namespace M {
-/// class D {};
-/// }
-/// }
-/// class C {};
-///
-/// class C c;
-/// N::M::D d;
-/// \endcode
-///
-/// \c elaboratedType() matches the type of the variable declarations of both
-/// \c c and \c d.
-extern const AstTypeMatcher<ElaboratedType> elaboratedType;
-
-/// Matches ElaboratedTypes whose qualifier, a NestedNameSpecifier,
+/// Matches Types whose qualifier, a NestedNameSpecifier,
/// matches \c InnerMatcher if the qualifier exists.
///
/// Given
@@ -7606,34 +7577,14 @@ extern const AstTypeMatcher<ElaboratedType> elaboratedType;
///
/// \c elaboratedType(hasQualifier(hasPrefix(specifiesNamespace(hasName("N"))))
/// matches the type of the variable declaration of \c d.
-AST_MATCHER_P(ElaboratedType, hasQualifier,
- internal::Matcher<NestedNameSpecifier>, InnerMatcher) {
- if (const NestedNameSpecifier *Qualifier = Node.getQualifier())
- return InnerMatcher.matches(*Qualifier, Finder, Builder);
+AST_MATCHER_P(Type, hasQualifier, internal::Matcher<NestedNameSpecifier>,
+ InnerMatcher) {
+ if (NestedNameSpecifier Qualifier = Node.getPrefix())
+ return InnerMatcher.matches(Qualifier, Finder, Builder);
return false;
}
-/// Matches ElaboratedTypes whose named type matches \c InnerMatcher.
-///
-/// Given
-/// \code
-/// namespace N {
-/// namespace M {
-/// class D {};
-/// }
-/// }
-/// N::M::D d;
-/// \endcode
-///
-/// \c elaboratedType(namesType(recordType(
-/// hasDeclaration(namedDecl(hasName("D")))))) matches the type of the variable
-/// declaration of \c d.
-AST_MATCHER_P(ElaboratedType, namesType, internal::Matcher<QualType>,
- InnerMatcher) {
- return InnerMatcher.matches(Node.getNamedType(), Finder, Builder);
-}
-
/// Matches types specified through a using declaration.
///
/// Given
@@ -7802,7 +7753,7 @@ AST_MATCHER_FUNCTION_P_OVERLOAD(
/// matches "A::"
AST_MATCHER_P(NestedNameSpecifier, specifiesType,
internal::Matcher<QualType>, InnerMatcher) {
- if (!Node.getAsType())
+ if (Node.getKind() != NestedNameSpecifier::Kind::Type)
return false;
return InnerMatcher.matches(QualType(Node.getAsType(), 0), Finder, Builder);
}
@@ -7820,8 +7771,12 @@ AST_MATCHER_P(NestedNameSpecifier, specifiesType,
/// matches "A::"
AST_MATCHER_P(NestedNameSpecifierLoc, specifiesTypeLoc,
internal::Matcher<TypeLoc>, InnerMatcher) {
- return Node && Node.getNestedNameSpecifier()->getAsType() &&
- InnerMatcher.matches(Node.getTypeLoc(), Finder, Builder);
+ if (!Node)
+ return false;
+ TypeLoc TL = Node.getAsTypeLoc();
+ if (!TL)
+ return false;
+ return InnerMatcher.matches(TL, Finder, Builder);
}
/// Matches on the prefix of a \c NestedNameSpecifier.
@@ -7836,10 +7791,21 @@ AST_MATCHER_P(NestedNameSpecifierLoc, specifiesTypeLoc,
AST_MATCHER_P_OVERLOAD(NestedNameSpecifier, hasPrefix,
internal::Matcher<NestedNameSpecifier>, InnerMatcher,
0) {
- const NestedNameSpecifier *NextNode = Node.getPrefix();
+ NestedNameSpecifier NextNode = std::nullopt;
+ switch (Node.getKind()) {
+ case NestedNameSpecifier::Kind::Namespace:
+ NextNode = Node.getAsNamespaceAndPrefix().Prefix;
+ break;
+ case NestedNameSpecifier::Kind::Type:
+ NextNode = Node.getAsType()->getPrefix();
+ break;
+ default:
+ break;
+ }
+
if (!NextNode)
return false;
- return InnerMatcher.matches(*NextNode, Finder, Builder);
+ return InnerMatcher.matches(NextNode, Finder, Builder);
}
/// Matches on the prefix of a \c NestedNameSpecifierLoc.
@@ -7854,7 +7820,12 @@ AST_MATCHER_P_OVERLOAD(NestedNameSpecifier, hasPrefix,
AST_MATCHER_P_OVERLOAD(NestedNameSpecifierLoc, hasPrefix,
internal::Matcher<NestedNameSpecifierLoc>, InnerMatcher,
1) {
- NestedNameSpecifierLoc NextNode = Node.getPrefix();
+ NestedNameSpecifierLoc NextNode;
+ if (TypeLoc TL = Node.getAsTypeLoc())
+ NextNode = TL.getPrefix();
+ else
+ NextNode = Node.getAsNamespaceAndPrefix().Prefix;
+
if (!NextNode)
return false;
return InnerMatcher.matches(NextNode, Finder, Builder);
@@ -7872,9 +7843,13 @@ AST_MATCHER_P_OVERLOAD(NestedNameSpecifierLoc, hasPrefix,
/// matches "ns::"
AST_MATCHER_P(NestedNameSpecifier, specifiesNamespace,
internal::Matcher<NamespaceDecl>, InnerMatcher) {
- if (!Node.getAsNamespace())
+ if (Node.getKind() != NestedNameSpecifier::Kind::Namespace)
+ return false;
+ const auto *Namespace =
+ dyn_cast<NamespaceDecl>(Node.getAsNamespaceAndPrefix().Namespace);
+ if (!Namespace)
return false;
- return InnerMatcher.matches(*Node.getAsNamespace(), Finder, Builder);
+ return InnerMatcher.matches(*Namespace, Finder, Builder);
}
/// Matches attributes.
diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
index 667a044abcef1..399af3d888551 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -1013,10 +1013,7 @@ class HasDeclarationMatcher : public MatcherInterface<T> {
// First, for any types that have a declaration, extract the declaration and
// match on it.
if (const auto *S = dyn_cast<TagType>(&Node)) {
- return matchesDecl(S->getDecl(), Finder, Builder);
- }
- if (const auto *S = dyn_cast<InjectedClassNameType>(&Node)) {
- return matchesDecl(S->getDecl(), Finder, Builder);
+ return matchesDecl(S->getOriginalDecl(), Finder, Builder);
}
if (const auto *S = dyn_cast<TemplateTypeParmType>(&Node)) {
return matchesDecl(S->getDecl(), Finder, Builder);
@@ -1027,6 +1024,9 @@ class HasDeclarationMatcher : public MatcherInterface<T> {
if (const auto *S = dyn_cast<UnresolvedUsingType>(&Node)) {
return matchesDecl(S->getDecl(), Finder, Builder);
}
+ if (const auto *S = dyn_cast<UsingType>(&Node)) {
+ return matchesDecl(S->getDecl(), Finder, Builder);
+ }
if (const auto *S = dyn_cast<ObjCObjectType>(&Node)) {
return matchesDecl(S->getInterface(), Finder, Builder);
}
@@ -1062,12 +1062,6 @@ class HasDeclarationMatcher : public MatcherInterface<T> {
Builder);
}
- // FIXME: We desugar elaborated types. This makes the assumption that users
- // do never want to match on whether a type is elaborated - there are
- // arguments for both sides; for now, continue desugaring.
- if (const auto *S = dyn_cast<ElaboratedType>(&Node)) {
- return matchesSpecialized(S->desugar(), Finder, Builder);
- }
// Similarly types found via using declarations.
// These are *usually* meaningless sugar, and this matches the historical
// behavior prior to the introduction of UsingType.
@@ -1207,8 +1201,8 @@ using AdaptativeDefaultToTypes =
/// All types that are supported by HasDeclarationMatcher above.
using HasDeclarationSupportedTypes =
TypeList<CallExpr, CXXConstructExpr, CXXNewExpr, DeclRefExpr, EnumType,
- ElaboratedType, InjectedClassNameType, LabelStmt, AddrLabelExpr,
- MemberExpr, QualType, RecordType, TagType,
+ InjectedClassNameType, LabelStmt, AddrLabelExpr, MemberExpr,
+ QualType, RecordType, TagType, UsingType,
TemplateSpecializationType, TemplateTypeParmType, TypedefType,
UnresolvedUsingType, ObjCIvarRefExpr, ObjCInterfaceDecl>;
@@ -1785,7 +1779,7 @@ class LocMatcher : public MatcherInterface<TLoc> {
private:
static DynTypedNode extract(const NestedNameSpecifierLoc &Loc) {
- return DynTypedNode::create(*Loc.getNestedNameSpecifier());
+ return DynTypedNode::create(Loc.getNestedNameSpecifier());
}
};
diff --git a/clang/include/clang/Analysis/FlowSensitive/ASTOps.h b/clang/include/clang/Analysis/FlowSensitive/ASTOps.h
index 8c7ee86d15c06..a404b06cd62ca 100644
--- a/clang/include/clang/Analysis/FlowSensitive/ASTOps.h
+++ b/clang/include/clang/Analysis/FlowSensitive/ASTOps.h
@@ -112,8 +112,14 @@ class AnalysisASTVisitor : public DynamicRecursiveASTVisitor {
// fields that are only used in these.
// Note: The operand of the `noexcept` operator is an unevaluated operand, but
// nevertheless it appears in the Clang CFG, so we don't exclude it here.
- bool TraverseDecltypeTypeLoc(DecltypeTypeLoc) override { return true; }
- bool TraverseTypeOfExprTypeLoc(TypeOfExprTypeLoc) override { return true; }
+ bool TraverseDecltypeTypeLoc(DecltypeTypeLoc,
+ bool TraverseQualifier) override {
+ return true;
+ }
+ bool TraverseTypeOfExprTypeLoc(TypeOfExprTypeLoc,
+ bool TraverseQualifier) override {
+ return true;
+ }
bool TraverseCXXTypeidExpr(CXXTypeidExpr *TIE) override {
if (TIE->isPotentiallyEvaluated())
return DynamicRecursiveASTVisitor::TraverseCXXTypeidExpr(TIE);
diff --git a/clang/include/clang/Basic/DeclNodes.td b/clang/include/clang/Basic/DeclNodes.td
index f1ebaf1db3fc0..b4c02949426a1 100644
--- a/clang/include/clang/Basic/DeclNodes.td
+++ b/clang/include/clang/Basic/DeclNodes.td
@@ -15,81 +15,80 @@ def PragmaComment : DeclNode<Decl>;
def PragmaDetectMismatch : DeclNode<Decl>;
def ExternCContext : DeclNode<Decl>, DeclContext;
def Named : DeclNode<Decl, "named declarations", 1>;
- def Namespace : DeclNode<Named, "namespaces">, DeclContext;
- def UsingDirective : DeclNode<Named>;
- def NamespaceAlias : DeclNode<Named>;
- def Label : DeclNode<Named, "labels">;
- def Type : DeclNode<Named, "types", 1>;
- def TypedefName : DeclNode<Type, "typedefs", 1>;
- def Typedef : DeclNode<TypedefName>;
- def TypeAlias : DeclNode<TypedefName>;
- def ObjCTypeParam : DeclNode<TypedefName>;
- def UnresolvedUsingTypename : DeclNode<Type>;
- def Tag : DeclNode<Type, "tag types", 1>, DeclContext;
- def Enum : DeclNode<Tag, "enums">;
- def Record : DeclNode<Tag, "structs, unions, classes">;
- def CXXRecord : DeclNode<Record, "classes">;
- def ClassTemplateSpecialization : DeclNode<CXXRecord>;
- def ClassTemplatePartialSpecialization
- : DeclNode<ClassTemplateSpecialization>;
- def TemplateTypeParm : DeclNode<Type>;
- def Value : DeclNode<Named, "value declarations", 1>;
- def EnumConstant : DeclNode<Value, "enumerators">;
- def UnresolvedUsingValue : DeclNode<Value>;
- def IndirectField : DeclNode<Value>;
- def Binding : DeclNode<Value>;
- def OMPDeclareReduction : DeclNode<Value>, DeclContext;
- def OMPDeclareMapper : DeclNode<Value>, DeclContext;
- def MSGuid : DeclNode<Value>;
- def UnnamedGlobalConstant : DeclNode<Value>;
- def TemplateParamObject : DeclNode<Value>;
- def Declarator : DeclNode<Value, "declarators", 1>;
- def Field : DeclNode<Declarator, "non-static data members">;
- def ObjCIvar : DeclNode<Field>;
- def ObjCAtDefsField : DeclNode<Field>;
- def MSProperty : DeclNode<Declarator>;
- def Function : DeclNode<Declarator, "functions">, DeclContext;
- def CXXDeductionGuide : DeclNode<Function>;
- def CXXMethod : DeclNode<Function>;
- def CXXConstructor : DeclNode<CXXMethod>;
- def CXXDestructor : DeclNode<CXXMethod>;
- def CXXConversion : DeclNode<CXXMethod>;
- def Var : DeclNode<Declarator, "variables">;
- def VarTemplateSpecialization : DeclNode<Var>;
- def VarTemplatePartialSpecialization
- : DeclNode<VarTemplateSpecialization>;
- def ImplicitParam : DeclNode<Var>;
- def ParmVar : DeclNode<Var, "parameters">;
- def Decomposition : DeclNode<Var>;
- def OMPCapturedExpr : DeclNode<Var>;
- def NonTypeTemplateParm : DeclNode<Declarator>;
- def Template : DeclNode<Named, "templates", 1>;
- def RedeclarableTemplate : DeclNode<Template, "redeclarable templates", 1>;
- def FunctionTemplate : DeclNode<RedeclarableTemplate>;
- def ClassTemplate : DeclNode<RedeclarableTemplate>;
- def VarTemplate : DeclNode<RedeclarableTemplate>;
- def TypeAliasTemplate : DeclNode<RedeclarableTemplate>;
- def TemplateTemplateParm : DeclNode<Template>;
- def BuiltinTemplate : DeclNode<Template>;
- def Concept : DeclNode<Template>;
- def BaseUsing : DeclNode<Named, "", 1>;
- def Using : DeclNode<BaseUsing>;
- def UsingEnum : DeclNode<BaseUsing>;
- def UsingPack : DeclNode<Named>;
- def UsingShadow : DeclNode<Named>;
- def ConstructorUsingShadow : DeclNode<UsingShadow>;
- def UnresolvedUsingIfExists : DeclNode<Named>;
- def ObjCMethod : DeclNode<Named, "Objective-C methods">, DeclContext;
- def ObjCContainer : DeclNode<Named, "Objective-C containers", 1>, DeclContext;
- def ObjCCategory : DeclNode<ObjCContainer>;
- def ObjCProtocol : DeclNode<ObjCContainer, "Objective-C protocols">;
- def ObjCInterface : DeclNode<ObjCContainer, "Objective-C interfaces">;
- def ObjCImpl
- : DeclNode<ObjCContainer, "Objective-C implementation declarations", 1>;
- def ObjCCategoryImpl : DeclNode<ObjCImpl>;
- def ObjCImplementation : DeclNode<ObjCImpl>;
- def ObjCProperty : DeclNode<Named, "Objective-C properties">;
- def ObjCCompatibleAlias : DeclNode<Named>;
+def NamespaceBase : DeclNode<Named, "namespace declarations", 1>;
+def Namespace : DeclNode<NamespaceBase, "namespaces">, DeclContext;
+def NamespaceAlias : DeclNode<NamespaceBase>;
+def UsingDirective : DeclNode<Named>;
+def Label : DeclNode<Named, "labels">;
+def Type : DeclNode<Named, "types", 1>;
+def TypedefName : DeclNode<Type, "typedefs", 1>;
+def Typedef : DeclNode<TypedefName>;
+def TypeAlias : DeclNode<TypedefName>;
+def ObjCTypeParam : DeclNode<TypedefName>;
+def UnresolvedUsingTypename : DeclNode<Type>;
+def Tag : DeclNode<Type, "tag types", 1>, DeclContext;
+def Enum : DeclNode<Tag, "enums">;
+def Record : DeclNode<Tag, "structs, unions, classes">;
+def CXXRecord : DeclNode<Record, "classes">;
+def ClassTemplateSpecialization : DeclNode<CXXRecord>;
+def ClassTemplatePartialSpecialization : DeclNode<ClassTemplateSpecialization>;
+def TemplateTypeParm : DeclNode<Type>;
+def Value : DeclNode<Named, "value declarations", 1>;
+def EnumConstant : DeclNode<Value, "enumerators">;
+def UnresolvedUsingValue : DeclNode<Value>;
+def IndirectField : DeclNode<Value>;
+def Binding : DeclNode<Value>;
+def OMPDeclareReduction : DeclNode<Value>, DeclContext;
+def OMPDeclareMapper : DeclNode<Value>, DeclContext;
+def MSGuid : DeclNode<Value>;
+def UnnamedGlobalConstant : DeclNode<Value>;
+def TemplateParamObject : DeclNode<Value>;
+def Declarator : DeclNode<Value, "declarators", 1>;
+def Field : DeclNode<Declarator, "non-static data members">;
+def ObjCIvar : DeclNode<Field>;
+def ObjCAtDefsField : DeclNode<Field>;
+def MSProperty : DeclNode<Declarator>;
+def Function : DeclNode<Declarator, "functions">, DeclContext;
+def CXXDeductionGuide : DeclNode<Function>;
+def CXXMethod : DeclNode<Function>;
+def CXXConstructor : DeclNode<CXXMethod>;
+def CXXDestructor : DeclNode<CXXMethod>;
+def CXXConversion : DeclNode<CXXMethod>;
+def Var : DeclNode<Declarator, "variables">;
+def VarTemplateSpecialization : DeclNode<Var>;
+def VarTemplatePartialSpecialization : DeclNode<VarTemplateSpecialization>;
+def ImplicitParam : DeclNode<Var>;
+def ParmVar : DeclNode<Var, "parameters">;
+def Decomposition : DeclNode<Var>;
+def OMPCapturedExpr : DeclNode<Var>;
+def NonTypeTemplateParm : DeclNode<Declarator>;
+def Template : DeclNode<Named, "templates", 1>;
+def RedeclarableTemplate : DeclNode<Template, "redeclarable templates", 1>;
+def FunctionTemplate : DeclNode<RedeclarableTemplate>;
+def ClassTemplate : DeclNode<RedeclarableTemplate>;
+def VarTemplate : DeclNode<R...
[truncated]
|
@llvm/pr-subscribers-backend-x86 Author: Matheus Izvekov (mizvekov) ChangesOther changes Second patch in the series starting at #147835 Patch is 800.27 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/148012.diff 173 Files Affected:
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index bae004896c11f..599155c5c9950 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -221,6 +221,19 @@ extern const internal::VariadicDynCastAllOfMatcher<Decl, TypedefNameDecl>
extern const internal::VariadicDynCastAllOfMatcher<Decl, TypeAliasDecl>
typeAliasDecl;
+/// \brief Matches shadow declarations introduced into a scope by a
+/// (resolved) using declaration.
+///
+/// Given
+/// \code
+/// namespace n { int f; }
+/// namespace declToImport { using n::f; }
+/// \endcode
+/// usingShadowDecl()
+/// matches \code f \endcode
+extern const internal::VariadicDynCastAllOfMatcher<Decl, UsingShadowDecl>
+ usingShadowDecl;
+
/// Matches type alias template declarations.
///
/// typeAliasTemplateDecl() matches
@@ -3718,7 +3731,7 @@ extern const internal::VariadicOperatorMatcherFunc<1, 1> unless;
/// Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>,
/// Matcher<TagType>, Matcher<TemplateSpecializationType>,
/// Matcher<TemplateTypeParmType>, Matcher<TypedefType>,
-/// Matcher<UnresolvedUsingType>
+/// Matcher<UnresolvedUsingType>, Matcher<UsingType>
inline internal::PolymorphicMatcher<
internal::HasDeclarationMatcher,
void(internal::HasDeclarationSupportedTypes), internal::Matcher<Decl>>
@@ -4353,7 +4366,13 @@ AST_POLYMORPHIC_MATCHER_P(throughUsingDecl,
AST_POLYMORPHIC_SUPPORTED_TYPES(DeclRefExpr,
UsingType),
internal::Matcher<UsingShadowDecl>, Inner) {
- const NamedDecl *FoundDecl = Node.getFoundDecl();
+ const NamedDecl *FoundDecl;
+ if constexpr (std::is_same_v<NodeType, UsingType>) {
+ FoundDecl = Node.getDecl();
+ } else {
+ static_assert(std::is_same_v<NodeType, DeclRefExpr>);
+ FoundDecl = Node.getFoundDecl();
+ }
if (const UsingShadowDecl *UsingDecl = dyn_cast<UsingShadowDecl>(FoundDecl))
return Inner.matches(*UsingDecl, Finder, Builder);
return false;
@@ -6982,37 +7001,6 @@ AST_POLYMORPHIC_MATCHER_P2(
InnerMatcher.matches(Args[Index], Finder, Builder);
}
-/// Matches C or C++ elaborated `TypeLoc`s.
-///
-/// Given
-/// \code
-/// struct s {};
-/// struct s ss;
-/// \endcode
-/// elaboratedTypeLoc()
-/// matches the `TypeLoc` of the variable declaration of `ss`.
-extern const internal::VariadicDynCastAllOfMatcher<TypeLoc, ElaboratedTypeLoc>
- elaboratedTypeLoc;
-
-/// Matches elaborated `TypeLoc`s that have a named `TypeLoc` matching
-/// `InnerMatcher`.
-///
-/// Given
-/// \code
-/// template <typename T>
-/// class C {};
-/// class C<int> c;
-///
-/// class D {};
-/// class D d;
-/// \endcode
-/// elaboratedTypeLoc(hasNamedTypeLoc(templateSpecializationTypeLoc()));
-/// matches the `TypeLoc` of the variable declaration of `c`, but not `d`.
-AST_MATCHER_P(ElaboratedTypeLoc, hasNamedTypeLoc, internal::Matcher<TypeLoc>,
- InnerMatcher) {
- return InnerMatcher.matches(Node.getNamedTypeLoc(), Finder, Builder);
-}
-
/// Matches type \c bool.
///
/// Given
@@ -7279,7 +7267,7 @@ extern const AstTypeMatcher<DecltypeType> decltypeType;
AST_TYPE_TRAVERSE_MATCHER(hasDeducedType, getDeducedType,
AST_POLYMORPHIC_SUPPORTED_TYPES(AutoType));
-/// Matches \c DecltypeType or \c UsingType nodes to find the underlying type.
+/// Matches \c QualType nodes to find the underlying type.
///
/// Given
/// \code
@@ -7289,10 +7277,13 @@ AST_TYPE_TRAVERSE_MATCHER(hasDeducedType, getDeducedType,
/// decltypeType(hasUnderlyingType(isInteger()))
/// matches the type of "a"
///
-/// Usable as: Matcher<DecltypeType>, Matcher<UsingType>
-AST_TYPE_TRAVERSE_MATCHER(hasUnderlyingType, getUnderlyingType,
- AST_POLYMORPHIC_SUPPORTED_TYPES(DecltypeType,
- UsingType));
+/// Usable as: Matcher<QualType>
+AST_MATCHER_P(Type, hasUnderlyingType, internal::Matcher<QualType>, Inner) {
+ QualType QT = Node.getLocallyUnqualifiedSingleStepDesugaredType();
+ if (QT == QualType(&Node, 0))
+ return false;
+ return Inner.matches(QT, Finder, Builder);
+}
/// Matches \c FunctionType nodes.
///
@@ -7571,27 +7562,7 @@ extern const AstTypeMatcher<RecordType> recordType;
/// and \c c.
extern const AstTypeMatcher<TagType> tagType;
-/// Matches types specified with an elaborated type keyword or with a
-/// qualified name.
-///
-/// Given
-/// \code
-/// namespace N {
-/// namespace M {
-/// class D {};
-/// }
-/// }
-/// class C {};
-///
-/// class C c;
-/// N::M::D d;
-/// \endcode
-///
-/// \c elaboratedType() matches the type of the variable declarations of both
-/// \c c and \c d.
-extern const AstTypeMatcher<ElaboratedType> elaboratedType;
-
-/// Matches ElaboratedTypes whose qualifier, a NestedNameSpecifier,
+/// Matches Types whose qualifier, a NestedNameSpecifier,
/// matches \c InnerMatcher if the qualifier exists.
///
/// Given
@@ -7606,34 +7577,14 @@ extern const AstTypeMatcher<ElaboratedType> elaboratedType;
///
/// \c elaboratedType(hasQualifier(hasPrefix(specifiesNamespace(hasName("N"))))
/// matches the type of the variable declaration of \c d.
-AST_MATCHER_P(ElaboratedType, hasQualifier,
- internal::Matcher<NestedNameSpecifier>, InnerMatcher) {
- if (const NestedNameSpecifier *Qualifier = Node.getQualifier())
- return InnerMatcher.matches(*Qualifier, Finder, Builder);
+AST_MATCHER_P(Type, hasQualifier, internal::Matcher<NestedNameSpecifier>,
+ InnerMatcher) {
+ if (NestedNameSpecifier Qualifier = Node.getPrefix())
+ return InnerMatcher.matches(Qualifier, Finder, Builder);
return false;
}
-/// Matches ElaboratedTypes whose named type matches \c InnerMatcher.
-///
-/// Given
-/// \code
-/// namespace N {
-/// namespace M {
-/// class D {};
-/// }
-/// }
-/// N::M::D d;
-/// \endcode
-///
-/// \c elaboratedType(namesType(recordType(
-/// hasDeclaration(namedDecl(hasName("D")))))) matches the type of the variable
-/// declaration of \c d.
-AST_MATCHER_P(ElaboratedType, namesType, internal::Matcher<QualType>,
- InnerMatcher) {
- return InnerMatcher.matches(Node.getNamedType(), Finder, Builder);
-}
-
/// Matches types specified through a using declaration.
///
/// Given
@@ -7802,7 +7753,7 @@ AST_MATCHER_FUNCTION_P_OVERLOAD(
/// matches "A::"
AST_MATCHER_P(NestedNameSpecifier, specifiesType,
internal::Matcher<QualType>, InnerMatcher) {
- if (!Node.getAsType())
+ if (Node.getKind() != NestedNameSpecifier::Kind::Type)
return false;
return InnerMatcher.matches(QualType(Node.getAsType(), 0), Finder, Builder);
}
@@ -7820,8 +7771,12 @@ AST_MATCHER_P(NestedNameSpecifier, specifiesType,
/// matches "A::"
AST_MATCHER_P(NestedNameSpecifierLoc, specifiesTypeLoc,
internal::Matcher<TypeLoc>, InnerMatcher) {
- return Node && Node.getNestedNameSpecifier()->getAsType() &&
- InnerMatcher.matches(Node.getTypeLoc(), Finder, Builder);
+ if (!Node)
+ return false;
+ TypeLoc TL = Node.getAsTypeLoc();
+ if (!TL)
+ return false;
+ return InnerMatcher.matches(TL, Finder, Builder);
}
/// Matches on the prefix of a \c NestedNameSpecifier.
@@ -7836,10 +7791,21 @@ AST_MATCHER_P(NestedNameSpecifierLoc, specifiesTypeLoc,
AST_MATCHER_P_OVERLOAD(NestedNameSpecifier, hasPrefix,
internal::Matcher<NestedNameSpecifier>, InnerMatcher,
0) {
- const NestedNameSpecifier *NextNode = Node.getPrefix();
+ NestedNameSpecifier NextNode = std::nullopt;
+ switch (Node.getKind()) {
+ case NestedNameSpecifier::Kind::Namespace:
+ NextNode = Node.getAsNamespaceAndPrefix().Prefix;
+ break;
+ case NestedNameSpecifier::Kind::Type:
+ NextNode = Node.getAsType()->getPrefix();
+ break;
+ default:
+ break;
+ }
+
if (!NextNode)
return false;
- return InnerMatcher.matches(*NextNode, Finder, Builder);
+ return InnerMatcher.matches(NextNode, Finder, Builder);
}
/// Matches on the prefix of a \c NestedNameSpecifierLoc.
@@ -7854,7 +7820,12 @@ AST_MATCHER_P_OVERLOAD(NestedNameSpecifier, hasPrefix,
AST_MATCHER_P_OVERLOAD(NestedNameSpecifierLoc, hasPrefix,
internal::Matcher<NestedNameSpecifierLoc>, InnerMatcher,
1) {
- NestedNameSpecifierLoc NextNode = Node.getPrefix();
+ NestedNameSpecifierLoc NextNode;
+ if (TypeLoc TL = Node.getAsTypeLoc())
+ NextNode = TL.getPrefix();
+ else
+ NextNode = Node.getAsNamespaceAndPrefix().Prefix;
+
if (!NextNode)
return false;
return InnerMatcher.matches(NextNode, Finder, Builder);
@@ -7872,9 +7843,13 @@ AST_MATCHER_P_OVERLOAD(NestedNameSpecifierLoc, hasPrefix,
/// matches "ns::"
AST_MATCHER_P(NestedNameSpecifier, specifiesNamespace,
internal::Matcher<NamespaceDecl>, InnerMatcher) {
- if (!Node.getAsNamespace())
+ if (Node.getKind() != NestedNameSpecifier::Kind::Namespace)
+ return false;
+ const auto *Namespace =
+ dyn_cast<NamespaceDecl>(Node.getAsNamespaceAndPrefix().Namespace);
+ if (!Namespace)
return false;
- return InnerMatcher.matches(*Node.getAsNamespace(), Finder, Builder);
+ return InnerMatcher.matches(*Namespace, Finder, Builder);
}
/// Matches attributes.
diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
index 667a044abcef1..399af3d888551 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -1013,10 +1013,7 @@ class HasDeclarationMatcher : public MatcherInterface<T> {
// First, for any types that have a declaration, extract the declaration and
// match on it.
if (const auto *S = dyn_cast<TagType>(&Node)) {
- return matchesDecl(S->getDecl(), Finder, Builder);
- }
- if (const auto *S = dyn_cast<InjectedClassNameType>(&Node)) {
- return matchesDecl(S->getDecl(), Finder, Builder);
+ return matchesDecl(S->getOriginalDecl(), Finder, Builder);
}
if (const auto *S = dyn_cast<TemplateTypeParmType>(&Node)) {
return matchesDecl(S->getDecl(), Finder, Builder);
@@ -1027,6 +1024,9 @@ class HasDeclarationMatcher : public MatcherInterface<T> {
if (const auto *S = dyn_cast<UnresolvedUsingType>(&Node)) {
return matchesDecl(S->getDecl(), Finder, Builder);
}
+ if (const auto *S = dyn_cast<UsingType>(&Node)) {
+ return matchesDecl(S->getDecl(), Finder, Builder);
+ }
if (const auto *S = dyn_cast<ObjCObjectType>(&Node)) {
return matchesDecl(S->getInterface(), Finder, Builder);
}
@@ -1062,12 +1062,6 @@ class HasDeclarationMatcher : public MatcherInterface<T> {
Builder);
}
- // FIXME: We desugar elaborated types. This makes the assumption that users
- // do never want to match on whether a type is elaborated - there are
- // arguments for both sides; for now, continue desugaring.
- if (const auto *S = dyn_cast<ElaboratedType>(&Node)) {
- return matchesSpecialized(S->desugar(), Finder, Builder);
- }
// Similarly types found via using declarations.
// These are *usually* meaningless sugar, and this matches the historical
// behavior prior to the introduction of UsingType.
@@ -1207,8 +1201,8 @@ using AdaptativeDefaultToTypes =
/// All types that are supported by HasDeclarationMatcher above.
using HasDeclarationSupportedTypes =
TypeList<CallExpr, CXXConstructExpr, CXXNewExpr, DeclRefExpr, EnumType,
- ElaboratedType, InjectedClassNameType, LabelStmt, AddrLabelExpr,
- MemberExpr, QualType, RecordType, TagType,
+ InjectedClassNameType, LabelStmt, AddrLabelExpr, MemberExpr,
+ QualType, RecordType, TagType, UsingType,
TemplateSpecializationType, TemplateTypeParmType, TypedefType,
UnresolvedUsingType, ObjCIvarRefExpr, ObjCInterfaceDecl>;
@@ -1785,7 +1779,7 @@ class LocMatcher : public MatcherInterface<TLoc> {
private:
static DynTypedNode extract(const NestedNameSpecifierLoc &Loc) {
- return DynTypedNode::create(*Loc.getNestedNameSpecifier());
+ return DynTypedNode::create(Loc.getNestedNameSpecifier());
}
};
diff --git a/clang/include/clang/Analysis/FlowSensitive/ASTOps.h b/clang/include/clang/Analysis/FlowSensitive/ASTOps.h
index 8c7ee86d15c06..a404b06cd62ca 100644
--- a/clang/include/clang/Analysis/FlowSensitive/ASTOps.h
+++ b/clang/include/clang/Analysis/FlowSensitive/ASTOps.h
@@ -112,8 +112,14 @@ class AnalysisASTVisitor : public DynamicRecursiveASTVisitor {
// fields that are only used in these.
// Note: The operand of the `noexcept` operator is an unevaluated operand, but
// nevertheless it appears in the Clang CFG, so we don't exclude it here.
- bool TraverseDecltypeTypeLoc(DecltypeTypeLoc) override { return true; }
- bool TraverseTypeOfExprTypeLoc(TypeOfExprTypeLoc) override { return true; }
+ bool TraverseDecltypeTypeLoc(DecltypeTypeLoc,
+ bool TraverseQualifier) override {
+ return true;
+ }
+ bool TraverseTypeOfExprTypeLoc(TypeOfExprTypeLoc,
+ bool TraverseQualifier) override {
+ return true;
+ }
bool TraverseCXXTypeidExpr(CXXTypeidExpr *TIE) override {
if (TIE->isPotentiallyEvaluated())
return DynamicRecursiveASTVisitor::TraverseCXXTypeidExpr(TIE);
diff --git a/clang/include/clang/Basic/DeclNodes.td b/clang/include/clang/Basic/DeclNodes.td
index f1ebaf1db3fc0..b4c02949426a1 100644
--- a/clang/include/clang/Basic/DeclNodes.td
+++ b/clang/include/clang/Basic/DeclNodes.td
@@ -15,81 +15,80 @@ def PragmaComment : DeclNode<Decl>;
def PragmaDetectMismatch : DeclNode<Decl>;
def ExternCContext : DeclNode<Decl>, DeclContext;
def Named : DeclNode<Decl, "named declarations", 1>;
- def Namespace : DeclNode<Named, "namespaces">, DeclContext;
- def UsingDirective : DeclNode<Named>;
- def NamespaceAlias : DeclNode<Named>;
- def Label : DeclNode<Named, "labels">;
- def Type : DeclNode<Named, "types", 1>;
- def TypedefName : DeclNode<Type, "typedefs", 1>;
- def Typedef : DeclNode<TypedefName>;
- def TypeAlias : DeclNode<TypedefName>;
- def ObjCTypeParam : DeclNode<TypedefName>;
- def UnresolvedUsingTypename : DeclNode<Type>;
- def Tag : DeclNode<Type, "tag types", 1>, DeclContext;
- def Enum : DeclNode<Tag, "enums">;
- def Record : DeclNode<Tag, "structs, unions, classes">;
- def CXXRecord : DeclNode<Record, "classes">;
- def ClassTemplateSpecialization : DeclNode<CXXRecord>;
- def ClassTemplatePartialSpecialization
- : DeclNode<ClassTemplateSpecialization>;
- def TemplateTypeParm : DeclNode<Type>;
- def Value : DeclNode<Named, "value declarations", 1>;
- def EnumConstant : DeclNode<Value, "enumerators">;
- def UnresolvedUsingValue : DeclNode<Value>;
- def IndirectField : DeclNode<Value>;
- def Binding : DeclNode<Value>;
- def OMPDeclareReduction : DeclNode<Value>, DeclContext;
- def OMPDeclareMapper : DeclNode<Value>, DeclContext;
- def MSGuid : DeclNode<Value>;
- def UnnamedGlobalConstant : DeclNode<Value>;
- def TemplateParamObject : DeclNode<Value>;
- def Declarator : DeclNode<Value, "declarators", 1>;
- def Field : DeclNode<Declarator, "non-static data members">;
- def ObjCIvar : DeclNode<Field>;
- def ObjCAtDefsField : DeclNode<Field>;
- def MSProperty : DeclNode<Declarator>;
- def Function : DeclNode<Declarator, "functions">, DeclContext;
- def CXXDeductionGuide : DeclNode<Function>;
- def CXXMethod : DeclNode<Function>;
- def CXXConstructor : DeclNode<CXXMethod>;
- def CXXDestructor : DeclNode<CXXMethod>;
- def CXXConversion : DeclNode<CXXMethod>;
- def Var : DeclNode<Declarator, "variables">;
- def VarTemplateSpecialization : DeclNode<Var>;
- def VarTemplatePartialSpecialization
- : DeclNode<VarTemplateSpecialization>;
- def ImplicitParam : DeclNode<Var>;
- def ParmVar : DeclNode<Var, "parameters">;
- def Decomposition : DeclNode<Var>;
- def OMPCapturedExpr : DeclNode<Var>;
- def NonTypeTemplateParm : DeclNode<Declarator>;
- def Template : DeclNode<Named, "templates", 1>;
- def RedeclarableTemplate : DeclNode<Template, "redeclarable templates", 1>;
- def FunctionTemplate : DeclNode<RedeclarableTemplate>;
- def ClassTemplate : DeclNode<RedeclarableTemplate>;
- def VarTemplate : DeclNode<RedeclarableTemplate>;
- def TypeAliasTemplate : DeclNode<RedeclarableTemplate>;
- def TemplateTemplateParm : DeclNode<Template>;
- def BuiltinTemplate : DeclNode<Template>;
- def Concept : DeclNode<Template>;
- def BaseUsing : DeclNode<Named, "", 1>;
- def Using : DeclNode<BaseUsing>;
- def UsingEnum : DeclNode<BaseUsing>;
- def UsingPack : DeclNode<Named>;
- def UsingShadow : DeclNode<Named>;
- def ConstructorUsingShadow : DeclNode<UsingShadow>;
- def UnresolvedUsingIfExists : DeclNode<Named>;
- def ObjCMethod : DeclNode<Named, "Objective-C methods">, DeclContext;
- def ObjCContainer : DeclNode<Named, "Objective-C containers", 1>, DeclContext;
- def ObjCCategory : DeclNode<ObjCContainer>;
- def ObjCProtocol : DeclNode<ObjCContainer, "Objective-C protocols">;
- def ObjCInterface : DeclNode<ObjCContainer, "Objective-C interfaces">;
- def ObjCImpl
- : DeclNode<ObjCContainer, "Objective-C implementation declarations", 1>;
- def ObjCCategoryImpl : DeclNode<ObjCImpl>;
- def ObjCImplementation : DeclNode<ObjCImpl>;
- def ObjCProperty : DeclNode<Named, "Objective-C properties">;
- def ObjCCompatibleAlias : DeclNode<Named>;
+def NamespaceBase : DeclNode<Named, "namespace declarations", 1>;
+def Namespace : DeclNode<NamespaceBase, "namespaces">, DeclContext;
+def NamespaceAlias : DeclNode<NamespaceBase>;
+def UsingDirective : DeclNode<Named>;
+def Label : DeclNode<Named, "labels">;
+def Type : DeclNode<Named, "types", 1>;
+def TypedefName : DeclNode<Type, "typedefs", 1>;
+def Typedef : DeclNode<TypedefName>;
+def TypeAlias : DeclNode<TypedefName>;
+def ObjCTypeParam : DeclNode<TypedefName>;
+def UnresolvedUsingTypename : DeclNode<Type>;
+def Tag : DeclNode<Type, "tag types", 1>, DeclContext;
+def Enum : DeclNode<Tag, "enums">;
+def Record : DeclNode<Tag, "structs, unions, classes">;
+def CXXRecord : DeclNode<Record, "classes">;
+def ClassTemplateSpecialization : DeclNode<CXXRecord>;
+def ClassTemplatePartialSpecialization : DeclNode<ClassTemplateSpecialization>;
+def TemplateTypeParm : DeclNode<Type>;
+def Value : DeclNode<Named, "value declarations", 1>;
+def EnumConstant : DeclNode<Value, "enumerators">;
+def UnresolvedUsingValue : DeclNode<Value>;
+def IndirectField : DeclNode<Value>;
+def Binding : DeclNode<Value>;
+def OMPDeclareReduction : DeclNode<Value>, DeclContext;
+def OMPDeclareMapper : DeclNode<Value>, DeclContext;
+def MSGuid : DeclNode<Value>;
+def UnnamedGlobalConstant : DeclNode<Value>;
+def TemplateParamObject : DeclNode<Value>;
+def Declarator : DeclNode<Value, "declarators", 1>;
+def Field : DeclNode<Declarator, "non-static data members">;
+def ObjCIvar : DeclNode<Field>;
+def ObjCAtDefsField : DeclNode<Field>;
+def MSProperty : DeclNode<Declarator>;
+def Function : DeclNode<Declarator, "functions">, DeclContext;
+def CXXDeductionGuide : DeclNode<Function>;
+def CXXMethod : DeclNode<Function>;
+def CXXConstructor : DeclNode<CXXMethod>;
+def CXXDestructor : DeclNode<CXXMethod>;
+def CXXConversion : DeclNode<CXXMethod>;
+def Var : DeclNode<Declarator, "variables">;
+def VarTemplateSpecialization : DeclNode<Var>;
+def VarTemplatePartialSpecialization : DeclNode<VarTemplateSpecialization>;
+def ImplicitParam : DeclNode<Var>;
+def ParmVar : DeclNode<Var, "parameters">;
+def Decomposition : DeclNode<Var>;
+def OMPCapturedExpr : DeclNode<Var>;
+def NonTypeTemplateParm : DeclNode<Declarator>;
+def Template : DeclNode<Named, "templates", 1>;
+def RedeclarableTemplate : DeclNode<Template, "redeclarable templates", 1>;
+def FunctionTemplate : DeclNode<RedeclarableTemplate>;
+def ClassTemplate : DeclNode<RedeclarableTemplate>;
+def VarTemplate : DeclNode<R...
[truncated]
|
@llvm/pr-subscribers-backend-mips Author: Matheus Izvekov (mizvekov) ChangesOther changes Second patch in the series starting at #147835 Patch is 800.27 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/148012.diff 173 Files Affected:
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index bae004896c11f..599155c5c9950 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -221,6 +221,19 @@ extern const internal::VariadicDynCastAllOfMatcher<Decl, TypedefNameDecl>
extern const internal::VariadicDynCastAllOfMatcher<Decl, TypeAliasDecl>
typeAliasDecl;
+/// \brief Matches shadow declarations introduced into a scope by a
+/// (resolved) using declaration.
+///
+/// Given
+/// \code
+/// namespace n { int f; }
+/// namespace declToImport { using n::f; }
+/// \endcode
+/// usingShadowDecl()
+/// matches \code f \endcode
+extern const internal::VariadicDynCastAllOfMatcher<Decl, UsingShadowDecl>
+ usingShadowDecl;
+
/// Matches type alias template declarations.
///
/// typeAliasTemplateDecl() matches
@@ -3718,7 +3731,7 @@ extern const internal::VariadicOperatorMatcherFunc<1, 1> unless;
/// Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>,
/// Matcher<TagType>, Matcher<TemplateSpecializationType>,
/// Matcher<TemplateTypeParmType>, Matcher<TypedefType>,
-/// Matcher<UnresolvedUsingType>
+/// Matcher<UnresolvedUsingType>, Matcher<UsingType>
inline internal::PolymorphicMatcher<
internal::HasDeclarationMatcher,
void(internal::HasDeclarationSupportedTypes), internal::Matcher<Decl>>
@@ -4353,7 +4366,13 @@ AST_POLYMORPHIC_MATCHER_P(throughUsingDecl,
AST_POLYMORPHIC_SUPPORTED_TYPES(DeclRefExpr,
UsingType),
internal::Matcher<UsingShadowDecl>, Inner) {
- const NamedDecl *FoundDecl = Node.getFoundDecl();
+ const NamedDecl *FoundDecl;
+ if constexpr (std::is_same_v<NodeType, UsingType>) {
+ FoundDecl = Node.getDecl();
+ } else {
+ static_assert(std::is_same_v<NodeType, DeclRefExpr>);
+ FoundDecl = Node.getFoundDecl();
+ }
if (const UsingShadowDecl *UsingDecl = dyn_cast<UsingShadowDecl>(FoundDecl))
return Inner.matches(*UsingDecl, Finder, Builder);
return false;
@@ -6982,37 +7001,6 @@ AST_POLYMORPHIC_MATCHER_P2(
InnerMatcher.matches(Args[Index], Finder, Builder);
}
-/// Matches C or C++ elaborated `TypeLoc`s.
-///
-/// Given
-/// \code
-/// struct s {};
-/// struct s ss;
-/// \endcode
-/// elaboratedTypeLoc()
-/// matches the `TypeLoc` of the variable declaration of `ss`.
-extern const internal::VariadicDynCastAllOfMatcher<TypeLoc, ElaboratedTypeLoc>
- elaboratedTypeLoc;
-
-/// Matches elaborated `TypeLoc`s that have a named `TypeLoc` matching
-/// `InnerMatcher`.
-///
-/// Given
-/// \code
-/// template <typename T>
-/// class C {};
-/// class C<int> c;
-///
-/// class D {};
-/// class D d;
-/// \endcode
-/// elaboratedTypeLoc(hasNamedTypeLoc(templateSpecializationTypeLoc()));
-/// matches the `TypeLoc` of the variable declaration of `c`, but not `d`.
-AST_MATCHER_P(ElaboratedTypeLoc, hasNamedTypeLoc, internal::Matcher<TypeLoc>,
- InnerMatcher) {
- return InnerMatcher.matches(Node.getNamedTypeLoc(), Finder, Builder);
-}
-
/// Matches type \c bool.
///
/// Given
@@ -7279,7 +7267,7 @@ extern const AstTypeMatcher<DecltypeType> decltypeType;
AST_TYPE_TRAVERSE_MATCHER(hasDeducedType, getDeducedType,
AST_POLYMORPHIC_SUPPORTED_TYPES(AutoType));
-/// Matches \c DecltypeType or \c UsingType nodes to find the underlying type.
+/// Matches \c QualType nodes to find the underlying type.
///
/// Given
/// \code
@@ -7289,10 +7277,13 @@ AST_TYPE_TRAVERSE_MATCHER(hasDeducedType, getDeducedType,
/// decltypeType(hasUnderlyingType(isInteger()))
/// matches the type of "a"
///
-/// Usable as: Matcher<DecltypeType>, Matcher<UsingType>
-AST_TYPE_TRAVERSE_MATCHER(hasUnderlyingType, getUnderlyingType,
- AST_POLYMORPHIC_SUPPORTED_TYPES(DecltypeType,
- UsingType));
+/// Usable as: Matcher<QualType>
+AST_MATCHER_P(Type, hasUnderlyingType, internal::Matcher<QualType>, Inner) {
+ QualType QT = Node.getLocallyUnqualifiedSingleStepDesugaredType();
+ if (QT == QualType(&Node, 0))
+ return false;
+ return Inner.matches(QT, Finder, Builder);
+}
/// Matches \c FunctionType nodes.
///
@@ -7571,27 +7562,7 @@ extern const AstTypeMatcher<RecordType> recordType;
/// and \c c.
extern const AstTypeMatcher<TagType> tagType;
-/// Matches types specified with an elaborated type keyword or with a
-/// qualified name.
-///
-/// Given
-/// \code
-/// namespace N {
-/// namespace M {
-/// class D {};
-/// }
-/// }
-/// class C {};
-///
-/// class C c;
-/// N::M::D d;
-/// \endcode
-///
-/// \c elaboratedType() matches the type of the variable declarations of both
-/// \c c and \c d.
-extern const AstTypeMatcher<ElaboratedType> elaboratedType;
-
-/// Matches ElaboratedTypes whose qualifier, a NestedNameSpecifier,
+/// Matches Types whose qualifier, a NestedNameSpecifier,
/// matches \c InnerMatcher if the qualifier exists.
///
/// Given
@@ -7606,34 +7577,14 @@ extern const AstTypeMatcher<ElaboratedType> elaboratedType;
///
/// \c elaboratedType(hasQualifier(hasPrefix(specifiesNamespace(hasName("N"))))
/// matches the type of the variable declaration of \c d.
-AST_MATCHER_P(ElaboratedType, hasQualifier,
- internal::Matcher<NestedNameSpecifier>, InnerMatcher) {
- if (const NestedNameSpecifier *Qualifier = Node.getQualifier())
- return InnerMatcher.matches(*Qualifier, Finder, Builder);
+AST_MATCHER_P(Type, hasQualifier, internal::Matcher<NestedNameSpecifier>,
+ InnerMatcher) {
+ if (NestedNameSpecifier Qualifier = Node.getPrefix())
+ return InnerMatcher.matches(Qualifier, Finder, Builder);
return false;
}
-/// Matches ElaboratedTypes whose named type matches \c InnerMatcher.
-///
-/// Given
-/// \code
-/// namespace N {
-/// namespace M {
-/// class D {};
-/// }
-/// }
-/// N::M::D d;
-/// \endcode
-///
-/// \c elaboratedType(namesType(recordType(
-/// hasDeclaration(namedDecl(hasName("D")))))) matches the type of the variable
-/// declaration of \c d.
-AST_MATCHER_P(ElaboratedType, namesType, internal::Matcher<QualType>,
- InnerMatcher) {
- return InnerMatcher.matches(Node.getNamedType(), Finder, Builder);
-}
-
/// Matches types specified through a using declaration.
///
/// Given
@@ -7802,7 +7753,7 @@ AST_MATCHER_FUNCTION_P_OVERLOAD(
/// matches "A::"
AST_MATCHER_P(NestedNameSpecifier, specifiesType,
internal::Matcher<QualType>, InnerMatcher) {
- if (!Node.getAsType())
+ if (Node.getKind() != NestedNameSpecifier::Kind::Type)
return false;
return InnerMatcher.matches(QualType(Node.getAsType(), 0), Finder, Builder);
}
@@ -7820,8 +7771,12 @@ AST_MATCHER_P(NestedNameSpecifier, specifiesType,
/// matches "A::"
AST_MATCHER_P(NestedNameSpecifierLoc, specifiesTypeLoc,
internal::Matcher<TypeLoc>, InnerMatcher) {
- return Node && Node.getNestedNameSpecifier()->getAsType() &&
- InnerMatcher.matches(Node.getTypeLoc(), Finder, Builder);
+ if (!Node)
+ return false;
+ TypeLoc TL = Node.getAsTypeLoc();
+ if (!TL)
+ return false;
+ return InnerMatcher.matches(TL, Finder, Builder);
}
/// Matches on the prefix of a \c NestedNameSpecifier.
@@ -7836,10 +7791,21 @@ AST_MATCHER_P(NestedNameSpecifierLoc, specifiesTypeLoc,
AST_MATCHER_P_OVERLOAD(NestedNameSpecifier, hasPrefix,
internal::Matcher<NestedNameSpecifier>, InnerMatcher,
0) {
- const NestedNameSpecifier *NextNode = Node.getPrefix();
+ NestedNameSpecifier NextNode = std::nullopt;
+ switch (Node.getKind()) {
+ case NestedNameSpecifier::Kind::Namespace:
+ NextNode = Node.getAsNamespaceAndPrefix().Prefix;
+ break;
+ case NestedNameSpecifier::Kind::Type:
+ NextNode = Node.getAsType()->getPrefix();
+ break;
+ default:
+ break;
+ }
+
if (!NextNode)
return false;
- return InnerMatcher.matches(*NextNode, Finder, Builder);
+ return InnerMatcher.matches(NextNode, Finder, Builder);
}
/// Matches on the prefix of a \c NestedNameSpecifierLoc.
@@ -7854,7 +7820,12 @@ AST_MATCHER_P_OVERLOAD(NestedNameSpecifier, hasPrefix,
AST_MATCHER_P_OVERLOAD(NestedNameSpecifierLoc, hasPrefix,
internal::Matcher<NestedNameSpecifierLoc>, InnerMatcher,
1) {
- NestedNameSpecifierLoc NextNode = Node.getPrefix();
+ NestedNameSpecifierLoc NextNode;
+ if (TypeLoc TL = Node.getAsTypeLoc())
+ NextNode = TL.getPrefix();
+ else
+ NextNode = Node.getAsNamespaceAndPrefix().Prefix;
+
if (!NextNode)
return false;
return InnerMatcher.matches(NextNode, Finder, Builder);
@@ -7872,9 +7843,13 @@ AST_MATCHER_P_OVERLOAD(NestedNameSpecifierLoc, hasPrefix,
/// matches "ns::"
AST_MATCHER_P(NestedNameSpecifier, specifiesNamespace,
internal::Matcher<NamespaceDecl>, InnerMatcher) {
- if (!Node.getAsNamespace())
+ if (Node.getKind() != NestedNameSpecifier::Kind::Namespace)
+ return false;
+ const auto *Namespace =
+ dyn_cast<NamespaceDecl>(Node.getAsNamespaceAndPrefix().Namespace);
+ if (!Namespace)
return false;
- return InnerMatcher.matches(*Node.getAsNamespace(), Finder, Builder);
+ return InnerMatcher.matches(*Namespace, Finder, Builder);
}
/// Matches attributes.
diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
index 667a044abcef1..399af3d888551 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -1013,10 +1013,7 @@ class HasDeclarationMatcher : public MatcherInterface<T> {
// First, for any types that have a declaration, extract the declaration and
// match on it.
if (const auto *S = dyn_cast<TagType>(&Node)) {
- return matchesDecl(S->getDecl(), Finder, Builder);
- }
- if (const auto *S = dyn_cast<InjectedClassNameType>(&Node)) {
- return matchesDecl(S->getDecl(), Finder, Builder);
+ return matchesDecl(S->getOriginalDecl(), Finder, Builder);
}
if (const auto *S = dyn_cast<TemplateTypeParmType>(&Node)) {
return matchesDecl(S->getDecl(), Finder, Builder);
@@ -1027,6 +1024,9 @@ class HasDeclarationMatcher : public MatcherInterface<T> {
if (const auto *S = dyn_cast<UnresolvedUsingType>(&Node)) {
return matchesDecl(S->getDecl(), Finder, Builder);
}
+ if (const auto *S = dyn_cast<UsingType>(&Node)) {
+ return matchesDecl(S->getDecl(), Finder, Builder);
+ }
if (const auto *S = dyn_cast<ObjCObjectType>(&Node)) {
return matchesDecl(S->getInterface(), Finder, Builder);
}
@@ -1062,12 +1062,6 @@ class HasDeclarationMatcher : public MatcherInterface<T> {
Builder);
}
- // FIXME: We desugar elaborated types. This makes the assumption that users
- // do never want to match on whether a type is elaborated - there are
- // arguments for both sides; for now, continue desugaring.
- if (const auto *S = dyn_cast<ElaboratedType>(&Node)) {
- return matchesSpecialized(S->desugar(), Finder, Builder);
- }
// Similarly types found via using declarations.
// These are *usually* meaningless sugar, and this matches the historical
// behavior prior to the introduction of UsingType.
@@ -1207,8 +1201,8 @@ using AdaptativeDefaultToTypes =
/// All types that are supported by HasDeclarationMatcher above.
using HasDeclarationSupportedTypes =
TypeList<CallExpr, CXXConstructExpr, CXXNewExpr, DeclRefExpr, EnumType,
- ElaboratedType, InjectedClassNameType, LabelStmt, AddrLabelExpr,
- MemberExpr, QualType, RecordType, TagType,
+ InjectedClassNameType, LabelStmt, AddrLabelExpr, MemberExpr,
+ QualType, RecordType, TagType, UsingType,
TemplateSpecializationType, TemplateTypeParmType, TypedefType,
UnresolvedUsingType, ObjCIvarRefExpr, ObjCInterfaceDecl>;
@@ -1785,7 +1779,7 @@ class LocMatcher : public MatcherInterface<TLoc> {
private:
static DynTypedNode extract(const NestedNameSpecifierLoc &Loc) {
- return DynTypedNode::create(*Loc.getNestedNameSpecifier());
+ return DynTypedNode::create(Loc.getNestedNameSpecifier());
}
};
diff --git a/clang/include/clang/Analysis/FlowSensitive/ASTOps.h b/clang/include/clang/Analysis/FlowSensitive/ASTOps.h
index 8c7ee86d15c06..a404b06cd62ca 100644
--- a/clang/include/clang/Analysis/FlowSensitive/ASTOps.h
+++ b/clang/include/clang/Analysis/FlowSensitive/ASTOps.h
@@ -112,8 +112,14 @@ class AnalysisASTVisitor : public DynamicRecursiveASTVisitor {
// fields that are only used in these.
// Note: The operand of the `noexcept` operator is an unevaluated operand, but
// nevertheless it appears in the Clang CFG, so we don't exclude it here.
- bool TraverseDecltypeTypeLoc(DecltypeTypeLoc) override { return true; }
- bool TraverseTypeOfExprTypeLoc(TypeOfExprTypeLoc) override { return true; }
+ bool TraverseDecltypeTypeLoc(DecltypeTypeLoc,
+ bool TraverseQualifier) override {
+ return true;
+ }
+ bool TraverseTypeOfExprTypeLoc(TypeOfExprTypeLoc,
+ bool TraverseQualifier) override {
+ return true;
+ }
bool TraverseCXXTypeidExpr(CXXTypeidExpr *TIE) override {
if (TIE->isPotentiallyEvaluated())
return DynamicRecursiveASTVisitor::TraverseCXXTypeidExpr(TIE);
diff --git a/clang/include/clang/Basic/DeclNodes.td b/clang/include/clang/Basic/DeclNodes.td
index f1ebaf1db3fc0..b4c02949426a1 100644
--- a/clang/include/clang/Basic/DeclNodes.td
+++ b/clang/include/clang/Basic/DeclNodes.td
@@ -15,81 +15,80 @@ def PragmaComment : DeclNode<Decl>;
def PragmaDetectMismatch : DeclNode<Decl>;
def ExternCContext : DeclNode<Decl>, DeclContext;
def Named : DeclNode<Decl, "named declarations", 1>;
- def Namespace : DeclNode<Named, "namespaces">, DeclContext;
- def UsingDirective : DeclNode<Named>;
- def NamespaceAlias : DeclNode<Named>;
- def Label : DeclNode<Named, "labels">;
- def Type : DeclNode<Named, "types", 1>;
- def TypedefName : DeclNode<Type, "typedefs", 1>;
- def Typedef : DeclNode<TypedefName>;
- def TypeAlias : DeclNode<TypedefName>;
- def ObjCTypeParam : DeclNode<TypedefName>;
- def UnresolvedUsingTypename : DeclNode<Type>;
- def Tag : DeclNode<Type, "tag types", 1>, DeclContext;
- def Enum : DeclNode<Tag, "enums">;
- def Record : DeclNode<Tag, "structs, unions, classes">;
- def CXXRecord : DeclNode<Record, "classes">;
- def ClassTemplateSpecialization : DeclNode<CXXRecord>;
- def ClassTemplatePartialSpecialization
- : DeclNode<ClassTemplateSpecialization>;
- def TemplateTypeParm : DeclNode<Type>;
- def Value : DeclNode<Named, "value declarations", 1>;
- def EnumConstant : DeclNode<Value, "enumerators">;
- def UnresolvedUsingValue : DeclNode<Value>;
- def IndirectField : DeclNode<Value>;
- def Binding : DeclNode<Value>;
- def OMPDeclareReduction : DeclNode<Value>, DeclContext;
- def OMPDeclareMapper : DeclNode<Value>, DeclContext;
- def MSGuid : DeclNode<Value>;
- def UnnamedGlobalConstant : DeclNode<Value>;
- def TemplateParamObject : DeclNode<Value>;
- def Declarator : DeclNode<Value, "declarators", 1>;
- def Field : DeclNode<Declarator, "non-static data members">;
- def ObjCIvar : DeclNode<Field>;
- def ObjCAtDefsField : DeclNode<Field>;
- def MSProperty : DeclNode<Declarator>;
- def Function : DeclNode<Declarator, "functions">, DeclContext;
- def CXXDeductionGuide : DeclNode<Function>;
- def CXXMethod : DeclNode<Function>;
- def CXXConstructor : DeclNode<CXXMethod>;
- def CXXDestructor : DeclNode<CXXMethod>;
- def CXXConversion : DeclNode<CXXMethod>;
- def Var : DeclNode<Declarator, "variables">;
- def VarTemplateSpecialization : DeclNode<Var>;
- def VarTemplatePartialSpecialization
- : DeclNode<VarTemplateSpecialization>;
- def ImplicitParam : DeclNode<Var>;
- def ParmVar : DeclNode<Var, "parameters">;
- def Decomposition : DeclNode<Var>;
- def OMPCapturedExpr : DeclNode<Var>;
- def NonTypeTemplateParm : DeclNode<Declarator>;
- def Template : DeclNode<Named, "templates", 1>;
- def RedeclarableTemplate : DeclNode<Template, "redeclarable templates", 1>;
- def FunctionTemplate : DeclNode<RedeclarableTemplate>;
- def ClassTemplate : DeclNode<RedeclarableTemplate>;
- def VarTemplate : DeclNode<RedeclarableTemplate>;
- def TypeAliasTemplate : DeclNode<RedeclarableTemplate>;
- def TemplateTemplateParm : DeclNode<Template>;
- def BuiltinTemplate : DeclNode<Template>;
- def Concept : DeclNode<Template>;
- def BaseUsing : DeclNode<Named, "", 1>;
- def Using : DeclNode<BaseUsing>;
- def UsingEnum : DeclNode<BaseUsing>;
- def UsingPack : DeclNode<Named>;
- def UsingShadow : DeclNode<Named>;
- def ConstructorUsingShadow : DeclNode<UsingShadow>;
- def UnresolvedUsingIfExists : DeclNode<Named>;
- def ObjCMethod : DeclNode<Named, "Objective-C methods">, DeclContext;
- def ObjCContainer : DeclNode<Named, "Objective-C containers", 1>, DeclContext;
- def ObjCCategory : DeclNode<ObjCContainer>;
- def ObjCProtocol : DeclNode<ObjCContainer, "Objective-C protocols">;
- def ObjCInterface : DeclNode<ObjCContainer, "Objective-C interfaces">;
- def ObjCImpl
- : DeclNode<ObjCContainer, "Objective-C implementation declarations", 1>;
- def ObjCCategoryImpl : DeclNode<ObjCImpl>;
- def ObjCImplementation : DeclNode<ObjCImpl>;
- def ObjCProperty : DeclNode<Named, "Objective-C properties">;
- def ObjCCompatibleAlias : DeclNode<Named>;
+def NamespaceBase : DeclNode<Named, "namespace declarations", 1>;
+def Namespace : DeclNode<NamespaceBase, "namespaces">, DeclContext;
+def NamespaceAlias : DeclNode<NamespaceBase>;
+def UsingDirective : DeclNode<Named>;
+def Label : DeclNode<Named, "labels">;
+def Type : DeclNode<Named, "types", 1>;
+def TypedefName : DeclNode<Type, "typedefs", 1>;
+def Typedef : DeclNode<TypedefName>;
+def TypeAlias : DeclNode<TypedefName>;
+def ObjCTypeParam : DeclNode<TypedefName>;
+def UnresolvedUsingTypename : DeclNode<Type>;
+def Tag : DeclNode<Type, "tag types", 1>, DeclContext;
+def Enum : DeclNode<Tag, "enums">;
+def Record : DeclNode<Tag, "structs, unions, classes">;
+def CXXRecord : DeclNode<Record, "classes">;
+def ClassTemplateSpecialization : DeclNode<CXXRecord>;
+def ClassTemplatePartialSpecialization : DeclNode<ClassTemplateSpecialization>;
+def TemplateTypeParm : DeclNode<Type>;
+def Value : DeclNode<Named, "value declarations", 1>;
+def EnumConstant : DeclNode<Value, "enumerators">;
+def UnresolvedUsingValue : DeclNode<Value>;
+def IndirectField : DeclNode<Value>;
+def Binding : DeclNode<Value>;
+def OMPDeclareReduction : DeclNode<Value>, DeclContext;
+def OMPDeclareMapper : DeclNode<Value>, DeclContext;
+def MSGuid : DeclNode<Value>;
+def UnnamedGlobalConstant : DeclNode<Value>;
+def TemplateParamObject : DeclNode<Value>;
+def Declarator : DeclNode<Value, "declarators", 1>;
+def Field : DeclNode<Declarator, "non-static data members">;
+def ObjCIvar : DeclNode<Field>;
+def ObjCAtDefsField : DeclNode<Field>;
+def MSProperty : DeclNode<Declarator>;
+def Function : DeclNode<Declarator, "functions">, DeclContext;
+def CXXDeductionGuide : DeclNode<Function>;
+def CXXMethod : DeclNode<Function>;
+def CXXConstructor : DeclNode<CXXMethod>;
+def CXXDestructor : DeclNode<CXXMethod>;
+def CXXConversion : DeclNode<CXXMethod>;
+def Var : DeclNode<Declarator, "variables">;
+def VarTemplateSpecialization : DeclNode<Var>;
+def VarTemplatePartialSpecialization : DeclNode<VarTemplateSpecialization>;
+def ImplicitParam : DeclNode<Var>;
+def ParmVar : DeclNode<Var, "parameters">;
+def Decomposition : DeclNode<Var>;
+def OMPCapturedExpr : DeclNode<Var>;
+def NonTypeTemplateParm : DeclNode<Declarator>;
+def Template : DeclNode<Named, "templates", 1>;
+def RedeclarableTemplate : DeclNode<Template, "redeclarable templates", 1>;
+def FunctionTemplate : DeclNode<RedeclarableTemplate>;
+def ClassTemplate : DeclNode<RedeclarableTemplate>;
+def VarTemplate : DeclNode<R...
[truncated]
|
@llvm/pr-subscribers-backend-aarch64 Author: Matheus Izvekov (mizvekov) ChangesOther changes Second patch in the series starting at #147835 Patch is 800.27 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/148012.diff 173 Files Affected:
diff --git a/clang/include/clang/ASTMatchers/ASTMatchers.h b/clang/include/clang/ASTMatchers/ASTMatchers.h
index bae004896c11f..599155c5c9950 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -221,6 +221,19 @@ extern const internal::VariadicDynCastAllOfMatcher<Decl, TypedefNameDecl>
extern const internal::VariadicDynCastAllOfMatcher<Decl, TypeAliasDecl>
typeAliasDecl;
+/// \brief Matches shadow declarations introduced into a scope by a
+/// (resolved) using declaration.
+///
+/// Given
+/// \code
+/// namespace n { int f; }
+/// namespace declToImport { using n::f; }
+/// \endcode
+/// usingShadowDecl()
+/// matches \code f \endcode
+extern const internal::VariadicDynCastAllOfMatcher<Decl, UsingShadowDecl>
+ usingShadowDecl;
+
/// Matches type alias template declarations.
///
/// typeAliasTemplateDecl() matches
@@ -3718,7 +3731,7 @@ extern const internal::VariadicOperatorMatcherFunc<1, 1> unless;
/// Matcher<MemberExpr>, Matcher<QualType>, Matcher<RecordType>,
/// Matcher<TagType>, Matcher<TemplateSpecializationType>,
/// Matcher<TemplateTypeParmType>, Matcher<TypedefType>,
-/// Matcher<UnresolvedUsingType>
+/// Matcher<UnresolvedUsingType>, Matcher<UsingType>
inline internal::PolymorphicMatcher<
internal::HasDeclarationMatcher,
void(internal::HasDeclarationSupportedTypes), internal::Matcher<Decl>>
@@ -4353,7 +4366,13 @@ AST_POLYMORPHIC_MATCHER_P(throughUsingDecl,
AST_POLYMORPHIC_SUPPORTED_TYPES(DeclRefExpr,
UsingType),
internal::Matcher<UsingShadowDecl>, Inner) {
- const NamedDecl *FoundDecl = Node.getFoundDecl();
+ const NamedDecl *FoundDecl;
+ if constexpr (std::is_same_v<NodeType, UsingType>) {
+ FoundDecl = Node.getDecl();
+ } else {
+ static_assert(std::is_same_v<NodeType, DeclRefExpr>);
+ FoundDecl = Node.getFoundDecl();
+ }
if (const UsingShadowDecl *UsingDecl = dyn_cast<UsingShadowDecl>(FoundDecl))
return Inner.matches(*UsingDecl, Finder, Builder);
return false;
@@ -6982,37 +7001,6 @@ AST_POLYMORPHIC_MATCHER_P2(
InnerMatcher.matches(Args[Index], Finder, Builder);
}
-/// Matches C or C++ elaborated `TypeLoc`s.
-///
-/// Given
-/// \code
-/// struct s {};
-/// struct s ss;
-/// \endcode
-/// elaboratedTypeLoc()
-/// matches the `TypeLoc` of the variable declaration of `ss`.
-extern const internal::VariadicDynCastAllOfMatcher<TypeLoc, ElaboratedTypeLoc>
- elaboratedTypeLoc;
-
-/// Matches elaborated `TypeLoc`s that have a named `TypeLoc` matching
-/// `InnerMatcher`.
-///
-/// Given
-/// \code
-/// template <typename T>
-/// class C {};
-/// class C<int> c;
-///
-/// class D {};
-/// class D d;
-/// \endcode
-/// elaboratedTypeLoc(hasNamedTypeLoc(templateSpecializationTypeLoc()));
-/// matches the `TypeLoc` of the variable declaration of `c`, but not `d`.
-AST_MATCHER_P(ElaboratedTypeLoc, hasNamedTypeLoc, internal::Matcher<TypeLoc>,
- InnerMatcher) {
- return InnerMatcher.matches(Node.getNamedTypeLoc(), Finder, Builder);
-}
-
/// Matches type \c bool.
///
/// Given
@@ -7279,7 +7267,7 @@ extern const AstTypeMatcher<DecltypeType> decltypeType;
AST_TYPE_TRAVERSE_MATCHER(hasDeducedType, getDeducedType,
AST_POLYMORPHIC_SUPPORTED_TYPES(AutoType));
-/// Matches \c DecltypeType or \c UsingType nodes to find the underlying type.
+/// Matches \c QualType nodes to find the underlying type.
///
/// Given
/// \code
@@ -7289,10 +7277,13 @@ AST_TYPE_TRAVERSE_MATCHER(hasDeducedType, getDeducedType,
/// decltypeType(hasUnderlyingType(isInteger()))
/// matches the type of "a"
///
-/// Usable as: Matcher<DecltypeType>, Matcher<UsingType>
-AST_TYPE_TRAVERSE_MATCHER(hasUnderlyingType, getUnderlyingType,
- AST_POLYMORPHIC_SUPPORTED_TYPES(DecltypeType,
- UsingType));
+/// Usable as: Matcher<QualType>
+AST_MATCHER_P(Type, hasUnderlyingType, internal::Matcher<QualType>, Inner) {
+ QualType QT = Node.getLocallyUnqualifiedSingleStepDesugaredType();
+ if (QT == QualType(&Node, 0))
+ return false;
+ return Inner.matches(QT, Finder, Builder);
+}
/// Matches \c FunctionType nodes.
///
@@ -7571,27 +7562,7 @@ extern const AstTypeMatcher<RecordType> recordType;
/// and \c c.
extern const AstTypeMatcher<TagType> tagType;
-/// Matches types specified with an elaborated type keyword or with a
-/// qualified name.
-///
-/// Given
-/// \code
-/// namespace N {
-/// namespace M {
-/// class D {};
-/// }
-/// }
-/// class C {};
-///
-/// class C c;
-/// N::M::D d;
-/// \endcode
-///
-/// \c elaboratedType() matches the type of the variable declarations of both
-/// \c c and \c d.
-extern const AstTypeMatcher<ElaboratedType> elaboratedType;
-
-/// Matches ElaboratedTypes whose qualifier, a NestedNameSpecifier,
+/// Matches Types whose qualifier, a NestedNameSpecifier,
/// matches \c InnerMatcher if the qualifier exists.
///
/// Given
@@ -7606,34 +7577,14 @@ extern const AstTypeMatcher<ElaboratedType> elaboratedType;
///
/// \c elaboratedType(hasQualifier(hasPrefix(specifiesNamespace(hasName("N"))))
/// matches the type of the variable declaration of \c d.
-AST_MATCHER_P(ElaboratedType, hasQualifier,
- internal::Matcher<NestedNameSpecifier>, InnerMatcher) {
- if (const NestedNameSpecifier *Qualifier = Node.getQualifier())
- return InnerMatcher.matches(*Qualifier, Finder, Builder);
+AST_MATCHER_P(Type, hasQualifier, internal::Matcher<NestedNameSpecifier>,
+ InnerMatcher) {
+ if (NestedNameSpecifier Qualifier = Node.getPrefix())
+ return InnerMatcher.matches(Qualifier, Finder, Builder);
return false;
}
-/// Matches ElaboratedTypes whose named type matches \c InnerMatcher.
-///
-/// Given
-/// \code
-/// namespace N {
-/// namespace M {
-/// class D {};
-/// }
-/// }
-/// N::M::D d;
-/// \endcode
-///
-/// \c elaboratedType(namesType(recordType(
-/// hasDeclaration(namedDecl(hasName("D")))))) matches the type of the variable
-/// declaration of \c d.
-AST_MATCHER_P(ElaboratedType, namesType, internal::Matcher<QualType>,
- InnerMatcher) {
- return InnerMatcher.matches(Node.getNamedType(), Finder, Builder);
-}
-
/// Matches types specified through a using declaration.
///
/// Given
@@ -7802,7 +7753,7 @@ AST_MATCHER_FUNCTION_P_OVERLOAD(
/// matches "A::"
AST_MATCHER_P(NestedNameSpecifier, specifiesType,
internal::Matcher<QualType>, InnerMatcher) {
- if (!Node.getAsType())
+ if (Node.getKind() != NestedNameSpecifier::Kind::Type)
return false;
return InnerMatcher.matches(QualType(Node.getAsType(), 0), Finder, Builder);
}
@@ -7820,8 +7771,12 @@ AST_MATCHER_P(NestedNameSpecifier, specifiesType,
/// matches "A::"
AST_MATCHER_P(NestedNameSpecifierLoc, specifiesTypeLoc,
internal::Matcher<TypeLoc>, InnerMatcher) {
- return Node && Node.getNestedNameSpecifier()->getAsType() &&
- InnerMatcher.matches(Node.getTypeLoc(), Finder, Builder);
+ if (!Node)
+ return false;
+ TypeLoc TL = Node.getAsTypeLoc();
+ if (!TL)
+ return false;
+ return InnerMatcher.matches(TL, Finder, Builder);
}
/// Matches on the prefix of a \c NestedNameSpecifier.
@@ -7836,10 +7791,21 @@ AST_MATCHER_P(NestedNameSpecifierLoc, specifiesTypeLoc,
AST_MATCHER_P_OVERLOAD(NestedNameSpecifier, hasPrefix,
internal::Matcher<NestedNameSpecifier>, InnerMatcher,
0) {
- const NestedNameSpecifier *NextNode = Node.getPrefix();
+ NestedNameSpecifier NextNode = std::nullopt;
+ switch (Node.getKind()) {
+ case NestedNameSpecifier::Kind::Namespace:
+ NextNode = Node.getAsNamespaceAndPrefix().Prefix;
+ break;
+ case NestedNameSpecifier::Kind::Type:
+ NextNode = Node.getAsType()->getPrefix();
+ break;
+ default:
+ break;
+ }
+
if (!NextNode)
return false;
- return InnerMatcher.matches(*NextNode, Finder, Builder);
+ return InnerMatcher.matches(NextNode, Finder, Builder);
}
/// Matches on the prefix of a \c NestedNameSpecifierLoc.
@@ -7854,7 +7820,12 @@ AST_MATCHER_P_OVERLOAD(NestedNameSpecifier, hasPrefix,
AST_MATCHER_P_OVERLOAD(NestedNameSpecifierLoc, hasPrefix,
internal::Matcher<NestedNameSpecifierLoc>, InnerMatcher,
1) {
- NestedNameSpecifierLoc NextNode = Node.getPrefix();
+ NestedNameSpecifierLoc NextNode;
+ if (TypeLoc TL = Node.getAsTypeLoc())
+ NextNode = TL.getPrefix();
+ else
+ NextNode = Node.getAsNamespaceAndPrefix().Prefix;
+
if (!NextNode)
return false;
return InnerMatcher.matches(NextNode, Finder, Builder);
@@ -7872,9 +7843,13 @@ AST_MATCHER_P_OVERLOAD(NestedNameSpecifierLoc, hasPrefix,
/// matches "ns::"
AST_MATCHER_P(NestedNameSpecifier, specifiesNamespace,
internal::Matcher<NamespaceDecl>, InnerMatcher) {
- if (!Node.getAsNamespace())
+ if (Node.getKind() != NestedNameSpecifier::Kind::Namespace)
+ return false;
+ const auto *Namespace =
+ dyn_cast<NamespaceDecl>(Node.getAsNamespaceAndPrefix().Namespace);
+ if (!Namespace)
return false;
- return InnerMatcher.matches(*Node.getAsNamespace(), Finder, Builder);
+ return InnerMatcher.matches(*Namespace, Finder, Builder);
}
/// Matches attributes.
diff --git a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
index 667a044abcef1..399af3d888551 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchersInternal.h
@@ -1013,10 +1013,7 @@ class HasDeclarationMatcher : public MatcherInterface<T> {
// First, for any types that have a declaration, extract the declaration and
// match on it.
if (const auto *S = dyn_cast<TagType>(&Node)) {
- return matchesDecl(S->getDecl(), Finder, Builder);
- }
- if (const auto *S = dyn_cast<InjectedClassNameType>(&Node)) {
- return matchesDecl(S->getDecl(), Finder, Builder);
+ return matchesDecl(S->getOriginalDecl(), Finder, Builder);
}
if (const auto *S = dyn_cast<TemplateTypeParmType>(&Node)) {
return matchesDecl(S->getDecl(), Finder, Builder);
@@ -1027,6 +1024,9 @@ class HasDeclarationMatcher : public MatcherInterface<T> {
if (const auto *S = dyn_cast<UnresolvedUsingType>(&Node)) {
return matchesDecl(S->getDecl(), Finder, Builder);
}
+ if (const auto *S = dyn_cast<UsingType>(&Node)) {
+ return matchesDecl(S->getDecl(), Finder, Builder);
+ }
if (const auto *S = dyn_cast<ObjCObjectType>(&Node)) {
return matchesDecl(S->getInterface(), Finder, Builder);
}
@@ -1062,12 +1062,6 @@ class HasDeclarationMatcher : public MatcherInterface<T> {
Builder);
}
- // FIXME: We desugar elaborated types. This makes the assumption that users
- // do never want to match on whether a type is elaborated - there are
- // arguments for both sides; for now, continue desugaring.
- if (const auto *S = dyn_cast<ElaboratedType>(&Node)) {
- return matchesSpecialized(S->desugar(), Finder, Builder);
- }
// Similarly types found via using declarations.
// These are *usually* meaningless sugar, and this matches the historical
// behavior prior to the introduction of UsingType.
@@ -1207,8 +1201,8 @@ using AdaptativeDefaultToTypes =
/// All types that are supported by HasDeclarationMatcher above.
using HasDeclarationSupportedTypes =
TypeList<CallExpr, CXXConstructExpr, CXXNewExpr, DeclRefExpr, EnumType,
- ElaboratedType, InjectedClassNameType, LabelStmt, AddrLabelExpr,
- MemberExpr, QualType, RecordType, TagType,
+ InjectedClassNameType, LabelStmt, AddrLabelExpr, MemberExpr,
+ QualType, RecordType, TagType, UsingType,
TemplateSpecializationType, TemplateTypeParmType, TypedefType,
UnresolvedUsingType, ObjCIvarRefExpr, ObjCInterfaceDecl>;
@@ -1785,7 +1779,7 @@ class LocMatcher : public MatcherInterface<TLoc> {
private:
static DynTypedNode extract(const NestedNameSpecifierLoc &Loc) {
- return DynTypedNode::create(*Loc.getNestedNameSpecifier());
+ return DynTypedNode::create(Loc.getNestedNameSpecifier());
}
};
diff --git a/clang/include/clang/Analysis/FlowSensitive/ASTOps.h b/clang/include/clang/Analysis/FlowSensitive/ASTOps.h
index 8c7ee86d15c06..a404b06cd62ca 100644
--- a/clang/include/clang/Analysis/FlowSensitive/ASTOps.h
+++ b/clang/include/clang/Analysis/FlowSensitive/ASTOps.h
@@ -112,8 +112,14 @@ class AnalysisASTVisitor : public DynamicRecursiveASTVisitor {
// fields that are only used in these.
// Note: The operand of the `noexcept` operator is an unevaluated operand, but
// nevertheless it appears in the Clang CFG, so we don't exclude it here.
- bool TraverseDecltypeTypeLoc(DecltypeTypeLoc) override { return true; }
- bool TraverseTypeOfExprTypeLoc(TypeOfExprTypeLoc) override { return true; }
+ bool TraverseDecltypeTypeLoc(DecltypeTypeLoc,
+ bool TraverseQualifier) override {
+ return true;
+ }
+ bool TraverseTypeOfExprTypeLoc(TypeOfExprTypeLoc,
+ bool TraverseQualifier) override {
+ return true;
+ }
bool TraverseCXXTypeidExpr(CXXTypeidExpr *TIE) override {
if (TIE->isPotentiallyEvaluated())
return DynamicRecursiveASTVisitor::TraverseCXXTypeidExpr(TIE);
diff --git a/clang/include/clang/Basic/DeclNodes.td b/clang/include/clang/Basic/DeclNodes.td
index f1ebaf1db3fc0..b4c02949426a1 100644
--- a/clang/include/clang/Basic/DeclNodes.td
+++ b/clang/include/clang/Basic/DeclNodes.td
@@ -15,81 +15,80 @@ def PragmaComment : DeclNode<Decl>;
def PragmaDetectMismatch : DeclNode<Decl>;
def ExternCContext : DeclNode<Decl>, DeclContext;
def Named : DeclNode<Decl, "named declarations", 1>;
- def Namespace : DeclNode<Named, "namespaces">, DeclContext;
- def UsingDirective : DeclNode<Named>;
- def NamespaceAlias : DeclNode<Named>;
- def Label : DeclNode<Named, "labels">;
- def Type : DeclNode<Named, "types", 1>;
- def TypedefName : DeclNode<Type, "typedefs", 1>;
- def Typedef : DeclNode<TypedefName>;
- def TypeAlias : DeclNode<TypedefName>;
- def ObjCTypeParam : DeclNode<TypedefName>;
- def UnresolvedUsingTypename : DeclNode<Type>;
- def Tag : DeclNode<Type, "tag types", 1>, DeclContext;
- def Enum : DeclNode<Tag, "enums">;
- def Record : DeclNode<Tag, "structs, unions, classes">;
- def CXXRecord : DeclNode<Record, "classes">;
- def ClassTemplateSpecialization : DeclNode<CXXRecord>;
- def ClassTemplatePartialSpecialization
- : DeclNode<ClassTemplateSpecialization>;
- def TemplateTypeParm : DeclNode<Type>;
- def Value : DeclNode<Named, "value declarations", 1>;
- def EnumConstant : DeclNode<Value, "enumerators">;
- def UnresolvedUsingValue : DeclNode<Value>;
- def IndirectField : DeclNode<Value>;
- def Binding : DeclNode<Value>;
- def OMPDeclareReduction : DeclNode<Value>, DeclContext;
- def OMPDeclareMapper : DeclNode<Value>, DeclContext;
- def MSGuid : DeclNode<Value>;
- def UnnamedGlobalConstant : DeclNode<Value>;
- def TemplateParamObject : DeclNode<Value>;
- def Declarator : DeclNode<Value, "declarators", 1>;
- def Field : DeclNode<Declarator, "non-static data members">;
- def ObjCIvar : DeclNode<Field>;
- def ObjCAtDefsField : DeclNode<Field>;
- def MSProperty : DeclNode<Declarator>;
- def Function : DeclNode<Declarator, "functions">, DeclContext;
- def CXXDeductionGuide : DeclNode<Function>;
- def CXXMethod : DeclNode<Function>;
- def CXXConstructor : DeclNode<CXXMethod>;
- def CXXDestructor : DeclNode<CXXMethod>;
- def CXXConversion : DeclNode<CXXMethod>;
- def Var : DeclNode<Declarator, "variables">;
- def VarTemplateSpecialization : DeclNode<Var>;
- def VarTemplatePartialSpecialization
- : DeclNode<VarTemplateSpecialization>;
- def ImplicitParam : DeclNode<Var>;
- def ParmVar : DeclNode<Var, "parameters">;
- def Decomposition : DeclNode<Var>;
- def OMPCapturedExpr : DeclNode<Var>;
- def NonTypeTemplateParm : DeclNode<Declarator>;
- def Template : DeclNode<Named, "templates", 1>;
- def RedeclarableTemplate : DeclNode<Template, "redeclarable templates", 1>;
- def FunctionTemplate : DeclNode<RedeclarableTemplate>;
- def ClassTemplate : DeclNode<RedeclarableTemplate>;
- def VarTemplate : DeclNode<RedeclarableTemplate>;
- def TypeAliasTemplate : DeclNode<RedeclarableTemplate>;
- def TemplateTemplateParm : DeclNode<Template>;
- def BuiltinTemplate : DeclNode<Template>;
- def Concept : DeclNode<Template>;
- def BaseUsing : DeclNode<Named, "", 1>;
- def Using : DeclNode<BaseUsing>;
- def UsingEnum : DeclNode<BaseUsing>;
- def UsingPack : DeclNode<Named>;
- def UsingShadow : DeclNode<Named>;
- def ConstructorUsingShadow : DeclNode<UsingShadow>;
- def UnresolvedUsingIfExists : DeclNode<Named>;
- def ObjCMethod : DeclNode<Named, "Objective-C methods">, DeclContext;
- def ObjCContainer : DeclNode<Named, "Objective-C containers", 1>, DeclContext;
- def ObjCCategory : DeclNode<ObjCContainer>;
- def ObjCProtocol : DeclNode<ObjCContainer, "Objective-C protocols">;
- def ObjCInterface : DeclNode<ObjCContainer, "Objective-C interfaces">;
- def ObjCImpl
- : DeclNode<ObjCContainer, "Objective-C implementation declarations", 1>;
- def ObjCCategoryImpl : DeclNode<ObjCImpl>;
- def ObjCImplementation : DeclNode<ObjCImpl>;
- def ObjCProperty : DeclNode<Named, "Objective-C properties">;
- def ObjCCompatibleAlias : DeclNode<Named>;
+def NamespaceBase : DeclNode<Named, "namespace declarations", 1>;
+def Namespace : DeclNode<NamespaceBase, "namespaces">, DeclContext;
+def NamespaceAlias : DeclNode<NamespaceBase>;
+def UsingDirective : DeclNode<Named>;
+def Label : DeclNode<Named, "labels">;
+def Type : DeclNode<Named, "types", 1>;
+def TypedefName : DeclNode<Type, "typedefs", 1>;
+def Typedef : DeclNode<TypedefName>;
+def TypeAlias : DeclNode<TypedefName>;
+def ObjCTypeParam : DeclNode<TypedefName>;
+def UnresolvedUsingTypename : DeclNode<Type>;
+def Tag : DeclNode<Type, "tag types", 1>, DeclContext;
+def Enum : DeclNode<Tag, "enums">;
+def Record : DeclNode<Tag, "structs, unions, classes">;
+def CXXRecord : DeclNode<Record, "classes">;
+def ClassTemplateSpecialization : DeclNode<CXXRecord>;
+def ClassTemplatePartialSpecialization : DeclNode<ClassTemplateSpecialization>;
+def TemplateTypeParm : DeclNode<Type>;
+def Value : DeclNode<Named, "value declarations", 1>;
+def EnumConstant : DeclNode<Value, "enumerators">;
+def UnresolvedUsingValue : DeclNode<Value>;
+def IndirectField : DeclNode<Value>;
+def Binding : DeclNode<Value>;
+def OMPDeclareReduction : DeclNode<Value>, DeclContext;
+def OMPDeclareMapper : DeclNode<Value>, DeclContext;
+def MSGuid : DeclNode<Value>;
+def UnnamedGlobalConstant : DeclNode<Value>;
+def TemplateParamObject : DeclNode<Value>;
+def Declarator : DeclNode<Value, "declarators", 1>;
+def Field : DeclNode<Declarator, "non-static data members">;
+def ObjCIvar : DeclNode<Field>;
+def ObjCAtDefsField : DeclNode<Field>;
+def MSProperty : DeclNode<Declarator>;
+def Function : DeclNode<Declarator, "functions">, DeclContext;
+def CXXDeductionGuide : DeclNode<Function>;
+def CXXMethod : DeclNode<Function>;
+def CXXConstructor : DeclNode<CXXMethod>;
+def CXXDestructor : DeclNode<CXXMethod>;
+def CXXConversion : DeclNode<CXXMethod>;
+def Var : DeclNode<Declarator, "variables">;
+def VarTemplateSpecialization : DeclNode<Var>;
+def VarTemplatePartialSpecialization : DeclNode<VarTemplateSpecialization>;
+def ImplicitParam : DeclNode<Var>;
+def ParmVar : DeclNode<Var, "parameters">;
+def Decomposition : DeclNode<Var>;
+def OMPCapturedExpr : DeclNode<Var>;
+def NonTypeTemplateParm : DeclNode<Declarator>;
+def Template : DeclNode<Named, "templates", 1>;
+def RedeclarableTemplate : DeclNode<Template, "redeclarable templates", 1>;
+def FunctionTemplate : DeclNode<RedeclarableTemplate>;
+def ClassTemplate : DeclNode<RedeclarableTemplate>;
+def VarTemplate : DeclNode<R...
[truncated]
|
374aefc
to
8da8c53
Compare
ddaea06
to
b16b022
Compare
7b74782
to
cfe89c1
Compare
1d0abee
to
1e4b214
Compare
42d0f68
to
4896f42
Compare
1e4b214
to
7ad6252
Compare
4896f42
to
73ffe31
Compare
7ad6252
to
b37d904
Compare
You can test this locally with the following command:git-clang-format --diff HEAD~1 HEAD --extensions cpp,h -- clang/include/clang/ASTMatchers/ASTMatchers.h clang/include/clang/ASTMatchers/ASTMatchersInternal.h clang/include/clang/Analysis/FlowSensitive/ASTOps.h clang/include/clang/Sema/DeclSpec.h clang/include/clang/Sema/ParsedTemplate.h clang/include/clang/Sema/Sema.h clang/include/clang/Serialization/ASTRecordWriter.h clang/lib/ASTMatchers/ASTMatchFinder.cpp clang/lib/ASTMatchers/ASTMatchersInternal.cpp clang/lib/ASTMatchers/Dynamic/Registry.cpp clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp clang/lib/Analysis/UnsafeBufferUsage.cpp clang/lib/CodeGen/CGCXXABI.cpp clang/lib/CodeGen/CGCall.cpp clang/lib/CodeGen/CGClass.cpp clang/lib/CodeGen/CGDebugInfo.cpp clang/lib/CodeGen/CGDecl.cpp clang/lib/CodeGen/CGExpr.cpp clang/lib/CodeGen/CGExprCXX.cpp clang/lib/CodeGen/CGHLSLRuntime.cpp clang/lib/CodeGen/CGNonTrivialStruct.cpp clang/lib/CodeGen/CGObjCMac.cpp clang/lib/CodeGen/CGOpenMPRuntime.cpp clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp clang/lib/CodeGen/CGPointerAuth.cpp clang/lib/CodeGen/CGStmt.cpp clang/lib/CodeGen/CGStmtOpenMP.cpp clang/lib/CodeGen/CGVTables.cpp clang/lib/CodeGen/CodeGenFunction.cpp clang/lib/CodeGen/CodeGenModule.cpp clang/lib/CodeGen/CodeGenTypes.cpp clang/lib/CodeGen/ItaniumCXXABI.cpp clang/lib/CodeGen/MicrosoftCXXABI.cpp clang/lib/CodeGen/Targets/X86.cpp clang/lib/ExtractAPI/DeclarationFragments.cpp clang/lib/Frontend/ASTConsumers.cpp clang/lib/Frontend/ASTUnit.cpp clang/lib/Index/IndexTypeSourceInfo.cpp clang/lib/Index/USRGeneration.cpp clang/lib/InstallAPI/Visitor.cpp clang/lib/Parse/ParseExprCXX.cpp clang/lib/Parse/ParseTemplate.cpp clang/lib/Parse/Parser.cpp clang/lib/Sema/DeclSpec.cpp clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.cpp clang/lib/Sema/HLSLBuiltinTypeDeclBuilder.h clang/lib/Sema/HeuristicResolver.cpp clang/lib/Sema/SemaAccess.cpp clang/lib/Sema/SemaCXXScopeSpec.cpp clang/lib/Sema/SemaCast.cpp clang/lib/Sema/SemaChecking.cpp clang/lib/Sema/SemaCodeComplete.cpp clang/lib/Sema/SemaCoroutine.cpp clang/lib/Sema/SemaDecl.cpp clang/lib/Sema/SemaDeclAttr.cpp clang/lib/Sema/SemaDeclCXX.cpp clang/lib/Sema/SemaDeclObjC.cpp clang/lib/Sema/SemaExceptionSpec.cpp clang/lib/Sema/SemaExpr.cpp clang/lib/Sema/SemaExprCXX.cpp clang/lib/Sema/SemaExprMember.cpp clang/lib/Sema/SemaExprObjC.cpp clang/lib/Sema/SemaFunctionEffects.cpp clang/lib/Sema/SemaHLSL.cpp clang/lib/Sema/SemaInit.cpp clang/lib/Sema/SemaLambda.cpp clang/lib/Sema/SemaLookup.cpp clang/lib/Sema/SemaOpenMP.cpp clang/lib/Sema/SemaOverload.cpp clang/lib/Sema/SemaStmt.cpp clang/lib/Sema/SemaStmtAsm.cpp clang/lib/Sema/SemaTemplate.cpp clang/lib/Sema/SemaTemplateDeduction.cpp clang/lib/Sema/SemaTemplateDeductionGuide.cpp clang/lib/Sema/SemaTemplateInstantiate.cpp clang/lib/Sema/SemaTemplateInstantiateDecl.cpp clang/lib/Sema/SemaTemplateVariadic.cpp clang/lib/Sema/SemaType.cpp clang/lib/Sema/SemaTypeTraits.cpp clang/lib/Serialization/ASTReader.cpp clang/lib/Serialization/ASTReaderDecl.cpp clang/lib/Serialization/ASTWriter.cpp clang/lib/Serialization/ASTWriterDecl.cpp clang/lib/Serialization/TemplateArgumentHasher.cpp clang/lib/StaticAnalyzer/Checkers/DynamicTypePropagation.cpp clang/lib/StaticAnalyzer/Checkers/LLVMConventionsChecker.cpp clang/lib/StaticAnalyzer/Checkers/NonnullGlobalConstantsChecker.cpp clang/lib/StaticAnalyzer/Checkers/NumberObjectConversionChecker.cpp clang/lib/StaticAnalyzer/Checkers/PaddingChecker.cpp clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp clang/lib/StaticAnalyzer/Checkers/WebKit/RefCntblBaseVirtualDtorChecker.cpp clang/lib/StaticAnalyzer/Core/CallEvent.cpp clang/lib/StaticAnalyzer/Core/MemRegion.cpp clang/lib/StaticAnalyzer/Core/SValBuilder.cpp clang/lib/Tooling/ASTDiff/ASTDiff.cpp clang/lib/Tooling/Refactoring/Lookup.cpp clang/lib/Tooling/Refactoring/Rename/USRLocFinder.cpp clang/lib/Tooling/Syntax/BuildTree.cpp clang/lib/Tooling/Transformer/RangeSelector.cpp clang/tools/libclang/CIndex.cpp clang/tools/libclang/CXCursor.cpp clang/tools/libclang/CXIndexDataConsumer.cpp clang/tools/libclang/CXType.cpp View the diff from clang-format here.diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 345a23ae9..c262b8f72 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -9224,8 +9224,7 @@ bool InitializationSequence::Diagnose(Sema &S,
if (const RecordType *Record
= Entity.getType()->getAs<RecordType>())
- S.Diag(Record->getDecl()->getLocation(),
- diag::note_previous_decl)
+ S.Diag(Record->getDecl()->getLocation(), diag::note_previous_decl)
<< S.Context.getCanonicalTagType(Record->getOriginalDecl());
}
break;
|
73ffe31
to
d8acbe8
Compare
b37d904
to
533e517
Compare
533e517
to
365a333
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re: Python bindings changes.
The tests currently fail because the libclang.so cannot even be built. Is this expected, as in, can it only be built after the last patch again? (I see that the tests passed on patch 6/6).
This should also probably get an entry in the bindings' breaking changes section of the release notes.
self.assertEqual(fields[1].type.kind, TypeKind.ELABORATED) | ||
self.assertEqual(fields[1].type.kind, TypeKind.TYPEDEF) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand the changes correctly, the ELABORATED
TypeKind is removed, right?
If so, that enum variant should also be removed from the TypeKind enum in the Python bindings.
I.e. variant 119 of TypeKind
in cindex.py
:
ELABORATED = 119 |
Other changes
Second patch in the series starting at #147835