Skip to content

Commit

Permalink
Revert "[clang] Implement ElaboratedType sugaring for types written b…
Browse files Browse the repository at this point in the history
…are"

This reverts commit bdc6974 because it
breaks all the LLDB tests that import the std module.

  import-std-module/array.TestArrayFromStdModule.py
  import-std-module/deque-basic.TestDequeFromStdModule.py
  import-std-module/deque-dbg-info-content.TestDbgInfoContentDequeFromStdModule.py
  import-std-module/forward_list.TestForwardListFromStdModule.py
  import-std-module/forward_list-dbg-info-content.TestDbgInfoContentForwardListFromStdModule.py
  import-std-module/list.TestListFromStdModule.py
  import-std-module/list-dbg-info-content.TestDbgInfoContentListFromStdModule.py
  import-std-module/queue.TestQueueFromStdModule.py
  import-std-module/stack.TestStackFromStdModule.py
  import-std-module/vector.TestVectorFromStdModule.py
  import-std-module/vector-bool.TestVectorBoolFromStdModule.py
  import-std-module/vector-dbg-info-content.TestDbgInfoContentVectorFromStdModule.py
  import-std-module/vector-of-vectors.TestVectorOfVectorsFromStdModule.py

https://green.lab.llvm.org/green/view/LLDB/job/lldb-cmake/45301/
  • Loading branch information
