Skip to content

Commit 3768ebc

Browse files
authored
merge main into amd-staging (llvm#4081)
2 parents 7e6479d + 8740131 commit 3768ebc

File tree

348 files changed

+8544
-4018
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

348 files changed

+8544
-4018
lines changed

.github/CODEOWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@
132132
/mlir/**/Transforms/Mem2Reg.* @moxinilian
133133
/mlir/**/Transforms/SROA.* @moxinilian
134134

135+
# MLIR IRDL-related
136+
/mlir/**/*IRDL* @moxinilian
137+
135138
# BOLT
136139
/bolt/ @aaupov @maksfb @rafaelauler @ayermolo @yota9 @paschalis-mpeis @yozhu
137140

amd/comgr/src/comgr-compiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ amd_comgr_status_t executeCommand(const Command &Job, raw_ostream &LogS,
670670
// Internally this call refers to the invocation created above, so at
671671
// this point the DiagnosticsEngine should accurately reflect all user
672672
// requested configuration from Argv.
673-
Clang->createDiagnostics(FS, &DiagClient, /* ShouldOwnClient */ false);
673+
Clang->createDiagnostics(&DiagClient, /* ShouldOwnClient */ false);
674674
if (!Clang->hasDiagnostics()) {
675675
return AMD_COMGR_STATUS_ERROR;
676676
}

clang-tools-extra/clang-include-fixer/IncludeFixer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ bool IncludeFixerActionFactory::runInvocation(
9494

9595
// Create the compiler's actual diagnostics engine. We want to drop all
9696
// diagnostics here.
97-
Compiler.createDiagnostics(Files->getVirtualFileSystem(),
98-
new clang::IgnoringDiagConsumer,
97+
Compiler.createDiagnostics(new clang::IgnoringDiagConsumer,
9998
/*ShouldOwnClient=*/true);
10099
Compiler.createSourceManager(*Files);
101100

clang-tools-extra/clangd/AST.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "clang/Basic/SourceManager.h"
3030
#include "clang/Basic/Specifiers.h"
3131
#include "clang/Index/USRGeneration.h"
32+
#include "clang/Sema/HeuristicResolver.h"
3233
#include "llvm/ADT/ArrayRef.h"
3334
#include "llvm/ADT/STLExtras.h"
3435
#include "llvm/ADT/SmallSet.h"
@@ -479,10 +480,12 @@ namespace {
479480
/// a deduced type set. The AST should be improved to simplify this scenario.
480481
class DeducedTypeVisitor : public RecursiveASTVisitor<DeducedTypeVisitor> {
481482
SourceLocation SearchedLocation;
483+
const HeuristicResolver *Resolver;
482484

483485
public:
484-
DeducedTypeVisitor(SourceLocation SearchedLocation)
485-
: SearchedLocation(SearchedLocation) {}
486+
DeducedTypeVisitor(SourceLocation SearchedLocation,
487+
const HeuristicResolver *Resolver)
488+
: SearchedLocation(SearchedLocation), Resolver(Resolver) {}
486489

487490
// Handle auto initializers:
488491
//- auto i = 1;
@@ -499,6 +502,14 @@ class DeducedTypeVisitor : public RecursiveASTVisitor<DeducedTypeVisitor> {
499502
return true;
500503

501504
if (auto *AT = D->getType()->getContainedAutoType()) {
505+
if (AT->isUndeducedAutoType()) {
506+
if (const auto *VD = dyn_cast<VarDecl>(D)) {
507+
if (Resolver && VD->hasInit()) {
508+
DeducedType = Resolver->resolveExprToType(VD->getInit());
509+
return true;
510+
}
511+
}
512+
}
502513
DeducedType = AT->desugar();
503514
}
504515
return true;
@@ -608,10 +619,12 @@ class DeducedTypeVisitor : public RecursiveASTVisitor<DeducedTypeVisitor> {
608619
};
609620
} // namespace
610621

611-
std::optional<QualType> getDeducedType(ASTContext &ASTCtx, SourceLocation Loc) {
622+
std::optional<QualType> getDeducedType(ASTContext &ASTCtx,
623+
const HeuristicResolver *Resolver,
624+
SourceLocation Loc) {
612625
if (!Loc.isValid())
613626
return {};
614-
DeducedTypeVisitor V(Loc);
627+
DeducedTypeVisitor V(Loc, Resolver);
615628
V.TraverseAST(ASTCtx);
616629
if (V.DeducedType.isNull())
617630
return std::nullopt;

clang-tools-extra/clangd/AST.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace clang {
3131
class SourceManager;
3232
class Decl;
3333
class DynTypedNode;
34+
class HeuristicResolver;
3435

3536
namespace clangd {
3637

@@ -167,7 +168,8 @@ QualType declaredType(const TypeDecl *D);
167168
/// Retrieves the deduced type at a given location (auto, decltype).
168169
/// It will return the underlying type.
169170
/// If the type is an undeduced auto, returns the type itself.
170-
std::optional<QualType> getDeducedType(ASTContext &, SourceLocation Loc);
171+
std::optional<QualType> getDeducedType(ASTContext &, const HeuristicResolver *,
172+
SourceLocation Loc);
171173

172174
// Find the abbreviated-function-template `auto` within a type, or returns null.
173175
// Similar to getContainedAutoTypeLoc, but these `auto`s are

clang-tools-extra/clangd/Compiler.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,9 @@ prepareCompilerInstance(std::unique_ptr<clang::CompilerInvocation> CI,
147147
}
148148

149149
auto Clang = std::make_unique<CompilerInstance>(std::move(CI));
150-
Clang->createDiagnostics(*VFS, &DiagsClient, false);
151-
152-
if (auto VFSWithRemapping = createVFSFromCompilerInvocation(
153-
Clang->getInvocation(), Clang->getDiagnostics(), VFS))
154-
VFS = VFSWithRemapping;
155-
Clang->createFileManager(VFS);
156-
150+
Clang->createVirtualFileSystem(VFS, &DiagsClient);
151+
Clang->createDiagnostics(&DiagsClient, false);
152+
Clang->createFileManager();
157153
if (!Clang->createTarget())
158154
return nullptr;
159155

clang-tools-extra/clangd/Hover.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,9 @@ std::optional<HoverInfo> getHover(ParsedAST &AST, Position Pos,
13091309
}
13101310
} else if (Tok.kind() == tok::kw_auto || Tok.kind() == tok::kw_decltype) {
13111311
HoverCountMetric.record(1, "keyword");
1312-
if (auto Deduced = getDeducedType(AST.getASTContext(), Tok.location())) {
1312+
if (auto Deduced =
1313+
getDeducedType(AST.getASTContext(), AST.getHeuristicResolver(),
1314+
Tok.location())) {
13131315
HI = getDeducedTypeHoverContents(*Deduced, Tok, AST.getASTContext(), PP,
13141316
Index);
13151317
HighlightRange = Tok.range(SM).toCharRange(SM);

clang-tools-extra/clangd/InlayHints.cpp

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -633,13 +633,30 @@ class InlayHintVisitor : public RecursiveASTVisitor<InlayHintVisitor> {
633633
}
634634

635635
if (auto *AT = D->getType()->getContainedAutoType()) {
636-
if (AT->isDeduced() && !D->getType()->isDependentType()) {
637-
// Our current approach is to place the hint on the variable
638-
// and accordingly print the full type
639-
// (e.g. for `const auto& x = 42`, print `const int&`).
640-
// Alternatively, we could place the hint on the `auto`
641-
// (and then just print the type deduced for the `auto`).
642-
addTypeHint(D->getLocation(), D->getType(), /*Prefix=*/": ");
636+
if (AT->isDeduced()) {
637+
QualType T;
638+
// If the type is dependent, HeuristicResolver *may* be able to
639+
// resolve it to something that's useful to print. In other
640+
// cases, it can't, and the resultng type would just be printed
641+
// as "<dependent type>", in which case don't hint it at all.
642+
if (D->getType()->isDependentType()) {
643+
if (D->hasInit()) {
644+
QualType Resolved = Resolver->resolveExprToType(D->getInit());
645+
if (Resolved != AST.DependentTy) {
646+
T = Resolved;
647+
}
648+
}
649+
} else {
650+
T = D->getType();
651+
}
652+
if (!T.isNull()) {
653+
// Our current approach is to place the hint on the variable
654+
// and accordingly print the full type
655+
// (e.g. for `const auto& x = 42`, print `const int&`).
656+
// Alternatively, we could place the hint on the `auto`
657+
// (and then just print the type deduced for the `auto`).
658+
addTypeHint(D->getLocation(), T, /*Prefix=*/": ");
659+
}
643660
}
644661
}
645662

clang-tools-extra/clangd/XRefs.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,9 @@ std::vector<LocatedSymbol> locateSymbolAt(ParsedAST &AST, Position Pos,
806806
if (Tok.kind() == tok::kw_auto || Tok.kind() == tok::kw_decltype) {
807807
// go-to-definition on auto should find the definition of the deduced
808808
// type, if possible
809-
if (auto Deduced = getDeducedType(AST.getASTContext(), Tok.location())) {
809+
if (auto Deduced =
810+
getDeducedType(AST.getASTContext(), AST.getHeuristicResolver(),
811+
Tok.location())) {
810812
auto LocSym = locateSymbolForType(AST, *Deduced, Index);
811813
if (!LocSym.empty())
812814
return LocSym;
@@ -1965,7 +1967,7 @@ std::vector<const CXXRecordDecl *> findRecordTypeAt(ParsedAST &AST,
19651967

19661968
// Return the type most associated with an AST node.
19671969
// This isn't precisely defined: we want "go to type" to do something useful.
1968-
static QualType typeForNode(const ASTContext &Ctx,
1970+
static QualType typeForNode(const ASTContext &Ctx, const HeuristicResolver *H,
19691971
const SelectionTree::Node *N) {
19701972
// If we're looking at a namespace qualifier, walk up to what it's qualifying.
19711973
// (If we're pointing at a *class* inside a NNS, N will be a TypeLoc).
@@ -1978,7 +1980,7 @@ static QualType typeForNode(const ASTContext &Ctx,
19781980
if (const TypeLoc *TL = N->ASTNode.get<TypeLoc>()) {
19791981
if (llvm::isa<DeducedType>(TL->getTypePtr()))
19801982
if (auto Deduced = getDeducedType(
1981-
N->getDeclContext().getParentASTContext(), TL->getBeginLoc()))
1983+
N->getDeclContext().getParentASTContext(), H, TL->getBeginLoc()))
19821984
return *Deduced;
19831985
// Exception: an alias => underlying type.
19841986
if (llvm::isa<TypedefType>(TL->getTypePtr()))
@@ -2161,7 +2163,8 @@ std::vector<LocatedSymbol> findType(ParsedAST &AST, Position Pos,
21612163
// information about the type you may have not known before
21622164
// (since unique_ptr<unique_ptr<T>> != unique_ptr<T>).
21632165
for (const QualType &Type : unwrapFindType(
2164-
typeForNode(AST.getASTContext(), N), AST.getHeuristicResolver()))
2166+
typeForNode(AST.getASTContext(), AST.getHeuristicResolver(), N),
2167+
AST.getHeuristicResolver()))
21652168
llvm::copy(locateSymbolForType(AST, Type, Index),
21662169
std::back_inserter(LocatedSymbols));
21672170

clang-tools-extra/clangd/refactor/tweaks/ExpandDeducedType.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ Expected<Tweak::Effect> ExpandDeducedType::apply(const Selection &Inputs) {
133133
auto &SrcMgr = Inputs.AST->getSourceManager();
134134

135135
std::optional<clang::QualType> DeducedType =
136-
getDeducedType(Inputs.AST->getASTContext(), Range.getBegin());
136+
getDeducedType(Inputs.AST->getASTContext(),
137+
Inputs.AST->getHeuristicResolver(), Range.getBegin());
137138

138139
// if we can't resolve the type, return an error message
139140
if (DeducedType == std::nullopt || (*DeducedType)->isUndeducedAutoType())

0 commit comments

Comments
 (0)