Skip to content

Commit d5a1d54

Browse files
authored
Merge branch 'main' into issue-8476
2 parents e973680 + 6023d17 commit d5a1d54

File tree

677 files changed

+26045
-11142
lines changed

Some content is hidden

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

677 files changed

+26045
-11142
lines changed

.github/workflows/pr-code-format.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ on:
1212
jobs:
1313
code_formatter:
1414
runs-on: ubuntu-latest
15+
timeout-minutes: 30
1516
if: github.repository == 'llvm/llvm-project'
1617
steps:
1718
- name: Fetch LLVM sources

clang-tools-extra/clangd/ModulesBuilder.cpp

Lines changed: 85 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,87 @@ class FailedPrerequisiteModules : public PrerequisiteModules {
9292
}
9393
};
9494

95+
struct ModuleFile {
96+
ModuleFile(StringRef ModuleName, PathRef ModuleFilePath)
97+
: ModuleName(ModuleName.str()), ModuleFilePath(ModuleFilePath.str()) {}
98+
99+
ModuleFile() = delete;
100+
101+
ModuleFile(const ModuleFile &) = delete;
102+
ModuleFile operator=(const ModuleFile &) = delete;
103+
104+
// The move constructor is needed for llvm::SmallVector.
105+
ModuleFile(ModuleFile &&Other)
106+
: ModuleName(std::move(Other.ModuleName)),
107+
ModuleFilePath(std::move(Other.ModuleFilePath)) {
108+
Other.ModuleName.clear();
109+
Other.ModuleFilePath.clear();
110+
}
111+
112+
ModuleFile &operator=(ModuleFile &&Other) {
113+
if (this == &Other)
114+
return *this;
115+
116+
this->~ModuleFile();
117+
new (this) ModuleFile(std::move(Other));
118+
return *this;
119+
}
120+
121+
~ModuleFile() {
122+
if (!ModuleFilePath.empty())
123+
llvm::sys::fs::remove(ModuleFilePath);
124+
}
125+
126+
std::string ModuleName;
127+
std::string ModuleFilePath;
128+
};
129+
130+
bool IsModuleFileUpToDate(
131+
PathRef ModuleFilePath,
132+
const PrerequisiteModules &RequisiteModules) {
133+
IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
134+
CompilerInstance::createDiagnostics(new DiagnosticOptions());
135+
136+
auto HSOpts = std::make_shared<HeaderSearchOptions>();
137+
RequisiteModules.adjustHeaderSearchOptions(*HSOpts);
138+
HSOpts->ForceCheckCXX20ModulesInputFiles = true;
139+
HSOpts->ValidateASTInputFilesContent = true;
140+
141+
PCHContainerOperations PCHOperations;
142+
std::unique_ptr<ASTUnit> Unit = ASTUnit::LoadFromASTFile(
143+
ModuleFilePath.str(), PCHOperations.getRawReader(), ASTUnit::LoadASTOnly,
144+
Diags, FileSystemOptions(), std::move(HSOpts));
145+
146+
if (!Unit)
147+
return false;
148+
149+
auto Reader = Unit->getASTReader();
150+
if (!Reader)
151+
return false;
152+
153+
bool UpToDate = true;
154+
Reader->getModuleManager().visit([&](serialization::ModuleFile &MF) -> bool {
155+
Reader->visitInputFiles(
156+
MF, /*IncludeSystem=*/false, /*Complain=*/false,
157+
[&](const serialization::InputFile &IF, bool isSystem) {
158+
if (!IF.getFile() || IF.isOutOfDate())
159+
UpToDate = false;
160+
});
161+
162+
return !UpToDate;
163+
});
164+
165+
return UpToDate;
166+
}
167+
168+
bool IsModuleFilesUpToDate(
169+
llvm::SmallVector<PathRef> ModuleFilePaths,
170+
const PrerequisiteModules &RequisiteModules) {
171+
return llvm::all_of(ModuleFilePaths, [&RequisiteModules](auto ModuleFilePath) {
172+
return IsModuleFileUpToDate(ModuleFilePath, RequisiteModules);
173+
});
174+
}
175+
95176
// StandalonePrerequisiteModules - stands for PrerequisiteModules for which all
96177
// the required modules are built successfully. All the module files
97178
// are owned by the StandalonePrerequisiteModules class.
@@ -135,29 +216,6 @@ class StandalonePrerequisiteModules : public PrerequisiteModules {
135216
}
136217

