Skip to content

Commit 45dc159

Browse files
authored
Merge pull request #109 from AMD-Lightning-Internal/upstream_merge_202501150708
merge main into amd-staging
2 parents 5eda221 + 983bad2 commit 45dc159

File tree

176 files changed

+10298
-9482
lines changed

Some content is hidden

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

176 files changed

+10298
-9482
lines changed

clang-tools-extra/clangd/CodeComplete.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,14 +1867,41 @@ class CodeCompleteFlow {
18671867
CodeCompleteResult Output;
18681868

18691869
// Convert the results to final form, assembling the expensive strings.
1870+
// If necessary, search the index for documentation comments.
1871+
LookupRequest Req;
1872+
llvm::DenseMap<SymbolID, uint32_t> SymbolToCompletion;
18701873
for (auto &C : Scored) {
18711874
Output.Completions.push_back(toCodeCompletion(C.first));
18721875
Output.Completions.back().Score = C.second;
18731876
Output.Completions.back().CompletionTokenRange = ReplacedRange;
1877+
if (Opts.Index && !Output.Completions.back().Documentation) {
1878+
for (auto &Cand : C.first) {
1879+
if (Cand.SemaResult &&
1880+
Cand.SemaResult->Kind == CodeCompletionResult::RK_Declaration) {
1881+
auto ID = clangd::getSymbolID(Cand.SemaResult->getDeclaration());
1882+
if (!ID)
1883+
continue;
1884+
Req.IDs.insert(ID);
1885+
SymbolToCompletion[ID] = Output.Completions.size() - 1;
1886+
}
1887+
}
1888+
}
18741889
}
18751890
Output.HasMore = Incomplete;
18761891
Output.Context = CCContextKind;
18771892
Output.CompletionRange = ReplacedRange;
1893+
1894+
// Look up documentation from the index.
1895+
if (Opts.Index) {
1896+
Opts.Index->lookup(Req, [&](const Symbol &S) {
1897+
if (S.Documentation.empty())
1898+
return;
1899+
auto &C = Output.Completions[SymbolToCompletion.at(S.ID)];
1900+
C.Documentation.emplace();
1901+
parseDocumentation(S.Documentation, *C.Documentation);
1902+
});
1903+
}
1904+
18781905
return Output;
18791906
}
18801907

clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,87 @@ int x = foo^
11361136
Contains(AllOf(named("foo"), doc("This comment should be retained!"))));
11371137
}
11381138