JDevlieghere committed Jul 13, 2022
1 parent bb3f99c commit 3968936
Show file tree
Hide file tree
Showing 285 changed files with 2,138 additions and 2,346 deletions.
14 changes: 8 additions & 6 deletions clang-tools-extra/clang-change-namespace/ChangeNamespace.cpp
Expand Up @@ -567,12 +567,14 @@ void ChangeNamespaceTool::run(
if (Loc.getTypeLocClass() == TypeLoc::Elaborated) {
NestedNameSpecifierLoc NestedNameSpecifier =
Loc.castAs<ElaboratedTypeLoc>().getQualifierLoc();
// FIXME: avoid changing injected class names.
if (auto *NNS = NestedNameSpecifier.getNestedNameSpecifier()) {
const Type *SpecifierType = NNS->getAsType();
if (SpecifierType && SpecifierType->isRecordType())
return;
}
// This happens for friend declaration of a base class with injected class
// name.
if (!NestedNameSpecifier.getNestedNameSpecifier())
return;
const Type *SpecifierType =
NestedNameSpecifier.getNestedNameSpecifier()->getAsType();
if (SpecifierType && SpecifierType->isRecordType())
return;
}
fixTypeLoc(Result, startLocationForType(Loc), endLocationForType(Loc), Loc);
} else if (const auto *VarRef =
Expand Down
Expand Up @@ -215,8 +215,7 @@ void FindAllSymbols::registerMatchers(MatchFinder *MatchFinder) {
// Uses of most types: just look at what the typeLoc refers to.
MatchFinder->addMatcher(
typeLoc(isExpansionInMainFile(),
loc(qualType(allOf(unless(elaboratedType()),
hasDeclaration(Types.bind("use")))))),
loc(qualType(hasDeclaration(Types.bind("use"))))),
this);
// Uses of typedefs: these are often transparent to hasDeclaration, so we need
// to handle them explicitly.
Expand Down
10 changes: 5 additions & 5 deletions clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
Expand Up @@ -87,9 +87,9 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
const auto ConstantExpr = ignoringParenImpCasts(
anyOf(integerLiteral(), unaryOperator(hasUnaryOperand(IntegerExpr)),
binaryOperator(hasLHS(IntegerExpr), hasRHS(IntegerExpr))));
const auto IntegerCallExpr = ignoringParenImpCasts(callExpr(
anyOf(hasType(isInteger()), hasType(hasCanonicalType(enumType()))),
unless(isInTemplateInstantiation())));
const auto IntegerCallExpr = ignoringParenImpCasts(
callExpr(anyOf(hasType(isInteger()), hasType(enumType())),
unless(isInTemplateInstantiation())));
const auto SizeOfExpr = sizeOfExpr(hasArgumentOfType(
hasUnqualifiedDesugaredType(type().bind("sizeof-arg-type"))));
const auto SizeOfZero =
Expand Down Expand Up @@ -147,8 +147,8 @@ void SizeofExpressionCheck::registerMatchers(MatchFinder *Finder) {
const auto StructAddrOfExpr = unaryOperator(
hasOperatorName("&"), hasUnaryOperand(ignoringParenImpCasts(
hasType(hasCanonicalType(recordType())))));
const auto PointerToStructType = hasUnqualifiedDesugaredType(
pointerType(pointee(hasCanonicalType(recordType()))));
const auto PointerToStructType =
hasUnqualifiedDesugaredType(pointerType(pointee(recordType())));
const auto PointerToStructExpr = ignoringParenImpCasts(expr(
hasType(hasCanonicalType(PointerToStructType)), unless(cxxThisExpr())));

Expand Down
Expand Up @@ -67,11 +67,10 @@ void SmartPtrArrayMismatchCheck::registerMatchers(MatchFinder *Finder) {
auto FindConstructExpr =
cxxConstructExpr(
hasDeclaration(FindConstructor), argumentCountIs(1),
hasArgument(0,
cxxNewExpr(isArray(),
hasType(hasCanonicalType(pointerType(
pointee(equalsBoundNode(PointerTypeN))))))
.bind(NewExprN)))
hasArgument(
0, cxxNewExpr(isArray(), hasType(pointerType(pointee(
equalsBoundNode(PointerTypeN)))))
.bind(NewExprN)))
.bind(ConstructExprN);
Finder->addMatcher(FindConstructExpr, this);
}
Expand Down Expand Up @@ -102,7 +101,7 @@ void SmartPtrArrayMismatchCheck::check(const MatchFinder::MatchResult &Result) {
SourceRange TemplateArgumentRange = TSTypeLoc.getArgLoc(0)
.getTypeSourceInfo()
->getTypeLoc()
.getSourceRange();
.getLocalSourceRange();
D << TemplateArgumentRange;

if (isInSingleDeclStmt(VarOrField)) {
Expand Down
Expand Up @@ -130,12 +130,7 @@ void AvoidCStyleCastsCheck::check(const MatchFinder::MatchResult &Result) {
// case of overloaded functions, so detection of redundant casts is trickier
// in this case. Don't emit "redundant cast" warnings for function
// pointer/reference types.
QualType Src = SourceTypeAsWritten, Dst = DestTypeAsWritten;
if (const auto *ElTy = dyn_cast<ElaboratedType>(Src))
Src = ElTy->getNamedType();
if (const auto *ElTy = dyn_cast<ElaboratedType>(Dst))
Dst = ElTy->getNamedType();
if (Src == Dst) {
if (SourceTypeAsWritten == DestTypeAsWritten) {
diag(CastExpr->getBeginLoc(), "redundant cast to the same type")
<< FixItHint::CreateRemoval(ReplaceRange);
return;
Expand Down
Expand Up @@ -36,8 +36,7 @@ void MultiwayPathsCoveredCheck::registerMatchers(MatchFinder *Finder) {
// otherwise the matcher does not work correctly, because it
// will not explicitly ignore enum conditions.
unless(ignoringImpCasts(
declRefExpr(hasType(hasCanonicalType(enumType())))
.bind("enum-condition"))))))
declRefExpr(hasType(enumType())).bind("enum-condition"))))))
.bind("switch"),
this);

Expand Down
13 changes: 6 additions & 7 deletions clang-tools-extra/clang-tidy/misc/MisplacedConstCheck.cpp
Expand Up @@ -21,13 +21,12 @@ void MisplacedConstCheck::registerMatchers(MatchFinder *Finder) {
pointee(anyOf(isConstQualified(), ignoringParens(functionType()))))));