137218
private:
138-
struct ModuleFile {
139-
ModuleFile(llvm::StringRef ModuleName, PathRef ModuleFilePath)
140-
: ModuleName(ModuleName.str()), ModuleFilePath(ModuleFilePath.str()) {}
141-
142-
ModuleFile(const ModuleFile &) = delete;
143-
ModuleFile operator=(const ModuleFile &) = delete;
144-
145-
// The move constructor is needed for llvm::SmallVector.
146-
ModuleFile(ModuleFile &&Other)
147-
: ModuleName(std::move(Other.ModuleName)),
148-
ModuleFilePath(std::move(Other.ModuleFilePath)) {}
149-
150-
ModuleFile &operator=(ModuleFile &&Other) = delete;
151-
152-
~ModuleFile() {
153-
if (!ModuleFilePath.empty())
154-
llvm::sys::fs::remove(ModuleFilePath);
155-
}
156-
157-
std::string ModuleName;
158-
std::string ModuleFilePath;
159-
};
160-
161219
llvm::SmallVector<ModuleFile, 8> RequiredModules;
162220
// A helper class to speedup the query if a module is built.
163221
llvm::StringSet<> BuiltModuleNames;
@@ -286,50 +344,10 @@ bool StandalonePrerequisiteModules::canReuse(
286344
if (RequiredModules.empty())
287345
return true;
288346

289-
CompilerInstance Clang;
290-
291-
Clang.setInvocation(std::make_shared<CompilerInvocation>(CI));
292-
IntrusiveRefCntPtr<DiagnosticsEngine> Diags =
293-
CompilerInstance::createDiagnostics(new DiagnosticOptions());
294-
Clang.setDiagnostics(Diags.get());
295-
296-
FileManager *FM = Clang.createFileManager(VFS);
297-
Clang.createSourceManager(*FM);
298-
299-
if (!Clang.createTarget())
300-
return false;
301-
302-
assert(Clang.getHeaderSearchOptsPtr());
303-
adjustHeaderSearchOptions(Clang.getHeaderSearchOpts());
304-
// Since we don't need to compile the source code actually, the TU kind here
305-
// doesn't matter.
306-
Clang.createPreprocessor(TU_Complete);
307-
Clang.getHeaderSearchOpts().ForceCheckCXX20ModulesInputFiles = true;
308-
Clang.getHeaderSearchOpts().ValidateASTInputFilesContent = true;
309-
310-
// Following the practice of clang's driver to suppres the checking for ODR
311-
// violation in GMF.
312-
// See
313-
// https://clang.llvm.org/docs/StandardCPlusPlusModules.html#object-definition-consistency
314-
// for example.
315-
Clang.getLangOpts().SkipODRCheckInGMF = true;
316-
317-
Clang.createASTReader();
318-
for (auto &RequiredModule : RequiredModules) {
319-
llvm::StringRef BMIPath = RequiredModule.ModuleFilePath;
320-
// FIXME: Loading BMI fully is too heavy considering something cheaply to
321-
// check if we can reuse the BMI.
322-
auto ReadResult =
323-
Clang.getASTReader()->ReadAST(BMIPath, serialization::MK_MainFile,
324-
SourceLocation(), ASTReader::ARR_None);
325-
326-
if (ReadResult != ASTReader::Success) {
327-
elog("Can't reuse {0}: {1}", BMIPath, ReadResult);
328-
return false;
329-
}
330-
}
331-
332-
return true;
347+
SmallVector<StringRef> BMIPaths;
348+
for (auto &MF : RequiredModules)
349+
BMIPaths.push_back(MF.ModuleFilePath);
350+
return IsModuleFilesUpToDate(BMIPaths, *this);
333351
}
334352

