Skip to content

Commit eb5e437

Browse files
committed
Merge from 'main' to 'sycl-web' (#11)
CONFLICT (content): Merge conflict in clang/lib/Sema/SemaDecl.cpp
2 parents 82f3d16 + 1b194ef commit eb5e437

Some content is hidden

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

43 files changed

+778
-112
lines changed

clang-tools-extra/clangd/CodeComplete.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,9 @@ struct CodeCompletionBuilder {
403403
if (C.IndexResult) {
404404
SetDoc(C.IndexResult->Documentation);
405405
} else if (C.SemaResult) {
406-
SetDoc(getDocComment(*ASTCtx, *C.SemaResult,
407-
/*CommentsFromHeader=*/false));
406+
const auto DocComment = getDocComment(*ASTCtx, *C.SemaResult,
407+
/*CommentsFromHeader=*/false);
408+
SetDoc(formatDocumentation(*SemaCCS, DocComment));
408409
}
409410
}
410411
if (Completion.Deprecated) {
@@ -715,6 +716,7 @@ bool contextAllowsIndex(enum CodeCompletionContext::Kind K) {
715716
case CodeCompletionContext::CCC_ObjCInstanceMessage:
716717
case CodeCompletionContext::CCC_ObjCClassMessage:
717718
case CodeCompletionContext::CCC_IncludedFile:
719+
case CodeCompletionContext::CCC_Attribute:
718720
// FIXME: Provide identifier based completions for the following contexts:
719721
case CodeCompletionContext::CCC_Other: // Be conservative.
720722
case CodeCompletionContext::CCC_NaturalLanguage:

clang-tools-extra/clangd/Hover.cpp

+19-1
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,22 @@ llvm::Optional<HoverInfo> getHover(ParsedAST &AST, Position Pos,
920920
if (TokensTouchingCursor.empty())
921921
return llvm::None;
922922

923+
// Show full header file path if cursor is on include directive.
924+
if (const auto MainFilePath =
925+
getCanonicalPath(SM.getFileEntryForID(SM.getMainFileID()), SM)) {
926+
for (const auto &Inc : AST.getIncludeStructure().MainFileIncludes) {
927+
if (Inc.Resolved.empty() || Inc.HashLine != Pos.line)
928+
continue;
929+
HoverInfo HI;
930+
HI.Name = std::string(llvm::sys::path::filename(Inc.Resolved));
931+
// FIXME: We don't have a fitting value for Kind.
932+
HI.Definition =
933+
URIForFile::canonicalize(Inc.Resolved, *MainFilePath).file().str();
934+
HI.DefinitionLanguage = "";
935+
return HI;
936+
}
937+
}
938+
923939
// To be used as a backup for highlighting the selected token, we use back as
924940
// it aligns better with biases elsewhere (editors tend to send the position
925941
// for the left of the hovered token).
@@ -998,6 +1014,7 @@ llvm::Optional<HoverInfo> getHover(ParsedAST &AST, Position Pos,
9981014

9991015
markup::Document HoverInfo::present() const {
10001016
markup::Document Output;
1017+
10011018
// Header contains a text of the form:
10021019
// variable `var`
10031020
//
@@ -1098,7 +1115,8 @@ markup::Document HoverInfo::present() const {
10981115
: Definition;
10991116
// Note that we don't print anything for global namespace, to not annoy
11001117
// non-c++ projects or projects that are not making use of namespaces.
1101-
Output.addCodeBlock(ScopeComment + DefinitionWithAccess);
1118+
Output.addCodeBlock(ScopeComment + DefinitionWithAccess,
1119+
DefinitionLanguage);
11021120
}
11031121

11041122
return Output;

clang-tools-extra/clangd/Hover.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct HoverInfo {
5858
std::string Documentation;
5959
/// Source code containing the definition of the symbol.
6060
std::string Definition;
61-
61+
const char *DefinitionLanguage = "cpp";
6262
/// Access specifier for declarations inside class/struct/unions, empty for
6363
/// others.
6464
std::string AccessSpecifier;

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

+3-5
Original file line numberDiff line numberDiff line change
@@ -624,10 +624,8 @@ TEST(ClangdServerTest, InvalidCompileCommand) {
624624
ClangdServer Server(CDB, FS, ClangdServer::optsForTest(), &DiagConsumer);
625625

626626
auto FooCpp = testPath("foo.cpp");
627-
// clang cannot create CompilerInvocation if we pass two files in the
628-
// CompileCommand. We pass the file in ExtraFlags once and CDB adds another
629-
// one in getCompileCommand().
630-
CDB.ExtraClangFlags.push_back(FooCpp);
627+
// clang cannot create CompilerInvocation in this case.
628+
CDB.ExtraClangFlags.push_back("-###");
631629

632630
// Clang can't parse command args in that case, but we shouldn't crash.
633631
runAddDocument(Server, FooCpp, "int main() {}");
@@ -1080,7 +1078,7 @@ TEST(ClangdServerTest, FallbackWhenPreambleIsNotReady) {
10801078
Opts.RunParser = CodeCompleteOptions::ParseIfReady;
10811079

10821080
// This will make compile command broken and preamble absent.
1083-
CDB.ExtraClangFlags = {"yolo.cc"};
1081+
CDB.ExtraClangFlags = {"-###"};
10841082
Server.addDocument(FooCpp, Code.code());
10851083
ASSERT_TRUE(Server.blockUntilIdleForTest());
10861084
auto Res = cantFail(runCodeComplete(Server, FooCpp, Code.point(), Opts));

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ TEST(CompletionTest, Documentation) {
907907
auto Results = completions(
908908
R"cpp(
909909
// Non-doxygen comment.
910-
int foo();
910+
__attribute__((annotate("custom_annotation"))) int foo();
911911
/// Doxygen comment.
912912
/// \param int a
913913
int bar(int a);
@@ -919,7 +919,8 @@ TEST(CompletionTest, Documentation) {
919919
int x = ^
920920
)cpp");
921921
EXPECT_THAT(Results.Completions,
922-
Contains(AllOf(Named("foo"), Doc("Non-doxygen comment."))));
922+
Contains(AllOf(Named("foo"),
923+
Doc("Annotation: custom_annotation\nNon-doxygen comment."))));
923924
EXPECT_THAT(
924925
Results.Completions,
925926
Contains(AllOf(Named("bar"), Doc("Doxygen comment.\n\\param int a"))));

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

+9
Original file line numberDiff line numberDiff line change
@@ -2760,6 +2760,15 @@ Passed by const reference as arg_a (converted to int)
27602760
27612761
// In test::Bar
27622762
int foo = 3)",
2763+
},
2764+
{
2765+
[](HoverInfo &HI) {
2766+
HI.Name = "stdio.h";
2767+
HI.Definition = "/usr/include/stdio.h";
2768+
},
2769+
R"(stdio.h
2770+
2771+
/usr/include/stdio.h)",
27632772
}};
27642773

27652774
for (const auto &C : Cases) {

clang/include/clang/Basic/Attr.td

+8
Original file line numberDiff line numberDiff line change
@@ -2458,6 +2458,14 @@ def BPFPreserveAccessIndex : InheritableAttr,
24582458
let LangOpts = [COnly];
24592459
}
24602460

2461+
def BTFTag : InheritableAttr {
2462+
let Spellings = [Clang<"btf_tag">];
2463+
let Args = [StringArgument<"BTFTag">];
2464+
let Subjects = SubjectList<[Var, Function, Record, Field], ErrorDiag>;
2465+
let Documentation = [BTFTagDocs];
2466+
let LangOpts = [COnly];
2467+
}
2468+
24612469
def WebAssemblyExportName : InheritableAttr,
24622470
TargetSpecificAttr<TargetWebAssembly> {
24632471
let Spellings = [Clang<"export_name">];

clang/include/clang/Basic/AttrDocs.td

+10
Original file line numberDiff line numberDiff line change
@@ -2039,6 +2039,16 @@ preserving struct or union member access debuginfo indices of this
20392039
struct or union, similar to clang ``__builtin_preserve_access_index()``.
20402040
}];
20412041
}
2042+
def BTFTagDocs : Documentation {
2043+
let Category = DocCatFunction;
2044+
let Content = [{
2045+
Clang supports the ``__attribute__((btf_tag("ARGUMENT")))`` attribute for all
2046+
targets. This attribute may be attached to a struct/union, struct/union field,
2047+
function, function parameter or variable declaration. If -g is specified,
2048+
the ``ARGUMENT`` info will be preserved in IR and be emitted to dwarf.
2049+
For BPF targets, the ``ARGUMENT`` info will be emitted to .BTF ELF section too.
2050+
}];
2051+
}
20422052

20432053
def MipsInterruptDocs : Documentation {
20442054
let Category = DocCatFunction;

clang/include/clang/Basic/DiagnosticFrontendKinds.td

+2
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,8 @@ def remark_module_build : Remark<"building module '%0' as '%1'">,
229229
InGroup<ModuleBuild>;
230230
def remark_module_build_done : Remark<"finished building module '%0'">,
231231
InGroup<ModuleBuild>;
232+
def remark_module_lock : Remark<"locking '%0' to build module '%1'">,
233+
InGroup<ModuleLock>;
232234
def err_modules_embed_file_not_found :
233235
Error<"file '%0' specified by '-fmodules-embed-file=' not found">,
234236
DefaultFatal;

clang/include/clang/Basic/DiagnosticGroups.td

+1
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,7 @@ def MismatchedParameterTypes : DiagGroup<"mismatched-parameter-types">;
465465
def MismatchedReturnTypes : DiagGroup<"mismatched-return-types">;
466466
def MismatchedTags : DiagGroup<"mismatched-tags">;
467467
def MissingFieldInitializers : DiagGroup<"missing-field-initializers">;
468+
def ModuleLock : DiagGroup<"module-lock">;
468469
def ModuleBuild : DiagGroup<"module-build">;
469470
def ModuleImport : DiagGroup<"module-import">;
470471
def ModuleConflict : DiagGroup<"module-conflict">;

clang/include/clang/Driver/Options.td

+6
Original file line numberDiff line numberDiff line change
@@ -5428,6 +5428,12 @@ def fmodules_embed_all_files : Joined<["-"], "fmodules-embed-all-files">,
54285428
HelpText<"Embed the contents of all files read by this compilation into "
54295429
"the produced module file.">,
54305430
MarshallingInfoFlag<FrontendOpts<"ModulesEmbedAllFiles">>;
5431+
defm fimplicit_modules_use_lock : BoolOption<"f", "implicit-modules-use-lock",
5432+
FrontendOpts<"BuildingImplicitModuleUsesLock">, DefaultTrue,
5433+
NegFlag<SetFalse>,
5434+
PosFlag<SetTrue, [],
5435+
"Use filesystem locks for implicit modules builds to avoid "
5436+
"duplicating work in competing clang invocations.">>;
54315437
// FIXME: We only need this in C++ modules / Modules TS if we might textually
54325438
// enter a different module (eg, when building a header unit).
54335439
def fmodules_local_submodule_visibility :

clang/include/clang/Frontend/FrontendOptions.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@ class FrontendOptions {
289289
/// Whether we are performing an implicit module build.
290290
unsigned BuildingImplicitModule : 1;
291291

292+
/// Whether to use a filesystem lock when building implicit modules.
293+
unsigned BuildingImplicitModuleUsesLock : 1;
294+
292295
/// Whether we should embed all used files into the PCM file.
293296
unsigned ModulesEmbedAllFiles : 1;
294297

@@ -461,9 +464,9 @@ class FrontendOptions {
461464
SkipFunctionBodies(false), UseGlobalModuleIndex(true),
462465
GenerateGlobalModuleIndex(true), ASTDumpDecls(false),
463466
ASTDumpLookups(false), BuildingImplicitModule(false),
464-
ModulesEmbedAllFiles(false), IncludeTimestamps(true),
465-
UseTemporary(true), AllowPCMWithCompilerErrors(false),
466-
TimeTraceGranularity(500) {}
467+
BuildingImplicitModuleUsesLock(true), ModulesEmbedAllFiles(false),
468+
IncludeTimestamps(true), UseTemporary(true),
469+
AllowPCMWithCompilerErrors(false), TimeTraceGranularity(500) {}
467470

468471
/// getInputKindForExtension - Return the appropriate input kind for a file
469472
/// extension. For example, "c" would return Language::C.

clang/include/clang/Parse/Parser.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -2835,7 +2835,10 @@ class Parser : public CodeCompletionHandler {
28352835
SourceLocation ScopeLoc,
28362836
CachedTokens &OpenMPTokens);
28372837

2838-
IdentifierInfo *TryParseCXX11AttributeIdentifier(SourceLocation &Loc);
2838+
IdentifierInfo *TryParseCXX11AttributeIdentifier(
2839+
SourceLocation &Loc,
2840+
Sema::AttributeCompletion Completion = Sema::AttributeCompletion::None,
2841+
const IdentifierInfo *EnclosingScope = nullptr);
28392842

28402843
void MaybeParseMicrosoftAttributes(ParsedAttributes &attrs,
28412844
SourceLocation *endLoc = nullptr) {

clang/include/clang/Sema/CodeCompleteConsumer.h

+3
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,9 @@ class CodeCompletionContext {
329329
/// Code completion inside the filename part of a #include directive.
330330
CCC_IncludedFile,
331331

332+
/// Code completion of an attribute name.
333+
CCC_Attribute,
334+
332335
/// An unknown context, in which we are recovering from a parsing
333336
/// error and don't know which completions we should give.
334337
CCC_Recovery

clang/include/clang/Sema/ParsedAttr.h

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ struct ParsedAttrInfo {
126126
}
127127

128128
static const ParsedAttrInfo &get(const AttributeCommonInfo &A);
129+
static ArrayRef<const ParsedAttrInfo *> getAllBuiltin();
129130
};
130131

131132
typedef llvm::Registry<ParsedAttrInfo> ParsedAttrInfoRegistry;

clang/include/clang/Sema/Sema.h

+10
Original file line numberDiff line numberDiff line change
@@ -3627,6 +3627,7 @@ class Sema final {
36273627
EnforceTCBAttr *mergeEnforceTCBAttr(Decl *D, const EnforceTCBAttr &AL);
36283628
EnforceTCBLeafAttr *mergeEnforceTCBLeafAttr(Decl *D,
36293629
const EnforceTCBLeafAttr &AL);
3630+
BTFTagAttr *mergeBTFTagAttr(Decl *D, const BTFTagAttr &AL);
36303631

36313632
void mergeDeclAttributes(NamedDecl *New, Decl *Old,
36323633
AvailabilityMergeKind AMK = AMK_Redeclaration);
@@ -12742,6 +12743,15 @@ class Sema final {
1274212743
const VirtSpecifiers *VS = nullptr);
1274312744
void CodeCompleteBracketDeclarator(Scope *S);
1274412745
void CodeCompleteCase(Scope *S);
12746+
enum class AttributeCompletion {
12747+
Attribute,
12748+
Scope,
12749+
None,
12750+
};
12751+
void CodeCompleteAttribute(
12752+
AttributeCommonInfo::Syntax Syntax,
12753+
AttributeCompletion Completion = AttributeCompletion::Attribute,
12754+
const IdentifierInfo *Scope = nullptr);
1274512755
/// Determines the preferred type of the current function argument, by
1274612756
/// examining the signatures of all possible overloads.
1274712757
/// Returns null if unknown or ambiguous, or if code completion is off.

clang/lib/Frontend/ASTUnit.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1989,6 +1989,7 @@ static void CalculateHiddenNames(const CodeCompletionContext &Context,
19891989
case CodeCompletionContext::CCC_ObjCClassMessage:
19901990
case CodeCompletionContext::CCC_ObjCCategoryName:
19911991
case CodeCompletionContext::CCC_IncludedFile:
1992+
case CodeCompletionContext::CCC_Attribute:
19921993
case CodeCompletionContext::CCC_NewName:
19931994
// We're looking for nothing, or we're looking for names that cannot
19941995
// be hidden.

0 commit comments

Comments
 (0)