1139+
TEST(CompletionTest, CommentsOnMembersFromHeader) {
1140+
MockFS FS;
1141+
MockCompilationDatabase CDB;
1142+
1143+
auto Opts = ClangdServer::optsForTest();
1144+
Opts.BuildDynamicSymbolIndex = true;
1145+
1146+
ClangdServer Server(CDB, FS, Opts);
1147+
1148+
FS.Files[testPath("foo.h")] = R"cpp(
1149+
struct alpha {
1150+
/// This is a member field.
1151+
int gamma;
1152+
1153+
/// This is a member function.
1154+
int delta();
1155+
};
1156+
)cpp";
1157+
1158+
auto File = testPath("foo.cpp");
1159+
Annotations Test(R"cpp(
1160+
#include "foo.h"
1161+
alpha a;
1162+
int x = a.^
1163+
)cpp");
1164+
runAddDocument(Server, File, Test.code());
1165+
auto CompletionList =
1166+
llvm::cantFail(runCodeComplete(Server, File, Test.point(), {}));
1167+
1168+
EXPECT_THAT(CompletionList.Completions,
1169+
Contains(AllOf(named("gamma"), doc("This is a member field."))));
1170+
EXPECT_THAT(
1171+
CompletionList.Completions,
1172+
Contains(AllOf(named("delta"), doc("This is a member function."))));
1173+
}
1174+
1175+
TEST(CompletionTest, CommentsOnMembersFromHeaderOverloadBundling) {
1176+
using testing::AnyOf;
1177+
MockFS FS;
1178+
MockCompilationDatabase CDB;
1179+
1180+
auto Opts = ClangdServer::optsForTest();
1181+
Opts.BuildDynamicSymbolIndex = true;
1182+
1183+
ClangdServer Server(CDB, FS, Opts);
1184+
1185+
FS.Files[testPath("foo.h")] = R"cpp(
1186+
struct alpha {
1187+
/// bool overload.
1188+
int delta(bool b);
1189+
1190+
/// int overload.
1191+
int delta(int i);
1192+
1193+
void epsilon(long l);
1194+
1195+
/// This one has a comment.
1196+
void epsilon(int i);
1197+
};
1198+
)cpp";
1199+
1200+
auto File = testPath("foo.cpp");
1201+
Annotations Test(R"cpp(
1202+
#include "foo.h"
1203+
alpha a;
1204+
int x = a.^
1205+
)cpp");
1206+
runAddDocument(Server, File, Test.code());
1207+
clangd::CodeCompleteOptions CCOpts;
1208+
CCOpts.BundleOverloads = true;
1209+
auto CompletionList =
1210+
llvm::cantFail(runCodeComplete(Server, File, Test.point(), CCOpts));
1211+
1212+
EXPECT_THAT(
1213+
CompletionList.Completions,
1214+
Contains(AllOf(named("epsilon"), doc("This one has a comment."))));
1215+
EXPECT_THAT(CompletionList.Completions,
1216+
Contains(AllOf(named("delta"), AnyOf(doc("bool overload."),
1217+
doc("int overload.")))));
1218+
}
1219+
11391220
TEST(CompletionTest, GlobalCompletionFiltering) {
11401221

11411222
Symbol Class = cls("XYZ");

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ C++23 Feature Support
321321
C++20 Feature Support
322322
^^^^^^^^^^^^^^^^^^^^^
323323

324+
- Implemented module level lookup for C++20 modules. (#GH90154)
325+
324326

325327
Resolutions to C++ Defect Reports
326328
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang/AST/DeclBase.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,10 @@ class alignas(8) Decl {
836836
return isFromASTFile() ? getImportedOwningModule() : getLocalOwningModule();
837837
}
838838

839+
/// Get the top level owning named module that owns this declaration if any.
840+
/// \returns nullptr if the declaration is not owned by a named module.
841+
Module *getTopLevelOwningNamedModule() const;
842+
839843
/// Get the module that owns this declaration for linkage purposes.
840844
/// There only ever is such a standard C++ module.
841845
Module *getOwningModuleForLinkage() const;
@@ -2722,6 +2726,12 @@ class DeclContext {
27222726
bool Deserialize = false) const;
27232727

27242728
private:
2729+
/// Lookup all external visible declarations and the external declarations
2730+
/// within the same module specified by \c NamedModule. We can't
2731+
/// get it from \c this since the same declaration may be declared in
2732+
/// multiple modules. e.g., namespace.
2733+
lookup_result lookupImpl(DeclarationName Name, Module *NamedModule) const;
2734+
27252735
/// Whether this declaration context has had externally visible
27262736
/// storage added since the last lookup. In this case, \c LookupPtr's
27272737
/// invariant may not hold and needs to be fixed before we perform

clang/include/clang/AST/ExternalASTMerger.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ class ExternalASTMerger : public ExternalASTSource {
141141

142142
/// Implementation of the ExternalASTSource API.
143143
bool FindExternalVisibleDeclsByName(const DeclContext *DC,
144-
DeclarationName Name) override;
144+
DeclarationName Name,
145+
Module *NamedModule) override;
145146

146147
/// Implementation of the ExternalASTSource API.
147148
void

clang/include/clang/AST/ExternalASTSource.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class RecordDecl;
5151
class Selector;
5252
class Stmt;
5353
class TagDecl;
54+
class Module;
5455

5556
/// Abstract interface for external sources of AST nodes.
5657
///
@@ -145,12 +146,20 @@ class ExternalASTSource : public RefCountedBase<ExternalASTSource> {
145146
/// Find all declarations with the given name in the given context,
146147
/// and add them to the context by calling SetExternalVisibleDeclsForName
147148
/// or SetNoExternalVisibleDeclsForName.
148-
/// \return \c true if any declarations might have been found, \c false if
149-
/// we definitely have no declarations with tbis name.
149+
/// \param DC the context for lookup.
150+
/// \param Name the name of the declarations to find.
151+
/// \param NamedModule find declarations visible to the given module
152+
/// \c NamedModule . This may be different from owning module of \c DC since
153+
/// there are declarations (e.g., namespace declaration) can appear in
154+
/// multiple modules.
155+
///
156+
/// \return \c true if any declarations might have been found, and \c false
157+
/// if we definitely have no declarations with this name.
150158
///
151159
/// The default implementation of this method is a no-op returning \c false.
152-
virtual bool
153-
FindExternalVisibleDeclsByName(const DeclContext *DC, DeclarationName Name);
160+
virtual bool FindExternalVisibleDeclsByName(const DeclContext *DC,
161+
DeclarationName Name,
162+
Module *NamedModule);
154163

155164
/// Load all the external specializations for the Decl \param D if \param
156165
/// OnlyPartial is false. Otherwise, load all the external **partial**

clang/include/clang/AST/Type.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7040,17 +7040,17 @@ class DependentNameType : public TypeWithKeyword, public llvm::FoldingSetNode {
70407040
: TypeWithKeyword(Keyword, DependentName, CanonType,
70417041
TypeDependence::DependentInstantiation |
70427042
toTypeDependence(NNS->getDependence())),
7043-
NNS(NNS), Name(Name) {}
7043+
NNS(NNS), Name(Name) {
7044+
assert(NNS);
7045+
assert(Name);
7046+
}
70447047

70457048
public:
70467049
/// Retrieve the qualification on this type.
70477050
NestedNameSpecifier *getQualifier() const { return NNS; }
70487051

7049-
/// Retrieve the type named by the typename specifier as an identifier.
7050-
///
7051-
/// This routine will return a non-NULL identifier pointer when the
7052-
/// form of the original typename was terminated by an identifier,
7053-
/// e.g., "typename T::type".
7052+
/// Retrieve the identifier that terminates this type name.
7053+
/// For example, "type" in "typename T::type".
70547054
const IdentifierInfo *getIdentifier() const {
70557055
return Name;
70567056
}

clang/include/clang/Driver/Multilib.h

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,30 @@ class Multilib {
101101

102102
raw_ostream &operator<<(raw_ostream &OS, const Multilib &M);
103103

104+
namespace custom_flag {
105+
struct Declaration;
106+
107+
struct ValueDetail {
108+
std::string Name;
109+
std::optional<SmallVector<std::string>> MacroDefines;
110+
Declaration *Decl;
111+
};
112+
113+
struct Declaration {
114+
std::string Name;
115+
SmallVector<ValueDetail> ValueList;
116+
std::optional<size_t> DefaultValueIdx;
117+
118+
Declaration() = default;
119+
Declaration(const Declaration &);
120+
Declaration(Declaration &&);
121+
Declaration &operator=(const Declaration &);
122+
Declaration &operator=(Declaration &&);
123+
};
124+
125+
static constexpr StringRef Prefix = "-fmultilib-flag=";
126+
} // namespace custom_flag
127+
104128
/// See also MultilibSetBuilder for combining multilibs into a set.
105129
class MultilibSet {
106130
public:
@@ -120,15 +144,18 @@ class MultilibSet {
120144

121145
private:
122146
multilib_list Multilibs;
123-
std::vector<FlagMatcher> FlagMatchers;
147+
SmallVector<FlagMatcher> FlagMatchers;
148+
SmallVector<custom_flag::Declaration> CustomFlagDecls;
124149
IncludeDirsFunc IncludeCallback;
125150
IncludeDirsFunc FilePathsCallback;
126151

127152
public:
128153
MultilibSet() = default;
129154
MultilibSet(multilib_list &&Multilibs,
130-
std::vector<FlagMatcher> &&FlagMatchers = {})
131-
: Multilibs(Multilibs), FlagMatchers(FlagMatchers) {}
155+
SmallVector<FlagMatcher> &&FlagMatchers = {},
156+
SmallVector<custom_flag::Declaration> &&CustomFlagDecls = {})
157+
: Multilibs(std::move(Multilibs)), FlagMatchers(std::move(FlagMatchers)),
158+
CustomFlagDecls(std::move(CustomFlagDecls)) {}
132159

133160
const multilib_list &getMultilibs() { return Multilibs; }
134161

clang/include/clang/Sema/MultiplexExternalSemaSource.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ class MultiplexExternalSemaSource : public ExternalSemaSource {
9595
/// Find all declarations with the given name in the
9696
/// given context.
9797
bool FindExternalVisibleDeclsByName(const DeclContext *DC,
98-
DeclarationName Name) override;
98+
DeclarationName Name,
99+
Module *NamedModule) override;
99100

100101
bool LoadExternalSpecializations(const Decl *D, bool OnlyPartial) override;
101102

clang/include/clang/Serialization/ASTBitCodes.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,8 @@ enum ASTRecordTypes {
738738
CXX_ADDED_TEMPLATE_SPECIALIZATION = 74,
739739

740740
CXX_ADDED_TEMPLATE_PARTIAL_SPECIALIZATION = 75,
741+
742+
UPDATE_MODULE_LOCAL_VISIBLE = 76,
741743
};
742744

743745
/// Record types used within a source manager block.
@@ -1334,6 +1336,10 @@ enum DeclCode {
13341336
/// into a DeclContext via DeclContext::lookup.
13351337
DECL_CONTEXT_VISIBLE,
13361338

1339+
/// A record containing the set of declarations that are
1340+
/// only visible from DeclContext in the same module.
1341+
DECL_CONTEXT_MODULE_LOCAL_VISIBLE,
1342+
13371343
/// A LabelDecl record.
13381344
DECL_LABEL,
13391345

0 commit comments

Comments
 (0)