335353
} // namespace clangd

clang-tools-extra/docs/clang-tidy/Contributing.rst

Lines changed: 47 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,15 @@ Writing a clang-tidy Check
127127

128128
So you have an idea of a useful check for :program:`clang-tidy`.
129129

130-
First, if you're not familiar with LLVM development, read through the `Getting
131-
Started with LLVM`_ document for instructions on setting up your workflow and
130+
First, if you're not familiar with LLVM development, read through the `Getting Started
131+
with the LLVM System`_ document for instructions on setting up your workflow and
132132
the `LLVM Coding Standards`_ document to familiarize yourself with the coding
133-
style used in the project. For code reviews we mostly use `LLVM Phabricator`_.
133+
style used in the project. For code reviews we currently use `LLVM Github`_,
134+
though historically we used Phabricator.
134135

135-
.. _Getting Started with LLVM: https://llvm.org/docs/GettingStarted.html
136+
.. _Getting Started with the LLVM System: https://llvm.org/docs/GettingStarted.html
136137
.. _LLVM Coding Standards: https://llvm.org/docs/CodingStandards.html
137-
.. _LLVM Phabricator: https://llvm.org/docs/Phabricator.html
138+
.. _LLVM Github: https://github.com/llvm/llvm-project
138139

139140
Next, you need to decide which module the check belongs to. Modules
140141
are located in subdirectories of `clang-tidy/
@@ -336,13 +337,25 @@ a starting point for your test cases. A rough outline of the process looks like
336337
The quickest way to prototype your matcher is to use :program:`clang-query` to
337338
interactively build up your matcher. For complicated matchers, build up a matching
338339
expression incrementally and use :program:`clang-query`'s ``let`` command to save named
339-
matching expressions to simplify your matcher. Just like breaking up a huge function
340-
into smaller chunks with intention-revealing names can help you understand a complex
341-
algorithm, breaking up a matcher into smaller matchers with intention-revealing names
342-
can help you understand a complicated matcher. Once you have a working matcher, the
343-
C++ API will be virtually identical to your interactively constructed matcher. You can
344-
use local variables to preserve your intention-revealing names that you applied to
345-
nested matchers.
340+
matching expressions to simplify your matcher.
341+
342+
.. code-block:: console
343+
344+
clang-query> let c1 cxxRecordDecl()
345+
clang-query> match c1
346+
347+
Alternatively, pressing the tab key after a previous matcher's open parentheses would also
348+
show which matchers can be chained with the previous matcher, though some matchers that work
349+
may not be listed.
350+
351+
Just like breaking up a huge function into smaller chunks with intention-revealing names
352+
can help you understand a complex algorithm, breaking up a matcher into smaller matchers
353+
with intention-revealing names can help you understand a complicated matcher.
354+
355+
Once you have a working clang-query matcher, the C++ API matchers will be the same or similar
356+
to your interactively constructed matcher (there can be cases where they differ slightly).
357+
You can use local variables to preserve your intention-revealing names that you applied
358+
to nested matchers.
346359

347360
Creating private matchers
348361
^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -646,10 +659,13 @@ directory. The path to this directory is available in a lit test with the varia
646659
Out-of-tree check plugins
647660
-------------------------
648661

662+
649663
Developing an out-of-tree check as a plugin largely follows the steps
650-
outlined above. The plugin is a shared library whose code lives outside
664+
outlined above, including creating a new module and doing the hacks to
665+
register the module. The plugin is a shared library whose code lives outside
651666
the clang-tidy build system. Build and link this shared library against
652-
LLVM as done for other kinds of Clang plugins.
667+
LLVM as done for other kinds of Clang plugins. If using CMake, use the keyword
668+
``MODULE`` while invoking ``add_library`` or ``llvm_add_library``.
653669

