Skip to content

Commit 4cb01f4

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:8aa8c0590c09a52737787ed7c35befa3fbede231 into amd-gfx:10fc52f95eba
Local branch amd-gfx 10fc52f Merged main:1ace91f925ad87c3e5eb836ad58fdffe60c4aea6 into amd-gfx:a9dc02e5ed6f Remote branch main 8aa8c05 [DXIL][Analysis] Collect Function properties in Metadata Analysis (llvm#105728)
2 parents 10fc52f + 8aa8c05 commit 4cb01f4

File tree

1,746 files changed

+272833
-425377
lines changed

Some content is hidden

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

1,746 files changed

+272833
-425377
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ on:
1212
jobs:
1313
code_formatter:
1414
runs-on: ubuntu-latest
15+
timeout-minutes: 30
16+
concurrency:
17+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
18+
cancel-in-progress: true
1519
if: github.repository == 'llvm/llvm-project'
1620
steps:
1721
- name: Fetch LLVM sources

.github/workflows/release-binaries-save-stage/action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ inputs:
1010
required: true
1111
type: 'string'
1212

13+
permissions:
14+
contents: read
15+
1316
runs:
1417
using: "composite"
1518
steps:
@@ -18,6 +21,9 @@ runs:
1821
- name: Package Build and Source Directories
1922
shell: bash
2023
run: |
24+
# Remove .git/config to avoid leaking GITHUB_TOKEN stored there.
25+
# See https://unit42.paloaltonetworks.com/github-repo-artifacts-leak-tokens/
26+
rm -Rf .git/config
2127
# Windows does not support symlinks, so we need to dereference them.
2228
tar --exclude build/ ${{ (runner.os == 'Windows' && '-h') || '' }} -c . | zstd -T0 -c > ../llvm-project.tar.zst
2329
mv ../llvm-project.tar.zst .

clang-tools-extra/clang-tidy/tool/run-clang-tidy.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -511,12 +511,10 @@ async def main() -> None:
511511
)
512512
invocation.append("-list-checks")
513513
invocation.append("-")
514-
if args.quiet:
515-
# Even with -quiet we still want to check if we can call clang-tidy.
516-
with open(os.devnull, "w") as dev_null:
517-
subprocess.check_call(invocation, stdout=dev_null)
518-
else:
519-
subprocess.check_call(invocation)
514+
# Even with -quiet we still want to check if we can call clang-tidy.
515+
subprocess.check_call(
516+
invocation, stdout=subprocess.DEVNULL if args.quiet else None
517+
)
520518
except:
521519
print("Unable to run clang-tidy.", file=sys.stderr)
522520
sys.exit(1)

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/cmake/caches/Fuchsia-stage2.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ foreach(target riscv32-unknown-elf)
382382
foreach(lang C;CXX;ASM)
383383
# TODO: The preprocessor defines workaround various issues in libc and libc++ integration.
384384
# These should be addressed and removed over time.
385-
set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS "--target=${target} -march=rv32imafc -mabi=ilp32f \"-Dvfprintf(stream, format, vlist)=vprintf(format, vlist)\" \"-Dfprintf(stream, format, ...)=printf(format)\" \"-Dtimeval=struct timeval{int tv_sec; int tv_usec;}\" \"-Dgettimeofday(tv, tz)\" -D_LIBCPP_PRINT=1" CACHE STRING "")
385+
set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS "--target=${target} -march=rv32imafc -mabi=ilp32f -Wno-atomic-alignment \"-Dvfprintf(stream, format, vlist)=vprintf(format, vlist)\" \"-Dfprintf(stream, format, ...)=printf(format)\" \"-Dtimeval=struct timeval{int tv_sec; int tv_usec;}\" \"-Dgettimeofday(tv, tz)\" -D_LIBCPP_PRINT=1" CACHE STRING "")
386386
endforeach()
387387
foreach(type SHARED;MODULE;EXE)
388388
set(RUNTIMES_${target}_CMAKE_${type}_LINKER_FLAGS "-fuse-ld=lld" CACHE STRING "")

0 commit comments

Comments
 (0)