Finder->addMatcher(
valueDecl(hasType(qualType(
isConstQualified(),
elaboratedType(namesType(typedefType(hasDeclaration(
anyOf(typedefDecl(NonConstAndNonFunctionPointerType)
.bind("typedef"),
typeAliasDecl(NonConstAndNonFunctionPointerType)
.bind("typeAlias")))))))))
valueDecl(
hasType(isConstQualified()),
hasType(typedefType(hasDeclaration(anyOf(
typedefDecl(NonConstAndNonFunctionPointerType).bind("typedef"),
typeAliasDecl(NonConstAndNonFunctionPointerType)
.bind("typeAlias"))))))
.bind("decl"),
this);
}
Expand Down
Expand Up @@ -400,7 +400,7 @@ static bool canBeModified(ASTContext *Context, const Expr *E) {
return true;
if (const auto *Cast = Parents[0].get<ImplicitCastExpr>()) {
if ((Cast->getCastKind() == CK_NoOp &&
Context->hasSameType(Cast->getType(), E->getType().withConst())) ||
Cast->getType() == E->getType().withConst()) ||
(Cast->getCastKind() == CK_LValueToRValue &&
!Cast->getType().isNull() && Cast->getType()->isFundamentalType()))
return false;
Expand Down
3 changes: 1 addition & 2 deletions clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
Expand Up @@ -48,8 +48,7 @@ AST_MATCHER(CXXRecordDecl, isMoveConstructible) {

static TypeMatcher notTemplateSpecConstRefType() {
return lValueReferenceType(
pointee(unless(elaboratedType(namesType(templateSpecializationType()))),
isConstQualified()));
pointee(unless(templateSpecializationType()), isConstQualified()));
}

static TypeMatcher nonConstValueType() {
Expand Down
34 changes: 16 additions & 18 deletions clang-tools-extra/clang-tidy/modernize/UseEqualsDefaultCheck.cpp
Expand Up @@ -153,24 +153,22 @@ static bool isCopyAssignmentAndCanBeDefaulted(ASTContext *Context,
// ((Base*)this)->operator=((Base)Other);
//
// So we are looking for a member call that fulfills:
if (match(traverse(
TK_AsIs,
compoundStmt(has(ignoringParenImpCasts(cxxMemberCallExpr(
// - The object is an implicit cast of 'this' to a
// pointer to
// a base class.
onImplicitObjectArgument(implicitCastExpr(
hasImplicitDestinationType(hasCanonicalType(pointsTo(
type(equalsNode(Base->getCanonicalTypeInternal()
.getTypePtr()))))),
hasSourceExpression(cxxThisExpr()))),
// - The called method is the operator=.
callee(cxxMethodDecl(isCopyAssignmentOperator())),
// - The argument is (an implicit cast to a Base of)
// the argument taken by "Operator".
argumentCountIs(1),
hasArgument(
0, declRefExpr(to(varDecl(equalsNode(Param)))))))))),
if (match(traverse(TK_AsIs,
compoundStmt(has(ignoringParenImpCasts(cxxMemberCallExpr(
// - The object is an implicit cast of 'this' to a
// pointer to
// a base class.
onImplicitObjectArgument(implicitCastExpr(
hasImplicitDestinationType(
pointsTo(type(equalsNode(Base)))),
hasSourceExpression(cxxThisExpr()))),
// - The called method is the operator=.
callee(cxxMethodDecl(isCopyAssignmentOperator())),
// - The argument is (an implicit cast to a Base of)
// the argument taken by "Operator".
argumentCountIs(1),
hasArgument(0, declRefExpr(to(varDecl(
equalsNode(Param)))))))))),
*Compound, *Context)
.empty())
return false;
Expand Down
Expand Up @@ -97,9 +97,7 @@ struct UnqualNameVisitor : public RecursiveASTVisitor<UnqualNameVisitor> {
if (TL.getQualifierLoc() &&
!TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()))
return false;
const auto *T = TL.getTypePtr();
return TraverseTypeLoc(TL.getNamedTypeLoc(),
T->getKeyword() != ETK_None || T->getQualifier());
return TraverseTypeLoc(TL.getNamedTypeLoc(), true);
}

bool VisitDeclRefExpr(DeclRefExpr *S) {
Expand Down
5 changes: 1 addition & 4 deletions clang-tools-extra/clangd/FindTarget.cpp
Expand Up @@ -950,10 +950,7 @@ class ExplicitReferenceCollector
// ElaboratedTypeLoc will reports information for its inner type loc.
// Otherwise we loose information about inner types loc's qualifier.
TypeLoc Inner = L.getNamedTypeLoc().getUnqualifiedLoc();
if (L.getBeginLoc() == Inner.getBeginLoc())
return RecursiveASTVisitor::TraverseTypeLoc(Inner);
else
TypeLocsToSkip.insert(Inner.getBeginLoc());
TypeLocsToSkip.insert(Inner.getBeginLoc());
return RecursiveASTVisitor::TraverseElaboratedTypeLoc(L);
}

Expand Down
20 changes: 10 additions & 10 deletions clang-tools-extra/clangd/unittests/ASTTests.cpp
Expand Up @@ -72,7 +72,7 @@ TEST(GetDeducedType, KwAutoKwDecltypeExpansion) {
template<typename T> class Foo {};
^auto v = Foo<X>();
)cpp",
"Foo<X>",
"Foo<class X>",
},
{
R"cpp( // auto on initializer list.
Expand All @@ -93,7 +93,7 @@ TEST(GetDeducedType, KwAutoKwDecltypeExpansion) {
return Foo();
}
)cpp",
"Foo",
"struct Foo",
},
{
R"cpp( // decltype in trailing return type
Expand All @@ -102,7 +102,7 @@ TEST(GetDeducedType, KwAutoKwDecltypeExpansion) {
return Foo();
}
)cpp",
"Foo",
"struct Foo",
},
{
R"cpp( // auto in function return type
Expand All @@ -111,7 +111,7 @@ TEST(GetDeducedType, KwAutoKwDecltypeExpansion) {
return Foo();
}
)cpp",
"Foo",
"struct Foo",
},
{
R"cpp( // auto& in function return type
Expand All @@ -121,7 +121,7 @@ TEST(GetDeducedType, KwAutoKwDecltypeExpansion) {
return x;
}
)cpp",
"Foo",
"struct Foo",
},
{
R"cpp( // auto* in function return type
Expand All @@ -131,7 +131,7 @@ TEST(GetDeducedType, KwAutoKwDecltypeExpansion) {
return x;
}
)cpp",
"Foo",
"struct Foo",
},
{
R"cpp( // const auto& in function return type
Expand All @@ -141,7 +141,7 @@ TEST(GetDeducedType, KwAutoKwDecltypeExpansion) {
return x;
}
)cpp",
"Foo",
"struct Foo",
},
{
R"cpp( // decltype(auto) in function return (value)
Expand All @@ -150,7 +150,7 @@ TEST(GetDeducedType, KwAutoKwDecltypeExpansion) {
return Foo();
}
)cpp",
"Foo",
"struct Foo",
},
{
R"cpp( // decltype(auto) in function return (ref)
Expand All @@ -160,7 +160,7 @@ TEST(GetDeducedType, KwAutoKwDecltypeExpansion) {
return (x);
}
)cpp",
"Foo &",
"struct Foo &",
},
{
R"cpp( // decltype(auto) in function return (const ref)
Expand All @@ -170,7 +170,7 @@ TEST(GetDeducedType, KwAutoKwDecltypeExpansion) {
return (x);
}
)cpp",
"const Foo &",
"const struct Foo &",
},
{
R"cpp( // auto on alias
Expand Down
3 changes: 1 addition & 2 deletions clang-tools-extra/clangd/unittests/DumpASTTests.cpp
Expand Up @@ -121,8 +121,7 @@ declaration: Var - root
expression: DeclRef - operator+
expression: MaterializeTemporary - lvalue
expression: CXXTemporaryObject - Foo
type: Elaborated
type: Record - Foo
type: Record - Foo
expression: IntegerLiteral - 42
)"},
{R"cpp(
Expand Down
11 changes: 5 additions & 6 deletions clang-tools-extra/clangd/unittests/FindTargetTests.cpp
Expand Up @@ -1612,14 +1612,13 @@ TEST_F(FindExplicitReferencesTest, All) {
{
R"cpp(
void foo() {
$0^class {} $1^x;
int (*$2^fptr)(int $3^a, int) = nullptr;
class {} $0^x;
int (*$1^fptr)(int $2^a, int) = nullptr;
}
)cpp",
"0: targets = {}\n"
"1: targets = {x}, decl\n"
"2: targets = {fptr}, decl\n"
"3: targets = {a}, decl\n"},
"0: targets = {x}, decl\n"
"1: targets = {fptr}, decl\n"
"2: targets = {a}, decl\n"},
// Namespace aliases should be handled properly.
{
R"cpp(
Expand Down

0 comments on commit 3968936

Please sign in to comment.