654670
The plugin can be loaded by passing `-load` to `clang-tidy` in addition to the
655671
names of the checks to enable.
@@ -664,6 +680,19 @@ compiled against the version of clang-tidy that will be loading the plugin.
664680
The plugins can use threads, TLS, or any other facilities available to in-tree
665681
code which is accessible from the external headers.
666682

683+
Note that testing out-of-tree checks might involve getting ``llvm-lit`` from an LLVM
684+
installation compiled from source. See `Getting Started with the LLVM System`_ for ways
685+
to do so.
686+
687+
Alternatively, get `lit`_ following the `test-suite guide`_ and get the `FileCheck`_ binary,
688+
and write a version of `check_clang_tidy.py`_ to suit your needs.
689+
690+
.. _Getting Started with the LLVM System: https://llvm.org/docs/GettingStarted.html
691+
.. _test-suite guide: https://llvm.org/docs/TestSuiteGuide.html
692+
.. _lit: https://llvm.org/docs/CommandGuide/lit.html
693+
.. _FileCheck: https://llvm.org/docs/CommandGuide/FileCheck.html
694+
.. _check_clang_tidy.py: https://github.com/llvm/llvm-project/blob/main/clang-tools-extra/test/clang-tidy/check_clang_tidy.py
695+
667696
Running clang-tidy on LLVM
668697
--------------------------
669698

@@ -688,10 +717,10 @@ warnings and errors. The script provides multiple configuration flags.
688717

689718
* To restrict the files examined you can provide one or more regex arguments
690719
that the file names are matched against.
691-
``run-clang-tidy.py clang-tidy/.*Check\.cpp`` will only analyze clang-tidy
720+
``run-clang-tidy.py clang-tidy/.*Check\.cpp`` will only analyze `clang-tidy`
692721
checks. It may also be necessary to restrict the header files that warnings
693-
are displayed from using the ``-header-filter`` flag. It has the same behavior
694-
as the corresponding :program:`clang-tidy` flag.
722+
are displayed from by using the ``-header-filter`` and ``-exclude-header-filter`` flags.
723+
They have the same behavior as the corresponding :program:`clang-tidy` flags.
695724

696725
* To apply suggested fixes ``-fix`` can be passed as an argument. This gathers
697726
all changes in a temporary directory and applies them. Passing ``-format``
@@ -758,4 +787,4 @@ There is only one argument that controls profile storage:
758787

759788
* If you run :program:`clang-tidy` from within ``/foo`` directory, and specify
760789
``-store-check-profile=.``, then the profile will still be saved to
761-
``/foo/<ISO8601-like timestamp>-example.cpp.json``
790+
``/foo/<ISO8601-like timestamp>-example.cpp.json``

clang/docs/ReleaseNotes.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,13 @@ Bug Fixes in This Version
285285
Bug Fixes to Compiler Builtins
286286
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
287287

288+
- Fix crash when atomic builtins are called with pointer to zero-size struct (#GH90330)
289+
290+
- Clang now allows pointee types of atomic builtin arguments to be complete template types
291+
that was not instantiated elsewhere.
292+
293+
- ``__noop`` can now be used in a constant expression. (#GH102064)
294+
288295
Bug Fixes to Attribute Support
289296
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
290297

@@ -326,6 +333,9 @@ Bug Fixes to C++ Support
326333
- Fix evaluation of the index of dependent pack indexing expressions/types specifiers (#GH105900)
327334
- Correctly handle subexpressions of an immediate invocation in the presence of implicit casts. (#GH105558)
328335
- Clang now correctly handles direct-list-initialization of a structured bindings from an array. (#GH31813)
336+
- Mangle placeholders for deduced types as a template-prefix, such that mangling
337+
of template template parameters uses the correct production. (#GH106182)
338+
- Fixed an assertion failure when converting vectors to int/float with invalid expressions. (#GH105486)
329339

330340
Bug Fixes to AST Handling
331341
^^^^^^^^^^^^^^^^^^^^^^^^^

clang/include/clang-c/Index.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2980,8 +2980,9 @@ enum CXTypeKind {
29802980
CXType_Atomic = 177,
29812981
CXType_BTFTagAttributed = 178,
29822982

2983-
// HLSL Intangible Types
2984-
CXType_HLSLResource = 179
2983+
// HLSL Types
2984+
CXType_HLSLResource = 179,
2985+
CXType_HLSLAttributedResource = 180
29852986
};
29862987

29872988
/**

clang/include/clang/AST/ASTContext.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ class ASTContext : public RefCountedBase<ASTContext> {
254254
mutable llvm::ContextualFoldingSet<DependentBitIntType, ASTContext &>
255255
DependentBitIntTypes;
256256
llvm::FoldingSet<BTFTagAttributedType> BTFTagAttributedTypes;
257+
llvm::FoldingSet<HLSLAttributedResourceType> HLSLAttributedResourceTypes;
257258

258259
mutable llvm::FoldingSet<CountAttributedType> CountAttributedTypes;
259260

@@ -1671,6 +1672,10 @@ class ASTContext : public RefCountedBase<ASTContext> {
16711672
QualType getBTFTagAttributedType(const BTFTypeTagAttr *BTFAttr,
16721673
QualType Wrapped);
16731674

1675+
QualType getHLSLAttributedResourceType(
1676+
QualType Wrapped, QualType Contained,
1677+
const HLSLAttributedResourceType::Attributes &Attrs);
1678+
16741679
QualType
16751680
getSubstTemplateTypeParmType(QualType Replacement, Decl *AssociatedDecl,
16761681
unsigned Index,

clang/include/clang/AST/ASTNodeTraverser.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,11 @@ class ASTNodeTraverser
439439
void VisitBTFTagAttributedType(const BTFTagAttributedType *T) {
440440
Visit(T->getWrappedType());
441441
}
442+
void VisitHLSLAttributedResourceType(const HLSLAttributedResourceType *T) {
443+
QualType Contained = T->getContainedType();
444+
if (!Contained.isNull())
445+
Visit(Contained);
446+
}
442447
void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *) {}
443448
void
444449
VisitSubstTemplateTypeParmPackType(const SubstTemplateTypeParmPackType *T) {

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,9 @@ DEF_TRAVERSE_TYPE(CountAttributedType, {
11461146
DEF_TRAVERSE_TYPE(BTFTagAttributedType,
11471147
{ TRY_TO(TraverseType(T->getWrappedType())); })
11481148

1149+
DEF_TRAVERSE_TYPE(HLSLAttributedResourceType,
1150+
{ TRY_TO(TraverseType(T->getWrappedType())); })
1151+
11491152
DEF_TRAVERSE_TYPE(ParenType, { TRY_TO(TraverseType(T->getInnerType())); })
11501153

11511154
DEF_TRAVERSE_TYPE(MacroQualifiedType,
@@ -1445,6 +1448,9 @@ DEF_TRAVERSE_TYPELOC(CountAttributedType,
14451448
DEF_TRAVERSE_TYPELOC(BTFTagAttributedType,
14461449
{ TRY_TO(TraverseTypeLoc(TL.getWrappedLoc())); })
14471450

1451+
DEF_TRAVERSE_TYPELOC(HLSLAttributedResourceType,
1452+
{ TRY_TO(TraverseTypeLoc(TL.getWrappedLoc())); })
1453+
14481454
DEF_TRAVERSE_TYPELOC(ElaboratedType, {
14491455
if (TL.getQualifierLoc()) {
14501456
TRY_TO(TraverseNestedNameSpecifierLoc(TL.getQualifierLoc()));

0 commit comments

Comments
 (0)